]> git.cworth.org Git - sup/commitdiff
make >From thing work correctly
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 28 Oct 2007 03:36:32 +0000 (03:36 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 28 Oct 2007 03:36:32 +0000 (03:36 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@638 5c8cc53c-5e98-4d25-b20a-d8db53a31250

doc/TODO
lib/sup/mbox/loader.rb
lib/sup/modes/edit-message-mode.rb
lib/sup/sent.rb

index d25d1a791fdc6fcc1eda78dda1aabbbc2fdf87b0..f73afa1c539dcfb721a5ab29bbc60c18a2654b8d 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -4,8 +4,8 @@ for 0.2
 x bugfix: contacts.txt isn't parsed correctly when there are spaces in
    aliases
 x bugfix: @ signs in names make sendmail die silently
-_ bugfix: sent.mbox and >From
-_ bugfix: tokenized email addresses (amazon.com, etc)
+x bugfix: sent.mbox and >From
+x bugfix: tokenized email addresses (amazon.com, etc)
 x bugfix: trailing spaces in buffermanager.ask
 x bugfix: need to URL-unescape maildir folders
 x bugfix: downcasing tab completion
index 48ddfba41a91b00622fccece63064f8ccd0fd85b..605a2c63fee18871640778ce3690bb1140b3d3ac 100644 (file)
@@ -68,7 +68,11 @@ class Loader < Source
       @f.seek offset
       begin
         RMail::Mailbox::MBoxReader.new(@f).each_message do |input|
-          return RMail::Parser.read(input)
+          m = RMail::Parser.read(input)
+          if m.body
+            m.body.gsub!(/^>From /, "From ")
+          end
+          return m
         end
       rescue RMail::Parser::Error => e
         raise FatalSourceError, "error parsing mbox file: #{e.message}"
index e616e66ce010f68d629620c82d3a5d569732940f..17985db1b12b5941e9b10d6ca5b4521125704e7a 100644 (file)
@@ -218,9 +218,9 @@ protected
     BufferManager.flash "Sending..."
 
     begin
-      IO.popen(acct.sendmail, "w") { |p| write_full_message_to p, date }
+      IO.popen(acct.sendmail, "w") { |p| write_full_message_to p, date, false }
       raise SendmailCommandFailed, "Couldn't execute #{acct.sendmail}" unless $? == 0
-      SentManager.write_sent_message(date, from_email) { |f| write_full_message_to f, date }
+      SentManager.write_sent_message(date, from_email) { |f| write_full_message_to f, date, true }
       BufferManager.kill_buffer buffer
       BufferManager.flash "Message sent!"
       true
@@ -237,7 +237,7 @@ protected
     BufferManager.flash "Saved for later editing."
   end
 
-  def write_full_message_to f, date=Time.now
+  def write_full_message_to f, date=Time.now, escape=false
     m = RMail::Message.new
     @header.each do |k, v|
       next if v.nil? || v.empty?
@@ -257,10 +257,12 @@ protected
     if @attachments.empty?
       m.header["Content-Type"] = "text/plain; charset=#{$encoding}"
       m.body = @body.join
+      m.body = sanitize_body m.body if escape
       m.body += sig_lines.join("\n") unless $config[:edit_signature]
     else
       body_m = RMail::Message.new
       body_m.body = @body.join
+      body_m.body = sanitize_body body_m.body if escape
       body_m.body += sig_lines.join("\n") unless $config[:edit_signature]
       body_m.header["Content-Type"] = "text/plain; charset=#{$encoding}"
       body_m.header["Content-Disposition"] = "inline"
@@ -271,6 +273,8 @@ protected
     f.puts m.to_s
   end
 
+  ## TODO: remove this. redundant with write_full_message_to.
+  ##
   ## this is going to change soon: draft messages (currently written
   ## with full=false) will be output as yaml.
   def write_message f, full=true, date=Time.now
@@ -290,12 +294,16 @@ EOS
     end
 
     f.puts
-    f.puts @body.map { |l| l =~ /^From / ? ">#{l}" : l }
+    f.puts sanitize_body(@body.join)
     f.puts sig_lines if full unless $config[:edit_signature]
   end  
 
 private
 
+  def sanitize_body body
+    body.gsub(/^From /, ">From ")
+  end
+
   def mentions_attachments?
     @body.any? { |l| l =~ /^[^>]/ && l =~ /\battach(ment|ed|ing|)\b/i }
   end
index b4a57ec259ecade31aefdd97cb35f1d174076319..05a88b9239c1f36d8bdf83911979445dc72114d4 100644 (file)
@@ -21,6 +21,7 @@ class SentManager
       f.puts "From #{from_email} #{date}"
       yield f
     end
+
     @source.each do |offset, labels|
       m = Message.new :source => @source, :source_info => offset, :labels => @source.labels
       Index.sync_message m