]> granicus.if.org Git - mutt/commitdiff
Added * option to unattachments command
authorAndrew Marks <amarks@red.ridge.amrx.net>
Fri, 5 Jul 2019 15:44:21 +0000 (08:44 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sun, 21 Jul 2019 16:06:28 +0000 (09:06 -0700)
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

doc/manual.xml.head
init.c
mutt.h
muttlib.c

index 01baff28f97e75ee3845e57ed747efe9226e1c28..b77dde757c2138211230a2f51bcac41944b08d6f 100644 (file)
@@ -8145,7 +8145,12 @@ The syntax is:
 
 <command>attachments</command>
 <arg choice="plain">
-<replaceable>?</replaceable>
+<option>?</option>
+</arg>
+
+<command>unattachments</command>
+<arg choice="plain">
+<option>*</option>
 </arg>
 </cmdsynopsis>
 
@@ -8254,6 +8259,10 @@ a command will list your current settings in Muttrc format, so that it
 can be pasted elsewhere.
 </para>
 
+<para>
+Entering the command <quote><command>unattachments</command> *</quote> as
+a command will Clear all attachment settings.
+</para>
 </sect1>
 
 <sect1 id="mime-lookup">
@@ -10108,6 +10117,13 @@ The following are the commands understood by Mutt:
 <arg choice="plain">
 <replaceable>mime-type</replaceable>
 </arg>
+
+<command><link linkend="attachments">attachments</link></command>
+<arg choice="plain"><option>?</option></arg>
+
+<command><link linkend="attachments">unattachments</link></command>
+<arg choice="plain"><option>*</option></arg>
+
 </cmdsynopsis>
 </listitem>
 
diff --git a/init.c b/init.c
index e02f12018e26a2bf55e6c6496854c0af985d86ae..621cd3c15e546099e077cac6fd40263f5af232a3 100644 (file)
--- 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 dcc3a2f10f0c446fad23b734713086498456219a..77082bdbb5b3e2a0d24e35773bd1e54436fa6a43 100644 (file)
--- 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 *);
index 4350136daf876ea0626838e7143b216b8a8d4ab3..8aa0011bb3dc28868701e0cbf14b24162d405dce 100644 (file)
--- 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;