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>
23 #include "mime-types.h"
27 #define BOUNDARYLEN 16
29 const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t";
31 const char *BodyTypes[] = {
43 const char *BodyEncodings[] = {
53 /****************************************************************************/
54 /* rfc822 header parameters */
55 /****************************************************************************/
57 char *parameter_getval(parameter_t *parm, const char *s)
60 if (!ascii_strcasecmp(parm->attribute, s))
67 void parameter_setval(parameter_t **p, const char *attribute, const char *value)
70 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
72 m_strreplace(&(*p)->value, value);
74 parameter_t *q = parameter_list_pop(p);
83 (*p) = parameter_new();
84 (*p)->attribute = m_strdup(attribute);
85 (*p)->value = m_strdup(value);
89 void parameter_delval(parameter_t **p, const char *attribute)
92 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
93 parameter_t *q = parameter_list_pop(p);
102 int parameter_equal(const parameter_t *p1, const parameter_t *p2)
105 if (m_strcmp(p1->attribute, p2->attribute)
106 || m_strcmp(p1->value, p2->value))
119 void parameter_set_boundary(parameter_t **parm)
121 char rs[BOUNDARYLEN + 1];
124 for (i = 0; i < BOUNDARYLEN; i++) {
125 rs[i] = __m_b64chars[lrand48() % sizeof(__m_b64chars)];
127 rs[BOUNDARYLEN] = '\0';
129 parameter_setval(parm, "boundary", rs);
133 /****************************************************************************/
135 /****************************************************************************/
137 void rfc1524_entry_wipe(rfc1524_entry *p)
139 p_delete(&p->command);
140 p_delete(&p->testcommand);
141 p_delete(&p->composecommand);
142 p_delete(&p->composetypecommand);
143 p_delete(&p->editcommand);
144 p_delete(&p->printcommand);
145 p_delete(&p->nametemplate);
146 p_delete(&p->convert);
149 void envelope_wipe(ENVELOPE *p)
151 address_list_wipe(&p->return_path);
152 address_list_wipe(&p->from);
153 address_list_wipe(&p->to);
154 address_list_wipe(&p->cc);
155 address_list_wipe(&p->bcc);
156 address_list_wipe(&p->sender);
157 address_list_wipe(&p->reply_to);
158 address_list_wipe(&p->mail_followup_to);
160 p_delete(&p->list_post);
161 p_delete(&p->subject);
162 /* real_subj is just an offset to subject and shouldn't be freed */
163 p_delete(&p->message_id);
164 p_delete(&p->supersedes);
166 p_delete(&p->x_label);
167 p_delete(&p->organization);
169 p_delete(&p->newsgroups);
171 p_delete(&p->followup_to);
172 p_delete(&p->x_comment_to);
175 mutt_buffer_free (&p->spam);
176 string_list_wipe(&p->references);
177 string_list_wipe(&p->in_reply_to);
178 string_list_wipe(&p->userhdrs);
181 void header_wipe(HEADER *h)
183 envelope_delete(&h->env);
184 mutt_free_body (&h->content);
185 p_delete(&h->maildir_flags);
189 string_list_wipe(&h->chain);
194 int url_parse_mailto(ENVELOPE *e, char **body, const char *src)
200 char scratch[HUGE_STRING];
204 string_list_t **last = &e->userhdrs;
206 if (!(t = strchr (src, ':')))
209 if ((tmp = m_strdup(t + 1)) == NULL)
212 if ((headers = strchr (tmp, '?')))
216 e->to = rfc822_parse_adrlist (e->to, tmp);
218 tag = headers ? strtok (headers, "&") : NULL;
220 for (; tag; tag = strtok (NULL, "&")) {
221 if ((value = strchr (tag, '=')))
223 if (!value || !*value)
229 if (!ascii_strcasecmp (tag, "body")) {
231 m_strreplace(body, value);
234 #define SAFEPFX (option (OPTSTRICTMAILTO) ? "" : "X-Mailto-")
235 taglen = m_strlen(tag) + m_strlen(SAFEPFX);
236 /* mutt_parse_rfc822_line makes some assumptions */
237 snprintf (scratch, sizeof (scratch), "%s%s: %s", SAFEPFX, tag, value);
239 scratch[taglen] = '\0';
240 value = vskipspaces(&scratch[taglen + 1]);
241 last = mutt_parse_rfc822_line (e, NULL, scratch, value, 0, 0, last);
242 /* if $strict_mailto is set, force editing headers to let
243 * users have a look at what we got */
244 if (!option (OPTSTRICTMAILTO)) {
245 set_option (OPTXMAILTO);
246 set_option (OPTEDITHDRS);