From 6d1bc24650b7964eff34532d8873481569ce3eb3 Mon Sep 17 00:00:00 2001 From: Ian Main Date: Tue, 28 Oct 2014 13:33:32 +1700 Subject: [PATCH] [PATCH v2] VIM: Better reply handling with multiple emails --- 21/f9b310c0188c0db901618a1338dafcea2158c7 | 151 ++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 21/f9b310c0188c0db901618a1338dafcea2158c7 diff --git a/21/f9b310c0188c0db901618a1338dafcea2158c7 b/21/f9b310c0188c0db901618a1338dafcea2158c7 new file mode 100644 index 000000000..a411d2934 --- /dev/null +++ b/21/f9b310c0188c0db901618a1338dafcea2158c7 @@ -0,0 +1,151 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 201EC431FBC + for ; Mon, 27 Oct 2014 13:33:46 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id R9QZTgH7-Dye for ; + Mon, 27 Oct 2014 13:33:38 -0700 (PDT) +Received: from cmta13.telus.net (cmta13.telus.net [209.171.16.86]) + by olra.theworths.org (Postfix) with ESMTP id 43829431FB6 + for ; Mon, 27 Oct 2014 13:33:38 -0700 (PDT) +Received: from ovo.mains.priv ([207.102.88.62]) by cmta13.telus.net with TELUS + id 8LZc1p00S1LiWEf01LZdfo; Mon, 27 Oct 2014 14:33:37 -0600 +X-Authority-Analysis: v=2.0 cv=OrmRPVDt c=1 sm=2 + a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=5da42lFW0Q062gHnLiMA:9 + a=aHUBcFr6y3_XmBIu:21 a=kCZGNj4xPFZNQwso:21 + a=EcQDfIwDZEqJA1f7rVUV8Q==:117 +X-Telus-Outbound-IP: 207.102.88.62 +From: Ian Main +To: notmuch@notmuchmail.org +Subject: [PATCH v2] VIM: Better reply handling with multiple emails +Date: Mon, 27 Oct 2014 13:33:32 -0700 +Message-Id: <1414442012-13995-1-git-send-email-imain@stemwinder.org> +X-Mailer: git-send-email 1.9.3 +In-Reply-To: <1412293857-31489-1-git-send-email-imain@stemwinder.org> +References: <1412293857-31489-1-git-send-email-imain@stemwinder.org> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 27 Oct 2014 20:33:46 -0000 + +This patch fixes reply handling when using multiple emails. This adds a +config check for other_email and uses that information when formulating +reply headers. It will strip out your own email addresses from the +reply and set the From: to be an email of yours found in the original +message. + +Note that this is built on top of the config change patch. + + Ian +--- + +This update uses hashes to ensure no duplicate emails are inserted into +the to/cc lists. It's also just a little easier to read. + + vim/notmuch.vim | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- + 1 file changed, 48 insertions(+), 5 deletions(-) + +diff --git a/vim/notmuch.vim b/vim/notmuch.vim +index cad9517..b480277 100644 +--- a/vim/notmuch.vim ++++ b/vim/notmuch.vim +@@ -476,6 +476,7 @@ ruby << EOF + end + + $db_name = nil ++ $all_emails = [] + $email = $email_name = $email_address = nil + $searches = [] + $threads = [] +@@ -494,8 +495,14 @@ ruby << EOF + $db_name = get_config_item('database.path') + $email_name = get_config_item('user.name') + $email_address = get_config_item('user.primary_email') ++ $secondary_email_addresses = get_config_item('user.primary_email') + $email_name = get_config_item('user.name') + $email = "%s <%s>" % [$email_name, $email_address] ++ other_emails = get_config_item('user.other_email') ++ $all_emails = other_emails.split("\n") ++ # Add the primary to this too as we use it for checking ++ # addresses when doing a reply ++ $all_emails.unshift($email_address) + end + + def vim_puts(s) +@@ -571,14 +578,50 @@ ruby << EOF + end + end + ++ def is_our_address(address) ++ $all_emails.each do |addy| ++ if address.to_s.index(addy) != nil ++ return addy ++ end ++ end ++ return nil ++ end ++ + def open_reply(orig) + reply = orig.reply do |m| +- # fix headers +- if not m[:reply_to] +- m.to = [orig[:from].to_s, orig[:to].to_s] ++ m.cc = [] ++ m.to = [] ++ email_addr = $email_address ++ # Use hashes for email addresses so we can eliminate duplicates. ++ to = Hash.new ++ cc = Hash.new ++ if orig[:from] ++ orig[:from].each do |o| ++ to[o.address] = o ++ end ++ end ++ if orig[:cc] ++ orig[:cc].each do |o| ++ cc[o.address] = o ++ end ++ end ++ if orig[:to] ++ orig[:to].each do |o| ++ cc[o.address] = o ++ end ++ end ++ to.each do |e_addr, addr| ++ m.to << addr ++ end ++ cc.each do |e_addr, addr| ++ if is_our_address(e_addr) ++ email_addr = is_our_address(e_addr) ++ else ++ m.cc << addr ++ end + end +- m.cc = orig[:cc] +- m.from = $email ++ m.to = m[:reply_to] if m[:reply_to] ++ m.from = "#{$email_name} <#{email_addr}>" + m.charset = 'utf-8' + end + +-- +1.9.3 + -- 2.26.2