From aa2a797ae63d7bfc00c3599261171844b2cd62dc Mon Sep 17 00:00:00 2001 From: Michael Elkins Date: Sat, 11 Sep 2010 07:34:26 -0700 Subject: [PATCH] add DISPNONE to mean no preferred Content-Disposition; make pgp-signature parts DISPNONE for multipart/signed --- crypt-gpgme.c | 4 ++-- mime.h | 3 ++- pgp.c | 6 +++--- recvattach.c | 13 ++++++++++-- sendlib.c | 58 ++++++++++++++++++++++++++++++++------------------- 5 files changed, 54 insertions(+), 30 deletions(-) diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 98987640..ca69edd2 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -918,7 +918,7 @@ static BODY *sign_message (BODY *a, int use_smime) { t->subtype = safe_strdup ("pgp-signature"); t->use_disp = 0; - t->disposition = DISPINLINE; + t->disposition = DISPNONE; t->encoding = ENC7BIT; } t->filename = sigfile; @@ -991,7 +991,7 @@ BODY *pgp_gpgme_encrypt_message (BODY *a, char *keylist, int sign) t->parts->next->encoding = ENC7BIT; t->parts->next->filename = outfile; t->parts->next->use_disp = 1; - t->parts->next->disposition = DISPINLINE; + t->parts->next->disposition = DISPATTACH; t->parts->next->unlink = 1; /* delete after sending the message */ t->parts->next->d_filename = safe_strdup ("msg.asc"); /* non pgp/mime can save */ diff --git a/mime.h b/mime.h index a374f25a..aec90722 100644 --- a/mime.h +++ b/mime.h @@ -48,7 +48,8 @@ enum { DISPINLINE, DISPATTACH, - DISPFORMDATA + DISPFORMDATA, + DISPNONE /* no preferred disposition */ }; /* MIME encoding/decoding global vars */ diff --git a/pgp.c b/pgp.c index a4208442..bf3640a6 100644 --- a/pgp.c +++ b/pgp.c @@ -1126,7 +1126,7 @@ BODY *pgp_sign_message (BODY *a) t->subtype = safe_strdup ("pgp-signature"); t->filename = safe_strdup (sigfile); t->use_disp = 0; - t->disposition = DISPINLINE; + t->disposition = DISPNONE; t->encoding = ENC7BIT; t->unlink = 1; /* ok to remove this file after sending. */ @@ -1378,7 +1378,7 @@ BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) t->parts->next->encoding = ENC7BIT; t->parts->next->filename = safe_strdup (tempfile); t->parts->next->use_disp = 1; - t->parts->next->disposition = DISPINLINE; + t->parts->next->disposition = DISPATTACH; t->parts->next->unlink = 1; /* delete after sending the message */ t->parts->next->d_filename = safe_strdup ("msg.asc"); /* non pgp/mime can save */ @@ -1557,7 +1557,7 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) #endif - b->disposition = DISPINLINE; + b->disposition = DISPNONE; b->unlink = 1; b->noconv = 1; diff --git a/recvattach.c b/recvattach.c index fc75b1bc..d9d87bcc 100644 --- a/recvattach.c +++ b/recvattach.c @@ -276,8 +276,17 @@ const char *mutt_attach_fmt (char *dest, case 'I': if (!optional) { - snprintf (dest, destlen, "%c", - (aptr->content->disposition == DISPINLINE) ? 'I' : 'A'); + const char dispchar[] = { 'I', 'A', 'F', '-' }; + char ch; + + if (aptr->content->disposition < sizeof(dispchar)) + ch = dispchar[aptr->content->disposition]; + else + { + dprint(1, (debugfile, "ERROR: invalid content-disposition %d\n", aptr->content->disposition)); + ch = '!'; + } + snprintf (dest, destlen, "%c", ch); } break; case 'm': diff --git a/sendlib.c b/sendlib.c index b252e088..8297ad5d 100644 --- a/sendlib.c +++ b/sendlib.c @@ -63,8 +63,6 @@ extern char RFC822Specials[]; -#define DISPOSITION(X) X==DISPATTACH?"attachment":"inline" - const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t"; char B64Chars[64] = { @@ -355,34 +353,50 @@ int mutt_write_mime_header (BODY *a, FILE *f) if (a->description) fprintf(f, "Content-Description: %s\n", a->description); - fprintf (f, "Content-Disposition: %s", DISPOSITION (a->disposition)); - - if (a->use_disp) + if (a->disposition != DISPNONE) { - if(!(fn = a->d_filename)) - fn = a->filename; + const char *dispstr[] = { + "inline", + "attachment", + "form-data" + }; - if (fn) + if (a->disposition < sizeof(dispstr)/sizeof(char*)) { - char *tmp; + fprintf (f, "Content-Disposition: %s", dispstr[a->disposition]); - /* Strip off the leading path... */ - if ((t = strrchr (fn, '/'))) - t++; - else - t = fn; + if (a->use_disp) + { + if (!(fn = a->d_filename)) + fn = a->filename; - buffer[0] = 0; - tmp = safe_strdup (t); - encode = rfc2231_encode_string (&tmp); - rfc822_cat (buffer, sizeof (buffer), tmp, MimeSpecials); - FREE (&tmp); - fprintf (f, "; filename%s=%s", encode ? "*" : "", buffer); + if (fn) + { + char *tmp; + + /* Strip off the leading path... */ + if ((t = strrchr (fn, '/'))) + t++; + else + t = fn; + + buffer[0] = 0; + tmp = safe_strdup (t); + encode = rfc2231_encode_string (&tmp); + rfc822_cat (buffer, sizeof (buffer), tmp, MimeSpecials); + FREE (&tmp); + fprintf (f, "; filename%s=%s", encode ? "*" : "", buffer); + } + } + + fputc ('\n', f); + } + else + { + dprint(1, (debugfile, "ERROR: invalid content-disposition %d\n", a->disposition)); } } - fputc ('\n', f); - if (a->encoding != ENC7BIT) fprintf(f, "Content-Transfer-Encoding: %s\n", ENCODING (a->encoding)); -- 2.40.0