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

diff --git a/4f/5c797710192d2fb53145a1f1f15b14fb408b9c b/4f/5c797710192d2fb53145a1f1f15b14fb408b9c
new file mode 100644 (file)
index 0000000..f652331
--- /dev/null
@@ -0,0 +1,147 @@
+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 1F4E1431FBC\r
+       for <notmuch@notmuchmail.org>; Mon, 27 Oct 2014 13:35:57 -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 kAUS8YcG4q4N for <notmuch@notmuchmail.org>;\r
+       Mon, 27 Oct 2014 13:35:49 -0700 (PDT)\r
+Received: from cmta20.telus.net (cmta20.telus.net [209.171.16.93])\r
+       by olra.theworths.org (Postfix) with ESMTP id 6884C431FB6\r
+       for <notmuch@notmuchmail.org>; Mon, 27 Oct 2014 13:35:49 -0700 (PDT)\r
+Received: from ovo.mains.priv ([207.102.88.62]) by cmta20.telus.net with TELUS\r
+       id 8Lbo1p00T1LiWEf01Lbog9; Mon, 27 Oct 2014 14:35:48 -0600\r
+X-Authority-Analysis: v=2.0 cv=B7NnJpRM c=1 sm=2\r
+       a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=MIf7E3Pt4rcRRfTYnnkA:9\r
+       a=lkvuNZSHYu07fJtA:21 a=gLeTeNXiYQ7GGDAl: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 v3] VIM: Better reply handling with multiple emails\r
+Date: Mon, 27 Oct 2014 13:35:46 -0700\r
+Message-Id: <1414442146-14364-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:35:57 -0000\r
+\r
+Fix reply handling when using multiple emails.  This adds a config\r
+check for other_email and uses that information when formulating reply\r
+headers.  It will strip out your own email addresses from the reply and\r
+set the From: to be an email of yours found in the original message.\r
+\r
+    Ian\r
+---\r
+\r
+Fix commit message.\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