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
enum
{
OPT_ABORT,
+ OPT_ABORTNOATTACH,
OPT_BOUNCE,
OPT_COPY,
OPT_DELETE,
int not; /* do not match */
} REGEXP;
+WHERE REGEXP AbortNoattachRegexp;
WHERE REGEXP Mask;
WHERE REGEXP QuoteRegexp;
WHERE REGEXP ReplyRegexp;
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
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);