Commit 7134ce77 authored by paz's avatar paz

Fix sending outgoing protected headers (subject).

If the incoming message had a "protected headers" subject, pass this on
in a way that enigmail recognizes.
parent a415c452
Pipeline #17871 passed with stages
in 19 minutes and 23 seconds
......@@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* Handle missing arguments for several keywords and reply with a helpful error-message.
* Send replies to keyword-usage and notices to admins regardless of the delivery-flag of their subscription. (#354)
* X-UNSUBSCRIBE will refuse to unsubscribe the last admin of a list. (#357)
* Handle "protected subjects" in a way that Thunderbird/Enigmail recognize. (#74)
### Changed
......
......@@ -22,6 +22,8 @@ $:.unshift libdir
# Monkeypatches
require 'schleuder/mail/parts_list.rb'
require 'schleuder/mail/message.rb'
require 'schleuder/mail/gpg.rb'
require 'schleuder/mail/encrypted_part.rb'
require 'schleuder/gpgme/import_status.rb'
require 'schleuder/gpgme/key.rb'
require 'schleuder/gpgme/sub_key.rb'
......
module Mail
module Gpg
class EncryptedPart < Mail::Part
alias_method :initialize_mailgpg, :initialize
def initialize(cleartext_mail, options = {})
if cleartext_mail.protected_headers_subject
cleartext_mail.content_type_parameters['protected-headers'] = 'v1'
end
initialize_mailgpg(cleartext_mail, options)
end
end
end
end
module Mail
module Gpg
class << self
alias_method :encrypt_mailgpg, :encrypt
def encrypt(cleartext_mail, options={})
encrypted_mail = encrypt_mailgpg(cleartext_mail, options)
if cleartext_mail.protected_headers_subject
encrypted_mail.subject = cleartext_mail.protected_headers_subject
end
encrypted_mail
end
end
end
end
......@@ -16,7 +16,7 @@ module Mail
attr_accessor :recipient
attr_accessor :original_message
attr_accessor :list
attr_accessor :protected_subject
attr_accessor :protected_headers_subject
# TODO: This should be in initialize(), but I couldn't understand the
# strange errors about wrong number of arguments when overriding
......@@ -52,7 +52,7 @@ module Mail
# mail-gpg pulls headers from the decrypted mime parts "up" into the main
# headers, which reveals protected subjects.
if self.subject != new.subject
new.protected_subject = self.subject.dup
new.protected_headers_subject = self.subject.dup
# Delete the protected headers which might leak information.
if new.parts.first.content_type == "text/rfc822-headers; protected-headers=v1"
......@@ -69,7 +69,8 @@ module Mail
clean.list = self.list
clean.gpg self.list.gpg_sign_options
clean.from = list.email
clean.subject = self.protected_subject || self.subject
clean.subject = self.subject
clean.protected_headers_subject = self.protected_headers_subject
clean.add_msgids(list, self)
clean.add_list_headers(list)
......@@ -81,7 +82,7 @@ module Mail
clean.add_part new_part
end
if self.protected_subject.present?
if self.protected_headers_subject.present?
new_part = Mail::Part.new
new_part.content_type = "text/rfc822-headers; protected-headers=v1"
new_part.body = "Subject: #{self.subject}\n"
......
......@@ -21,6 +21,29 @@ describe "protected subject" do
teardown_list_and_mailer(list)
end
it "is included in mime-headers" do
list = create(:list)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
mail = Mail.read("spec/fixtures/mails/protected-headers.eml")
mail.deliver
encrypted_mail = Mail::TestMailer.deliveries.first
Mail::TestMailer.deliveries.clear
begin
Schleuder::Runner.new().run(encrypted_mail.to_s, list.email)
rescue SystemExit
end
raw = Mail::TestMailer.deliveries.first
message = Mail.create_message_to_list(raw.to_s, list.request_address, list).setup
expect(raw.to_s).not_to match('Re: the real subject')
expect(message.subject).to eql("Re: the real subject")
expect(message.content_type_parameters['protected-headers']).to eql("v1")
teardown_list_and_mailer(list)
end
it "is included as mime-part in body" do
list = create(:list)
list.subscribe("schleuder@example.org", '59C71FB38AEE22E091C78259D06350440F759BD3', true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment