[PATCH] VIM: Better reply handling with multiple emails
authorIan Main <imain@stemwinder.org>
Thu, 2 Oct 2014 23:50:57 +0000 (16:50 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:04:52 +0000 (10:04 -0800)
72/d358491a47451b1c3b55ef6d5f8c7e002141b2 [new file with mode: 0644]

diff --git a/72/d358491a47451b1c3b55ef6d5f8c7e002141b2 b/72/d358491a47451b1c3b55ef6d5f8c7e002141b2
new file mode 100644 (file)
index 0000000..1f6417b
--- /dev/null
@@ -0,0 +1,149 @@
+Return-Path: <imain@stemwinder.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 98CF3431FC0\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Oct 2014 16:51:10 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 78Vp4OHm7tEm for <notmuch@notmuchmail.org>;\r
+       Thu,  2 Oct 2014 16:51:02 -0700 (PDT)\r
+Received: from cmta5.telus.net (cmta5.telus.net [209.171.16.78])\r
+       by olra.theworths.org (Postfix) with ESMTP id 4DC21431FB6\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Oct 2014 16:51:02 -0700 (PDT)\r
+Received: from ovo.mains.priv ([207.102.88.62]) by cmta5.telus.net with TELUS\r
+       id yPr01o00B1LiWEf01Pr08k; Thu, 02 Oct 2014 17:51:01 -0600\r
+X-Authority-Analysis: v=2.0 cv=JvIvWrEC c=1 sm=2\r
+       a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8\r
+       a=MIf7E3Pt4rcRRfTYnnkA:9 a=Gtbg3cE-PUpUMIzN:21 a=nIKZ8RB3skwjJD9N:21\r
+       a=EcQDfIwDZEqJA1f7rVUV8Q==:117\r
+X-Telus-Outbound-IP: 207.102.88.62\r
+From: Ian Main <imain@stemwinder.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] VIM: Better reply handling with multiple emails\r
+Date: Thu,  2 Oct 2014 16:50:57 -0700\r
+Message-Id: <1412293857-31489-1-git-send-email-imain@stemwinder.org>\r
+X-Mailer: git-send-email 1.9.3\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 02 Oct 2014 23:51:10 -0000\r
+\r
+This patch fixes reply handling when using multiple emails.  This adds a\r
+config check for other_email and uses that information when formulating\r
+reply headers.  It will strip out your own email addresses from the\r
+reply and set the From: to be an email of yours found in the original\r
+message.\r
+\r
+Note that this is built on top of the config change patch.\r
+\r
+    Ian\r
+---\r
+ vim/notmuch.vim | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----\r
+ 1 file changed, 52 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
+index b251af6..fbd0e21 100644\r
+--- a/vim/notmuch.vim\r
++++ b/vim/notmuch.vim\r
+@@ -467,6 +467,7 @@ ruby << EOF\r
+       end\r
\r
+       $db_name = nil\r
++      $all_emails = []\r
+       $email = $email_name = $email_address = nil\r
+       $searches = []\r
+       $threads = []\r
+@@ -485,8 +486,14 @@ ruby << EOF\r
+               $db_name = get_config_item('database.path')\r
+               $email_name = get_config_item('user.name')\r
+               $email_address = get_config_item('user.primary_email')\r
++              $secondary_email_addresses = get_config_item('user.primary_email')\r
+               $email_name = get_config_item('user.name')\r
+               $email = "%s <%s>" % [$email_name, $email_address]\r
++              other_emails = get_config_item('user.other_email')\r
++              $all_emails = other_emails.split("\n")\r
++              # Add the primary to this too as we use it for checking\r
++              # addresses when doing a reply\r
++              $all_emails.unshift($email_address)\r
+       end\r
\r
+       def vim_puts(s)\r
+@@ -562,14 +569,54 @@ ruby << EOF\r
+               end\r
+       end\r
\r
++      def is_our_address(address)\r
++              $all_emails.each do |addy|\r
++                      if address.to_s.index(addy) != nil\r
++                              return addy\r
++                      end\r
++              end\r
++              return nil\r
++      end\r
++\r
+       def open_reply(orig)\r
+               reply = orig.reply do |m|\r
+-                      # fix headers\r
+-                      if not m[:reply_to]\r
+-                              m.to = [orig[:from].to_s, orig[:to].to_s]\r
++                      m.cc = []\r
++                      email_addr = $email_address\r
++                      # Append addresses to the new to: from the original from:\r
++                      # so long as they are not ours.\r
++                      if orig[:from]\r
++                              orig[:from].each do |o|\r
++                                      if not is_our_address(o)\r
++                                              m.to << o\r
++                                      end\r
++                              end\r
++                      end\r
++                      # This copies the cc list to the new email while\r
++                      # stripping out our own addresses and sets the from:\r
++                      # address to ours if it finds one.\r
++                      if orig[:cc]\r
++                              orig[:cc].each do |o|\r
++                                      if is_our_address(o)\r
++                                              email_addr = is_our_address(o)\r
++                                      else\r
++                                              m.cc << o\r
++                                      end\r
++                              end\r
++                      end\r
++                      # This copies the to list to the new email while\r
++                      # stripping out our own addresses and sets the from:\r
++                      # address to ours if it finds one.\r
++                      if orig[:to]\r
++                              orig[:to].each do |o|\r
++                                      if is_our_address(o)\r
++                                              email_addr = is_our_address(o)\r
++                                      else\r
++                                              m.to << o\r
++                                      end\r
++                              end\r
+                       end\r
+-                      m.cc = orig[:cc]\r
+-                      m.from = $email\r
++                      m.to = m[:reply_to] if m[:reply_to]\r
++                      m.from = "#{$email_name} <#{email_addr}>"\r
+                       m.charset = 'utf-8'\r
+               end\r
\r
+-- \r
+1.9.3\r
+\r