From 6b7eac5c51cbef4acd1ab7f48884e7b614f71678 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Sat, 6 Oct 2018 22:02:08 -0400 Subject: Accept inbound emails from a variety of ingresses --- app/models/action_mailbox/inbound_email/message_id.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/action_mailbox/inbound_email/message_id.rb b/app/models/action_mailbox/inbound_email/message_id.rb index 590dbfc4d7..601c5f1a7e 100644 --- a/app/models/action_mailbox/inbound_email/message_id.rb +++ b/app/models/action_mailbox/inbound_email/message_id.rb @@ -7,7 +7,14 @@ module ActionMailbox::InboundEmail::MessageId module ClassMethods def create_and_extract_message_id!(raw_email, **options) - create! raw_email: raw_email, message_id: extract_message_id(raw_email), **options + create! message_id: extract_message_id(raw_email), **options do |inbound_email| + case raw_email + when ActionDispatch::Http::UploadedFile + inbound_email.raw_email.attach raw_email + else + inbound_email.raw_email.attach io: raw_email.tap(&:rewind), filename: "message.eml", content_type: "message/rfc822" + end + end end private -- cgit v1.2.3 From b3919d01554d31c5486d17332f4a4dde89a23239 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Thu, 18 Oct 2018 10:23:17 -0400 Subject: Don't require Postfix to send form data --- app/models/action_mailbox/inbound_email/message_id.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'app/models') diff --git a/app/models/action_mailbox/inbound_email/message_id.rb b/app/models/action_mailbox/inbound_email/message_id.rb index 601c5f1a7e..5cfcadaba1 100644 --- a/app/models/action_mailbox/inbound_email/message_id.rb +++ b/app/models/action_mailbox/inbound_email/message_id.rb @@ -6,20 +6,15 @@ module ActionMailbox::InboundEmail::MessageId end module ClassMethods - def create_and_extract_message_id!(raw_email, **options) - create! message_id: extract_message_id(raw_email), **options do |inbound_email| - case raw_email - when ActionDispatch::Http::UploadedFile - inbound_email.raw_email.attach raw_email - else - inbound_email.raw_email.attach io: raw_email.tap(&:rewind), filename: "message.eml", content_type: "message/rfc822" - end + def create_and_extract_message_id!(source, **options) + create! message_id: extract_message_id(source), **options do |inbound_email| + inbound_email.raw_email.attach io: StringIO.new(source), filename: "message.eml", content_type: "message/rfc822" end end private - def extract_message_id(raw_email) - mail_from_source(raw_email.read).message_id + def extract_message_id(source) + mail_from_source(source).message_id rescue => e # FIXME: Add logging with "Couldn't extract Message ID, so will generating a new random ID instead" end -- cgit v1.2.3