{"action":"created","issue":{"url":"https://api.github.com/repos/WinRb/Viewpoint/issues/210","labels_url":"https://api.github.com/repos/WinRb/Viewpoint/issues/210/labels{/name}","comments_url":"https://api.github.com/repos/WinRb/Viewpoint/issues/210/comments","events_url":"https://api.github.com/repos/WinRb/Viewpoint/issues/210/events","html_url":"https://github.com/WinRb/Viewpoint/issues/210","id":94382868,"number":210,"title":"Saving attachments that are messages","user":{"login":"chrisdpeters","id":159187,"avatar_url":"https://avatars.githubusercontent.com/u/159187?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisdpeters","html_url":"https://github.com/chrisdpeters","followers_url":"https://api.github.com/users/chrisdpeters/followers","following_url":"https://api.github.com/users/chrisdpeters/following{/other_user}","gists_url":"https://api.github.com/users/chrisdpeters/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisdpeters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisdpeters/subscriptions","organizations_url":"https://api.github.com/users/chrisdpeters/orgs","repos_url":"https://api.github.com/users/chrisdpeters/repos","events_url":"https://api.github.com/users/chrisdpeters/events{/privacy}","received_events_url":"https://api.github.com/users/chrisdpeters/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-10T20:13:44Z","updated_at":"2015-07-28T02:57:28Z","closed_at":null,"body":"I have a task that loops through a message's attachments and uploads them to a file store via Paperclip:\r\n\r\n    item.attachments.each do |email_attachment|\r\n      # We can extend `StringIO` to become a data structure that works with Paperclip.\r\n      # See end of this post:\r\n      # http://steve.dynedge.co.uk/2010/12/09/receiving-and-saving-incoming-email-images-and-attachments-with-paperclip-and-rails-3/\r\n      file = StringIO.new(Base64.decode64(email_attachment.content))\r\n      file.class.class_eval { attr_accessor :original_filename, :content_type }\r\n      file.original_filename = email_attachment.name\r\n      file.content_type = email_attachment.content_type\r\n\r\n      Attachment.create! referral: referral, attachment: file\r\n    end\r\n\r\nThis works absolutely fantastic for most attachments, except if the attachment is an attached message. (I'm guessing it would save as an `.eml` or `.msg` file, but it's been a while since I've used Exchange/Outlook myself.)\r\n\r\nIn that case, the line that calls `email_attachment.content` (line 5 in the snippet above) throws this exception:\r\n\r\n    NoMethodError: undefined method `content' for #<Viewpoint::EWS::Types::ItemAttachment:0x007f507c2ffb38>\r\n\r\nThe `content_type` for the attachment is `message/rfc822`.\r\n\r\nIs there a way that I can save this as a file and upload to my app's file storage via Paperclip?"},"comment":{"url":"https://api.github.com/repos/WinRb/Viewpoint/issues/comments/125418141","html_url":"https://github.com/WinRb/Viewpoint/issues/210#issuecomment-125418141","issue_url":"https://api.github.com/repos/WinRb/Viewpoint/issues/210","id":125418141,"user":{"login":"zenchild","id":89312,"avatar_url":"https://avatars.githubusercontent.com/u/89312?v=3","gravatar_id":"","url":"https://api.github.com/users/zenchild","html_url":"https://github.com/zenchild","followers_url":"https://api.github.com/users/zenchild/followers","following_url":"https://api.github.com/users/zenchild/following{/other_user}","gists_url":"https://api.github.com/users/zenchild/gists{/gist_id}","starred_url":"https://api.github.com/users/zenchild/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zenchild/subscriptions","organizations_url":"https://api.github.com/users/zenchild/orgs","repos_url":"https://api.github.com/users/zenchild/repos","events_url":"https://api.github.com/users/zenchild/events{/privacy}","received_events_url":"https://api.github.com/users/zenchild/received_events","type":"User","site_admin":false},"created_at":"2015-07-28T02:57:28Z","updated_at":"2015-07-28T02:57:28Z","body":"@chrisdpeters did you ever get this sorted out. I'm guessing the feature to do this isn't built yet. I can't chase this one down myself presently so if you find a solution and want to post it I would be very appreciative.\r\n"}}