]> granicus.if.org Git - neomutt/commitdiff
Delete Attachments upon OP_QUIT 1372/head
authorryt <0x747972@gmail.com>
Sat, 27 Oct 2018 00:01:30 +0000 (02:01 +0200)
committerRichard Russon <rich@flatcap.org>
Sun, 28 Oct 2018 17:02:47 +0000 (17:02 +0000)
globals.h
main.c
mutt_attach.c
mutt_attach.h

index 4bb3bc190315e2304f3afd69a78ad38507ddf82c..00776d50c995172775377733946568ad6358a301 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -69,6 +69,7 @@ WHERE struct ListHead Muttrc INITVAL(STAILQ_HEAD_INITIALIZER(Muttrc));
 #ifdef USE_SIDEBAR
 WHERE struct ListHead SidebarWhitelist INITVAL(STAILQ_HEAD_INITIALIZER(SidebarWhitelist));
 #endif
+WHERE struct ListHead TempAttachmentsList INITVAL(STAILQ_HEAD_INITIALIZER(TempAttachmentsList));
 WHERE struct ListHead UserHeader INITVAL(STAILQ_HEAD_INITIALIZER(UserHeader));
 
 /* Lists of AttachMatch */
diff --git a/main.c b/main.c
index c1da0e6dac627db4500b5fae1b68656048d7ff2d..344794bab838ff6180dd9da5f2fa67eb4e85a82a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -59,6 +59,7 @@
 #include "keymap.h"
 #include "mailbox.h"
 #include "menu.h"
+#include "mutt_attach.h"
 #include "mutt_curses.h"
 #include "mutt_history.h"
 #include "mutt_logging.h"
@@ -1239,6 +1240,7 @@ main_curses:
   if (repeat_error && ErrorBufMessage)
     puts(ErrorBuf);
 main_exit:
+  mutt_unlink_temp_attachments();
   mutt_list_free(&queries);
   crypto_module_free();
   mutt_window_free();
index dc7345f3f62b26ddc6fda0e0d7fe057a2037eec3..8a68f2a6d4ab9469f293cfb100291301cac1ec4d 100644 (file)
@@ -636,9 +636,8 @@ return_error:
     rfc1524_free_entry(&entry);
   if (fp && tempfile[0])
   {
-    /* Restore write permission so mutt_file_unlink can open the file for writing */
-    mutt_file_chmod_add(tempfile, S_IWUSR);
-    mutt_file_unlink(tempfile);
+    /* add temporary file to TempAttachmentsList to be deleted on exit */
+    mutt_add_temp_attachment(tempfile);
   }
   else if (unlink_tempfile)
     unlink(tempfile);
@@ -1149,3 +1148,28 @@ int mutt_print_attachment(FILE *fp, struct Body *a)
     return 0;
   }
 }
+
+/**
+ * mutt_add_temp_attachment - Add file to list of temporary attachments
+ * @param filename filename with full path
+ */
+void mutt_add_temp_attachment(char *filename)
+{
+  mutt_list_insert_tail(&TempAttachmentsList, mutt_str_strdup(filename));
+}
+
+/**
+ * mutt_unlink_temp_attachments - Delete all temporary attachments
+ */
+void mutt_unlink_temp_attachments(void)
+{
+  struct ListNode *np = NULL;
+
+  STAILQ_FOREACH(np, &TempAttachmentsList, entries)
+  {
+    mutt_file_chmod_add(np->data, S_IWUSR);
+    mutt_file_unlink(np->data);
+  }
+
+  mutt_list_free(&TempAttachmentsList);
+}
index eb0f83dd742babc1a454d5fd7b2db39f260ca7c5..4990bb387e4615e403c6263d2081ff67079ade5c 100644 (file)
@@ -55,4 +55,8 @@ int mutt_pipe_attachment(FILE *fp, struct Body *b, const char *path, char *outfi
 int mutt_print_attachment(FILE *fp, struct Body *a);
 int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct Email *e);
 
+/* small helper functions to handle temporary attachment files */
+void mutt_add_temp_attachment(char *filename);
+void mutt_unlink_temp_attachments(void);
+
 #endif /* MUTT_MUTT_ATTACH_H */