Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 77 / a4fa20419cd173fd82effadafa99ce61d61755
1 Return-Path: <awg@lagos.xvx.ca>\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 4D5F2429E55\r
6         for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 19:12:51 -0800 (PST)\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 9pyE6XfhJ1K2 for <notmuch@notmuchmail.org>;\r
16         Wed, 15 Feb 2012 19:12:47 -0800 (PST)\r
17 Received: from idcmail-mo1so.shaw.ca (idcmail-mo1so.shaw.ca [24.71.223.10])\r
18         by olra.theworths.org (Postfix) with ESMTP id 52805429E42\r
19         for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 19:12:47 -0800 (PST)\r
20 Received: from pd3ml1so-ssvc.prod.shaw.ca ([10.0.141.140])\r
21         by pd4mo1so-svcs.prod.shaw.ca with ESMTP; 15 Feb 2012 20:12:46 -0700\r
22 X-Cloudmark-SP-Filtered: true\r
23 X-Cloudmark-SP-Result: v=1.1 cv=MPNiKFfsidoaPqBs0kThsodqbsbgvPHp5CGEg9DOvhI=\r
24         c=1 sm=1\r
25         a=bJ4VeapOTk4A:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
26         a=Ip1p9aMYQwLSyBp_cu4A:9 a=kK51L1ATiIlFzoh5DWsA:7\r
27         a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
28 Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
29         by pd3ml1so-dmz.prod.shaw.ca with ESMTP; 15 Feb 2012 20:12:46 -0700\r
30 Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
31         id C8E788004C2C; Wed, 15 Feb 2012 20:12:45 -0700 (MST)\r
32 From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
33 To: notmuch@notmuchmail.org\r
34 Subject: [PATCH v5.2 2/7] reply: Factor out reply creation\r
35 Date: Wed, 15 Feb 2012 20:12:32 -0700\r
36 Message-Id: <1329361957-28493-3-git-send-email-awg+notmuch@xvx.ca>\r
37 X-Mailer: git-send-email 1.7.5.4\r
38 In-Reply-To: <1329361957-28493-1-git-send-email-awg+notmuch@xvx.ca>\r
39 References: <1329361957-28493-1-git-send-email-awg+notmuch@xvx.ca>\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Thu, 16 Feb 2012 03:12:51 -0000\r
53 \r
54 Factor out the creation of a reply message based on an original\r
55 message so it can be shared by different reply formats.\r
56 ---\r
57  notmuch-reply.c |  101 +++++++++++++++++++++++++++++++-----------------------\r
58  1 files changed, 58 insertions(+), 43 deletions(-)\r
59 \r
60 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
61 index 6b244e6..8e56245 100644\r
62 --- a/notmuch-reply.c\r
63 +++ b/notmuch-reply.c\r
64 @@ -505,6 +505,61 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message\r
65      return NULL;\r
66  }\r
67  \r
68 +static GMimeMessage *\r
69 +create_reply_message(void *ctx,\r
70 +                    notmuch_config_t *config,\r
71 +                    notmuch_message_t *message,\r
72 +                    notmuch_bool_t reply_all)\r
73 +{\r
74 +    const char *subject, *from_addr = NULL;\r
75 +    const char *in_reply_to, *orig_references, *references;\r
76 +\r
77 +    /* The 1 means we want headers in a "pretty" order. */\r
78 +    GMimeMessage *reply = g_mime_message_new (1);\r
79 +    if (reply == NULL) {\r
80 +       fprintf (stderr, "Out of memory\n");\r
81 +       return NULL;\r
82 +    }\r
83 +\r
84 +    subject = notmuch_message_get_header (message, "subject");\r
85 +    if (subject) {\r
86 +       if (strncasecmp (subject, "Re:", 3))\r
87 +           subject = talloc_asprintf (ctx, "Re: %s", subject);\r
88 +       g_mime_message_set_subject (reply, subject);\r
89 +    }\r
90 +\r
91 +    from_addr = add_recipients_from_message (reply, config,\r
92 +                                            message, reply_all);\r
93 +\r
94 +    if (from_addr == NULL)\r
95 +       from_addr = guess_from_received_header (config, message);\r
96 +\r
97 +    if (from_addr == NULL)\r
98 +       from_addr = notmuch_config_get_user_primary_email (config);\r
99 +\r
100 +    from_addr = talloc_asprintf (ctx, "%s <%s>",\r
101 +                                notmuch_config_get_user_name (config),\r
102 +                                from_addr);\r
103 +    g_mime_object_set_header (GMIME_OBJECT (reply),\r
104 +                             "From", from_addr);\r
105 +\r
106 +    in_reply_to = talloc_asprintf (ctx, "<%s>",\r
107 +                                  notmuch_message_get_message_id (message));\r
108 +\r
109 +    g_mime_object_set_header (GMIME_OBJECT (reply),\r
110 +                             "In-Reply-To", in_reply_to);\r
111 +\r
112 +    orig_references = notmuch_message_get_header (message, "references");\r
113 +    references = talloc_asprintf (ctx, "%s%s%s",\r
114 +                                 orig_references ? orig_references : "",\r
115 +                                 orig_references ? " " : "",\r
116 +                                 in_reply_to);\r
117 +    g_mime_object_set_header (GMIME_OBJECT (reply),\r
118 +                             "References", references);\r
119 +\r
120 +    return reply;\r
121 +}\r
122 +\r
123  static int\r
124  notmuch_reply_format_default(void *ctx,\r
125                              notmuch_config_t *config,\r
126 @@ -515,8 +570,6 @@ notmuch_reply_format_default(void *ctx,\r
127      GMimeMessage *reply;\r
128      notmuch_messages_t *messages;\r
129      notmuch_message_t *message;\r
130 -    const char *subject, *from_addr = NULL;\r
131 -    const char *in_reply_to, *orig_references, *references;\r
132      const notmuch_show_format_t *format = &format_reply;\r
133  \r
134      for (messages = notmuch_query_search_messages (query);\r
135 @@ -525,48 +578,10 @@ notmuch_reply_format_default(void *ctx,\r
136      {\r
137         message = notmuch_messages_get (messages);\r
138  \r
139 -       /* The 1 means we want headers in a "pretty" order. */\r
140 -       reply = g_mime_message_new (1);\r
141 -       if (reply == NULL) {\r
142 -           fprintf (stderr, "Out of memory\n");\r
143 -           return 1;\r
144 -       }\r
145 -\r
146 -       subject = notmuch_message_get_header (message, "subject");\r
147 -       if (subject) {\r
148 -           if (strncasecmp (subject, "Re:", 3))\r
149 -               subject = talloc_asprintf (ctx, "Re: %s", subject);\r
150 -           g_mime_message_set_subject (reply, subject);\r
151 -       }\r
152 -\r
153 -       from_addr = add_recipients_from_message (reply, config, message,\r
154 -                                                reply_all);\r
155 +       reply = create_reply_message (ctx, config, message, reply_all);\r
156  \r
157 -       if (from_addr == NULL)\r
158 -           from_addr = guess_from_received_header (config, message);\r
159 -\r
160 -       if (from_addr == NULL)\r
161 -           from_addr = notmuch_config_get_user_primary_email (config);\r
162 -\r
163 -       from_addr = talloc_asprintf (ctx, "%s <%s>",\r
164 -                                    notmuch_config_get_user_name (config),\r
165 -                                    from_addr);\r
166 -       g_mime_object_set_header (GMIME_OBJECT (reply),\r
167 -                                 "From", from_addr);\r
168 -\r
169 -       in_reply_to = talloc_asprintf (ctx, "<%s>",\r
170 -                            notmuch_message_get_message_id (message));\r
171 -\r
172 -       g_mime_object_set_header (GMIME_OBJECT (reply),\r
173 -                                 "In-Reply-To", in_reply_to);\r
174 -\r
175 -       orig_references = notmuch_message_get_header (message, "references");\r
176 -       references = talloc_asprintf (ctx, "%s%s%s",\r
177 -                                     orig_references ? orig_references : "",\r
178 -                                     orig_references ? " " : "",\r
179 -                                     in_reply_to);\r
180 -       g_mime_object_set_header (GMIME_OBJECT (reply),\r
181 -                                 "References", references);\r
182 +       if (!reply)\r
183 +           continue;\r
184  \r
185         show_reply_headers (reply);\r
186  \r
187 -- \r
188 1.7.5.4\r
189 \r