[PATCH v2] VIM: Better reply handling with multiple emails
[notmuch-archives.git] / 21 / f9b310c0188c0db901618a1338dafcea2158c7
1 Return-Path: <imain@stemwinder.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 201EC431FBC\r
6         for <notmuch@notmuchmail.org>; Mon, 27 Oct 2014 13:33:46 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id R9QZTgH7-Dye for <notmuch@notmuchmail.org>;\r
16         Mon, 27 Oct 2014 13:33:38 -0700 (PDT)\r
17 Received: from cmta13.telus.net (cmta13.telus.net [209.171.16.86])\r
18         by olra.theworths.org (Postfix) with ESMTP id 43829431FB6\r
19         for <notmuch@notmuchmail.org>; Mon, 27 Oct 2014 13:33:38 -0700 (PDT)\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta13.telus.net with TELUS\r
21         id 8LZc1p00S1LiWEf01LZdfo; Mon, 27 Oct 2014 14:33:37 -0600\r
22 X-Authority-Analysis: v=2.0 cv=OrmRPVDt c=1 sm=2\r
23         a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=5da42lFW0Q062gHnLiMA:9\r
24         a=aHUBcFr6y3_XmBIu:21 a=kCZGNj4xPFZNQwso:21\r
25         a=EcQDfIwDZEqJA1f7rVUV8Q==:117\r
26 X-Telus-Outbound-IP: 207.102.88.62\r
27 From: Ian Main <imain@stemwinder.org>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [PATCH v2] VIM: Better reply handling with multiple emails\r
30 Date: Mon, 27 Oct 2014 13:33:32 -0700\r
31 Message-Id: <1414442012-13995-1-git-send-email-imain@stemwinder.org>\r
32 X-Mailer: git-send-email 1.9.3\r
33 In-Reply-To: <1412293857-31489-1-git-send-email-imain@stemwinder.org>\r
34 References: <1412293857-31489-1-git-send-email-imain@stemwinder.org>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Mon, 27 Oct 2014 20:33:46 -0000\r
48 \r
49 This patch fixes reply handling when using multiple emails.  This adds a\r
50 config check for other_email and uses that information when formulating\r
51 reply headers.  It will strip out your own email addresses from the\r
52 reply and set the From: to be an email of yours found in the original\r
53 message.\r
54 \r
55 Note that this is built on top of the config change patch.\r
56 \r
57     Ian\r
58 ---\r
59 \r
60 This update uses hashes to ensure no duplicate emails are inserted into\r
61 the to/cc lists.  It's also just a little easier to read.\r
62 \r
63  vim/notmuch.vim | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-----\r
64  1 file changed, 48 insertions(+), 5 deletions(-)\r
65 \r
66 diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
67 index cad9517..b480277 100644\r
68 --- a/vim/notmuch.vim\r
69 +++ b/vim/notmuch.vim\r
70 @@ -476,6 +476,7 @@ ruby << EOF\r
71         end\r
72  \r
73         $db_name = nil\r
74 +       $all_emails = []\r
75         $email = $email_name = $email_address = nil\r
76         $searches = []\r
77         $threads = []\r
78 @@ -494,8 +495,14 @@ ruby << EOF\r
79                 $db_name = get_config_item('database.path')\r
80                 $email_name = get_config_item('user.name')\r
81                 $email_address = get_config_item('user.primary_email')\r
82 +               $secondary_email_addresses = get_config_item('user.primary_email')\r
83                 $email_name = get_config_item('user.name')\r
84                 $email = "%s <%s>" % [$email_name, $email_address]\r
85 +               other_emails = get_config_item('user.other_email')\r
86 +               $all_emails = other_emails.split("\n")\r
87 +               # Add the primary to this too as we use it for checking\r
88 +               # addresses when doing a reply\r
89 +               $all_emails.unshift($email_address)\r
90         end\r
91  \r
92         def vim_puts(s)\r
93 @@ -571,14 +578,50 @@ ruby << EOF\r
94                 end\r
95         end\r
96  \r
97 +       def is_our_address(address)\r
98 +               $all_emails.each do |addy|\r
99 +                       if address.to_s.index(addy) != nil\r
100 +                               return addy\r
101 +                       end\r
102 +               end\r
103 +               return nil\r
104 +       end\r
105 +\r
106         def open_reply(orig)\r
107                 reply = orig.reply do |m|\r
108 -                       # fix headers\r
109 -                       if not m[:reply_to]\r
110 -                               m.to = [orig[:from].to_s, orig[:to].to_s]\r
111 +                       m.cc = []\r
112 +                       m.to = []\r
113 +                       email_addr = $email_address\r
114 +                       # Use hashes for email addresses so we can eliminate duplicates.\r
115 +                       to = Hash.new\r
116 +                       cc = Hash.new\r
117 +                       if orig[:from]\r
118 +                               orig[:from].each do |o|\r
119 +                                       to[o.address] = o\r
120 +                               end\r
121 +                       end\r
122 +                       if orig[:cc]\r
123 +                               orig[:cc].each do |o|\r
124 +                                       cc[o.address] = o\r
125 +                               end\r
126 +                       end\r
127 +                       if orig[:to]\r
128 +                               orig[:to].each do |o|\r
129 +                                       cc[o.address] = o\r
130 +                               end\r
131 +                       end\r
132 +                       to.each do |e_addr, addr|\r
133 +                               m.to << addr\r
134 +                       end\r
135 +                       cc.each do |e_addr, addr|\r
136 +                               if is_our_address(e_addr)\r
137 +                                       email_addr = is_our_address(e_addr)\r
138 +                               else\r
139 +                                       m.cc << addr\r
140 +                               end\r
141                         end\r
142 -                       m.cc = orig[:cc]\r
143 -                       m.from = $email\r
144 +                       m.to = m[:reply_to] if m[:reply_to]\r
145 +                       m.from = "#{$email_name} <#{email_addr}>"\r
146                         m.charset = 'utf-8'\r
147                 end\r
148  \r
149 -- \r
150 1.9.3\r
151 \r