diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 1998-11-18 22:56:57 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 1998-11-18 22:56:57 +0000 |
commit | b226bc2cc5db75b72c08042b95977c28b9ef2322 (patch) | |
tree | e6a594d7eca4356caee700156546ebd26c508433 | |
parent | 98df548e97d14a9f6ba75e7c4cea7cbfbf389cef (diff) |
This patch simplifies the generation of content type parameters
significantly by introducing a funciton mutt_set_parameter().
Additionally, we re-use code from parse.c for parsing user-input
content type headers on the compose screen.
-rw-r--r-- | compose.c | 31 | ||||
-rw-r--r-- | lib.c | 23 | ||||
-rw-r--r-- | parse.c | 6 | ||||
-rw-r--r-- | pgp.c | 30 | ||||
-rw-r--r-- | protos.h | 5 | ||||
-rw-r--r-- | sendlib.c | 33 |
6 files changed, 64 insertions, 64 deletions
@@ -720,19 +720,26 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ idx[menu->current]->content->subtype); if (mutt_get_field ("Content-Type: ", buf, sizeof (buf), 0) == 0 && buf[0]) { - char *p = strchr (buf, '/'); + char *s; + PARAMETER *par; + BODY *b; + + b = idx[menu->current]->content; + + s = b->filename; par = b->parameter; + b->filename = NULL; b->parameter = NULL; + + mutt_parse_content_type(buf, b); - if (p) - { - *p++ = 0; - if ((i = mutt_check_mime_type (buf)) != TYPEOTHER) - { - idx[menu->current]->content->type = i; - safe_free ((void **) &idx[menu->current]->content->subtype); - idx[menu->current]->content->subtype = safe_strdup (p); - menu->redraw = REDRAW_CURRENT; - } - } + safe_free((void **) &b->filename); + b->filename =s; + + if ((s = mutt_get_parameter("charset", b->parameter))) + mutt_set_parameter("charset", s, &par); + + /* ignore the other parameters for now */ + mutt_free_parameter(&b->parameter); + b->parameter = par; } break; @@ -385,6 +385,29 @@ char *mutt_get_parameter (const char *s, PARAMETER *p) return NULL; } +void mutt_set_parameter (const char *attribute, const char *value, PARAMETER **p) +{ + PARAMETER *q; + for(q = *p; q; q = q->next) + { + if (mutt_strcasecmp (attribute, q->attribute) == 0) + { + safe_free((void **) &q->value); + q->value = safe_strdup(value); + return; + } + } + + q = mutt_new_parameter(); + q->attribute = safe_strdup(attribute); + q->value = safe_strdup(value); + q->next = *p; + *p = q; +} + + + + /* returns 1 if Mutt can't display this type of data, 0 otherwise */ int mutt_needs_mailcap (BODY *m) { @@ -245,7 +245,7 @@ int mutt_check_mime_type (const char *s) return TYPEOTHER; } -static void parse_content_type (char *s, BODY *ct) +void mutt_parse_content_type (char *s, BODY *ct) { char *pc; char *subtype; @@ -382,7 +382,7 @@ BODY *mutt_read_mime_header (FILE *fp, int digest) if (!mutt_strncasecmp ("content-", line, 8)) { if (!mutt_strcasecmp ("type", line + 8)) - parse_content_type (c, p); + mutt_parse_content_type (c, p); else if (!mutt_strcasecmp ("transfer-encoding", line + 8)) p->encoding = mutt_check_encoding (c); else if (!mutt_strcasecmp ("disposition", line + 8)) @@ -928,7 +928,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs) if (mutt_strcasecmp (line+8, "type") == 0) { if (hdr) - parse_content_type (p, hdr->content); + mutt_parse_content_type (p, hdr->content); matched = 1; } else if (mutt_strcasecmp (line+8, "transfer-encoding") == 0) @@ -1031,7 +1031,6 @@ static void convert_to_7bit (BODY *a) static BODY *pgp_sign_message (BODY *a) { - PARAMETER *p; BODY *t; char buffer[LONG_STRING]; char sigfile[_POSIX_PATH_MAX], signedfile[_POSIX_PATH_MAX]; @@ -1129,19 +1128,9 @@ static BODY *pgp_sign_message (BODY *a) t->use_disp = 0; t->encoding = ENC7BIT; - t->parameter = p = mutt_new_parameter (); - p->attribute = safe_strdup ("protocol"); - p->value = safe_strdup ("application/pgp-signature"); - - p->next = mutt_new_parameter (); - p = p->next; - p->attribute = safe_strdup ("micalg"); - p->value = safe_strdup (PgpSignMicalg); - - p->next = mutt_new_parameter (); - p = p->next; - p->attribute = safe_strdup ("boundary"); - p->value = mutt_generate_boundary (); + mutt_set_parameter ("protocol", "application/pgp-signature", &t->parameter); + mutt_set_parameter ("micalg", PgpSignMicalg, &t->parameter); + mutt_generate_boundary (&t->parameter); t->parts = a; a = t; @@ -1243,7 +1232,6 @@ static BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) char pgpinfile[_POSIX_PATH_MAX]; FILE *pgpin, *pgperr, *fpout, *fptmp; BODY *t; - PARAMETER *p; int err = 0; int empty; pid_t thepid; @@ -1337,15 +1325,9 @@ static BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) t->encoding = ENC7BIT; t->use_disp = 0; - t->parameter = p = mutt_new_parameter (); - p->attribute = safe_strdup ("protocol"); - p->value = safe_strdup ("application/pgp-encrypted"); - - p->next = mutt_new_parameter (); - p = p->next; - p->attribute = safe_strdup ("boundary"); - p->value = mutt_generate_boundary (); - + mutt_set_parameter("protocol", "application/pgp-encrypted", &t->parameter); + mutt_generate_boundary(&t->parameter); + t->parts = mutt_new_body (); t->parts->type = TYPEAPPLICATION; t->parts->subtype = safe_strdup ("pgp-encrypted"); @@ -63,8 +63,10 @@ int _mutt_traverse_thread (CONTEXT *ctx, HEADER *hdr, int flag); typedef const char * format_t (char *, size_t, char, const char *, const char *, const char *, const char *, unsigned long, format_flag); void mutt_FormatString (char *, size_t, const char *, format_t *, unsigned long, format_flag); - +void mutt_parse_content_type (char *, BODY *); void mutt_update_encoding (BODY *a); +void mutt_generate_boundary (PARAMETER **); +void mutt_set_parameter (const char *, const char *, PARAMETER **); FILE *mutt_open_read (const char *, pid_t *); @@ -110,7 +112,6 @@ const char *mutt_attach_fmt ( char *mutt_expand_path (char *, size_t); char *mutt_find_hook (int, const char *); -char *mutt_generate_boundary (void); char *mutt_gen_msgid (void); char *mutt_get_name (ADDRESS *); char *mutt_get_parameter (const char *, PARAMETER *); @@ -535,16 +535,18 @@ int mutt_write_mime_body (BODY *a, FILE *f) } #define BOUNDARYLEN 16 -char *mutt_generate_boundary (void) +void mutt_generate_boundary (PARAMETER **parm) { - char *rs = (char *)safe_malloc (BOUNDARYLEN + 1); + char rs[BOUNDARYLEN + 1]; char *p = rs; int i; rs[BOUNDARYLEN] = 0; - for (i=0;i<BOUNDARYLEN;i++) *p++ = B64Chars[LRAND() % sizeof (B64Chars)]; + for (i=0;i<BOUNDARYLEN;i++) + *p++ = B64Chars[LRAND() % sizeof (B64Chars)]; *p = 0; - return (rs); + + mutt_set_parameter ("boundary", rs, parm); } /* analyze the contents of a file to determine which MIME encoding to use */ @@ -935,19 +937,7 @@ void mutt_update_encoding (BODY *a) mutt_stamp_attachment(a); if (a->type == TYPETEXT) - { - /* make sure the charset is valid */ - if (a->parameter) - safe_free ((void **) &a->parameter->value); - else - { - a->parameter = mutt_new_parameter (); - a->parameter->attribute = safe_strdup ("charset"); - } - a->parameter->value = safe_strdup (set_text_charset (info)); - } - - + mutt_set_parameter ("charset", set_text_charset (info), &a->parameter); #ifdef _PGPPATH /* save the info in case this message is signed. we will want to do Q-P @@ -1077,9 +1067,8 @@ BODY *mutt_make_file_attach (const char *path) */ att->type = TYPETEXT; att->subtype = safe_strdup ("plain"); - att->parameter = mutt_new_parameter (); - att->parameter->attribute = safe_strdup ("charset"); - att->parameter->value = safe_strdup (set_text_charset (info)); + + mutt_set_parameter("charset", set_text_charset(info), &att->parameter); } else { @@ -1131,9 +1120,7 @@ BODY *mutt_make_multipart (BODY *b) new->type = TYPEMULTIPART; new->subtype = safe_strdup ("mixed"); new->encoding = get_toplevel_encoding (b); - new->parameter = mutt_new_parameter (); - new->parameter->attribute = safe_strdup ("boundary"); - new->parameter->value = mutt_generate_boundary (); + mutt_generate_boundary(&new->parameter); new->use_disp = 0; new->parts = b; |