Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

solved to_yaml problem

  • Loading branch information...
commit 35cbec39228ec8f4789dc65ea9de25ea5fdd9f9b 1 parent 38db71c
davatis authored July 15, 2011

Showing 1 changed file with 27 additions and 7 deletions. Show diff stats Hide diff stats

  1. 34  lib/mail/message.rb
34  lib/mail/message.rb
@@ -1711,19 +1711,39 @@ def encoded
1711 1711
       buffer
1712 1712
     end
1713 1713
 
1714  
-    def to_yaml
1715  
-      ready_to_send!
  1714
+    def to_yaml(opts = {})
1716 1715
       hash = {}
  1716
+      hash['headers'] = {}
1717 1717
       header.fields.each do |field|
1718  
-        hash[field.name] = field.value
  1718
+        hash['headers'][field.name] = field.value
  1719
+      end
  1720
+      hash['delivery_handler'] = delivery_handler.to_s if delivery_handler
  1721
+      hash['transport_encoding'] = transport_encoding.to_s
  1722
+      special_variables = [:@header, :@delivery_handler, :@transport_encoding]
  1723
+      (instance_variables.map(&:to_sym) - special_variables).each do |var|
  1724
+        hash[var.to_s] = instance_variable_get(var)
1719 1725
       end
1720  
-      hash['subject'] = subject
1721  
-      hash['body'] = body.encoded(content_transfer_encoding)
1722  
-      hash.to_yaml
  1726
+      hash.to_yaml(opts)
1723 1727
     end
1724 1728
 
1725 1729
     def self.from_yaml(str)
1726  
-      from_hash(YAML::load(str))
  1730
+      hash = YAML.load(str)
  1731
+      m = Mail::Message.new(:headers => hash['headers'])
  1732
+      hash.delete('headers')
  1733
+      hash.each do |k,v|
  1734
+        case
  1735
+        when k == 'delivery_handler'
  1736
+          begin
  1737
+            m.delivery_handler = Object.const_get(v) unless v.blank?
  1738
+          rescue NameError
  1739
+          end
  1740
+        when k == 'transport_encoding'
  1741
+          m.transport_encoding(v)
  1742
+        when k =~ /^@/
  1743
+          m.instance_variable_set(k.to_sym, v)
  1744
+        end
  1745
+      end
  1746
+      m
1727 1747
     end
1728 1748
 
1729 1749
     def self.from_hash(hash)

0 notes on commit 35cbec3

Please sign in to comment.
Something went wrong with that request. Please try again.