From: ryt <0x747972@gmail.com> Date: Sat, 27 Oct 2018 00:01:30 +0000 (+0200) Subject: Delete Attachments upon OP_QUIT X-Git-Tag: 2019-10-25~582 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39a03d5e8973063a0ced15ce1c79f99d26d6f083;p=neomutt Delete Attachments upon OP_QUIT --- diff --git a/globals.h b/globals.h index 4bb3bc190..00776d50c 100644 --- 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 c1da0e6da..344794bab 100644 --- 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(); diff --git a/mutt_attach.c b/mutt_attach.c index dc7345f3f..8a68f2a6d 100644 --- a/mutt_attach.c +++ b/mutt_attach.c @@ -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); +} diff --git a/mutt_attach.h b/mutt_attach.h index eb0f83dd7..4990bb387 100644 --- a/mutt_attach.h +++ b/mutt_attach.h @@ -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 */