Created
April 24, 2016 19:40
-
-
Save jordangraft/058250eddf8c5f6a635e43e97f534a5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Email < ActiveRecord::Base | |
def self.process_incoming_email(message_id) | |
obj = AWS::S3.new.buckets['my-email-bucket'].objects[message_id] | |
contents = obj.read | |
from = contents.match(/(?<=From: )(.*?)(?=\n)/).try(:to_s) | |
to = contents.match(/(?<=To: )(.*?)(?=\n)/).try(:to_s) | |
subject = contents.match(/(?<=Subject: )(.*?)(?=\n)/).try(:to_s) | |
body = contents.match(/(?<=Content-Type: text\/html; charset\=UTF-8)(.*?)(?=--)/m).try(:to_s) | |
self.create( | |
from: from, | |
to: to, | |
subject: subject, | |
body: body | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment