From 37652c6ff8acf7acb2196371a2c049647fc4b6c5 Mon Sep 17 00:00:00 2001 From: Eduardo Chappa Date: Sun, 31 Jul 2016 20:38:01 -0600 Subject: [PATCH] * When Alpine opens an attachment, it sometimes changes the extension of the file that is being opened and replaces it by another for the same mime type. If Alpine finds that the extension of the file corresponds with the mime type, according to the mime-types file, then it will keep it, and no substitution will be made. --- alpine/mailpart.c | 10 +++++----- pith/mimetype.c | 18 ++++++++++++++++++ pith/mimetype.h | 1 + pith/pine.hlp | 6 ++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/alpine/mailpart.c b/alpine/mailpart.c index ac8cdd7..651786c 100644 --- a/alpine/mailpart.c +++ b/alpine/mailpart.c @@ -2115,11 +2115,11 @@ display_attachment(long int msgno, ATTACH_S *a, int flags) (void) get_filename_parameter(sender_filename, sizeof(sender_filename), a->body, &extp); - if(!set_mime_extension_by_type(ext, mtype)){ /* extension from type */ - if(extp && extp[0]){ /* extension from filename */ - strncpy(ext, extp, sizeof(ext)); - ext[sizeof(ext)-1] = '\0'; - } + if(check_mime_type_by_extension(extp, mtype) + || (!set_mime_extension_by_type(ext, mtype) /* extension from type */ + && extp && extp[0])){ /* extension from filename */ + strncpy(ext, extp, sizeof(ext)); + ext[sizeof(ext)-1] = '\0'; } /* create a temp file */ diff --git a/pith/mimetype.c b/pith/mimetype.c index a529226..5b5bed7 100644 --- a/pith/mimetype.c +++ b/pith/mimetype.c @@ -18,6 +18,7 @@ static char rcsid[] = "$Id: mimetype.c 955 2008-03-06 23:52:36Z hubert@u.washing #include "../pith/headers.h" #include "../pith/mimetype.h" +#include "../pith/mimedesc.h" #include "../pith/state.h" #include "../pith/conf.h" #include "../pith/mailcap.h" @@ -92,6 +93,23 @@ set_mime_extension_by_type (char *ext, char *mtype) } +int +check_mime_type_by_extension (char *ext, char *mtype) +{ + MT_MAP_T e2t; + char mimet[128]; + + if((e2t.from.ext = ext) != NULL && *e2t.from.ext + && mt_srch_mime_type(mt_srch_by_ext, &e2t)){ + snprintf(mimet, sizeof(mimet), "%s/%s", + body_type_names(e2t.to.mime.type), e2t.to.mime.subtype); + mimet[sizeof(mimet) - 1] = '\0'; + fs_give((void **)& e2t.to.mime.subtype); + return strucmp(mimet, mtype) ? 0 : 1; + } + + return(0); +} /* diff --git a/pith/mimetype.h b/pith/mimetype.h index 62f2044..0f06b4b 100644 --- a/pith/mimetype.h +++ b/pith/mimetype.h @@ -42,6 +42,7 @@ typedef int (* MT_OPERATORPROC)(MT_MAP_T *, FILE *); /* exported protoypes */ int set_mime_type_by_extension(BODY *, char *); int set_mime_extension_by_type(char *, char *); +int check_mime_type_by_extension(char *, char *); int mt_srch_by_ext(MT_MAP_T *, FILE *); int mt_get_file_ext(char *, char **); int mt_srch_mime_type(MT_OPERATORPROC, MT_MAP_T *); diff --git a/pith/pine.hlp b/pith/pine.hlp index a195096..36d6940 100644 --- a/pith/pine.hlp +++ b/pith/pine.hlp @@ -341,6 +341,12 @@ Additions include:
  • When selecting messages by number, the "." character can be used to specify the message on which the cursor is on. + +
  • When Alpine opens an attachment, it sometimes changes the extension + of the file that is being opened and replaces it by another for the + same mime type. If Alpine finds that the extension of the file + corresponds with the mime type, according to the mime-types file, + then it will keep it, and no substitution will be made. -- 2.11.4.GIT