Class: AirbrakeEmailProcessor
- Inherits:
-
Object
- Object
- AirbrakeEmailProcessor
- Defined in:
- lib/caperoma/services/airbrake_email_processor.rb
Instance Method Summary collapse
-
#process ⇒ Object
stub for test env.
Instance Method Details
#process ⇒ Object
stub for test env
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/caperoma/services/airbrake_email_processor.rb', line 5 def process account = Account.gmail Gmail.new(account.email, account.password) do |gmail| gmail.inbox.emails(:unread, from: '[email protected]').select { |email| email.subject.include? '[Ruck.us]' }.each do |email| # get reply address reply_to = "#{email.to.first.mailbox}@#{email.to.first.host}" # generate reply body body = '' story = PivotalFetcher.get_story_by_title(email.subject) if story.present? && story.respond_to?(:url) body = "Duplicate of: #{story.url}" else story = PivotalFetcher.create_story(email.subject, email.body.raw_source[0..1000]) body = "Created new story: #{story.url}" end # compose reply email (to get identifiers) reply = email.reply do subject "Re: #{email.subject}" body body end # bugfix to make reply work new_email = gmail.compose do to reply_to # note it's generated email, not airbrake one subject reply.subject in_reply_to reply.in_reply_to references reply.references body reply.body.raw_source end # deliver reply new_email.deliver! # archive email email.mark(:read) email.archive! end end end |