From: Pietro Cerutti Date: Wed, 7 Nov 2018 12:59:21 +0000 (+0000) Subject: Implement mailcap option x-neomutt-keep X-Git-Tag: 2019-10-25~549^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33217aa6137a18d1e32b430131b70a87718d4261;p=neomutt Implement mailcap option x-neomutt-keep The option x-neomutt-keep instructs neomutt not to remove the attachment after the view-command has quit. This is helpful with mime types handled by commands such as firefox, which fork before opening the attachment in the main instance. Example: application/pdf; evince; x-neomutt-keep; --- diff --git a/mutt_attach.c b/mutt_attach.c index 8a68f2a6d..be6566717 100644 --- a/mutt_attach.c +++ b/mutt_attach.c @@ -632,15 +632,21 @@ int mutt_view_attachment(FILE *fp, struct Body *a, int flag, struct Email *e, return_error: - if (entry) - rfc1524_free_entry(&entry); - if (fp && tempfile[0]) + if (!entry || !entry->xneomuttkeep) { - /* add temporary file to TempAttachmentsList to be deleted on exit */ - mutt_add_temp_attachment(tempfile); + if (fp && tempfile[0]) + { + /* add temporary file to TempAttachmentsList to be deleted on exit */ + mutt_add_temp_attachment(tempfile); + } + else if (unlink_tempfile) + { + unlink(tempfile); + } } - else if (unlink_tempfile) - unlink(tempfile); + + if (entry) + rfc1524_free_entry(&entry); if (pagerfile[0]) mutt_file_unlink(pagerfile); diff --git a/rfc1524.c b/rfc1524.c index 75d143a5b..42826fcea 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -340,6 +340,11 @@ static int rfc1524_mailcap_parse(struct Body *a, char *filename, char *type, FREE(&test_command); } } + else if (mutt_str_strncasecmp(field, "x-neomutt-keep", 14) == 0) + { + if (entry) + entry->xneomuttkeep = true; + } } /* while (ch) */ if (opt == MUTT_AUTOVIEW) @@ -377,6 +382,7 @@ static int rfc1524_mailcap_parse(struct Body *a, char *filename, char *type, FREE(&entry->convert); entry->needsterminal = false; entry->copiousoutput = false; + entry->xneomuttkeep = false; } } } /* while (!found && (buf = mutt_file_read_line ())) */ diff --git a/rfc1524.h b/rfc1524.h index b4496dc2b..58e6ba5f9 100644 --- a/rfc1524.h +++ b/rfc1524.h @@ -46,6 +46,7 @@ struct Rfc1524MailcapEntry char *convert; bool needsterminal : 1; /**< endwin() and system */ bool copiousoutput : 1; /**< needs pager, basically */ + bool xneomuttkeep : 1; /**< do not remove the file on command exit */ }; struct Rfc1524MailcapEntry *rfc1524_new_entry(void);