From 23ef65905eb75664d22459cfbe509ae7a6ad9377 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 5 Dec 2012 15:50:31 +0000 Subject: Move counters to mail object. --- lib/mail_handler/backends/mail_extensions.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/mail_handler/backends/mail_extensions.rb') diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index cbe0491ed..a3c70213c 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -3,5 +3,7 @@ module Mail attr_accessor :url_part_number attr_accessor :rfc822_attachment # when a whole email message is attached as text attr_accessor :within_rfc822_attachment # for parts within a message attached as text (for getting subject mainly) + attr_accessor :count_parts_count + attr_accessor :count_first_uudecode_count end end \ No newline at end of file -- cgit v1.2.3 From 74029c7c3994fa09374ea92be01138999a65af0a Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 09:04:26 +0000 Subject: Patch the Message initialize method so that it doesn't strip the initial input - trailing spaces can be meaningful. --- lib/mail_handler/backends/mail_extensions.rb | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lib/mail_handler/backends/mail_extensions.rb') diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index a3c70213c..d9106948d 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -5,5 +5,44 @@ module Mail attr_accessor :within_rfc822_attachment # for parts within a message attached as text (for getting subject mainly) attr_accessor :count_parts_count attr_accessor :count_first_uudecode_count + + # A patched version of the message initializer to work around a bug where stripping the original + # input removes meaningful spaces - e.g. in the case of uuencoded bodies. + def initialize(*args, &block) + @body = nil + @body_raw = nil + @separate_parts = false + @text_part = nil + @html_part = nil + @errors = nil + @header = nil + @charset = 'UTF-8' + @defaulted_charset = true + + @perform_deliveries = true + @raise_delivery_errors = true + + @delivery_handler = nil + + @delivery_method = Mail.delivery_method.dup + + @transport_encoding = Mail::Encodings.get_encoding('7bit') + + @mark_for_delete = false + + if args.flatten.first.respond_to?(:each_pair) + init_with_hash(args.flatten.first) + else + # The replacement of this commented out line is the change. + # init_with_string(args.flatten[0].to_s.strip) + init_with_string(args.flatten[0].to_s) + end + + if block_given? + instance_eval(&block) + end + + self + end end end \ No newline at end of file -- cgit v1.2.3 From 67ab55412f1fad8f6ab9e457f6d81b68d6a47b8c Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 16:25:49 +0000 Subject: Patch the parameter hash used in Mail to handle nil values. --- lib/mail_handler/backends/mail_extensions.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/mail_handler/backends/mail_extensions.rb') diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index d9106948d..f756abd1a 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -1,3 +1,5 @@ +require 'mail/message' +require 'mail/fields/common/parameter_hash' module Mail class Message attr_accessor :url_part_number @@ -45,4 +47,21 @@ module Mail self end end + + # A patched version of the parameter hash that handles nil values without throwing + # an error. + class ParameterHash < IndifferentHash + + def encoded + map.sort { |a,b| a.first.to_s <=> b.first.to_s }.map do |key_name, value| + # The replacement of this commented out line is the change + # unless value.ascii_only? + unless value.nil? || value.ascii_only? + value = Mail::Encodings.param_encode(value) + key_name = "#{key_name}*" + end + %Q{#{key_name}=#{quote_token(value)}} + end.join(";\r\n\s") + end + end end \ No newline at end of file -- cgit v1.2.3