Skip to content

Commit 03a164f

Browse files
authored
Merge pull request #1511 from mikel/feature/parse_lf
Handle parsing of LF-only body with separate parts
2 parents 731818d + f0ad8d4 commit 03a164f

File tree

5 files changed

+234
-3
lines changed

5 files changed

+234
-3
lines changed

.github/workflows/adhoc.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Adhoc RSpec tests
2+
3+
on:
4+
workflow_dispatch:
5+
6+
pull_request:
7+
branches: [ feature/parse_lf ]
8+
push:
9+
branches: [ feature/parse_lf ]
10+
11+
jobs:
12+
ruby:
13+
name: ${{ matrix.ruby }} (timeout ${{ matrix.timeout }})
14+
runs-on: ubuntu-latest
15+
timeout-minutes: ${{ matrix.timeout }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- ruby: 2.5
21+
timeout: 5
22+
- ruby: 2.6
23+
timeout: 5
24+
- ruby: 2.7
25+
timeout: 5
26+
- ruby: '3.0'
27+
timeout: 5
28+
- ruby: 3.1
29+
timeout: 5
30+
- ruby: jruby
31+
timeout: 10
32+
- ruby: jruby-head
33+
timeout: 10
34+
- ruby: jruby-9.4
35+
timeout: 10
36+
- ruby: jruby-9.3
37+
timeout: 10
38+
- ruby: jruby-9.2
39+
timeout: 10
40+
steps:
41+
- name: Psych 5.0.0 needs libyaml-dev
42+
run: |
43+
sudo apt-get update
44+
sudo apt-get install libyaml-dev
45+
- uses: actions/checkout@v2
46+
with:
47+
ref: feature/parse_lf
48+
- uses: ruby/setup-ruby@v1
49+
with:
50+
ruby-version: ${{ matrix.ruby }}
51+
rubygems: 3.2.3
52+
bundler-cache: true
53+
cache-version: 4
54+
- name: Show psych
55+
run: |
56+
gem list psych --details
57+
continue-on-error: true
58+
- name: Run tests1
59+
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
60+
continue-on-error: true
61+
- name: Run tests2
62+
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
63+
continue-on-error: true
64+
- name: Run tests3
65+
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
66+
continue-on-error: true
67+
- name: Run tests4
68+
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
69+
continue-on-error: true
70+
- name: Run tests5
71+
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
72+
continue-on-error: true
73+
- name: Run tests6
74+
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
75+
continue-on-error: true
76+
- name: Run Summary
77+
run: |
78+
echo "${{ env.action_state }}"
79+
# This will be be true for a successful run
80+
test "${{ env.action_state }}" != 'failed'

lib/mail/body.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def initialize(string = '')
3939
else
4040
# Do join first incase we have been given an Array in Ruby 1.9
4141
if string.respond_to?(:join)
42-
@raw_source = ::Mail::Utilities.to_crlf(string.join(''))
42+
@raw_source = string.join('')
4343
elsif string.respond_to?(:to_s)
44-
@raw_source = ::Mail::Utilities.to_crlf(string.to_s)
44+
@raw_source = string.to_s
4545
else
4646
raise "You can only assign a string or an object that responds_to? :join or :to_s to a body."
4747
end
@@ -272,7 +272,7 @@ def extract_parts
272272
parts_regex = /
273273
(?: # non-capturing group
274274
\A | # start of string OR
275-
\r\n # line break
275+
\r?\n # line break with optional CR
276276
)
277277
(
278278
--#{Regexp.escape(boundary || "")} # boundary delimiter
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From [email protected] Tue May 10 11:28:07 2005
2+
Return-Path: <[email protected]>
3+
X-Original-To: [email protected]
4+
Delivered-To: [email protected]
5+
Received: from localhost (localhost [127.0.0.1])
6+
by xxx.xxxxx.com (Postfix) with ESMTP id 50FD3A96F
7+
for <[email protected]>; Tue, 10 May 2005 17:26:50 +0000 (GMT)
8+
Received: from xxx.xxxxx.com ([127.0.0.1])
9+
by localhost (xxx.xxxxx.com [127.0.0.1]) (amavisd-new, port 10024)
10+
with LMTP id 70060-03 for <[email protected]>;
11+
Tue, 10 May 2005 17:26:49 +0000 (GMT)
12+
Received: from xxx.xxxxx.com (xxx.xxxxx.com [69.36.39.150])
13+
by xxx.xxxxx.com (Postfix) with ESMTP id 8B957A94B
14+
for <[email protected]>; Tue, 10 May 2005 17:26:48 +0000 (GMT)
15+
Received: from xxx.xxxxx.com (xxx.xxxxx.com [64.233.184.203])
16+
by xxx.xxxxx.com (Postfix) with ESMTP id 9972514824C
17+
for <[email protected]>; Tue, 10 May 2005 12:26:40 -0500 (CDT)
18+
Received: by xxx.xxxxx.com with SMTP id 68so1694448wri
19+
for <[email protected]>; Tue, 10 May 2005 10:26:40 -0700 (PDT)
20+
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
21+
s=beta; d=xxxxx.com;
22+
h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type;
23+
b=g8ZO5ttS6GPEMAz9WxrRk9+9IXBUfQIYsZLL6T88+ECbsXqGIgfGtzJJFn6o9CE3/HMrrIGkN5AisxVFTGXWxWci5YA/7PTVWwPOhJff5BRYQDVNgRKqMl/SMttNrrRElsGJjnD1UyQ/5kQmcBxq2PuZI5Zc47u6CILcuoBcM+A=
24+
Received: by 10.54.96.19 with SMTP id t19mr621017wrb;
25+
Tue, 10 May 2005 10:26:39 -0700 (PDT)
26+
Received: by 10.54.110.5 with HTTP; Tue, 10 May 2005 10:26:39 -0700 (PDT)
27+
Message-ID: <[email protected]>
28+
Date: Tue, 10 May 2005 11:26:39 -0600
29+
From: Test Tester <[email protected]>
30+
Reply-To: Test Tester <[email protected]>
31+
32+
Subject: Another PDF with 🎉 Unicode chars in it 🍿
33+
Mime-Version: 1.0
34+
Content-Type: multipart/mixed;
35+
boundary="----=_Part_2192_32400445.1115745999735"
36+
X-Virus-Scanned: amavisd-new at textdrive.com
37+
38+
------=_Part_2192_32400445.1115745999735
39+
Content-Type: text/plain; charset=ISO-8859-1
40+
Content-Transfer-Encoding: quoted-printable
41+
Content-Disposition: inline
42+
43+
Just attaching another PDF, here, to see what the message looks like,
44+
and to see if I can figure out what is going wrong here. Â
45+
46+
------=_Part_2192_32400445.1115745999735
47+
Content-Type: application/pdf; name="broken.pdf"
48+
Content-Transfer-Encoding: base64
49+
Content-Disposition: attachment; filename="broken.pdf"
50+
51+
JVBERi0xLjQNCiXk9tzfDQoxIDAgb2JqDQo8PCAvTGVuZ3RoIDIgMCBSDQogICAvRmlsdGVyIC9G
52+
bGF0ZURlY29kZQ0KPj4NCnN0cmVhbQ0KeJy9Wt2KJbkNvm/od6jrhZxYln9hWEh2p+8HBvICySaE
53+
ycLuTV4/1ifJ9qnq09NpSBimu76yLUuy/qzqcPz7+em3Ixx/CDc6CsXxs3b5+fvfjr/8cPz6/BRu
54+
rbfAx/n3739/fuJylJ5u5fjX81OuDr4deK4Bz3z/aDP+8fz0yw8g0Ofq7ktr1Mn+u28rvhy/jVeD
55+
QSa+9YNKHP/pxjvDNfVAx/m3MFz54FhvTbaseaxiDoN2LeMVMw+yA7RbHSCDzxZuaYB2E1Yay7QU
56+
x89vz0+tyFDKMlAHK5yqLmnjF+c4RjEiQIUeKwblXMe+AsZjN1J5yGQL5DHpDHksurM81rF6PKab
57+
gK6zAarIDzIiUY23rJsN9iorAE816aIu6lsgAdQFsuhhkHOUFgVjp2GjMqSewITXNQ27jrMeamkg
58+
1rPI3iLWG2CIaSBB+V1245YVRICGbbpYKHc2USFDl6M09acQVQYhlwIrkBNLISvXhGlF1wi5FHCw
59+
wxZkoGNJlVeJCEsqKA+3YAV5AMb6KkeaqEJQmFKKQU8T1pRi2ihE1Y4CDrqoYFFXYjJJOatsyzuI
60+
8SIlykuxKTMibWK8H1PgEvqYgs4GmQSrEjJAalgGirIhik+p4ZQN9E3ETFPAHE1b8pp1l/0Rc1gl
61+
fQs0ABWvyoZZzU8VnPXwVVcO9BEsyjEJaO6eBoZRyKGlrKoYoOygA8BGIzgwN3RQ15ouigG5idZQ
62+
fx2U4Db2CqiLO0WHAZoylGiCAqhniNQjFjQPSkmjwfNTgQ6M1Ih+eWo36wFmjIxDJZiGUBiWsAyR
63+
xX3EekGOizkGI96Ol9zVZTAivikURhRsHh2E3JhWMpSTZCnnonrLhMCodgrNcgo4uyJUJc6qnVss
64+
nrGd1Ptr0YwisCOYyIbUwVjV4xBUNLbguSO2YHujonAMJkMdSI7bIw91Akq2AUlMUWGFTMAOamjU
65+
OvZQCxIkY2pCpMFo/IwLdVLHs6nddwTRrgoVbvLU9eB0G4EMndV0TNoxHbt3JBWwK6hhv3iHfDtF
66+
yokB302IpEBTnWICde4uYc/1khDbSIkQopO6lcqamGBu1OSE3N5IPSsZX00CkSHRiiyx6HQIShsS
67+
HSVNswdVsaOUSAWq9aYhDtGDaoG5a3lBGkYt/lFlBFt1UqrYnzVtUpUQnLiZeouKgf1KhRBViRRk
68+
ExepJCzTwEmFDalIRbLEGtw0gfpESOpIAF/NnpPzcVCG86s0g2DuSyd41uhNGbEgaSrWEXORErbw
69+
------=_Part_2192_32400445.1115745999735--
70+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From [email protected] Tue May 10 11:28:07 2005
2+
Return-Path: <[email protected]>
3+
X-Original-To: [email protected]
4+
Delivered-To: [email protected]
5+
Received: from localhost (localhost [127.0.0.1])
6+
by xxx.xxxxx.com (Postfix) with ESMTP id 50FD3A96F
7+
for <[email protected]>; Tue, 10 May 2005 17:26:50 +0000 (GMT)
8+
Received: from xxx.xxxxx.com ([127.0.0.1])
9+
by localhost (xxx.xxxxx.com [127.0.0.1]) (amavisd-new, port 10024)
10+
with LMTP id 70060-03 for <[email protected]>;
11+
Tue, 10 May 2005 17:26:49 +0000 (GMT)
12+
Received: from xxx.xxxxx.com (xxx.xxxxx.com [69.36.39.150])
13+
by xxx.xxxxx.com (Postfix) with ESMTP id 8B957A94B
14+
for <[email protected]>; Tue, 10 May 2005 17:26:48 +0000 (GMT)
15+
Received: from xxx.xxxxx.com (xxx.xxxxx.com [64.233.184.203])
16+
by xxx.xxxxx.com (Postfix) with ESMTP id 9972514824C
17+
for <[email protected]>; Tue, 10 May 2005 12:26:40 -0500 (CDT)
18+
Received: by xxx.xxxxx.com with SMTP id 68so1694448wri
19+
for <[email protected]>; Tue, 10 May 2005 10:26:40 -0700 (PDT)
20+
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
21+
s=beta; d=xxxxx.com;
22+
h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type;
23+
b=g8ZO5ttS6GPEMAz9WxrRk9+9IXBUfQIYsZLL6T88+ECbsXqGIgfGtzJJFn6o9CE3/HMrrIGkN5AisxVFTGXWxWci5YA/7PTVWwPOhJff5BRYQDVNgRKqMl/SMttNrrRElsGJjnD1UyQ/5kQmcBxq2PuZI5Zc47u6CILcuoBcM+A=
24+
Received: by 10.54.96.19 with SMTP id t19mr621017wrb;
25+
Tue, 10 May 2005 10:26:39 -0700 (PDT)
26+
Received: by 10.54.110.5 with HTTP; Tue, 10 May 2005 10:26:39 -0700 (PDT)
27+
Message-ID: <[email protected]>
28+
Date: Tue, 10 May 2005 11:26:39 -0600
29+
From: Test Tester <[email protected]>
30+
Reply-To: Test Tester <[email protected]>
31+
32+
Subject: Another PDF with 🎉 Unicode chars in it 🍿
33+
Mime-Version: 1.0
34+
Content-Type: multipart/mixed;
35+
boundary="----=_Part_2192_32400445.1115745999735"
36+
X-Virus-Scanned: amavisd-new at textdrive.com
37+
38+
------=_Part_2192_32400445.1115745999735
39+
Content-Type: text/plain; charset=ISO-8859-1
40+
Content-Transfer-Encoding: quoted-printable
41+
Content-Disposition: inline
42+
43+
Just attaching another PDF, here, to see what the message looks like,
44+
and to see if I can figure out what is going wrong here. Â
45+
46+
------=_Part_2192_32400445.1115745999735
47+
Content-Type: application/pdf; name="broken.pdf"
48+
Content-Transfer-Encoding: base64
49+
Content-Disposition: attachment; filename="broken.pdf"
50+
51+
JVBERi0xLjQNCiXk9tzfDQoxIDAgb2J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MUWGFTMAOamjU
65+
OvZQCxIkY2pCpMFo/IwLdVLHs6nddwTRrgoVbvLU9eB0G4EMndV0TNoxHbt3JBWwK6hhv3iHfDtF
66+
yokB302IpEBTnWICde4uYc/1khDbSIkQopO6lcqamGBu1OSE3N5IPSsZX00CkSHRiiyx6HQIShsS
67+
HSVNswdVsaOUSAWq9aYhDtGDaoG5a3lBGkYt/lFlBFt1UqrYnzVtUpUQnLiZeouKgf1KhRBViRRk
68+
ExepJCzTwEmFDalIRbLEGtw0gfpESOpIAF/NnpPzcVCG86s0g2DuSyd41uhNGbEgaSrWEXORErbw
69+
------=_Part_2192_32400445.1115745999735--
70+

spec/mail/attachments_list_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,23 @@ def check_decoded(actual, expected)
234234
expect(mail.attachments[0].decoded.length).to eq 1026
235235
end
236236

237+
it "should decode an attachment and non-ascii text" do
238+
mail = read_fixture('emails/attachment_emails/attachment_pdf_non_ascii.eml')
239+
expect(mail.attachments[0].decoded.length).to eq 1026
240+
end
241+
237242
it "should decode an attachment with linefeeds" do
238243
mail = read_fixture('emails/attachment_emails/attachment_pdf_lf.eml')
239244
expect(mail.attachments.size).to eq(1)
240245
expect(mail.attachments[0].decoded.length).to eq 1026
241246
end
242247

248+
it "should decode an attachment with linefeeds and non-ascii text" do
249+
mail = read_fixture('emails/attachment_emails/attachment_pdf_non_ascii_lf.eml')
250+
expect(mail.attachments.size).to eq(1)
251+
expect(mail.attachments[0].decoded.length).to eq 1026
252+
end
253+
243254
it "should find an attachment that has an encoded name value" do
244255
mail = read_fixture('emails/attachment_emails/attachment_with_encoded_name.eml')
245256
expect(mail.attachments.length).to eq 1

0 commit comments

Comments
 (0)