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>
26 #include <lib-lua/lib-lua.h>
28 @import "../lib-lua/base.cpkg"
30 #define BOUNDARYLEN 16
31 const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t";
33 const char *BodyTypes[] = {
45 const char *BodyEncodings[] = {
58 ** ``$spam_separator'' controls what happens when multiple spam headers
59 ** are matched: if \fIunset\fP, each successive header will overwrite any
60 ** previous matches value for the spam label. If \fIset\fP, each successive
61 ** match will append to the previous, using ``$spam_separator'' as a
64 string_t spam_separator = m_strdup(",");
67 /****************************************************************************/
68 /* rfc822 header parameters */
69 /****************************************************************************/
71 char *parameter_getval(parameter_t *parm, const char *s)
74 if (!ascii_strcasecmp(parm->attribute, s))
81 void parameter_setval(parameter_t **p, const char *attribute, const char *value)
84 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
86 m_strreplace(&(*p)->value, value);
88 parameter_t *q = parameter_list_pop(p);
97 (*p) = parameter_new();
98 (*p)->attribute = m_strdup(attribute);
99 (*p)->value = m_strdup(value);
103 void parameter_delval(parameter_t **p, const char *attribute)
106 if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
107 parameter_t *q = parameter_list_pop(p);
108 parameter_delete(&q);
116 int parameter_equal(const parameter_t *p1, const parameter_t *p2)
119 if (m_strcmp(p1->attribute, p2->attribute)
120 || m_strcmp(p1->value, p2->value))
133 void parameter_set_boundary(parameter_t **parm)
135 char rs[BOUNDARYLEN + 1];
138 for (i = 0; i < BOUNDARYLEN; i++) {
139 rs[i] = __m_b64chars[lrand48() % sizeof(__m_b64chars)];
141 rs[BOUNDARYLEN] = '\0';
143 parameter_setval(parm, "boundary", rs);
147 /****************************************************************************/
149 /****************************************************************************/
151 void envelope_wipe(ENVELOPE *p)
153 address_list_wipe(&p->return_path);
154 address_list_wipe(&p->from);
155 address_list_wipe(&p->to);
156 address_list_wipe(&p->cc);
157 address_list_wipe(&p->bcc);
158 address_list_wipe(&p->sender);
159 address_list_wipe(&p->reply_to);
160 address_list_wipe(&p->mail_followup_to);
162 p_delete(&p->list_post);
163 p_delete(&p->subject);
164 /* real_subj is just an offset to subject and shouldn't be freed */
165 p_delete(&p->message_id);
166 p_delete(&p->supersedes);
168 p_delete(&p->x_label);
169 p_delete(&p->organization);
171 p_delete(&p->newsgroups);
173 p_delete(&p->followup_to);
174 p_delete(&p->x_comment_to);
177 mutt_buffer_free (&p->spam);
178 string_list_wipe(&p->references);
179 string_list_wipe(&p->in_reply_to);
180 string_list_wipe(&p->userhdrs);
183 void body_wipe(BODY *b)
186 parameter_list_wipe(&b->parameter);
188 if (b->unlink && b->filename) {
189 unlink (b->filename);
192 p_delete(&b->filename);
193 p_delete(&b->content);
195 p_delete(&b->subtype);
196 p_delete(&b->description);
197 p_delete(&b->form_name);
200 /* Don't free twice (b->hdr->content = b->parts) */
201 b->hdr->content = NULL;
202 header_delete(&b->hdr);
206 body_list_wipe(&b->parts);
209 void header_wipe(HEADER *h)
211 envelope_delete(&h->env);
212 body_list_wipe(&h->content);
213 p_delete(&h->maildir_flags);
216 string_list_wipe(&h->chain);
221 /****************************************************************************/
223 /****************************************************************************/
225 int mutt_is_message_type(BODY *b)
229 if (b->type != TYPEMESSAGE)
232 tok = mime_which_token(b->subtype, -1);
233 return tok == MIME_RFC822 || tok == MIME_NEWS;
236 int mutt_is_text_part(BODY * b)
238 char *s = b->subtype;
240 if (mutt_is_application_pgp(b))
248 return mime_which_token(s, -1) == MIME_DELIVERY_STATUS;
250 case TYPEAPPLICATION:
251 return mime_which_token(s, -1) == MIME_PGP_KEYS;