2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * Copyright © 2006 Pierre Habouzit
20 * Copyright notice from original mutt:
21 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
22 * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
25 #include <lib-lib/ascii.h>
26 #include <lib-lib/url.h>
30 #define BOUNDARYLEN 16
32 const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t";
34 const char *BodyTypes[] = {
46 const char *BodyEncodings[] = {
56 /****************************************************************************/
57 /* rfc822 header parameters */
58 /****************************************************************************/
60 char *parameter_getval(parameter_t *parm, const char *s)
63 if (!ascii_strcasecmp(parm->attribute, s))
70 void parameter_setval(parameter_t **p, const char *attribute, const char *value)
73 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
75 m_strreplace(&(*p)->value, value);
77 parameter_t *q = parameter_list_pop(p);
86 (*p) = parameter_new();
87 (*p)->attribute = m_strdup(attribute);
88 (*p)->value = m_strdup(value);
92 void parameter_delval(parameter_t **p, const char *attribute)
95 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
96 parameter_t *q = parameter_list_pop(p);
105 int parameter_equal(const parameter_t *p1, const parameter_t *p2)
108 if (m_strcmp(p1->attribute, p2->attribute)
109 || m_strcmp(p1->value, p2->value))
122 void parameter_set_boundary(parameter_t **parm)
124 char rs[BOUNDARYLEN + 1];
127 for (i = 0; i < BOUNDARYLEN; i++) {
128 rs[i] = __m_b64chars[lrand48() % sizeof(__m_b64chars)];
130 rs[BOUNDARYLEN] = '\0';
132 parameter_setval(parm, "boundary", rs);
136 /****************************************************************************/
138 /****************************************************************************/
140 void envelope_wipe(ENVELOPE *p)
142 address_list_wipe(&p->return_path);
143 address_list_wipe(&p->from);
144 address_list_wipe(&p->to);
145 address_list_wipe(&p->cc);
146 address_list_wipe(&p->bcc);
147 address_list_wipe(&p->sender);
148 address_list_wipe(&p->reply_to);
149 address_list_wipe(&p->mail_followup_to);
151 p_delete(&p->list_post);
152 p_delete(&p->subject);
153 /* real_subj is just an offset to subject and shouldn't be freed */
154 p_delete(&p->message_id);
155 p_delete(&p->supersedes);
157 p_delete(&p->x_label);
158 p_delete(&p->organization);
160 p_delete(&p->newsgroups);
162 p_delete(&p->followup_to);
163 p_delete(&p->x_comment_to);
166 mutt_buffer_free (&p->spam);
167 string_list_wipe(&p->references);
168 string_list_wipe(&p->in_reply_to);
169 string_list_wipe(&p->userhdrs);
172 void body_wipe(BODY *b)
175 parameter_list_wipe(&b->parameter);
177 if (b->unlink && b->filename) {
178 unlink (b->filename);
181 p_delete(&b->filename);
182 p_delete(&b->content);
184 p_delete(&b->subtype);
185 p_delete(&b->description);
186 p_delete(&b->form_name);
189 /* Don't free twice (b->hdr->content = b->parts) */
190 b->hdr->content = NULL;
191 header_delete(&b->hdr);
195 body_list_wipe(&b->parts);
198 void header_wipe(HEADER *h)
200 envelope_delete(&h->env);
201 body_list_wipe(&h->content);
202 p_delete(&h->maildir_flags);
206 string_list_wipe(&h->chain);
212 /****************************************************************************/
214 /****************************************************************************/
216 int mutt_is_text_part(BODY * b)
218 char *s = b->subtype;
220 if (mutt_is_application_pgp(b))
228 return mime_which_token(s, -1) == MIME_DELIVERY_STATUS;
230 case TYPEAPPLICATION:
231 return mime_which_token(s, -1) == MIME_PGP_KEYS;
240 int url_parse_mailto(ENVELOPE *e, char **body, const char *src)
246 char scratch[HUGE_STRING];
250 string_list_t **last = &e->userhdrs;
252 if (!(t = strchr (src, ':')))
255 if ((tmp = m_strdup(t + 1)) == NULL)
258 if ((headers = strchr (tmp, '?')))
262 e->to = rfc822_parse_adrlist(e->to, tmp);
264 tag = headers ? strtok (headers, "&") : NULL;
266 for (; tag; tag = strtok(NULL, "&")) {
267 if ((value = strchr (tag, '=')))
269 if (!value || !*value)
275 if (mime_which_token(tag, -1) == MIME_BODY) {
277 m_strreplace(body, value);
279 #define SAFEPFX (option(OPTSTRICTMAILTO) ? "" : "X-Mailto-")
280 taglen = m_strlen(tag) + strlen(SAFEPFX);
281 /* mutt_parse_rfc822_line makes some assumptions */
282 snprintf(scratch, sizeof(scratch), "%s%s: %s", SAFEPFX, tag, value);
284 scratch[taglen] = '\0';
285 value = vskipspaces(&scratch[taglen + 1]);
286 last = mutt_parse_rfc822_line (e, NULL, scratch, value, 0, 0, last);
287 /* if $strict_mailto is set, force editing headers to let
288 * users have a look at what we got */
289 if (!option (OPTSTRICTMAILTO)) {
290 set_option (OPTXMAILTO);
291 set_option (OPTEDITHDRS);