diff --git a/lib/mail/message.rb b/lib/mail/message.rb index a7318f844..5df6a2fe9 100644 --- a/lib/mail/message.rb +++ b/lib/mail/message.rb @@ -1918,7 +1918,7 @@ def decode_body # Returns true if this part is an attachment, # false otherwise. def attachment? - !!find_attachment + !!(content_disposition == "attachment" || find_attachment) end # Returns the attachment data if there is any diff --git a/spec/fixtures/emails/attachment_emails/attachment_without_a_filename.eml b/spec/fixtures/emails/attachment_emails/attachment_without_a_filename.eml new file mode 100644 index 000000000..cfe426908 --- /dev/null +++ b/spec/fixtures/emails/attachment_emails/attachment_without_a_filename.eml @@ -0,0 +1,28 @@ +MIME-Version: 1.0 (Apple Message framework v730) +Content-Type: multipart/mixed; boundary=Apple-Mail-13-196941151 +Message-Id: <9169D984-4E0B-45EF-82D4-8F5E53AD7012@example.com> +From: foo@example.com +Subject: testing +Date: Mon, 6 Jun 2005 22:21:22 +0200 +To: blah@example.com + + +--Apple-Mail-13-196941151 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; + charset=ISO-8859-1; + delsp=yes; + format=flowed + +This is the first part. + +--Apple-Mail-13-196941151 +Content-Type: text/x-ruby-script; +Content-Transfer-Encoding: 7bit +Content-Disposition: attachment; + +puts "Hello, world!" +gets + +--Apple-Mail-13-196941151-- + diff --git a/spec/mail/attachments_list_spec.rb b/spec/mail/attachments_list_spec.rb index 0f5245404..73d5f5150 100644 --- a/spec/mail/attachments_list_spec.rb +++ b/spec/mail/attachments_list_spec.rb @@ -279,6 +279,12 @@ def check_decoded(actual, expected) expect(mail.attachments.first.filename).to eq "ciƫle.txt" end + it "should decode an attachment without a filename" do + mail = read_fixture('emails/attachment_emails/attachment_without_a_filename.eml') + expect(mail.attachments.length).to eq 1 + expect(mail.attachments.first.filename).to eq nil + end + it "should find attachments inside parts with content-type message/rfc822" do mail = read_fixture('emails/attachment_emails/attachment_message_rfc822.eml') expect(mail.attachments.length).to eq 2