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