]> git.cworth.org Git - sup/commitdiff
Add message bouncing capability
authorBen Walton <bwalton@artsci.utoronto.ca>
Sun, 7 Jun 2009 16:38:41 +0000 (12:38 -0400)
committerBen Walton <bwalton@artsci.utoronto.ca>
Sun, 7 Jun 2009 16:38:41 +0000 (12:38 -0400)
Bouncing a message is akin to redirecting a mail with a .forward
entry.  It is passed back to the mail system as it sits on disk.

By pressing ! while viewing a message, you can now re-inject it to the
mail system using either the command defined in bounce_sendmail or the
sendmail command for the default account with any instance of -t
removed. The user is prompted for the recipients of the message and is
offered a chance to confirm the bounce before it is sent.

The message is _not_ stored in the sent box, as this doesn't make
sense with bounced messages (and would not show up uniquely anyway).

The bounce_sendmail configuration item allows users that require
different sendmail commands depending on where the bounce is destined
to write a wrapper around their local mail tools to pick and choose
the appropriate injection method for the message based on the
addresses passed in.  Most systems can likely use: sendmail -oem -i

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
lib/sup.rb
lib/sup/modes/thread-view-mode.rb

index 96510b2e2d7419629a0a3fd3e9d96eafca29c36e..76444c95d0168860303c488c19d17512c5920895 100644 (file)
@@ -207,6 +207,7 @@ else
     :confirm_top_posting => true,
     :discard_snippets_from_encrypted_messages => false,
     :default_attachment_save_dir => "",
+    :bounce_sendmail => "",
   }
   begin
     FileUtils.mkdir_p Redwood::BASE_DIR
index 42c62809fa8f80cb10c4730948de7fa4a208eff6..8842e59abf479be4de6ceef388770a23ad56563a 100644 (file)
@@ -41,6 +41,7 @@ EOS
 #    k.add :collapse_non_new_messages, "Collapse all but unread messages", 'N'
     k.add :reply, "Reply to a message", 'r'
     k.add :forward, "Forward a message or attachment", 'f'
+    k.add :bounce, "Bounce message to other recipient(s)", '!'
     k.add :alias, "Edit alias/nickname for a person", 'i'
     k.add :edit_as_new, "Edit message as new", 'D'
     k.add :save_to_disk, "Save message/attachment to disk", 's'
@@ -172,6 +173,38 @@ EOS
     end
   end
 
+  def bounce
+    m = @message_lines[curpos] or return
+    to = BufferManager.ask_for_contacts(:people, "Bounce To: ") or return
+
+    defcmd = AccountManager.default_account.sendmail.sub(/\s(\-(ti|it|t))\b/) do |match|
+      case "$1"
+        when '-t' then ''
+        else ' -i'
+      end
+    end
+
+    cmd = case $config[:bounce_sendmail]
+          when nil, /^$/ then defcmd
+          else $config[:bounce_sendmail]
+          end + ' ' + to.map { |t| t.email }.join(' ')
+
+    bt = to.size > 1 ? "#{to.size} recipients" : to.to_s
+
+    if BufferManager.ask_yes_or_no "Really bounce to #{bt}?"
+      Redwood::log "Bounce Command: #{cmd}"
+      begin
+        IO.popen(cmd, 'w') do |sm|
+          sm.puts m.raw_message
+        end
+        raise SendmailCommandFailed, "Couldn't execute #{cmd}" unless $? == 0
+      rescue SystemCallError, SendmailCommandFailed => e
+        Redwood::log "Problem sending mail: #{e.message}"
+        BufferManager.flash "Problem sending mail: #{e.message}"
+      end
+    end
+  end
+
   include CanAliasContacts
   def alias
     p = @person_lines[curpos] or return