]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/edit-message-mode.rb
Merge branch 'dlload-bugfix'
[sup] / lib / sup / modes / edit-message-mode.rb
index 89476b32f194ccc941f15e095a05cab625cf03da..31aa8972766c34d17ae8f9cda5379b5363af559f 100644 (file)
@@ -23,7 +23,7 @@ Variables:
   from_email: the email part of the From: line, or nil if empty
 Return value:
   A string (multi-line ok) containing the text of the signature, or nil to
-  use the default signature.
+  use the default signature, or :none for no signature.
 EOS
 
   HookManager.register "before-edit", <<EOS
@@ -305,8 +305,9 @@ protected
     m = RMail::Message.new
     m.header["Content-Type"] = "text/plain; charset=#{$encoding}"
     m.body = @body.join("\n")
-    m.body = m.body
     m.body += sig_lines.join("\n") unless $config[:edit_signature]
+    ## body must end in a newline or GPG signatures will be WRONG!
+    m.body += "\n" unless m.body =~ /\n\Z/
 
     ## there are attachments, so wrap body in an attachment of its own
     unless @attachments.empty?
@@ -320,8 +321,8 @@ protected
 
     ## do whatever crypto transformation is necessary
     if @crypto_selector && @crypto_selector.val != :none
-      from_email = PersonManager.person_for(@header["From"]).email
-      to_email = (@header["To"] + @header["Cc"] + @header["Bcc"]).map { |p| PersonManager.person_for(p).email }
+      from_email = Person.from_address(@header["From"]).email
+      to_email = [@header["To"], @header["Cc"], @header["Bcc"]].flatten.compact.map { |p| Person.from_address(p).email }
 
       m = CryptoManager.send @crypto_selector.val, from_email, to_email, m
     end
@@ -377,12 +378,11 @@ protected
        if text
          @header[field] = parse_header field, text
          update
-         field
        end
     else
-      default =
-        case field
+      default = case field
         when *MULTI_HEADERS
+          @header[field] ||= []
           @header[field].join(", ")
         else
           @header[field]
@@ -393,7 +393,6 @@ protected
         text = contacts.map { |s| s.longname }.join(", ")
         @header[field] = parse_header field, text
         update
-        field
       end
     end
   end
@@ -413,11 +412,13 @@ private
   end
 
   def sig_lines
-    p = PersonManager.person_for(@header["From"])
+    p = Person.from_address(@header["From"])
     from_email = p && p.email
 
     ## first run the hook
     hook_sig = HookManager.run "signature", :header => @header, :from_email => from_email
+
+    return [] if hook_sig == :none
     return ["", "-- "] + hook_sig.split("\n") if hook_sig
 
     ## no hook, do default signature generation based on config.yaml