Skip to content

Handle parsing of LF-only body with separate parts #1511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7b05a98
Handle parsing of LF-only body with separate parts
sebbASF Feb 13, 2019
e4a0bb7
Add adhoc workflow for this branch
sebbASF Dec 4, 2022
e75e096
Forgot to use ref here
sebbASF Dec 4, 2022
5298e4b
Try to force error
sebbASF Dec 5, 2022
46cdba7
Try downdating psych
sebbASF Dec 5, 2022
416cc19
Try earlier
sebbASF Dec 5, 2022
5fd2315
Try adding libyaml-dev
sebbASF Dec 5, 2022
4c637f5
Try backdating psych
sebbASF Dec 5, 2022
7d2ffba
Try after gemspec
sebbASF Dec 5, 2022
5b2cf92
Does not help
sebbASF Dec 5, 2022
9ad20f4
Typo
sebbASF Dec 5, 2022
9fc9184
Try with default rubygems
sebbASF Dec 5, 2022
4a0a682
Default version is broken
sebbASF Dec 5, 2022
20bcbf2
CF with non-jruby version
sebbASF Dec 6, 2022
f079af5
See if we can backdate psych for JRuby
sebbASF Dec 6, 2022
40c6e93
Emulate psych workflow
sebbASF Dec 6, 2022
6d9b94f
Was it just an issue with setup?
sebbASF Dec 6, 2022
2b3010d
Sync with main repo
sebbASF Dec 6, 2022
389aeb0
Can we trigger jruby failure
sebbASF Dec 6, 2022
f7110b5
Can we cache the status?
sebbASF Dec 6, 2022
639c3b2
Syntaxo
sebbASF Dec 6, 2022
bd6c85e
Better check
sebbASF Dec 6, 2022
0d13b67
Half a dozen
sebbASF Dec 6, 2022
cac4079
Omitted
sebbASF Dec 6, 2022
0bd05f0
ALlow for longer test
sebbASF Dec 6, 2022
826c5d1
Did not seem to work; try exact version
sebbASF Dec 6, 2022
354a6ad
Does not seem to be picking up Gemfile fix
sebbASF Dec 6, 2022
8a82002
Try again
sebbASF Dec 6, 2022
1e1ad97
Trr another approach
sebbASF Dec 6, 2022
22a6975
Expand test now that psych 4.0.6 is loaded
sebbASF Dec 6, 2022
96f5e6d
Psych has been fixed in 5.0.1
sebbASF Dec 8, 2022
77bdddb
Try to drop cached 5.0.0
sebbASF Dec 8, 2022
ed544df
No longer needed
sebbASF Dec 8, 2022
ebfc80c
More tests to trigger
sebbASF Dec 8, 2022
8895695
JRuby needs longer
sebbASF Dec 8, 2022
f0ad8d4
Merge pull request #1520 from sebbASF/feature/parse_lf
mikel Dec 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/adhoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Adhoc RSpec tests

on:
workflow_dispatch:

pull_request:
branches: [ feature/parse_lf ]
push:
branches: [ feature/parse_lf ]

