Commit f47a159b authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

Add $abort_noattach and $abort_noattach_regexp options.

$abort_noattach_regexp is matched against the body of a message.  If
so, the $abort_noattach quadoption is used to prompt whether to abort
sending.

Thanks to Antonio Radici for bringing the original version of the
patch to our attention, which he pulled from
https://github.com/tlvince/pkgbuild/blob/master/mutt-kiss/mutt-attach.patch

This version was rewritten to use a regexp, to fix a few issues, and
to better fit in with Mutt styles and conventions.
parent 6829c390
Pipeline #18722545 passed with stages
in 23 minutes and 49 seconds
......@@ -88,6 +88,25 @@ struct option_t
struct option_t MuttVars[] = {
/*++*/
{ "abort_noattach", DT_QUAD, R_NONE, OPT_ABORTNOATTACH, MUTT_NO },
/*
** .pp
** When the body of the message matches $$abort_noattach_regexp and
** there are no attachments, this quadoption controls whether to
** abort sending the message.
*/
{ "abort_noattach_regexp", DT_RX, R_NONE, UL &AbortNoattachRegexp, UL "attach" },
/*
** .pp
** Specifies a regular expression to match against the body of the
** message, to determine if an attachment was mentioned but
** mistakenly forgotten. If it matches, $$abort_noattach will be
** consulted to determine if message sending will be aborted.
** .pp
** Like other regular expressions in Mutt, the search is case
** sensitive if the pattern contains at least one upper case letter,
** and case insensitive otherwise.
*/
{ "abort_nosubject", DT_QUAD, R_NONE, OPT_SUBJECT, MUTT_ASKYES },
/*
** .pp
......
......@@ -284,6 +284,7 @@ enum
enum
{
OPT_ABORT,
OPT_ABORTNOATTACH,
OPT_BOUNCE,
OPT_COPY,
OPT_DELETE,
......
......@@ -46,6 +46,7 @@ typedef struct
int not; /* do not match */
} REGEXP;
WHERE REGEXP AbortNoattachRegexp;
WHERE REGEXP Mask;
WHERE REGEXP QuoteRegexp;
WHERE REGEXP ReplyRegexp;
......
......@@ -1133,6 +1133,31 @@ static int has_recips (ADDRESS *a)
return c;
}
static int has_attach_keyword (char *filename)
{
int match = 0;
char buffer[LONG_STRING];
FILE *fp;
if ((fp = safe_fopen (filename, "r")) == NULL)
{
mutt_perror (filename);
return 0;
}
while (fgets (buffer, sizeof(buffer), fp) != NULL)
{
if (regexec (AbortNoattachRegexp.rx, buffer, 0, NULL, 0) == 0)
{
match = 1;
break;
}
}
safe_fclose (&fp);
return match;
}
/*
* Returns 0 if the message was successfully sent
* -1 if the message was aborted or an error occurred
......@@ -1715,6 +1740,24 @@ main_loop:
goto main_loop;
}
/* Scan for a mention of an attachment in the message body and
* prompt if there is none. */
if (!(flags & SENDBATCH) &&
(quadoption (OPT_ABORTNOATTACH) != MUTT_NO) &&
AbortNoattachRegexp.pattern &&
!msg->content->next &&
(msg->content->type == TYPETEXT) &&
!ascii_strcasecmp (msg->content->subtype, "plain") &&
has_attach_keyword (msg->content->filename))
{
if (query_quadoption (OPT_ABORTNOATTACH, _("No attachments, abort sending?")) != MUTT_NO)
{
if (quadoption (OPT_ABORTNOATTACH) == MUTT_YES)
mutt_error _("Attachment referenced in message is missing");
goto main_loop;
}
}
if (msg->content->next)
msg->content = mutt_make_multipart (msg->content);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment