Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 72 / d358491a47451b1c3b55ef6d5f8c7e002141b2
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 98CF3431FC0\r
6         for <notmuch@notmuchmail.org>; Thu,  2 Oct 2014 16:51:10 -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 78Vp4OHm7tEm for <notmuch@notmuchmail.org>;\r
16         Thu,  2 Oct 2014 16:51:02 -0700 (PDT)\r
17 Received: from cmta5.telus.net (cmta5.telus.net [209.171.16.78])\r
18         by olra.theworths.org (Postfix) with ESMTP id 4DC21431FB6\r
19         for <notmuch@notmuchmail.org>; Thu,  2 Oct 2014 16:51:02 -0700 (PDT)\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta5.telus.net with TELUS\r
21         id yPr01o00B1LiWEf01Pr08k; Thu, 02 Oct 2014 17:51:01 -0600\r
22 X-Authority-Analysis: v=2.0 cv=JvIvWrEC c=1 sm=2\r
23         a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8\r
24         a=MIf7E3Pt4rcRRfTYnnkA:9 a=Gtbg3cE-PUpUMIzN:21 a=nIKZ8RB3skwjJD9N: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] VIM: Better reply handling with multiple emails\r
30 Date: Thu,  2 Oct 2014 16:50:57 -0700\r
31 Message-Id: <1412293857-31489-1-git-send-email-imain@stemwinder.org>\r
32 X-Mailer: git-send-email 1.9.3\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.13\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37         <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
39         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Thu, 02 Oct 2014 23:51:10 -0000\r
46 \r
47 This patch fixes reply handling when using multiple emails.  This adds a\r
48 config check for other_email and uses that information when formulating\r
49 reply headers.  It will strip out your own email addresses from the\r
50 reply and set the From: to be an email of yours found in the original\r
51 message.\r
52 \r
53 Note that this is built on top of the config change patch.\r
54 \r
55     Ian\r
56 ---\r
57  vim/notmuch.vim | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----\r
58  1 file changed, 52 insertions(+), 5 deletions(-)\r
59 \r
60 diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
61 index b251af6..fbd0e21 100644\r
62 --- a/vim/notmuch.vim\r
63 +++ b/vim/notmuch.vim\r
64 @@ -467,6 +467,7 @@ ruby << EOF\r
65         end\r
66  \r
67         $db_name = nil\r
68 +       $all_emails = []\r
69         $email = $email_name = $email_address = nil\r
70         $searches = []\r
71         $threads = []\r
72 @@ -485,8 +486,14 @@ ruby << EOF\r
73                 $db_name = get_config_item('database.path')\r
74                 $email_name = get_config_item('user.name')\r
75                 $email_address = get_config_item('user.primary_email')\r
76 +               $secondary_email_addresses = get_config_item('user.primary_email')\r
77                 $email_name = get_config_item('user.name')\r
78                 $email = "%s <%s>" % [$email_name, $email_address]\r
79 +               other_emails = get_config_item('user.other_email')\r
80 +               $all_emails = other_emails.split("\n")\r
81 +               # Add the primary to this too as we use it for checking\r
82 +               # addresses when doing a reply\r
83 +               $all_emails.unshift($email_address)\r
84         end\r
85  \r
86         def vim_puts(s)\r
87 @@ -562,14 +569,54 @@ ruby << EOF\r
88                 end\r
89         end\r
90  \r
91 +       def is_our_address(address)\r
92 +               $all_emails.each do |addy|\r
93 +                       if address.to_s.index(addy) != nil\r
94 +                               return addy\r
95 +                       end\r
96 +               end\r
97 +               return nil\r
98 +       end\r
99 +\r
100         def open_reply(orig)\r
101                 reply = orig.reply do |m|\r
102 -                       # fix headers\r
103 -                       if not m[:reply_to]\r
104 -                               m.to = [orig[:from].to_s, orig[:to].to_s]\r
105 +                       m.cc = []\r
106 +                       email_addr = $email_address\r
107 +                       # Append addresses to the new to: from the original from:\r
108 +                       # so long as they are not ours.\r
109 +                       if orig[:from]\r
110 +                               orig[:from].each do |o|\r
111 +                                       if not is_our_address(o)\r
112 +                                               m.to << o\r
113 +                                       end\r
114 +                               end\r
115 +                       end\r
116 +                       # This copies the cc list to the new email while\r
117 +                       # stripping out our own addresses and sets the from:\r
118 +                       # address to ours if it finds one.\r
119 +                       if orig[:cc]\r
120 +                               orig[:cc].each do |o|\r
121 +                                       if is_our_address(o)\r
122 +                                               email_addr = is_our_address(o)\r
123 +                                       else\r
124 +                                               m.cc << o\r
125 +                                       end\r
126 +                               end\r
127 +                       end\r
128 +                       # This copies the to list to the new email while\r
129 +                       # stripping out our own addresses and sets the from:\r
130 +                       # address to ours if it finds one.\r
131 +                       if orig[:to]\r
132 +                               orig[:to].each do |o|\r
133 +                                       if is_our_address(o)\r
134 +                                               email_addr = is_our_address(o)\r
135 +                                       else\r
136 +                                               m.to << o\r
137 +                                       end\r
138 +                               end\r
139                         end\r
140 -                       m.cc = orig[:cc]\r
141 -                       m.from = $email\r
142 +                       m.to = m[:reply_to] if m[:reply_to]\r
143 +                       m.from = "#{$email_name} <#{email_addr}>"\r
144                         m.charset = 'utf-8'\r
145                 end\r
146  \r
147 -- \r
148 1.9.3\r
149 \r