Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 4f / 5c797710192d2fb53145a1f1f15b14fb408b9c
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 1F4E1431FBC\r
6         for <notmuch@notmuchmail.org>; Mon, 27 Oct 2014 13:35:57 -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 kAUS8YcG4q4N for <notmuch@notmuchmail.org>;\r
16         Mon, 27 Oct 2014 13:35:49 -0700 (PDT)\r
17 Received: from cmta20.telus.net (cmta20.telus.net [209.171.16.93])\r
18         by olra.theworths.org (Postfix) with ESMTP id 6884C431FB6\r
19         for <notmuch@notmuchmail.org>; Mon, 27 Oct 2014 13:35:49 -0700 (PDT)\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta20.telus.net with TELUS\r
21         id 8Lbo1p00T1LiWEf01Lbog9; Mon, 27 Oct 2014 14:35:48 -0600\r
22 X-Authority-Analysis: v=2.0 cv=B7NnJpRM c=1 sm=2\r
23         a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=MIf7E3Pt4rcRRfTYnnkA:9\r
24         a=lkvuNZSHYu07fJtA:21 a=gLeTeNXiYQ7GGDAl: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 v3] VIM: Better reply handling with multiple emails\r
30 Date: Mon, 27 Oct 2014 13:35:46 -0700\r
31 Message-Id: <1414442146-14364-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:35:57 -0000\r
48 \r
49 Fix reply handling when using multiple emails.  This adds a config\r
50 check for other_email and uses that information when formulating reply\r
51 headers.  It will strip out your own email addresses from the reply and\r
52 set the From: to be an email of yours found in the original message.\r
53 \r
54     Ian\r
55 ---\r
56 \r
57 Fix commit message.\r
58 \r
59  vim/notmuch.vim | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-----\r
60  1 file changed, 48 insertions(+), 5 deletions(-)\r
61 \r
62 diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
63 index cad9517..b480277 100644\r
64 --- a/vim/notmuch.vim\r
65 +++ b/vim/notmuch.vim\r
66 @@ -476,6 +476,7 @@ ruby << EOF\r
67         end\r
68  \r
69         $db_name = nil\r
70 +       $all_emails = []\r
71         $email = $email_name = $email_address = nil\r
72         $searches = []\r
73         $threads = []\r
74 @@ -494,8 +495,14 @@ ruby << EOF\r
75                 $db_name = get_config_item('database.path')\r
76                 $email_name = get_config_item('user.name')\r
77                 $email_address = get_config_item('user.primary_email')\r
78 +               $secondary_email_addresses = get_config_item('user.primary_email')\r
79                 $email_name = get_config_item('user.name')\r
80                 $email = "%s <%s>" % [$email_name, $email_address]\r
81 +               other_emails = get_config_item('user.other_email')\r
82 +               $all_emails = other_emails.split("\n")\r
83 +               # Add the primary to this too as we use it for checking\r
84 +               # addresses when doing a reply\r
85 +               $all_emails.unshift($email_address)\r
86         end\r
87  \r
88         def vim_puts(s)\r
89 @@ -571,14 +578,50 @@ ruby << EOF\r
90                 end\r
91         end\r
92  \r
93 +       def is_our_address(address)\r
94 +               $all_emails.each do |addy|\r
95 +                       if address.to_s.index(addy) != nil\r
96 +                               return addy\r
97 +                       end\r
98 +               end\r
99 +               return nil\r
100 +       end\r
101 +\r
102         def open_reply(orig)\r
103                 reply = orig.reply do |m|\r
104 -                       # fix headers\r
105 -                       if not m[:reply_to]\r
106 -                               m.to = [orig[:from].to_s, orig[:to].to_s]\r
107 +                       m.cc = []\r
108 +                       m.to = []\r
109 +                       email_addr = $email_address\r
110 +                       # Use hashes for email addresses so we can eliminate duplicates.\r
111 +                       to = Hash.new\r
112 +                       cc = Hash.new\r
113 +                       if orig[:from]\r
114 +                               orig[:from].each do |o|\r
115 +                                       to[o.address] = o\r
116 +                               end\r
117 +                       end\r
118 +                       if orig[:cc]\r
119 +                               orig[:cc].each do |o|\r
120 +                                       cc[o.address] = o\r
121 +                               end\r
122 +                       end\r
123 +                       if orig[:to]\r
124 +                               orig[:to].each do |o|\r
125 +                                       cc[o.address] = o\r
126 +                               end\r
127 +                       end\r
128 +                       to.each do |e_addr, addr|\r
129 +                               m.to << addr\r
130 +                       end\r
131 +                       cc.each do |e_addr, addr|\r
132 +                               if is_our_address(e_addr)\r
133 +                                       email_addr = is_our_address(e_addr)\r
134 +                               else\r
135 +                                       m.cc << addr\r
136 +                               end\r
137                         end\r
138 -                       m.cc = orig[:cc]\r
139 -                       m.from = $email\r
140 +                       m.to = m[:reply_to] if m[:reply_to]\r
141 +                       m.from = "#{$email_name} <#{email_addr}>"\r
142                         m.charset = 'utf-8'\r
143                 end\r
144  \r
145 -- \r
146 1.9.3\r
147 \r