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 #include <lib-lib/ascii.h>
21 #include <lib-lib/url.h>
25 #define BOUNDARYLEN 16
27 const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t";
29 const char *BodyTypes[] = {
41 const char *BodyEncodings[] = {
51 /****************************************************************************/
52 /* rfc822 header parameters */
53 /****************************************************************************/
55 char *parameter_getval(parameter_t *parm, const char *s)
58 if (!ascii_strcasecmp(parm->attribute, s))
65 void parameter_setval(parameter_t **p, const char *attribute, const char *value)
68 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
70 m_strreplace(&(*p)->value, value);
72 parameter_t *q = parameter_list_pop(p);
81 (*p) = parameter_new();
82 (*p)->attribute = m_strdup(attribute);
83 (*p)->value = m_strdup(value);
87 void parameter_delval(parameter_t **p, const char *attribute)
90 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
91 parameter_t *q = parameter_list_pop(p);
100 int parameter_equal(const parameter_t *p1, const parameter_t *p2)
103 if (m_strcmp(p1->attribute, p2->attribute)
104 || m_strcmp(p1->value, p2->value))
117 void parameter_set_boundary(parameter_t **parm)
119 char rs[BOUNDARYLEN + 1];
122 for (i = 0; i < BOUNDARYLEN; i++) {
123 rs[i] = __m_b64chars[lrand48() % sizeof(__m_b64chars)];
125 rs[BOUNDARYLEN] = '\0';
127 parameter_setval(parm, "boundary", rs);
131 /****************************************************************************/
133 /****************************************************************************/
135 void rfc1524_entry_wipe(rfc1524_entry *p)
137 p_delete(&p->command);
138 p_delete(&p->testcommand);
139 p_delete(&p->composecommand);
140 p_delete(&p->composetypecommand);
141 p_delete(&p->editcommand);
142 p_delete(&p->printcommand);
143 p_delete(&p->nametemplate);
144 p_delete(&p->convert);
147 void envelope_wipe(ENVELOPE *p)
149 address_list_wipe(&p->return_path);
150 address_list_wipe(&p->from);
151 address_list_wipe(&p->to);
152 address_list_wipe(&p->cc);
153 address_list_wipe(&p->bcc);
154 address_list_wipe(&p->sender);
155 address_list_wipe(&p->reply_to);
156 address_list_wipe(&p->mail_followup_to);
158 p_delete(&p->list_post);
159 p_delete(&p->subject);
160 /* real_subj is just an offset to subject and shouldn't be freed */
161 p_delete(&p->message_id);
162 p_delete(&p->supersedes);
164 p_delete(&p->x_label);
165 p_delete(&p->organization);
167 p_delete(&p->newsgroups);
169 p_delete(&p->followup_to);
170 p_delete(&p->x_comment_to);
173 mutt_buffer_free (&p->spam);
174 string_list_wipe(&p->references);
175 string_list_wipe(&p->in_reply_to);
176 string_list_wipe(&p->userhdrs);
179 void body_wipe(BODY *b)
182 parameter_list_wipe(&b->parameter);
184 if (b->unlink && b->filename) {
185 unlink (b->filename);
188 p_delete(&b->filename);
189 p_delete(&b->content);
191 p_delete(&b->subtype);
192 p_delete(&b->description);
193 p_delete(&b->form_name);
196 /* Don't free twice (b->hdr->content = b->parts) */
197 b->hdr->content = NULL;
198 header_delete(&b->hdr);
202 body_list_wipe(&b->parts);
205 void header_wipe(HEADER *h)
207 envelope_delete(&h->env);
208 body_list_wipe(&h->content);
209 p_delete(&h->maildir_flags);
213 string_list_wipe(&h->chain);
221 int url_parse_mailto(ENVELOPE *e, char **body, const char *src)
227 char scratch[HUGE_STRING];
231 string_list_t **last = &e->userhdrs;
233 if (!(t = strchr (src, ':')))
236 if ((tmp = m_strdup(t + 1)) == NULL)
239 if ((headers = strchr (tmp, '?')))
243 e->to = rfc822_parse_adrlist(e->to, tmp);
245 tag = headers ? strtok (headers, "&") : NULL;
247 for (; tag; tag = strtok(NULL, "&")) {
248 if ((value = strchr (tag, '=')))
250 if (!value || !*value)
256 if (mime_which_token(tag, -1) == MIME_BODY) {
258 m_strreplace(body, value);
260 #define SAFEPFX (option(OPTSTRICTMAILTO) ? "" : "X-Mailto-")
261 taglen = m_strlen(tag) + strlen(SAFEPFX);
262 /* mutt_parse_rfc822_line makes some assumptions */
263 snprintf(scratch, sizeof(scratch), "%s%s: %s", SAFEPFX, tag, value);
265 scratch[taglen] = '\0';
266 value = vskipspaces(&scratch[taglen + 1]);
267 last = mutt_parse_rfc822_line (e, NULL, scratch, value, 0, 0, last);
268 /* if $strict_mailto is set, force editing headers to let
269 * users have a look at what we got */
270 if (!option (OPTSTRICTMAILTO)) {
271 set_option (OPTXMAILTO);
272 set_option (OPTEDITHDRS);