commit 29da2972f07c8f6087cd862929332fcf13626c85
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Tue Jun 15 03:05:07 2010 +0200

    [evol] reorganize TMail extra methods

diff --git a/lib/cyborghood/base/lang_additions.rb b/lib/cyborghood/base/lang_additions.rb
index d5da542..d478aea 100644
--- a/lib/cyborghood/base/lang_additions.rb
+++ b/lib/cyborghood/base/lang_additions.rb
@@ -16,6 +16,14 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #++
 
+# add Rails load path for Debian, until rails framework is split properly
+DEB_RAILS_PATH = "/usr/share/rails" unless Object.constants.include?("DEB_RAILS_PATH")
+Dir.new(DEB_RAILS_PATH).each do |file|
+        next if file =~ /^\./
+        path = File.join(DEB_RAILS_PATH, file, "lib")
+        $: << path if File.directory?(path)
+end
+
 require 'ostruct'
 
 class Hash
@@ -43,8 +51,13 @@ end
 
 # WARNING: the TMail send_to() method is _unsuable_, even with the following fixes
 require 'tmail'
+require 'action_mailer/quoting'
+require 'action_mailer/utils'
 module TMail
   class Mail
+    extend ActionMailer::Quoting
+    include ActionMailer::Utils
+
     # fix method using obsoleted from_address() method
     def do_send_to( smtp )
       from = from_addrs or raise ArgumentError, 'no from address'
@@ -60,6 +73,41 @@ module TMail
       end
     end
 
+    # extra methods
+
+    def quoted_printable_body=(txt)
+      self.transfer_encoding = "quoted-printable"
+      self.body = [normalize_new_lines(txt)].pack("M")
+    end
+
+    def self.header_value_pretty(v)
+      Unquoter.unquote_and_convert_to(v.to_s, "UTF-8")
+    end
+
+    def self.header_value_smtp(v)
+      quote_address_if_necessary(v, "UTF-8")
+    end
+
+    ["from", "to", "cc", "bcc", "reply_to"].each do |h|
+      class_eval <<-EOF
+        def #{h}_addrs_pretty
+          return nil if self.#{h}_addrs.nil?
+          self.#{h}_addrs.collect do |a|
+            self.class.header_value_pretty(a)
+          end
+        end
+
+        def #{h}_pretty
+          (self.#{h}_addrs_pretty || []).join(", ")
+        end
+      EOF
+    end
+
+    def subject_pretty
+      self.class.header_value_pretty(self.subject)
+    end
+  end
+
     private
 
     # reuse current boundary if already exist, not to break signed parts
@@ -91,5 +139,4 @@ module TMail
         strategy.write epilogue()
       end
     end
-  end
 end
diff --git a/lib/cyborghood/mail.rb b/lib/cyborghood/mail.rb
index ebc0737..d0b1361 100644
--- a/lib/cyborghood/mail.rb
+++ b/lib/cyborghood/mail.rb
@@ -16,19 +16,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #++
 
-# add Rails load path for Debian, until rails framework is split properly
-DEB_RAILS_PATH = "/usr/share/rails" unless Object.constants.include?("DEB_RAILS_PATH")
-Dir.new(DEB_RAILS_PATH).each do |file|
-        next if file =~ /^\./
-        path = File.join(DEB_RAILS_PATH, file, "lib")
-        $: << path if File.directory?(path)
-end
-
 require 'delegate'
 require 'tmail'
 require 'tmail_gpg'
-require 'action_mailer/quoting'
-require 'action_mailer/utils'
 require 'net/smtp'
 require 'fileutils'
 require 'digest/md5'
@@ -61,8 +51,6 @@ module CyborgHood
   end
 
   class Mail < Delegator
-    include ActionMailer::Quoting
-    include ActionMailer::Utils
     include I18nTranslation
 
     DEFAULT_MAX_DRIFT_TIME = 3600
@@ -78,7 +66,6 @@ module CyborgHood
       elsif msg.is_a? TMail::Mail
         @mail = msg
       else
-        # unquote headers and transform into TMail object
         @mail = TMail::Mail.parse(msg)
       end
     end
@@ -93,32 +80,6 @@ module CyborgHood
       @mail
     end
 
-    def self.header_value_pretty(v)
-      TMail::Unquoter.unquote_and_convert_to(v.to_s, "UTF-8")
-    end
-
-    def self.header_value_smtp(v)
-      quote_address_if_necessary(v, "UTF-8")
-    end
-
-    ["from", "to", "cc", "bcc"].each do |h|
-      class_eval <<-EOF
-        def #{h}_addrs_pretty
-          @mail.#{h}_addrs.collect do |a|
-            self.class.header_value_pretty(a)
-          end
-        end
-
-        def #{h}_pretty
-          self.#{h}_addrs_pretty.join(", ")
-        end
-      EOF
-    end
-
-    def subject_pretty
-      self.class.header_value_pretty(self.subject)
-    end
-
     def process
       if is_marked?
         return MailReport.new(:error => _("Replay detected."))
@@ -133,11 +94,10 @@ module CyborgHood
     def create_reply
       tmail_reply = @mail.create_reply
       tmail_reply.from_addrs = TMail::Address.parse(@config.mail.from_address || self.to.first)
-      tmail_reply.to_addrs = (@mail.reply_to_addrs || @mail.from_addrs).collect do |a|
-        address = TMail::Unquoter.unquote_and_convert_to(a.to_s, "UTF-8")
-	quoted_address = quote_address_if_necessary(address, "UTF-8")
-        TMail::Address.parse(quoted_address)
+      tmail_reply.to_addrs = (@mail.reply_to_addrs_pretty || @mail.from_addrs_pretty).collect do |a|
+        TMail::Address.parse(@mail.class.header_value_smtp(a))
       end
+      p tmail_reply.to_addrs
       reply = self.class.new(tmail_reply.to_s)
       reply.set_custom_headers
       reply.user = self.user
@@ -167,7 +127,7 @@ module CyborgHood
 
     def check_headers
       @mail.header.keys.each do |h|
-        @mail[h] = quote_address_if_necessary(@mail[h].to_s, "utf-8")
+        @mail[h] = @mail.class.quote_address_if_necessary(@mail[h].to_s, "utf-8")
       end
     end
 
@@ -204,11 +164,6 @@ module CyborgHood
       crypt(fingerprint)
     end
 
-    def quoted_printable_body=(txt)
-      @mail.transfer_encoding = "quoted-printable"
-      @mail.body = [normalize_new_lines(txt)].pack("M")
-    end
-
     private
 
     def process_signed
