X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-mime%2Frfc1524.c;h=422a82d23e2e5647adfa6d3812382a9c2a1db704;hp=4fe4f2b355222dd09ffaeb2c6435b108fa24752a;hb=5fbd8a74d24624a118c9b835b136c73b8da076d7;hpb=2a2f2f9a5bad73c883b7f9c9b4166d932b6aaf37 diff --git a/lib-mime/rfc1524.c b/lib-mime/rfc1524.c index 4fe4f2b..422a82d 100644 --- a/lib-mime/rfc1524.c +++ b/lib-mime/rfc1524.c @@ -35,24 +35,7 @@ * rfc1524. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include +#include #include @@ -60,6 +43,43 @@ #include "mime.h" #include "attach.h" +void rfc1524_entry_wipe(rfc1524_entry *p) +{ + p_delete(&p->command); + p_delete(&p->testcommand); + p_delete(&p->composecommand); + p_delete(&p->composetypecommand); + p_delete(&p->editcommand); + p_delete(&p->printcommand); + p_delete(&p->nametemplate); + p_delete(&p->convert); +} + +/* returns 1 if Mutt can't display this type of data, 0 otherwise */ +int rfc1524_mailcap_isneeded(BODY * m) +{ + switch (m->type) { + case TYPEMULTIPART: + case TYPEMESSAGE: + return 0; + + case TYPEAPPLICATION: + return !(mutt_is_application_pgp(m) || mutt_is_application_smime(m)); + + case TYPETEXT: + switch (mime_which_token(m->subtype, -1)) { + case MIME_PLAIN: + case MIME_RFC822_HEADERS: + case MIME_ENRICHED: + return 0; + default: + return 1; + } + default: + return 1; + } +} + /* The command semantics include the following: * %s is the filename that contains the mail body data * %t is the content type, like text/plain @@ -83,7 +103,7 @@ int rfc1524_expand_command(BODY *a, const char *filename, const char *mtype, m_strcpy(type, sizeof(type), mtype); - if (option(OPTMAILCAPSANITIZE)) + if (mod_mime.mailcap_sanitize) mutt_sanitize_filename(type, 0); while (command[x] && x < clen && y < ssizeof(buf)) { @@ -108,7 +128,7 @@ int rfc1524_expand_command(BODY *a, const char *filename, const char *mtype, m_strcpy(pval, sizeof(pval), parameter_getval(a->parameter, param)); - if (option(OPTMAILCAPSANITIZE)) + if (mod_mime.mailcap_sanitize) mutt_sanitize_filename(pval, 0); y += mutt_quote_filename(buf + y, sizeof(buf) - y, pval); @@ -281,7 +301,7 @@ rfc1524_mailcap_parse(BODY *a, const char *filename, const char *type, ssize_t len = m_strlen(value) + STRING; char *testcmd = p_new(char, len); - strcpy(testcmd, value); + m_strcpy(testcmd, len, value); rfc1524_expand_command(a, a->filename, type, testcmd, len); found = !mutt_system(testcmd); p_delete(&testcmd); @@ -318,7 +338,7 @@ rfc1524_mailcap_parse(BODY *a, const char *filename, const char *type, rfc1524_entry_init(entry); } } /* while (!found && (buf = mutt_read_line ())) */ - fclose (fp); + m_fclose(&fp); error: p_delete(&buf); @@ -326,60 +346,46 @@ rfc1524_mailcap_parse(BODY *a, const char *filename, const char *type, } -/************** READ MARK **********************/ - /* * rfc1524_mailcap_lookup attempts to find the given type in the * list of mailcap files. On success, this returns the entry information * in *entry, and returns 1. On failure (not found), returns 0. * If entry == NULL just return 1 if the given type is found. */ -int rfc1524_mailcap_lookup (BODY * a, char *type, rfc1524_entry * entry, - int opt) +int rfc1524_mailcap_lookup(BODY *a, char *type, rfc1524_entry *entry, int opt) { - char path[_POSIX_PATH_MAX]; - int x; - int found = FALSE; - char *curr = MailcapPath; - - /* rfc1524 specifies that a path of mailcap files should be searched. - * joy. They say - * $HOME/.mailcap:/etc/mailcap:/usr/etc/mailcap:/usr/local/etc/mailcap, etc - * and overriden by the MAILCAPS environment variable, and, just to be nice, - * we'll make it specifiable in .muttrc - */ - if (!curr || !*curr) { - mutt_error _("No mailcap path specified"); + const char *p = mod_mime.mailcap_path; - return 0; - } + mutt_check_lookup_list(a, type, STRING); - mutt_check_lookup_list (a, type, SHORT_STRING); + for (;;) { + const char *q; + char path[_POSIX_PATH_MAX]; - while (!found && *curr) { - x = 0; - while (*curr && *curr != ':' && x < ssizeof (path) - 1) { - path[x++] = *curr; - curr++; - } - if (*curr) - curr++; + while (*p == ':') + p++; + + if (!*p) + break; - if (!x) - continue; + q = strchrnul(p, ':'); + m_strncpy(path, sizeof(path), p, q - p); + mutt_expand_path(path, sizeof(path)); - path[x] = '\0'; - mutt_expand_path (path, sizeof (path)); + if (rfc1524_mailcap_parse(a, path, type, entry, opt)) + return 1; - found = rfc1524_mailcap_parse (a, path, type, entry, opt); - } + p = q; + } - if (entry && !found) - mutt_error (_("mailcap entry for type %s not found"), type); + if (entry) + mutt_error(_("mailcap entry for type %s not found"), type); - return found; + return 0; } +/************** READ MARK **********************/ + /* This routine will create a _temporary_ filename matching the * name template given if this needs to be done. @@ -417,9 +423,8 @@ int rfc1524_expand_filename (char *nametemplate, m_strcpy(newfile, nflen, oldfile); } else if (!oldfile) { - mutt_expand_fmt (newfile, nflen, nametemplate, "mutt"); - } - else { /* oldfile && nametemplate */ + m_file_fmt(newfile, nflen, nametemplate, "mutt"); + } else { /* oldfile && nametemplate */ /* first, compare everything left from the "%s"