[PATCH v2] VIM: Better reply handling with multiple emails
authorIan Main <imain@stemwinder.org>
Mon, 27 Oct 2014 20:33:32 +0000 (13:33 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:05:43 +0000 (10:05 -0800)
21/f9b310c0188c0db901618a1338dafcea2158c7 [new file with mode: 0644]

diff --git a/21/f9b310c0188c0db901618a1338dafcea2158c7 b/21/f9b310c0188c0db901618a1338dafcea2158c7
new file mode 100644 (file)
index 0000000..a411d29
--- /dev/null
@@ -0,0 +1,151 @@
+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 201EC431FBC\r
+       for <notmuch@notmuchmail.org>; Mon, 27 Oct 2014 13:33:46 -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 R9QZTgH7-Dye for <notmuch@notmuchmail.org>;\r
+       Mon, 27 Oct 2014 13:33:38 -0700 (PDT)\r
+Received: from cmta13.telus.net (cmta13.telus.net [209.171.16.86])\r
+       by olra.theworths.org (Postfix) with ESMTP id 43829431FB6\r
+       for <notmuch@notmuchmail.org>; Mon, 27 Oct 2014 13:33:38 -0700 (PDT)\r
+Received: from ovo.mains.priv ([207.102.88.62]) by cmta13.telus.net with TELUS\r
+       id 8LZc1p00S1LiWEf01LZdfo; Mon, 27 Oct 2014 14:33:37 -0600\r
+X-Authority-Analysis: v=2.0 cv=OrmRPVDt c=1 sm=2\r
+       a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=5da42lFW0Q062gHnLiMA:9\r
+       a=aHUBcFr6y3_XmBIu:21 a=kCZGNj4xPFZNQwso: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 v2] VIM: Better reply handling with multiple emails\r
+Date: Mon, 27 Oct 2014 13:33:32 -0700\r
+Message-Id: <1414442012-13995-1-git-send-email-imain@stemwinder.org>\r
+X-Mailer: git-send-email 1.9.3\r
+In-Reply-To: <1412293857-31489-1-git-send-email-imain@stemwinder.org>\r
+References: <1412293857-31489-1-git-send-email-imain@stemwinder.org>\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: Mon, 27 Oct 2014 20:33:46 -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
+\r
+This update uses hashes to ensure no duplicate emails are inserted into\r
+the to/cc lists.  It's also just a little easier to read.\r
+\r
+ vim/notmuch.vim | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-----\r
+ 1 file changed, 48 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
+index cad9517..b480277 100644\r
+--- a/vim/notmuch.vim\r
++++ b/vim/notmuch.vim\r
+@@ -476,6 +476,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
+@@ -494,8 +495,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
+@@ -571,14 +578,50 @@ 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
++                      m.to = []\r
++                      email_addr = $email_address\r
++                      # Use hashes for email addresses so we can eliminate duplicates.\r
++                      to = Hash.new\r
++                      cc = Hash.new\r
++                      if orig[:from]\r
++                              orig[:from].each do |o|\r
++                                      to[o.address] = o\r
++                              end\r
++                      end\r
++                      if orig[:cc]\r
++                              orig[:cc].each do |o|\r
++                                      cc[o.address] = o\r
++                              end\r
++                      end\r
++                      if orig[:to]\r
++                              orig[:to].each do |o|\r
++                                      cc[o.address] = o\r
++                              end\r
++                      end\r
++                      to.each do |e_addr, addr|\r
++                              m.to << addr\r
++                      end\r
++                      cc.each do |e_addr, addr|\r
++                              if is_our_address(e_addr)\r
++                                      email_addr = is_our_address(e_addr)\r
++                              else\r
++                                      m.cc << addr\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