snprintf (buf, sizeof (buf), "%s/%s", TYPE (b), b->subtype);
m_strcpy(obuf, sizeof(obuf), buf);
if (b->parameter) {
- PARAMETER *p;
+ parameter_t *p;
ssize_t l;
for (p = b->parameter; p; p = p->next) {
*l = NULL;
}
-static unsigned char *dump_parameter (PARAMETER * p, unsigned char *d,
+static unsigned char *dump_parameter (parameter_t * p, unsigned char *d,
int *off)
{
unsigned int counter = 0;
}
static void
-restore_parameter (PARAMETER ** p, const unsigned char *d, int *off)
+restore_parameter (parameter_t ** p, const unsigned char *d, int *off)
{
unsigned int counter;
t->use_disp = 0;
t->disposition = DISPINLINE;
- mutt_generate_boundary (&t->parameter);
- mutt_set_parameter ("protocol",
- use_smime ? "application/pkcs7-signature"
- : "application/pgp-signature", &t->parameter);
+ parameter_set_boundary(&t->parameter);
+ parameter_setval(&t->parameter, "protocol",
+ use_smime ? "application/pkcs7-signature"
+ : "application/pgp-signature");
/* Get the micalg from gpgme. Old gpgme versions don't support this
for S/MIME so we assume sha-1 in this case. */
if (!get_micalg (ctx, buf, sizeof buf))
- mutt_set_parameter ("micalg", buf, &t->parameter);
+ parameter_setval(&t->parameter, "micalg", buf);
else if (use_smime)
- mutt_set_parameter ("micalg", "sha1", &t->parameter);
+ parameter_setval(&t->parameter, "micalg", "sha1");
gpgme_release (ctx);
t->parts = a;
t->type = TYPEAPPLICATION;
if (use_smime) {
t->subtype = m_strdup("pkcs7-signature");
- mutt_set_parameter ("name", "smime.p7s", &t->parameter);
+ parameter_setval(&t->parameter, "name", "smime.p7s");
t->encoding = ENCBASE64;
t->use_disp = 1;
t->disposition = DISPATTACH;
t->use_disp = 0;
t->disposition = DISPINLINE;
- mutt_generate_boundary (&t->parameter);
- mutt_set_parameter ("protocol", "application/pgp-encrypted", &t->parameter);
+ parameter_set_boundary(&t->parameter);
+ parameter_setval(&t->parameter, "protocol", "application/pgp-encrypted");
t->parts = mutt_new_body ();
t->parts->type = TYPEAPPLICATION;
t = mutt_new_body ();
t->type = TYPEAPPLICATION;
t->subtype = m_strdup("pkcs7-mime");
- mutt_set_parameter ("name", "smime.p7m", &t->parameter);
- mutt_set_parameter ("smime-type", "enveloped-data", &t->parameter);
+ parameter_setval(&t->parameter, "name", "smime.p7m");
+ parameter_setval(&t->parameter, "smime-type", "enveloped-data");
t->encoding = ENCBASE64; /* The output of OpenSSL SHOULD be binary */
t->use_disp = 1;
t->disposition = DISPATTACH;
/* fix the content type */
- mutt_set_parameter ("format", "fixed", &b->parameter);
- mutt_set_parameter ("x-action", enc ? "pgp-encrypted" : "pgp-signed",
- &b->parameter);
-
+ parameter_setval(&b->parameter, "format", "fixed");
+ parameter_setval(&b->parameter, "x-action",
+ enc ? "pgp-encrypted" : "pgp-signed");
return 1;
}
/* fix the content type */
- mutt_set_parameter ("format", "fixed", &b->parameter);
+ parameter_setval(&b->parameter, "format", "fixed");
if (enc)
- mutt_set_parameter ("x-action", "pgp-encrypted", &b->parameter);
+ parameter_setval(&b->parameter, "x-action", "pgp-encrypted");
else if (sgn)
- mutt_set_parameter ("x-action", "pgp-signed", &b->parameter);
+ parameter_setval(&b->parameter, "x-action", "pgp-signed");
else if (key)
- mutt_set_parameter ("x-action", "pgp-keys", &b->parameter);
+ parameter_setval(&b->parameter, "x-action", "pgp-keys");
return 1;
}
t->use_disp = 0;
t->disposition = DISPINLINE;
- mutt_generate_boundary (&t->parameter);
- mutt_set_parameter ("protocol", "application/pgp-signature", &t->parameter);
- mutt_set_parameter ("micalg", pgp_micalg (sigfile), &t->parameter);
+ parameter_set_boundary(&t->parameter);
+ parameter_setval(&t->parameter, "protocol", "application/pgp-signature");
+ parameter_setval(&t->parameter, "micalg", pgp_micalg (sigfile));
t->parts = a;
a = t;
t->use_disp = 0;
t->disposition = DISPINLINE;
- mutt_generate_boundary (&t->parameter);
- mutt_set_parameter ("protocol", "application/pgp-encrypted", &t->parameter);
+ parameter_set_boundary(&t->parameter);
+ parameter_setval(&t->parameter, "protocol", "application/pgp-encrypted");
t->parts = mutt_new_body ();
t->parts->type = TYPEAPPLICATION;
b->type = TYPETEXT;
b->subtype = m_strdup("plain");
- mutt_set_parameter ("x-action",
- flags & ENCRYPT ? "pgp-encrypted" : "pgp-signed",
- &b->parameter);
- mutt_set_parameter ("charset", send_charset, &b->parameter);
+ parameter_setval(&b->parameter, "x-action",
+ flags & ENCRYPT ? "pgp-encrypted" : "pgp-signed");
+ parameter_setval(&b->parameter, "charset", send_charset);
b->filename = m_strdup(pgpoutfile);
-#if 0
- /* The following is intended to give a clue to some completely brain-dead
- * "mail environments" which are typically used by large corporations.
- */
-
- b->d_filename = m_strdup("msg.pgp");
- b->use_disp = 1;
-
-#endif
-
b->disposition = DISPINLINE;
b->unlink = 1;
t = mutt_new_body ();
t->type = TYPEAPPLICATION;
t->subtype = m_strdup("x-pkcs7-mime");
- mutt_set_parameter ("name", "smime.p7m", &t->parameter);
- mutt_set_parameter ("smime-type", "enveloped-data", &t->parameter);
+ parameter_setval(&t->parameter, "name", "smime.p7m");
+ parameter_setval(&t->parameter, "smime-type", "enveloped-data");
t->encoding = ENCBASE64; /* The output of OpenSSL SHOULD be binary */
t->use_disp = 1;
t->disposition = DISPATTACH;
t->use_disp = 0;
t->disposition = DISPINLINE;
- mutt_generate_boundary (&t->parameter);
+ parameter_set_boundary(&t->parameter);
/* check if this can be extracted from private key somehow.... */
- mutt_set_parameter ("micalg", "sha1", &t->parameter);
- mutt_set_parameter ("protocol", "application/x-pkcs7-signature",
- &t->parameter);
+ parameter_setval(&t->parameter, "micalg", "sha1");
+ parameter_setval(&t->parameter, "protocol",
+ "application/x-pkcs7-signature");
t->parts = a;
a = t;
}
-
-
-
-
/*
* Handling S/MIME - bodies.
*/
-
-
-
-
static
pid_t smime_invoke_verify (FILE ** smimein, FILE ** smimeout,
FILE ** smimeerr, int smimeinfd, int smimeoutfd,
/****************************************************************************/
typedef struct address_t {
+ struct address_t *next;
char *personal; /* real name of address */
char *mailbox; /* mailbox and host address */
int group; /* group mailbox? */
- struct address_t *next;
} address_t;
DO_INIT(address_t, address);
/* rfc822 header parameters */
/****************************************************************************/
-typedef struct parameter {
+typedef struct parameter_t {
+ struct parameter_t *next;
char *attribute;
char *value;
- struct parameter *next;
-} PARAMETER;
+} parameter_t;
-DO_INIT(PARAMETER, parameter);
-static inline void parameter_wipe(PARAMETER *param) {
+DO_INIT(parameter_t, parameter);
+static inline void parameter_wipe(parameter_t *param) {
p_delete(¶m->attribute);
p_delete(¶m->value);
}
-DO_NEW(PARAMETER, parameter);
-DO_DELETE(PARAMETER, parameter);
-DO_SLIST(PARAMETER, parameter, parameter_delete);
+DO_NEW(parameter_t, parameter);
+DO_DELETE(parameter_t, parameter);
+DO_SLIST(parameter_t, parameter, parameter_delete);
+
+char *parameter_getval(parameter_t *, const char *);
+void parameter_setval(parameter_t **, const char *, const char *);
+void parameter_delval(parameter_t ** p, const char *);
+void parameter_set_boundary(parameter_t **);
-char *parameter_getval(PARAMETER *, const char *);
+int parameter_equal(const parameter_t *, const parameter_t *);
/****************************************************************************/
/* rfc822 envelopes */
typedef struct body {
char *xtype; /* content-type if x-unknown */
char *subtype; /* content-type subtype */
- PARAMETER *parameter; /* parameters of the content-type */
+ parameter_t *parameter; /* parameters of the content-type */
char *description; /* content-description */
char *form_name; /* Content-Disposition form-data name param */
off_t hdr_offset; /* offset in stream where the headers begin.
#include "mutt.h"
+#define BOUNDARYLEN 16
+
const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t";
const char *BodyTypes[] = {
/* rfc822 header parameters */
/****************************************************************************/
-char *parameter_getval(PARAMETER *parm, const char *s)
+char *parameter_getval(parameter_t *parm, const char *s)
{
while (parm) {
if (!ascii_strcasecmp(parm->attribute, s))
return NULL;
}
+void parameter_setval(parameter_t **p, const char *attribute, const char *value)
+{
+ while (*p) {
+ if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
+ if (value) {
+ m_strreplace(&(*p)->value, value);
+ } else {
+ parameter_t *q = parameter_list_pop(p);
+ parameter_delete(&q);
+ }
+ return;
+ }
+ p = &(*p)->next;
+ }
+
+ if (value) {
+ (*p) = parameter_new();
+ (*p)->attribute = m_strdup(attribute);
+ (*p)->value = m_strdup(value);
+ }
+}
+
+void parameter_delval(parameter_t **p, const char *attribute)
+{
+ while (*p) {
+ if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
+ parameter_t *q = parameter_list_pop(p);
+ parameter_delete(&q);
+ return;
+ }
+
+ p = &(*p)->next;
+ }
+}
+
+int parameter_equal(const parameter_t *p1, const parameter_t *p2)
+{
+ while (p1 && p2) {
+ if (m_strcmp(p1->attribute, p2->attribute)
+ || m_strcmp(p1->value, p2->value))
+ return 0;
+
+ p1 = p1->next;
+ p2 = p2->next;
+ }
+
+ if (p1 || p2)
+ return 0;
+
+ return 1;
+}
+
+void parameter_set_boundary(parameter_t **parm)
+{
+ char rs[BOUNDARYLEN + 1];
+ int i;
+
+ for (i = 0; i < BOUNDARYLEN; i++) {
+ rs[i] = __m_b64chars[lrand48() % sizeof(__m_b64chars)];
+ }
+ rs[BOUNDARYLEN] = '\0';
+
+ parameter_setval(parm, "boundary", rs);
+}
+
+
/****************************************************************************/
/* XXX */
/****************************************************************************/
/****************************************************************************/
int rfc2231_encode_string(char **);
-void rfc2231_decode_parameters(PARAMETER **);
+void rfc2231_decode_parameters(parameter_t **);
#endif /* MUTT_LIB_MIME_MIME_H */
*list = par;
}
-static void purge_empty_parameters(PARAMETER **headp)
+static void purge_empty_parameters(parameter_t **headp)
{
while (*headp) {
- PARAMETER *p = *headp;
+ parameter_t *p = *headp;
if (!p->attribute || !p->value) {
p = parameter_list_pop(headp);
/* process continuation parameters */
/* XXX: MC: not read */
static void
-rfc2231_join_continuations(PARAMETER **head, rfc2231_param *par)
+rfc2231_join_continuations(parameter_t **head, rfc2231_param *par)
{
rfc2231_param *q;
/****************************************************************************/
/* XXX: MC: not read */
-void rfc2231_decode_parameters (PARAMETER ** headp)
+void rfc2231_decode_parameters (parameter_t ** headp)
{
- PARAMETER *head = NULL;
- PARAMETER **last;
- PARAMETER *p, *q;
+ parameter_t *head = NULL;
+ parameter_t **last;
+ parameter_t *p, *q;
rfc2231_param *conthead = NULL;
rfc2231_param *conttmp;
}
}
-static PARAMETER *parse_parameters(const char *s)
+static parameter_t *parse_parameters(const char *s)
{
- PARAMETER *res = NULL;
- PARAMETER **list = &res;
+ parameter_t *res = NULL;
+ parameter_t **list = &res;
while (*s) {
const char *p;
- PARAMETER *new;
+ parameter_t *new;
int i;
s = skipspaces(s);
if (ct->type == TYPETEXT) {
pc = parameter_getval(ct->parameter, "charset");
if (!pc) {
- mutt_set_parameter("charset",
- option(OPTSTRICTMIME) ? "us-ascii" :
- charset_getfirst(AssumedCharset),
- &ct->parameter);
+ parameter_setval(&ct->parameter, "charset",
+ option(OPTSTRICTMIME)
+ ? "us-ascii"
+ : charset_getfirst(AssumedCharset));
}
}
}
/* Check to see if a default filename was given */
if ((s = strchr (s, ';'))) {
- PARAMETER *parms = parse_parameters(vskipspaces(s));
+ parameter_t *parms = parse_parameters(vskipspaces(s));
if ((s = parameter_getval(parms, "filename")))
m_strreplace(&ct->filename, s);
char tmp[_POSIX_PATH_MAX];
BODY *b;
- PARAMETER *par, **ppar;
+ parameter_t *par, **ppar;
short use_disp;
return (s);
}
-void mutt_set_parameter (const char *attribute, const char *value,
- PARAMETER ** p)
-{
- PARAMETER *q;
-
- if (!value) {
- mutt_delete_parameter (attribute, p);
- return;
- }
-
- for (q = *p; q; q = q->next) {
- if (ascii_strcasecmp (attribute, q->attribute) == 0) {
- m_strreplace(&q->value, value);
- return;
- }
- }
-
- q = parameter_new();
- q->attribute = m_strdup(attribute);
- q->value = m_strdup(value);
- parameter_list_push(p, q);
-}
-
-void mutt_delete_parameter (const char *attribute, PARAMETER ** p)
-{
- while (*p) {
- if (!ascii_strcasecmp(attribute, (*p)->attribute)) {
- PARAMETER *q = parameter_list_pop(p);
- parameter_delete(&q);
- return;
- }
-
- p = &(*p)->next;
- }
-}
-
/* returns 1 if Mutt can't display this type of data, 0 otherwise */
int mutt_needs_mailcap (BODY * m)
{
}
}
-int mutt_cmp_param (const PARAMETER * p1, const PARAMETER * p2)
-{
- while (p1 && p2) {
- if (m_strcmp(p1->attribute, p2->attribute) ||
- m_strcmp(p1->value, p2->value))
- return (0);
-
- p1 = p1->next;
- p2 = p2->next;
- }
- if (p1 || p2)
- return (0);
-
- return (1);
-}
-
int mutt_cmp_body (const BODY * b1, const BODY * b2)
{
if (b1->type != b2->type ||
b1->encoding != b2->encoding ||
m_strcmp(b1->subtype, b2->subtype) ||
m_strcmp(b1->description, b2->description) ||
- !mutt_cmp_param (b1->parameter, b2->parameter) ||
+ !parameter_equal(b1->parameter, b2->parameter) ||
b1->length != b2->length)
return (0);
return (1);
b->noconv = 0;
}
- mutt_delete_parameter ("x-mutt-noconv", &b->parameter);
+ parameter_delval(&b->parameter, "x-mutt-noconv");
}
mutt_adv_mktemp (NULL, file, sizeof (file));
b->type = TYPETEXT;
m_strreplace(&b->subtype, "plain");
- mutt_delete_parameter ("x-action", &b->parameter);
+ parameter_delval(&b->parameter, "x-action");
}
else
mutt_decode_attachment (b, &s);
void mutt_FormatString (char *, ssize_t, const char *, format_t *,
unsigned long, format_flag);
-void mutt_generate_boundary (PARAMETER **);
-void mutt_delete_parameter (const char *attribute, PARAMETER ** p);
-void mutt_set_parameter (const char *, const char *, PARAMETER **);
-
FILE *mutt_open_read (const char *, pid_t *);
void set_quadoption (int, int);
int mutt_cmp_addr (const address_t * a, const address_t * b);
int mutt_cmp_list (const string_list_t * a, const string_list_t * b);
int mutt_cmp_env (const ENVELOPE * e1, const ENVELOPE * e2);
-int mutt_cmp_param (const PARAMETER * p1, const PARAMETER * p2);
int mutt_cmp_body (const BODY * b1, const BODY * b2);
time_t mutt_decrease_mtime (const char *, struct stat *);
msg->content->disposition = DISPINLINE;
if (option (OPTTEXTFLOWED) && msg->content->type == TYPETEXT
&& !ascii_strcasecmp (msg->content->subtype, "plain")) {
- mutt_set_parameter ("format", "flowed", &msg->content->parameter);
+ parameter_setval(&msg->content->parameter, "format", "flowed");
if (option (OPTDELSP))
- mutt_set_parameter ("delsp", "yes", &msg->content->parameter);
+ parameter_setval(&msg->content->parameter, "delsp", "yes");
}
if (!tempfile) {
fprintf (f, "Content-Type: %s/%s", TYPE (a), a->subtype);
if (a->parameter) {
- PARAMETER *p;
+ parameter_t *p;
len = 25 + m_strlen(a->subtype); /* approximate len. of content-type */
#undef write_as_text_part
-#define BOUNDARYLEN 16
-void mutt_generate_boundary (PARAMETER ** parm)
-{
- char rs[BOUNDARYLEN + 1];
- char *p = rs;
- int i;
-
- rs[BOUNDARYLEN] = 0;
- for (i = 0; i < BOUNDARYLEN; i++)
- *p++ = __m_b64chars[lrand48() % sizeof(__m_b64chars)];
- *p = 0;
-
- mutt_set_parameter ("boundary", rs, parm);
-}
-
typedef struct {
int from;
int whitespace;
&fromcode, &tocode, info) != -1) {
if (!chs) {
charset_canonicalize (chsbuf, sizeof (chsbuf), tocode);
- mutt_set_parameter ("charset", chsbuf, &b->parameter);
+ parameter_setval(&b->parameter, "charset", chsbuf);
}
b->file_charset = fromcode;
p_delete(&tocode);
safe_fclose (&fp);
if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
- mutt_set_parameter ("charset", (!info->hibin ? "us-ascii" :
- Charset
- && !charset_is_us_ascii (Charset) ? Charset :
- "unknown-8bit"), &b->parameter);
+ parameter_setval(&b->parameter, "charset",
+ (!info->hibin ? "us-ascii"
+ : Charset && !charset_is_us_ascii(Charset) ? Charset : "unknown-8bit"));
return info;
}
a->noconv = 0;
if (!a->force_charset && !a->noconv)
- mutt_delete_parameter ("charset", &a->parameter);
+ parameter_delval(&a->parameter, "charset");
if ((info = mutt_get_content_info (a->filename, a)) == NULL)
return;
new->type = TYPEMULTIPART;
new->subtype = m_strdup("mixed");
new->encoding = get_toplevel_encoding (b);
- mutt_generate_boundary (&new->parameter);
+ parameter_set_boundary(&new->parameter);
new->use_disp = 0;
new->disposition = DISPINLINE;
new->parts = b;
if (b->type == TYPEMESSAGE || b->type == TYPEMULTIPART)
set_noconv_flags (b->parts, flag);
else if (b->type == TYPETEXT && b->noconv) {
- if (flag)
- mutt_set_parameter ("x-mutt-noconv", "yes", &b->parameter);
- else
- mutt_delete_parameter ("x-mutt-noconv", &b->parameter);
+ parameter_setval(&b->parameter, "x-mutt-noconv", flag ? "yes" : NULL);
}
}
}