updated on Fri Jan 6 08:01:17 UTC 2012
[aur-mirror.git] / uber-mutt / mutt-attach.patch
blobc926ca307dc97727c2bd88a84dcb0d7ac3bb4bf5
1 diff -ur a/globals.h b/globals.h
2 --- a/globals.h 2010-05-28 17:16:31.000000000 -0400
3 +++ b/globals.h 2010-05-28 21:28:58.000000000 -0400
4 @@ -34,6 +34,7 @@
5 WHERE char *AliasFile;
6 WHERE char *AliasFmt;
7 WHERE char *AssumedCharset;
8 +WHERE char *AttachKeyword;
9 WHERE char *AttachSep;
10 WHERE char *Attribution;
11 WHERE char *AttachCharset;
12 diff -ur a/init.h b/init.h
13 --- a/init.h 2010-05-28 17:11:18.000000000 -0400
14 +++ b/init.h 2010-05-28 21:29:27.000000000 -0400
15 @@ -83,6 +83,14 @@
17 struct option_t MuttVars[] = {
18 /*++*/
19 + { "abort_noattach", DT_QUAD, R_NONE, OPT_ATTACH, M_ASKYES },
20 + /*
21 + ** .pp
22 + ** If set to \fIyes\fP, when composing messages containing the word
23 + ** specified by $attach_keyword (default is "attach") and no attachments
24 + ** are given, composition will be aborted. If set to \fIno\fP, composing
25 + ** messages as such will never be aborted.
26 + */
27 { "abort_nosubject", DT_QUAD, R_NONE, OPT_SUBJECT, M_ASKYES },
29 ** .pp
30 @@ -241,6 +249,13 @@
31 ** .pp
32 ** For an explanation of ``soft-fill'', see the $$index_format documentation.
34 + { "attach_keyword", DT_STR, R_NONE, UL &AttachKeyword, UL "attach" },
35 + /*
36 + ** .pp
37 + ** If $abort_attach is not set to no, then the body of the message
38 + ** will be scanned for this keyword, and if found, you will be prompted
39 + ** if there are no attachments. This is case insensitive.
40 + */
41 { "attach_sep", DT_STR, R_NONE, UL &AttachSep, UL "\n" },
43 ** .pp
44 diff -ur a/mutt.h b/mutt.h
45 --- a/mutt.h 2010-05-28 17:13:48.000000000 -0400
46 +++ b/mutt.h 2010-05-28 21:29:44.000000000 -0400
47 @@ -286,6 +286,8 @@
48 OPT_SUBJECT,
49 OPT_VERIFYSIG, /* verify PGP signatures */
51 + OPT_ATTACH, /* forgotten attachment detector */
53 /* THIS MUST BE THE LAST VALUE. */
54 OPT_MAX
56 diff -ur a/send.c b/send.c
57 --- a/send.c 2010-05-28 21:42:58.000000000 -0400
58 +++ b/send.c 2010-05-28 21:44:39.000000000 -0400
59 @@ -1113,6 +1113,34 @@
62 int
63 +mutt_search_attach_keyword(char* filename)
65 + /* searches for the magic keyword "attach" within a file */
66 + int found = 0;
67 + char* inputline = malloc(1024);
68 + char* lowerKeyword = malloc(strlen(AttachKeyword)+1);
69 + FILE *attf = fopen(filename, "r");
70 + int i;
71 + for (i=0; i <= strlen(AttachKeyword); i++) {
72 + lowerKeyword[i] = tolower(AttachKeyword[i]);
73 + }
74 + while (!feof(attf)) {
75 + fgets(inputline, 1024, attf);
76 + for (i=0; i < strlen(inputline); i++) {
77 + inputline[i] = tolower(inputline[i]);
78 + }
79 + if (strstr(inputline, lowerKeyword)) {
80 + found = 1;
81 + break;
82 + }
83 + }
84 + free(inputline);
85 + free(lowerKeyword);
86 + fclose(attf);
87 + return found;
90 +int
91 ci_send_message (int flags, /* send mode */
92 HEADER *msg, /* template to use for new message */
93 char *tempfile, /* file specified by -i or -H */
94 @@ -1605,6 +1633,21 @@
95 goto main_loop;
98 + if (mutt_search_attach_keyword(msg->content->filename) &&
99 + !msg->content->next &&
100 + query_quadoption(OPT_ATTACH, _("No attachments, cancel sending?")) != M_NO)
102 + /* if the abort is automatic, print an error message */
103 + if (quadoption (OPT_ATTACH) == M_YES) {
104 + char errorstr[512];
105 + if (snprintf(errorstr, 512,
106 + "Message contains magic keyword \"%s\", but no attachments. Not sending.", AttachKeyword)==-1)
107 + errorstr[511] = 0; // terminate if need be. our string shouldnt be this long.
108 + mutt_error _(errorstr);
110 + goto main_loop;
113 if (msg->content->next)
114 msg->content = mutt_make_multipart (msg->content);