From: Andrew Marks Date: Fri, 5 Jul 2019 15:44:21 +0000 (-0700) Subject: Added * option to unattachments command X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53d5550bf34cc927f2bdba9c712694e443db3abf;p=mutt Added * option to unattachments command The * option clears all previous attachments settings. A list_free_generic method is added to muttlib to enable generic freeing of specific LIST structures. free_attachments_data is used with list_free_generic to clear four LISTs which manage allowed and excluded inline and attached "attachments" refs #1 --- diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 01baff28..b77dde75 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -8145,7 +8145,12 @@ The syntax is: attachments -? + + + +unattachments + + @@ -8254,6 +8259,10 @@ a command will list your current settings in Muttrc format, so that it can be pasted elsewhere. + +Entering the command unattachments * as +a command will Clear all attachment settings. + @@ -10108,6 +10117,13 @@ The following are the commands understood by Mutt: mime-type + +attachments + + +unattachments + + diff --git a/init.c b/init.c index e02f1201..621cd3c1 100644 --- a/init.c +++ b/init.c @@ -1354,6 +1354,18 @@ static int parse_attachments (BUFFER *buf, BUFFER *s, union pointer_long_t udata return parse_attach_list(buf, s, listp, err); } +/* + * Cleanup a single LIST item who's data is an ATTACH_MATCH + */ +static void free_attachments_data (char **data) +{ + if (data == NULL || *data == NULL) return; + ATTACH_MATCH *a = (ATTACH_MATCH *) *data; + regfree(&a->minor_rx); + FREE (&a->major); + FREE (data); /*__FREE_CHECKED__*/ +} + static int parse_unattachments (BUFFER *buf, BUFFER *s, union pointer_long_t udata, BUFFER *err) { char op, *p; @@ -1368,6 +1380,17 @@ static int parse_unattachments (BUFFER *buf, BUFFER *s, union pointer_long_t uda p = buf->data; op = *p++; + + if (op == '*') + { + mutt_free_list_generic(&AttachAllow, free_attachments_data); + mutt_free_list_generic(&AttachExclude, free_attachments_data); + mutt_free_list_generic(&InlineAllow, free_attachments_data); + mutt_free_list_generic(&InlineExclude, free_attachments_data); + _attachments_clean(); + return 0; + } + if (op != '+' && op != '-') { op = '+'; diff --git a/mutt.h b/mutt.h index dcc3a2f1..77082bdb 100644 --- a/mutt.h +++ b/mutt.h @@ -640,6 +640,7 @@ typedef struct replace_list_t #define mutt_new_rx_list() safe_calloc (1, sizeof (RX_LIST)) #define mutt_new_replace_list() safe_calloc (1, sizeof (REPLACE_LIST)) void mutt_free_list (LIST **); +void mutt_free_list_generic (LIST **list, void (*data_free)(char **)); void mutt_free_rx_list (RX_LIST **); void mutt_free_replace_list (REPLACE_LIST **); LIST *mutt_copy_list (LIST *); diff --git a/muttlib.c b/muttlib.c index 4350136d..8aa0011b 100644 --- a/muttlib.c +++ b/muttlib.c @@ -324,6 +324,27 @@ void mutt_free_list (LIST **list) } } +void mutt_free_list_generic(LIST **list, void (*data_free)(char **)) +{ + LIST *p; + + /* wrap mutt_free_list if no data_free function was provided */ + if (data_free == NULL) + { + mutt_free_list(list); + return; + } + + if (!list) return; + while (*list) + { + p = *list; + *list = (*list)->next; + data_free(&p->data); + FREE (&p); + } +} + LIST *mutt_copy_list (LIST *p) { LIST *t, *r=NULL, *l=NULL;