jobs:
ruby:
name: ${{ matrix.ruby }} (timeout ${{ matrix.timeout }})
runs-on: ubuntu-latest
timeout-minutes: ${{ matrix.timeout }}
strategy:
fail-fast: false
matrix:
include:
- ruby: 2.5
timeout: 5
- ruby: 2.6
timeout: 5
- ruby: 2.7
timeout: 5
- ruby: '3.0'
timeout: 5
- ruby: 3.1
timeout: 5
- ruby: jruby
timeout: 10
- ruby: jruby-head
timeout: 10
- ruby: jruby-9.4
timeout: 10
- ruby: jruby-9.3
timeout: 10
- ruby: jruby-9.2
timeout: 10
steps:
- name: Psych 5.0.0 needs libyaml-dev
run: |
sudo apt-get update
sudo apt-get install libyaml-dev
- uses: actions/checkout@v2
with:
ref: feature/parse_lf
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
rubygems: 3.2.3
bundler-cache: true
cache-version: 4
- name: Show psych
run: |
gem list psych --details
continue-on-error: true
- name: Run tests1
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
continue-on-error: true
- name: Run tests2
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
continue-on-error: true
- name: Run tests3
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
continue-on-error: true
- name: Run tests4
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
continue-on-error: true
- name: Run tests5
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
continue-on-error: true
- name: Run tests6
run: bundle exec rake spec || echo "action_state=failed" >> $GITHUB_ENV
continue-on-error: true
- name: Run Summary
run: |
echo "${{ env.action_state }}"
# This will be be true for a successful run
test "${{ env.action_state }}" != 'failed'
6 changes: 3 additions & 3 deletions lib/mail/body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def initialize(string = '')
else
# Do join first incase we have been given an Array in Ruby 1.9
if string.respond_to?(:join)
@raw_source = ::Mail::Utilities.to_crlf(string.join(''))
@raw_source = string.join('')
elsif string.respond_to?(:to_s)
@raw_source = ::Mail::Utilities.to_crlf(string.to_s)
@raw_source = string.to_s
else
raise "You can only assign a string or an object that responds_to? :join or :to_s to a body."
end
Expand Down Expand Up @@ -272,7 +272,7 @@ def extract_parts
parts_regex = /
(?: # non-capturing group
\A | # start of string OR
\r\n # line break
\r?\n # line break with optional CR
)
(
--#{Regexp.escape(boundary || "")} # boundary delimiter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
From [email protected] Tue May 10 11:28:07 2005
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from localhost (localhost [127.0.0.1])
by xxx.xxxxx.com (Postfix) with ESMTP id 50FD3A96F
for <[email protected]>; Tue, 10 May 2005 17:26:50 +0000 (GMT)
Received: from xxx.xxxxx.com ([127.0.0.1])
by localhost (xxx.xxxxx.com [127.0.0.1]) (amavisd-new, port 10024)
with LMTP id 70060-03 for <[email protected]>;
Tue, 10 May 2005 17:26:49 +0000 (GMT)
Received: from xxx.xxxxx.com (xxx.xxxxx.com [69.36.39.150])
by xxx.xxxxx.com (Postfix) with ESMTP id 8B957A94B
for <[email protected]>; Tue, 10 May 2005 17:26:48 +0000 (GMT)
Received: from xxx.xxxxx.com (xxx.xxxxx.com [64.233.184.203])
by xxx.xxxxx.com (Postfix) with ESMTP id 9972514824C
for <[email protected]>; Tue, 10 May 2005 12:26:40 -0500 (CDT)
Received: by xxx.xxxxx.com with SMTP id 68so1694448wri
for <[email protected]>; Tue, 10 May 2005 10:26:40 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
s=beta; d=xxxxx.com;
h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type;
b=g8ZO5ttS6GPEMAz9WxrRk9+9IXBUfQIYsZLL6T88+ECbsXqGIgfGtzJJFn6o9CE3/HMrrIGkN5AisxVFTGXWxWci5YA/7PTVWwPOhJff5BRYQDVNgRKqMl/SMttNrrRElsGJjnD1UyQ/5kQmcBxq2PuZI5Zc47u6CILcuoBcM+A=
Received: by 10.54.96.19 with SMTP id t19mr621017wrb;
Tue, 10 May 2005 10:26:39 -0700 (PDT)
Received: by 10.54.110.5 with HTTP; Tue, 10 May 2005 10:26:39 -0700 (PDT)
Message-ID: <[email protected]>
Date: Tue, 10 May 2005 11:26:39 -0600
From: Test Tester <[email protected]>
Reply-To: Test Tester <[email protected]>
To: [email protected], [email protected]
Subject: Another PDF with 🎉 Unicode chars in it 🍿
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_2192_32400445.1115745999735"
X-Virus-Scanned: amavisd-new at textdrive.com

------=_Part_2192_32400445.1115745999735
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Just attaching another PDF, here, to see what the message looks like,
and to see if I can figure out what is going wrong here. Â

------=_Part_2192_32400445.1115745999735
Content-Type: application/pdf; name="broken.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="broken.pdf"

JVBERi0xLjQNCiXk9tzfDQoxI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dVLHs6nddwTRrgoVbvLU9eB0G4EMndV0TNoxHbt3JBWwK6hhv3iHfDtF
yokB302IpEBTnWICde4uYc/1khDbSIkQopO6lcqamGBu1OSE3N5IPSsZX00CkSHRiiyx6HQIShsS
HSVNswdVsaOUSAWq9aYhDtGDaoG5a3lBGkYt/lFlBFt1UqrYnzVtUpUQnLiZeouKgf1KhRBViRRk
ExepJCzTwEmFDalIRbLEGtw0gfpESOpIAF/NnpPzcVCG86s0g2DuSyd41uhNGbEgaSrWEXORErbw
------=_Part_2192_32400445.1115745999735--

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
From [email protected] Tue May 10 11:28:07 2005
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from localhost (localhost [127.0.0.1])
by xxx.xxxxx.com (Postfix) with ESMTP id 50FD3A96F
for <[email protected]>; Tue, 10 May 2005 17:26:50 +0000 (GMT)
Received: from xxx.xxxxx.com ([127.0.0.1])
by localhost (xxx.xxxxx.com [127.0.0.1]) (amavisd-new, port 10024)
with LMTP id 70060-03 for <[email protected]>;
Tue, 10 May 2005 17:26:49 +0000 (GMT)
Received: from xxx.xxxxx.com (xxx.xxxxx.com [69.36.39.150])
by xxx.xxxxx.com (Postfix) with ESMTP id 8B957A94B
for <[email protected]>; Tue, 10 May 2005 17:26:48 +0000 (GMT)
Received: from xxx.xxxxx.com (xxx.xxxxx.com [64.233.184.203])
by xxx.xxxxx.com (Postfix) with ESMTP id 9972514824C
for <[email protected]>; Tue, 10 May 2005 12:26:40 -0500 (CDT)
Received: by xxx.xxxxx.com with SMTP id 68so1694448wri
for <[email protected]>; Tue, 10 May 2005 10:26:40 -0700 (PDT)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
s=beta; d=xxxxx.com;
h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type;
b=g8ZO5ttS6GPEMAz9WxrRk9+9IXBUfQIYsZLL6T88+ECbsXqGIgfGtzJJFn6o9CE3/HMrrIGkN5AisxVFTGXWxWci5YA/7PTVWwPOhJff5BRYQDVNgRKqMl/SMttNrrRElsGJjnD1UyQ/5kQmcBxq2PuZI5Zc47u6CILcuoBcM+A=
Received: by 10.54.96.19 with SMTP id t19mr621017wrb;
Tue, 10 May 2005 10:26:39 -0700 (PDT)
Received: by 10.54.110.5 with HTTP; Tue, 10 May 2005 10:26:39 -0700 (PDT)
Message-ID: <[email protected]>
Date: Tue, 10 May 2005 11:26:39 -0600
From: Test Tester <[email protected]>
Reply-To: Test Tester <[email protected]>
To: [email protected], [email protected]
Subject: Another PDF with 🎉 Unicode chars in it 🍿
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_2192_32400445.1115745999735"
X-Virus-Scanned: amavisd-new at textdrive.com

------=_Part_2192_32400445.1115745999735
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Just attaching another PDF, here, to see what the message looks like,
and to see if I can figure out what is going wrong here. Â

------=_Part_2192_32400445.1115745999735
Content-Type: application/pdf; name="broken.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="broken.pdf"

JVBERi0xLjQNCiXk9tzfDQoxIDAgb2JqDQo8PCAvTGVuZ3RoIDIgMCBSDQogICAvRmlsdGVyIC9G
bGF0ZURlY29kZQ0KPj4NCnN0cmVhbQ0KeJy9Wt2KJbkNvm/od6jrhZxYln9hWEh2p+8HBvICySaE
ycLuTV4/1ifJ9qnq09NpSBimu76yLUuy/qzqcPz7+em3Ixx/CDc6CsXxs3b5+fvfjr/8cPz6/BRu
rbfAx/n3739/fuJylJ5u5fjX81OuDr4deK4Bz3z/aDP+8fz0yw8g0Ofq7ktr1Mn+u28rvhy/jVeD
QSa+9YNKHP/pxjvDNfVAx/m3MFz54FhvTbaseaxiDoN2LeMVMw+yA7RbHSCDzxZuaYB2E1Yay7QU
x89vz0+tyFDKMlAHK5yqLmnjF+c4RjEiQIUeKwblXMe+AsZjN1J5yGQL5DHpDHksurM81rF6PKab
gK6zAarIDzIiUY23rJsN9iorAE816aIu6lsgAdQFsuhhkHOUFgVjp2GjMqSewITXNQ27jrMeamkg
1rPI3iLWG2CIaSBB+V1245YVRICGbbpYKHc2USFDl6M09acQVQYhlwIrkBNLISvXhGlF1wi5FHCw
wxZkoGNJlVeJCEsqKA+3YAV5AMb6KkeaqEJQmFKKQU8T1pRi2ihE1Y4CDrqoYFFXYjJJOatsyzuI
8SIlykuxKTMibWK8H1PgEvqYgs4GmQSrEjJAalgGirIhik+p4ZQN9E3ETFPAHE1b8pp1l/0Rc1gl
fQs0ABWvyoZZzU8VnPXwVVcO9BEsyjEJaO6eBoZRyKGlrKoYoOygA8BGIzgwN3RQ15ouigG5idZQ
fx2U4Db2CqiLO0WHAZoylGiCAqhniNQjFjQPSkmjwfNTgQ6M1Ih+eWo36wFmjIxDJZiGUBiWsAyR
xX3EekGOizkGI96Ol9zVZTAivikURhRsHh2E3JhWMpSTZCnnonrLhMCodgrNcgo4uyJUJc6qnVss
nrGd1Ptr0YwisCOYyIbUwVjV4xBUNLbguSO2YHujonAMJkMdSI7bIw91Akq2AUlMUWGFTMAOamjU
OvZQCxIkY2pCpMFo/IwLdVLHs6nddwTRrgoVbvLU9eB0G4EMndV0TNoxHbt3JBWwK6hhv3iHfDtF
yokB302IpEBTnWICde4uYc/1khDbSIkQopO6lcqamGBu1OSE3N5IPSsZX00CkSHRiiyx6HQIShsS
HSVNswdVsaOUSAWq9aYhDtGDaoG5a3lBGkYt/lFlBFt1UqrYnzVtUpUQnLiZeouKgf1KhRBViRRk
ExepJCzTwEmFDalIRbLEGtw0gfpESOpIAF/NnpPzcVCG86s0g2DuSyd41uhNGbEgaSrWEXORErbw
------=_Part_2192_32400445.1115745999735--

11 changes: 11 additions & 0 deletions spec/mail/attachments_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,23 @@ def check_decoded(actual, expected)
expect(mail.attachments[0].decoded.length).to eq 1026
end

it "should decode an attachment and non-ascii text" do
mail = read_fixture('emails/attachment_emails/attachment_pdf_non_ascii.eml')
expect(mail.attachments[0].decoded.length).to eq 1026
end

it "should decode an attachment with linefeeds" do
mail = read_fixture('emails/attachment_emails/attachment_pdf_lf.eml')
expect(mail.attachments.size).to eq(1)
expect(mail.attachments[0].decoded.length).to eq 1026
end

it "should decode an attachment with linefeeds and non-ascii text" do
mail = read_fixture('emails/attachment_emails/attachment_pdf_non_ascii_lf.eml')
expect(mail.attachments.size).to eq(1)
expect(mail.attachments[0].decoded.length).to eq 1026
end

it "should find an attachment that has an encoded name value" do
mail = read_fixture('emails/attachment_emails/attachment_with_encoded_name.eml')
expect(mail.attachments.length).to eq 1
Expand Down