FIX: properly handle attachments in received emails

FIX: properly handle attachments in received emails

This regressed in 1ac3e547 when we added support for eml attachments.

diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb
index 457ffa4..7a5bc22 100644
--- a/lib/email/receiver.rb
+++ b/lib/email/receiver.rb
@@ -931,18 +931,20 @@ module Email
     end
 
     def attachments
-      # strip blacklisted attachments (mostly signatures)
       @attachments ||= begin
-        attachments =  @mail.parts.select { |part| part.attachment? && is_whitelisted_attachment?(part) }
+        attachments = @mail.attachments.select { |attachment| is_whitelisted_attachment?(attachment) }
         attachments << @mail if @mail.attachment? && is_whitelisted_attachment?(@mail)
+
+        @mail.parts.each do |part|
+          attachments << part if part.attachment? && is_whitelisted_attachment?(part)
+        end
+
         attachments
       end
     end
 
     def create_post_with_attachments(options = {})
-      # deal with attachments
       options[:raw] = add_attachments(options[:raw], options[:user], options)
-
       create_post(options)
     end
 
diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb
index 0488974..d706316 100644
--- a/spec/components/email/receiver_spec.rb
+++ b/spec/components/email/receiver_spec.rb
@@ -522,10 +522,14 @@ describe Email::Receiver do
     end
 
     it "supports attachments" do
-      SiteSetting.authorized_extensions = "txt"
+      SiteSetting.authorized_extensions = "txt|jpg"
       expect { process(:attached_txt_file) }.to change { topic.posts.count }
       expect(topic.posts.last.raw).to match(/<a\sclass='attachment'[^>]*>text\.txt<\/a>/)
       expect(topic.posts.last.uploads.length).to eq 1
+
+      expect { process(:apple_mail_attachment) }.to change { topic.posts.count }
+      expect(topic.posts.last.raw).to match /<img.+?src="\/uploads\/default\/original\//
+      expect(topic.posts.last.uploads.length).to eq 1
     end
 
     it "supports eml attachments" do
diff --git a/spec/fixtures/emails/apple_mail_attachment.eml b/spec/fixtures/emails/apple_mail_attachment.eml
new file mode 100644
index 0000000..2ce35f7
Binary files /dev/null and b/spec/fixtures/emails/apple_mail_attachment.eml differ

GitHub sha: db76e5a3

This commit has been mentioned on Discourse Meta. There might be relevant details there: