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