Skip to content

Commit d02f274

Browse files
committed
don't add multiple contradictory Content-Transfer-Encoding headers
Fixes #502.
1 parent e2bdf6a commit d02f274

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

Manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ test/test_messages_dir.rb
165165
test/test_yaml_regressions.rb
166166
test/unit/service/test_label_service.rb
167167
test/unit/test_contact.rb
168+
test/unit/test_edit_message_mode.rb
168169
test/unit/test_horizontal_selector.rb
169170
test/unit/test_locale_fiddler.rb
170171
test/unit/test_person.rb

lib/sup/modes/edit_message_mode.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,10 @@ def transfer_encode msg_part
716716
## encode to quoted-printable for all text/* MIME types,
717717
## use base64 otherwise
718718
if msg_part.header["Content-Type"] =~ /text\/.*/
719-
msg_part.header["Content-Transfer-Encoding"] = 'quoted-printable'
719+
msg_part.header.set "Content-Transfer-Encoding", "quoted-printable"
720720
msg_part.body = [msg_part.body].pack('M')
721721
else
722-
msg_part.header["Content-Transfer-Encoding"] = 'base64'
722+
msg_part.header.set "Content-Transfer-Encoding", "base64"
723723
msg_part.body = [msg_part.body].pack('m')
724724
end
725725
msg_part

test/unit/test_edit_message_mode.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
require "test_helper"
2+
3+
require "sup"
4+
5+
class DummySelector
6+
attr_accessor :val
7+
def initialize val
8+
@val = val
9+
end
10+
end
11+
12+
class DummyCryptoManager
13+
def have_crypto?; true; end
14+
def sign from, to, payload
15+
envelope = RMail::Message.new
16+
envelope.header["Content-Type"] = "multipart/signed; protocol=testdummy"
17+
envelope.add_part payload
18+
envelope
19+
end
20+
end
21+
22+
class TestEditMessageMode < Minitest::Test
23+
def setup
24+
$config = {}
25+
@path = Dir.mktmpdir
26+
Redwood::HookManager.init File.join(@path, "hooks")
27+
Redwood::AccountManager.init :default => {name: "test", email: "sender@example.invalid"}
28+
Redwood::CryptoManager.instance_variable_set :@instance, DummyCryptoManager.new
29+
end
30+
31+
def teardown
32+
Redwood::CryptoManager.deinstantiate!
33+
Redwood::AccountManager.deinstantiate!
34+
Redwood::HookManager.deinstantiate!
35+
FileUtils.rm_r @path
36+
$config = nil
37+
end
38+
39+
def test_attachment_content_transfer_encoding_signed
40+
## RMail::Message#make_attachment will choose
41+
## Content-Transfer-Encoding: 8bit for a CSV file.
42+
attachment_filename = File.join @path, "dummy.csv"
43+
## Include some high bytes in the attachment contents in order to
44+
## exercise quote-printable transfer encoding.
45+
File.write attachment_filename, "löl,\ntest,\n"
46+
47+
opts = {
48+
:header => {
49+
"From" => "sender@example.invalid",
50+
"To" => "recip@example.invalid",
51+
},
52+
:attachments => {
53+
"dummy.csv" => RMail::Message.make_file_attachment(attachment_filename),
54+
},
55+
}
56+
mode = Redwood::EditMessageMode.new opts
57+
mode.instance_variable_set :@crypto_selector, DummySelector.new(:sign)
58+
59+
msg = mode.send :build_message, Time.now
60+
## The outermost message is a (fake) multipart/signed created by DummyCryptoManager#send.
61+
## Inside that we have our inline message at index 0 and CSV attachment at index 1.
62+
attachment = msg.part(0).part(1)
63+
## The attachment should have been re-encoded as quoted-printable for GPG signing.
64+
assert_equal "l=C3=B6l,\ntest,\n", attachment.body
65+
## There shouldn't be multiple Content-Transfer-Encoding headers.
66+
## This was: https://github.com/sup-heliotrope/sup/issues/502
67+
assert_equal ["quoted-printable"], attachment.header.fetch_all("Content-Transfer-Encoding")
68+
end
69+
end

0 commit comments

Comments
 (0)