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/lib-lib.h>
29 #define BOUNDARYLEN 16
31 const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t";
33 const char *BodyTypes[] = {
45 const char *BodyEncodings[] = {
55 /****************************************************************************/
56 /* rfc822 header parameters */
57 /****************************************************************************/
59 char *parameter_getval(parameter_t *parm, const char *s)
62 if (!ascii_strcasecmp(parm->attribute, s))
69 void parameter_setval(parameter_t **p, const char *attribute, const char *value)
72 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
74 m_strreplace(&(*p)->value, value);
76 parameter_t *q = parameter_list_pop(p);
85 (*p) = parameter_new();
86 (*p)->attribute = m_strdup(attribute);
87 (*p)->value = m_strdup(value);
91 void parameter_delval(parameter_t **p, const char *attribute)
94 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
95 parameter_t *q = parameter_list_pop(p);
104 int parameter_equal(const parameter_t *p1, const parameter_t *p2)
107 if (m_strcmp(p1->attribute, p2->attribute)
108 || m_strcmp(p1->value, p2->value))
121 void parameter_set_boundary(parameter_t **parm)
123 char rs[BOUNDARYLEN + 1];
126 for (i = 0; i < BOUNDARYLEN; i++) {
127 rs[i] = __m_b64chars[lrand48() % sizeof(__m_b64chars)];
129 rs[BOUNDARYLEN] = '\0';
131 parameter_setval(parm, "boundary", rs);
135 /****************************************************************************/
137 /****************************************************************************/
139 void envelope_wipe(ENVELOPE *p)
141 address_list_wipe(&p->return_path);
142 address_list_wipe(&p->from);
143 address_list_wipe(&p->to);
144 address_list_wipe(&p->cc);
145 address_list_wipe(&p->bcc);
146 address_list_wipe(&p->sender);
147 address_list_wipe(&p->reply_to);
148 address_list_wipe(&p->mail_followup_to);
150 p_delete(&p->list_post);
151 p_delete(&p->subject);
152 /* real_subj is just an offset to subject and shouldn't be freed */
153 p_delete(&p->message_id);
154 p_delete(&p->supersedes);
156 p_delete(&p->x_label);
157 p_delete(&p->organization);
159 p_delete(&p->newsgroups);
161 p_delete(&p->followup_to);
162 p_delete(&p->x_comment_to);
165 mutt_buffer_free (&p->spam);
166 string_list_wipe(&p->references);
167 string_list_wipe(&p->in_reply_to);
168 string_list_wipe(&p->userhdrs);
171 void body_wipe(BODY *b)
174 parameter_list_wipe(&b->parameter);
176 if (b->unlink && b->filename) {
177 unlink (b->filename);
180 p_delete(&b->filename);
181 p_delete(&b->content);
183 p_delete(&b->subtype);
184 p_delete(&b->description);
185 p_delete(&b->form_name);
188 /* Don't free twice (b->hdr->content = b->parts) */
189 b->hdr->content = NULL;
190 header_delete(&b->hdr);
194 body_list_wipe(&b->parts);
197 void header_wipe(HEADER *h)
199 envelope_delete(&h->env);
200 body_list_wipe(&h->content);
201 p_delete(&h->maildir_flags);
204 string_list_wipe(&h->chain);
209 /****************************************************************************/
211 /****************************************************************************/
213 int mutt_is_message_type(BODY *b)
217 if (b->type != TYPEMESSAGE)
220 tok = mime_which_token(b->subtype, -1);
221 return tok == MIME_RFC822 || tok == MIME_NEWS;
224 int mutt_is_text_part(BODY * b)
226 char *s = b->subtype;
228 if (mutt_is_application_pgp(b))
236 return mime_which_token(s, -1) == MIME_DELIVERY_STATUS;
238 case TYPEAPPLICATION:
239 return mime_which_token(s, -1) == MIME_PGP_KEYS;