Skip to content

Commit 8542ad7

Browse files
ahorekeval
authored andcommitted
rfc822 attachments
1 parent 20bc36c commit 8542ad7

File tree

3 files changed

+107
-3
lines changed

3 files changed

+107
-3
lines changed

lib/mail/attachments_list.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ def initialize(parts_list)
77
@content_disposition_type = 'attachment'
88
parts_list.map { |p|
99
if p.mime_type == 'message/rfc822'
10-
Mail.new(p.body.encoded).attachments
10+
parts = []
11+
parts << p if p.attachment?
12+
parts.concat Mail.new(p.body.encoded).attachments
1113
elsif p.parts.empty?
1214
p if p.attachment?
1315
else
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
From: test@example.com
2+
To: foo@example.com
3+
Subject: test
4+
Date: Tue, 21 Apr 2020 15:40:22 +0200 (CEST)
5+
Message-Id: <9169D984-4E0B-45EF-82D5-8F5E53AD7012@example.com>
6+
Mime-Version: 1.0
7+
Content-Type: multipart/mixed;
8+
boundary="------=_MB7A4C516C-8688-4B63-8C13-CC0B5BA90B2B"
9+
Content-Transfer-Encoding: 7bit
10+
11+
--------=_MB7A4C516C-8688-4B63-8C13-CC0B5BA90B2B
12+
Content-Type: multipart/related;
13+
boundary="------=_MB7DFCF053-5DBC-4ABA-BA34-0A2FA19EC02A"
14+
Content-Transfer-Encoding: 7bit
15+
16+
17+
--------=_MB7DFCF053-5DBC-4ABA-BA34-0A2FA19EC02A
18+
Content-Type: multipart/alternative;
19+
boundary="------=_MB41C5AACC-67CF-4DFC-A53A-865270BC750F"
20+
Content-Transfer-Encoding: 7bit
21+
22+
--------=_MB41C5AACC-67CF-4DFC-A53A-865270BC750F
23+
Content-Type: text/html;
24+
charset=utf-8
25+
Content-Transfer-Encoding: quoted-printable
26+
27+
<html><body><img src=3D"cid:emedfeb92f-a786-4718-a446-98db8afb53fb@kronos=
28+
" /></body></html>=
29+
30+
31+
--------=_MB41C5AACC-67CF-4DFC-A53A-865270BC750F--
32+
33+
--------=_MB7DFCF053-5DBC-4ABA-BA34-0A2FA19EC02A
34+
Content-Type: image/png;
35+
name=img.png
36+
Content-Transfer-Encoding: base64
37+
Content-Disposition: inline;
38+
size=370;
39+
filename=img.png
40+
Content-ID: <emedfeb92f-a786-4718-a446-98db8afb53fb@kronos>
41+
42+
iVBORw0KGgoAAAANSUhEUgAAACoAAAAgCAIAAADrOn1qAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB
43+
JElEQVRIx+2WzYmFMBDHs2FPQu4hTXiwBSFV2MU0IaagxBoiaA+CAbGFuAcXCb4nG/Nenizkf5CB
44+
GfklmQ8GrXdIa70ZGN2qhE/4hP9Dxpgz1zAMcfFKqaqqlFJPXQDQNE0svDFGCIEQEkIcTqCU2lxt
45+
2wa8gReeUgoAm+2eYGcjhAAgz/Or+G/POM75xt6/rgEAW8BVfa3r6h/tXndXALvruqIoLjce53zP
46+
wov3/odj5/HxH3shFv5Q5097IVblH9h7vt1eCCiCa2PnwHYrUQgRMno9tzMpZVmWUsozV13XAbse
47+
8v9nmqYzV9/30VdNSumZK2DcpnUj4T8uay3G+Db8siyEkBvw1tp5nsdxZIz9rhta689lGmNCCGMs
48+
y7KQbeft+gGA2/AdlcTEpAAAAABJRU5ErkJggg==
49+
50+
--------=_MB7DFCF053-5DBC-4ABA-BA34-0A2FA19EC02A--
51+
52+
--------=_MB7A4C516C-8688-4B63-8C13-CC0B5BA90B2B
53+
Content-Type: message/rfc822;
54+
name=Testmail.eml
55+
Content-Disposition: attachment;
56+
filename=Testmail.eml
57+
58+
From xxxx@xxxx.com Tue May 10 11:28:07 2005
59+
Return-Path: <xxxx@xxxx.com>
60+
X-Original-To: xxxx@xxxx.com
61+
Delivered-To: xxxx@xxxx.com
62+
Received: from localhost (localhost [127.0.0.1])
63+
by xxx.xxxxx.com (Postfix) with ESMTP id 50FD3A96F
64+
for <xxxx@xxxx.com>; Tue, 10 May 2005 17:26:50 +0000 (GMT)
65+
Received: from xxx.xxxxx.com ([127.0.0.1])
66+
by localhost (xxx.xxxxx.com [127.0.0.1]) (amavisd-new, port 10024)
67+
with LMTP id 70060-03 for <xxxx@xxxx.com>;
68+
Tue, 10 May 2005 17:26:49 +0000 (GMT)
69+
Received: from xxx.xxxxx.com (xxx.xxxxx.com [69.36.39.150])
70+
by xxx.xxxxx.com (Postfix) with ESMTP id 8B957A94B
71+
for <xxxx@xxxx.com>; Tue, 10 May 2005 17:26:48 +0000 (GMT)
72+
Received: from xxx.xxxxx.com (xxx.xxxxx.com [64.233.184.203])
73+
by xxx.xxxxx.com (Postfix) with ESMTP id 9972514824C
74+
for <xxxx@xxxx.com>; Tue, 10 May 2005 12:26:40 -0500 (CDT)
75+
Received: by xxx.xxxxx.com with SMTP id 68so1694448wri
76+
for <xxxx@xxxx.com>; Tue, 10 May 2005 10:26:40 -0700 (PDT)
77+
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
78+
s=beta; d=xxxxx.com;
79+
h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type;
80+
b=g8ZO5ttS6GPEMAz9WxrRk9+9IXBUfQIYsZLL6T88+ECbsXqGIgfGtzJJFn6o9CE3/HMrrIGkN5AisxVFTGXWxWci5YA/7PTVWwPOhJff5BRYQDVNgRKqMl/SMttNrrRElsGJjnD1UyQ/5kQmcBxq2PuZI5Zc47u6CILcuoBcM+A=
81+
Received: by 10.54.96.19 with SMTP id t19mr621017wrb;
82+
Tue, 10 May 2005 10:26:39 -0700 (PDT)
83+
Received: by 10.54.110.5 with HTTP; Tue, 10 May 2005 10:26:39 -0700 (PDT)
84+
Message-ID: <xxxx@xxxx.com>
85+
Date: Tue, 10 May 2005 11:26:39 -0600
86+
From: Test Tester <xxxx@xxxx.com>
87+
Reply-To: Test Tester <xxxx@xxxx.com>
88+
To: xxxx@xxxx.com, xxxx@xxxx.com
89+
Subject: Another PDF
90+
Mime-Version: 1.0
91+
Content-Type: multipart/mixed;
92+
boundary="----=_Part_2192_32400445.1115745999735"
93+
X-Virus-Scanned: amavisd-new at textdrive.com
94+
95+
--------=_MB7A4C516C-8688-4B63-8C13-CC0B5BA90B2B--

spec/mail/attachments_list_spec.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,15 @@ def check_decoded(actual, expected)
270270

271271
it "should find attachments inside parts with content-type message/rfc822" do
272272
mail = read_fixture('emails/attachment_emails/attachment_message_rfc822.eml')
273-
expect(mail.attachments.length).to eq 1
274-
expect(mail.attachments[0].decoded.length).to eq 1026
273+
expect(mail.attachments.length).to eq 2
274+
expect(mail.attachments[1].decoded.length).to eq 1026
275+
end
276+
277+
it "should include content-type message/rfc822 as an attachment" do
278+
mail = read_fixture('emails/attachment_emails/attachment_message_rfc822_inline_image.eml')
279+
expect(mail.attachments.length).to eq 2
280+
expect(mail.attachments[1].decoded.length).to eq 1815
281+
expect(mail.attachments[0].inline?).to eq(true)
275282
end
276283

277284
it "attach filename decoding (issue 83)" do

0 commit comments

Comments
 (0)