aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mail_handler/backends/mail_extensions.rb
diff options
context:
space:
mode:
authorHenare Degan <henare.degan@gmail.com>2013-03-02 18:07:30 +1100
committerHenare Degan <henare.degan@gmail.com>2013-03-02 18:07:30 +1100
commit9564ca12234e27e2292b5382596664634d4994e0 (patch)
treeebc741a52e4c223f34528ca7466bd2623f829eea /lib/mail_handler/backends/mail_extensions.rb
parenta74855165779821ba531fd3f9c3767fc3d10ac60 (diff)
Backport Mail 2.5's to_yaml to prevent an exception with Ruby 1.8
Diffstat (limited to 'lib/mail_handler/backends/mail_extensions.rb')
-rw-r--r--lib/mail_handler/backends/mail_extensions.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb
index 29ae32542..c9f16e361 100644
--- a/lib/mail_handler/backends/mail_extensions.rb
+++ b/lib/mail_handler/backends/mail_extensions.rb
@@ -46,6 +46,28 @@ module Mail
self
end
+
+ # HACK: Backported from Mail 2.5 for Ruby 1.8 support
+ # Can be removed when we no longer support Ruby 1.8
+ def to_yaml(opts = {})
+ hash = {}
+ hash['headers'] = {}
+ header.fields.each do |field|
+ hash['headers'][field.name] = field.value
+ end
+ hash['delivery_handler'] = delivery_handler.to_s if delivery_handler
+ hash['transport_encoding'] = transport_encoding.to_s
+ special_variables = [:@header, :@delivery_handler, :@transport_encoding]
+ if multipart?
+ hash['multipart_body'] = []
+ body.parts.map { |part| hash['multipart_body'] << part.to_yaml }
+ special_variables.push(:@body, :@text_part, :@html_part)
+ end
+ (instance_variables.map(&:to_sym) - special_variables).each do |var|
+ hash[var.to_s] = instance_variable_get(var)
+ end
+ hash.to_yaml(opts)
+ end
end
# A patched version of the parameter hash that handles nil values without throwing