From: Pierre Habouzit Date: Fri, 30 Mar 2007 23:19:57 +0000 (+0200) Subject: More things to the Mime package. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=92c3d4c767ddbc0e0c64dd6e132ce10627550580;p=apps%2Fmadmutt.git More things to the Mime package. Signed-off-by: Pierre Habouzit --- diff --git a/globals.h b/globals.h index 921a8bf..bd0caf6 100644 --- a/globals.h +++ b/globals.h @@ -76,9 +76,6 @@ WHERE short NetInc; WHERE char *Mixmaster; WHERE char *MixEntryFormat; - -WHERE char *OperatingSystem INITVAL (NULL); - WHERE char *Muttrc INITVAL (NULL); #ifdef USE_NNTP @@ -148,15 +145,12 @@ WHERE char *XtermIcon; WHERE char *CurrentFolder; WHERE char *LastFolder; -WHERE string_list_t *AutoViewList INITVAL (0); -WHERE string_list_t *AlternativeOrderList INITVAL (0); WHERE string_list_t *AttachAllow INITVAL(0); WHERE string_list_t *AttachExclude INITVAL(0); WHERE string_list_t *InlineAllow INITVAL(0); WHERE string_list_t *InlineExclude INITVAL(0); WHERE string_list_t *HeaderOrderList INITVAL (0); WHERE string_list_t *Ignore INITVAL (0); -WHERE string_list_t *MimeLookupList INITVAL (0); WHERE string_list_t *UnIgnore INITVAL (0); /* bit vector for boolean variables */ diff --git a/init.c b/init.c index a897897..549ba24 100644 --- a/init.c +++ b/init.c @@ -519,40 +519,6 @@ int query_quadoption (int opt, const char *prompt) /* not reached */ } -static void add_to_list(string_list_t **list, const char *str) -{ - /* don't add a NULL or empty string to the list */ - if (m_strisempty(str)) - return; - - /* check to make sure the item is not already on this list */ - while (*list) { - if (!ascii_strcasecmp(str, (*list)->data)) - return; - list = &(*list)->next; - } - - *list = p_new(string_list_t, 1); - (*list)->data = m_strdup(str); -} - -static void remove_from_list(string_list_t **l, const char *str) -{ - if (!m_strcmp("*", str)) { - string_list_wipe(l); /* ``unCMD *'' means delete all current entries */ - return; - } - - while (*l) { - if (!ascii_strcasecmp(str, (*l)->data)) { - string_list_t *it = string_list_pop(l); - string_item_delete(&it); - } else { - l = &(*l)->next; - } - } -} - static int parse_unignore (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ ((unused)), BUFFER * err __attribute__ ((unused))) @@ -561,10 +527,12 @@ static int parse_unignore (BUFFER * buf, BUFFER * s, mutt_extract_token (buf, s, 0); /* don't add "*" to the unignore list */ - if (m_strcmp (buf->data, "*")) - add_to_list (&UnIgnore, buf->data); - - remove_from_list (&Ignore, buf->data); + if (m_strcmp(buf->data, "*")) { + string_list_add(&UnIgnore, buf->data); + string_list_remove(&Ignore, buf->data); + } else { + string_list_wipe(&Ignore); + } } while (MoreArgs (s)); return 0; @@ -576,8 +544,12 @@ static int parse_ignore (BUFFER * buf, BUFFER * s, { do { mutt_extract_token (buf, s, 0); - remove_from_list (&UnIgnore, buf->data); - add_to_list (&Ignore, buf->data); + if (m_strcmp(buf->data, "*")) { + string_list_remove(&UnIgnore, buf->data); + } else { + string_list_wipe(&UnIgnore); + } + string_list_add(&Ignore, buf->data); } while (MoreArgs(s)); return 0; } @@ -587,7 +559,7 @@ static int parse_list(BUFFER * buf, BUFFER * s, unsigned long data, { do { mutt_extract_token (buf, s, 0); - add_to_list ((string_list_t **) data, buf->data); + string_list_add ((string_list_t **) data, buf->data); } while (MoreArgs(s)); return 0; } @@ -600,11 +572,11 @@ static int parse_unlist (BUFFER * buf, BUFFER * s, unsigned long data, /* * Check for deletion of entire list */ - if (m_strcmp(buf->data, "*") == 0) { + if (!m_strcmp(buf->data, "*")) { string_list_wipe((string_list_t **) data); break; } - remove_from_list ((string_list_t **) data, buf->data); + string_list_remove((string_list_t **) data, buf->data); } while (MoreArgs (s)); @@ -713,7 +685,7 @@ static int parse_unattach_list (BUFFER *buf, BUFFER *s, string_list_t **ldata, } major = mutt_check_mime_type(tmp); - /* We must do our own walk here because remove_from_list() will only + /* We must do our own walk here because string_list_remove() will only * remove the string_list_t->data, not anything pointed to by the string_list_t->data. */ lastp = NULL; for(lp = *ldata; lp; ) { diff --git a/init.h b/init.h index 95c5285..7174182 100644 --- a/init.h +++ b/init.h @@ -1197,15 +1197,6 @@ struct option_t MuttVars[] = { ** This specifies the folder into which read mail in your ``$$spoolfile'' ** folder will be appended. */ - {"operating_system", DT_STR, R_NONE, UL &OperatingSystem, "" }, - /* - ** .pp - ** This specifies the operating system name for the \fTUser-Agent:\fP header field. If - ** this is \fIunset\fP, it will be set to the operating system name that \fTuname(2)\fP - ** returns. If \fTuname(2)\fP fails, ``UNIX'' will be used. - ** .pp - ** It may, for example, look as: ``\fTMadmutt 1.5.9i (Linux)\fP''. - */ {"sidebar_boundary", DT_STR, R_BOTH, UL &SidebarBoundary, "." }, /* ** .pp @@ -3440,10 +3431,7 @@ struct command_t Commands[] = { {"alias", parse_alias, 0}, {"attachments", parse_attachments, 0 }, {"ignore", parse_ignore, 0}, - {"alternative_order", parse_list, UL &AlternativeOrderList}, - {"auto_view", parse_list, UL &AutoViewList}, {"hdr_order", parse_list, UL &HeaderOrderList}, - {"mime_lookup", parse_list, UL &MimeLookupList}, {"my_hdr", parse_my_hdr, 0}, {"reset", parse_set, M_SET_RESET}, {"set", parse_set, 0}, @@ -3453,10 +3441,7 @@ struct command_t Commands[] = { {"unalias", parse_unalias, 0}, {"unattachments", parse_unattachments, 0}, {"unignore", parse_unignore, 0}, - {"unalternative_order", parse_unlist, UL &AlternativeOrderList}, - {"unauto_view", parse_unlist, UL &AutoViewList}, {"unhdr_order", parse_unlist, UL &HeaderOrderList}, - {"unmime_lookup", parse_unlist, UL &MimeLookupList}, {"unmy_hdr", parse_unmy_hdr, 0}, {NULL, NULL, 0} }; diff --git a/lib-lib/list.c b/lib-lib/list.c index 25a6125..c1a7039 100644 --- a/lib-lib/list.c +++ b/lib-lib/list.c @@ -48,6 +48,32 @@ int string_list_contains(const string_list_t *t, const char *s, const char *any) return 0; } +void string_list_add(string_list_t **list, const char *str) +{ + if (m_strisempty(str)) + return; + + while (*list) { + if (!ascii_strcasecmp(str, (*list)->data)) + return; + list = &(*list)->next; + } + + *list = p_new(string_list_t, 1); + (*list)->data = m_strdup(str); +} + +void string_list_remove(string_list_t **l, const char *str) +{ + while (*l) { + if (!ascii_strcasecmp(str, (*l)->data)) { + string_list_t *it = string_list_pop(l); + string_item_delete(&it); + } else { + l = &(*l)->next; + } + } +} /* FIXME: b0rken API's, replace that at any cost */ string_list_t *mutt_add_list_n(string_list_t *head, const void *data, size_t len) { diff --git a/lib-lib/list.h b/lib-lib/list.h index 957c900..4f54d32 100644 --- a/lib-lib/list.h +++ b/lib-lib/list.h @@ -87,6 +87,8 @@ DO_SLIST(string_list_t, string, string_item_delete); string_list_t *string_list_dup(const string_list_t *); int string_list_contains(const string_list_t *, const char *, const char *); +void string_list_add(string_list_t **, const char *); +void string_list_remove(string_list_t **l, const char *str); /* FIXME: b0rken API's, replace that at any cost */ /* add an element to a list */ diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index 6600270..110e565 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -133,6 +133,7 @@ exit 0 ## mailcap_path ## mailcap_sanitize ## no +## operating_system ## quit ## send_charset ## sendmail diff --git a/lib-lua/madmutt.cpkg b/lib-lua/madmutt.cpkg index d083405..9c2dc05 100644 --- a/lib-lua/madmutt.cpkg +++ b/lib-lua/madmutt.cpkg @@ -58,6 +58,12 @@ static char *madmutt_init_shorthost(void) return p_dupstr(utsname.nodename, p - utsname.nodename); } +static char *madmutt_init_os(void) +{ + struct utsname un; + return m_strdup(uname(&un) < 0 ? "Unix" : un.sysname); +} + static char *madmutt_init_hostname(void) { char buffer[STRING]; @@ -137,6 +143,16 @@ static char *madmutt_init_hostname(void) */ path_t shell = madmutt_init_shell(); + /* + ** .pp + ** This specifies the operating system name for the \fTUser-Agent:\fP header field. If + ** this is \fIunset\fP, it will be set to the operating system name that \fTuname(2)\fP + ** returns. If \fTuname(2)\fP fails, ``UNIX'' will be used. + ** .pp + ** It may, for example, look as: ``\fTMadmutt 1.5.9i (Linux)\fP''. + */ + string_t operating_system = madmutt_init_os(); + path_t username = madmutt_init_username(); path_t homedir = madmutt_init_homedir(); diff --git a/lib-mime/mime.cpkg b/lib-mime/mime.cpkg index 332bc1f..1340ad4 100644 --- a/lib-mime/mime.cpkg +++ b/lib-mime/mime.cpkg @@ -53,6 +53,7 @@ const char *BodyEncodings[] = { }; rx_t *SpamList = NULL, *NoSpamList = NULL; +string_list_t *AutoViewList, *AlternativeOrderList, *MimeLookupList; static char *mailcap_init(void) { @@ -110,6 +111,45 @@ static char *mailcap_init(void) } RETURN(); }; + + void auto_view(string_t s) { + string_list_add(&AutoViewList, s); + RETURN(); + }; + void unauto_view(string_t s) { + if (m_strcmp(s, "*")) { + string_list_remove(&AutoViewList, s); + } else { + string_list_wipe(&AutoViewList); + } + RETURN(); + }; + + void alternative_order(string_t s) { + string_list_add(&AlternativeOrderList, s); + RETURN(); + }; + void unalternative_order(string_t s) { + if (m_strcmp(s, "*")) { + string_list_remove(&AlternativeOrderList, s); + } else { + string_list_wipe(&AlternativeOrderList); + } + RETURN(); + }; + + void lookup(string_t s) { + string_list_add(&MimeLookupList, s); + RETURN(); + }; + void unlookup(string_t s) { + if (m_strcmp(s, "*")) { + string_list_remove(&MimeLookupList, s); + } else { + string_list_wipe(&MimeLookupList); + } + RETURN(); + }; }; /****************************************************************************/ diff --git a/lib-mime/mime.h b/lib-mime/mime.h index 7c0b7d3..0bbdea8 100644 --- a/lib-mime/mime.h +++ b/lib-mime/mime.h @@ -40,6 +40,10 @@ extern const char *BodyTypes[]; extern const char *BodyEncodings[]; extern rx_t *SpamList, *NoSpamList; +extern string_list_t *AutoViewList; +extern string_list_t *AlternativeOrderList; +extern string_list_t *MimeLookupList; + /* MIME encoding/decoding global vars */ #define is_multipart(x) \ diff --git a/sendlib.c b/sendlib.c index 1802e1d..ad29311 100644 --- a/sendlib.c +++ b/sendlib.c @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -1498,16 +1497,12 @@ int mutt_write_rfc822_header (FILE * fp, ENVELOPE * env, BODY * attach, } if (mode == 0 && !privacy && option (OPTXMAILER) && !has_agent) { - const char *os; - - if (OperatingSystem != NULL) { - os = OperatingSystem; + if (MCore.operating_system) { + fprintf(fp, "User-Agent: %s (%s)\n", mutt_make_version(), + MCore.operating_system); } else { - struct utsname un; - os = (uname(&un) == -1) ? "UNIX" : un.sysname; + fprintf(fp, "User-Agent: %s\n", mutt_make_version()); } - /* Add a vanity header */ - fprintf (fp, "User-Agent: %s (%s)\n", mutt_make_version(), os); } return (ferror (fp) == 0 ? 0 : -1);