Mercurial > hg > mlmmj
annotate contrib/receivestrip/mlmmj-receive-strip.c @ 748:dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
author | Chris Webb |
---|---|
date | Sun, 03 Oct 2010 21:40:42 +1100 |
parents | contrib/recievestrip/mlmmj-recieve-strip.c@c334ffdf8807 |
children |
rev | line source |
---|---|
631
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
1 /* Copyright (C) 2007 Sascha Sommer <ssommer at suse.de> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
2 * |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
3 * Permission is hereby granted, free of charge, to any person obtaining a copy |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
4 * of this software and associated documentation files (the "Software"), to |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
5 * deal in the Software without restriction, including without limitation the |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
7 * sell copies of the Software, and to permit persons to whom the Software is |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
8 * furnished to do so, subject to the following conditions: |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
9 * |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
10 * The above copyright notice and this permission notice shall be included in |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
11 * all copies or substantial portions of the Software. |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
12 * |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
19 * IN THE SOFTWARE. |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
20 */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
21 |
748
dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
Chris Webb
parents:
676
diff
changeset
|
22 /* a version of mlmmj-receive that parses the mail on the fly and strips unwanted |
631
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
23 mime parts |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
24 opens the files control/mimedeny and control/mimestrip for a list of mime |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
25 types for body parts that should be denied or stripped. |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
26 It adds an extra header X-ThisMailContainsUnwantedMimeParts: Y for mails that |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
27 contain disallowed mimeparts and X-ThisMailContainsUnwantedMimeParts: N otherwise |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
28 */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
29 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
30 #include <stdlib.h> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
31 #include <string.h> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
32 #include <unistd.h> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
33 #include <sys/stat.h> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
34 #include <fcntl.h> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
35 #include <stdio.h> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
36 #include <errno.h> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
37 #include <string.h> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
38 #include <sys/types.h> |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
39 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
40 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
41 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
42 #include "mlmmj.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
43 #include "mygetline.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
44 #include "gethdrline.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
45 #include "strgen.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
46 #include "chomp.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
47 #include "ctrlvalue.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
48 #include "ctrlvalues.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
49 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
50 #include "log_error.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
51 #include "wrappers.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
52 #include "memory.h" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
53 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
54 #define UNWANTED_MIME_HDR "X-ThisMailContainsUnwantedMimeParts: N\n" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
55 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
56 /* append a copy of a string to a string list */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
57 static void append_strtolist(struct strlist *list, char* str) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
58 list->count++; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
59 list->strs = myrealloc(list->strs, |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
60 sizeof(char *) * (list->count + 1)); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
61 list->strs[list->count-1] = mystrdup(str); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
62 list->strs[list->count] = NULL; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
63 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
64 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
65 /* free all strings in a strlist */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
66 static void free_strlist(struct strlist *list) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
67 if(!list) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
68 return; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
69 if(list->strs) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
70 int i; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
71 for(i=0;i < list->count;i++) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
72 myfree(list->strs[i]); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
73 myfree(list->strs); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
74 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
75 list->strs = NULL; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
76 list->count = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
77 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
78 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
79 static int findit(char *line, char **headers) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
80 { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
81 int i = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
82 size_t len; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
83 |
676
c334ffdf8807
Added a sanity check in mlmmj-receive-strip (Chris Webb)
mortenp
parents:
631
diff
changeset
|
84 if (!headers) |
c334ffdf8807
Added a sanity check in mlmmj-receive-strip (Chris Webb)
mortenp
parents:
631
diff
changeset
|
85 return 0; |
c334ffdf8807
Added a sanity check in mlmmj-receive-strip (Chris Webb)
mortenp
parents:
631
diff
changeset
|
86 |
631
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
87 while(headers[i]) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
88 len = strlen(headers[i]); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
89 if(strncasecmp(line, headers[i], len) == 0) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
90 return 1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
91 i++; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
92 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
93 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
94 return 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
95 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
96 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
97 /* extract mime_type and boundary from the Content-Type header |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
98 * allocates a string for the mime_type if one is found |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
99 * always allocates a boundarie (using "--" when none is found) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
100 * the caller needs to free the allocated strings |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
101 */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
102 static void extract_boundary(struct strlist *allhdrs, char** mime_type, char** boundary) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
103 { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
104 int x; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
105 *boundary = NULL; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
106 *mime_type = NULL; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
107 for( x = 0 ; x < allhdrs->count ; x++ ){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
108 char* hdr = allhdrs->strs[x]; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
109 if(hdr && !strncasecmp(hdr,"Content-Type:",13)){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
110 char* pos = hdr + 13; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
111 size_t len = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
112 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
113 /* find the start of the mimetype */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
114 while(*pos && (*pos == ' ' || *pos == '\t')) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
115 ++pos; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
116 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
117 if(*pos == '"'){ /* handle quoted mime types */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
118 ++pos; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
119 while(pos[len] && pos[len] != '"') |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
120 ++len; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
121 }else{ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
122 while(pos[len] && pos[len] != ' ' && pos[len] != '\t' && pos[len] != ';') |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
123 ++len; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
124 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
125 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
126 /* extract mime type if any */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
127 if(len){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
128 *mime_type = mymalloc(len+1); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
129 strncpy(*mime_type,pos,len); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
130 (*mime_type)[len] = '\0'; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
131 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
132 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
133 pos += len; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
134 len = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
135 /* find start of the boundary info */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
136 while(*pos && strncasecmp(pos,"boundary=",9)) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
137 ++pos; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
138 if(*pos == '\0') /* no boundary */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
139 break; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
140 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
141 pos += 9; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
142 if(*pos == '"'){ /* quoted boundary */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
143 ++pos; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
144 while(pos[len] && pos[len] != '"') |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
145 ++len; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
146 }else{ /* unquoted boundary */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
147 while(pos[len] && pos[len] != ' ' && pos[len] != '\t' && pos[len] != ';') |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
148 ++len; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
149 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
150 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
151 /* extract boundary */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
152 *boundary = mymalloc(len + 3); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
153 strcpy(*boundary,"--"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
154 strncat(*boundary,pos,len); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
155 break; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
156 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
157 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
158 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
159 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
160 /* read all mail headers and save them in a strlist |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
161 * check what to do with parts that contain the given mime_type |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
162 *return values |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
163 * 0: ok |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
164 * 1: strip |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
165 * sets deny to 1 if the entire mail should be denied |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
166 */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
167 #define MIME_OK 0 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
168 #define MIME_STRIP 1 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
169 static int read_hdrs(int fd, struct strlist *allhdrs,struct strlist* delmime,struct strlist* denymime,int* deny,char** boundary) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
170 int result = MIME_OK; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
171 char* mime_type = NULL; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
172 allhdrs->strs = NULL; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
173 allhdrs->count = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
174 /* read headers */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
175 while(1) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
176 char* line = mygetline(fd); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
177 if(!line) /* end of file and also end of headers */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
178 break; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
179 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
180 /* end of headers */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
181 if(line[0] == '\n'){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
182 myfree(line); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
183 break; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
184 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
185 if(!allhdrs->count || ((line[0] != '\t') && (line[0] != ' '))) /* first header line or no more unfolding */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
186 append_strtolist(allhdrs,line); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
187 else{ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
188 char* tmp = concatstr(2, allhdrs->strs[allhdrs->count-1], line); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
189 myfree(allhdrs->strs[allhdrs->count-1]); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
190 allhdrs->strs[allhdrs->count-1] = tmp; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
191 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
192 myfree(line); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
193 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
194 extract_boundary(allhdrs,&mime_type,boundary); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
195 if(mime_type) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
196 /* check if this part should be stripped */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
197 if(delmime && findit(mime_type, delmime->strs)) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
198 result = MIME_STRIP; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
199 /* check if the mail should be denied */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
200 if(denymime && findit(mime_type, denymime->strs)) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
201 *deny = 1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
202 myfree(mime_type); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
203 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
204 return result; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
205 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
206 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
207 /* writes the mail headers if unwantedmime_hdrpos is not NULL an UNWANTED_MIME_HDR |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
208 * is inserted and its position saved in unwantedmime_hdrpos |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
209 * returns 0 on success |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
210 */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
211 static int write_hdrs(int outfd,struct strlist* hdrs,off_t* unwantedmime_hdrpos) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
212 int i; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
213 for(i = 0; i < hdrs->count ; i++) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
214 if(writen(outfd, hdrs->strs[i], strlen(hdrs->strs[i])) < 0){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
215 log_error(LOG_ARGS, "Error when dumping headers"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
216 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
217 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
218 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
219 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
220 /* if this is not the header of an embedded part add the header that will |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
221 indicate if the mail contains unwanted mime parts */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
222 if(unwantedmime_hdrpos) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
223 if(writen(outfd, UNWANTED_MIME_HDR,strlen(UNWANTED_MIME_HDR)) < 0){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
224 log_error(LOG_ARGS, "Error writting unwanted mime header"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
225 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
226 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
227 /* get the current position so that we can update the header later */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
228 *unwantedmime_hdrpos = lseek(outfd,0,SEEK_CUR); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
229 if(*unwantedmime_hdrpos < 2){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
230 log_error(LOG_ARGS, "Error getting file position"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
231 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
232 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
233 *unwantedmime_hdrpos -= 2; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
234 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
235 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
236 /* write a single line feed to terminate the header part */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
237 if(writen(outfd, "\n", 1) < 0) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
238 log_error(LOG_ARGS,"Error writting end of hdrs."); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
239 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
240 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
241 return 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
242 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
243 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
244 /* set the unwanted mime_hdr to Y */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
245 static int update_unwantedmime_hdr(int outfd,off_t unwantedmime_hdrpos) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
246 /* seek to the header position */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
247 if(lseek(outfd,unwantedmime_hdrpos,SEEK_SET) < 0) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
248 log_error(LOG_ARGS,"Error seeking to the unwantedmime_hdr"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
249 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
250 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
251 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
252 /* update the header */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
253 if(writen(outfd, "Y\n",2) < 0){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
254 log_error(LOG_ARGS, "Error writting extra header"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
255 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
256 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
257 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
258 /* seek back to the end of the mail */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
259 if(lseek(outfd,0,SEEK_END) < 0) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
260 log_error(LOG_ARGS,"Error seeking to the mail end"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
261 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
262 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
263 return 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
264 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
265 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
266 static int parse_body(int infd,int outfd, struct strlist* delmime, struct strlist* denymime, |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
267 int* deny,char* boundary){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
268 int strip = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
269 char* line; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
270 while((line = mygetline(infd))) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
271 if(boundary && !strncmp(line,boundary,strlen(boundary))){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
272 strip = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
273 /* check if the boundary is the beginning of a new part */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
274 if(strncmp(line + strlen(boundary),"--",2)){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
275 struct strlist hdrs; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
276 char* new_boundary = NULL; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
277 /* check if this part should be stripped */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
278 if(read_hdrs(infd, &hdrs,delmime,denymime,deny,&new_boundary) == MIME_STRIP) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
279 strip = 1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
280 else { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
281 /* write boundary */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
282 if(writen(outfd, line, strlen(line)) < 0){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
283 log_error(LOG_ARGS, "Error writting boundary"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
284 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
285 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
286 /* write hdr */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
287 if(write_hdrs(outfd, &hdrs, NULL) < 0){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
288 log_error(LOG_ARGS, "Error writting hdrs"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
289 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
290 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
291 /* parse embedded part if a new boundary was found */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
292 if(new_boundary && parse_body(infd,outfd,delmime,denymime,deny,new_boundary) != 0) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
293 log_error(LOG_ARGS, "Could not parse embedded part"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
294 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
295 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
296 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
297 free_strlist(&hdrs); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
298 if(new_boundary) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
299 myfree(new_boundary); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
300 }else{ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
301 /* write end of part */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
302 if(writen(outfd, line, strlen(line)) < 0){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
303 log_error(LOG_ARGS, "Error writting hdrs"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
304 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
305 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
306 /* and leave */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
307 myfree(line); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
308 break; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
309 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
310 }else { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
311 if(!strip) { /* write the current line */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
312 if(writen(outfd, line, strlen(line)) < 0){ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
313 log_error(LOG_ARGS, "Error when dumping line"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
314 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
315 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
316 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
317 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
318 myfree(line); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
319 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
320 return 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
321 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
322 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
323 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
324 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
325 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
326 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
327 /* read a mail stripping unwanted parts */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
328 static int dump_mail(int infd, int outfd,char* listdir) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
329 struct strlist hdrs; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
330 struct strlist* delmime; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
331 struct strlist* denymime; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
332 char* boundary=NULL; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
333 int deny = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
334 int result; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
335 off_t unwantedmime_hdr_pos = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
336 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
337 /* get list control values */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
338 delmime = ctrlvalues(listdir, "mimestrip"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
339 denymime = ctrlvalues(listdir, "mimedeny"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
340 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
341 /* read mail header */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
342 result = read_hdrs(infd, &hdrs,delmime,denymime,&deny,&boundary); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
343 /* write mail header */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
344 if(write_hdrs(outfd,&hdrs,&unwantedmime_hdr_pos) < 0) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
345 log_error(LOG_ARGS, "Could not write mail headers"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
346 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
347 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
348 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
349 /* free mail header */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
350 free_strlist(&hdrs); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
351 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
352 if(result == MIME_OK && !deny) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
353 /* try to parse the mail */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
354 if(parse_body(infd,outfd,delmime,denymime,&deny,boundary) != 0) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
355 log_error(LOG_ARGS, "Could not parse mail"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
356 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
357 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
358 myfree(boundary); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
359 }else |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
360 deny = 1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
361 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
362 /* dump rest of mail */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
363 if(dumpfd2fd(infd, outfd) != 0) { |
748
dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
Chris Webb
parents:
676
diff
changeset
|
364 log_error(LOG_ARGS, "Could not receive mail"); |
631
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
365 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
366 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
367 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
368 /* update header */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
369 if(deny) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
370 if(update_unwantedmime_hdr(outfd,unwantedmime_hdr_pos) != 0) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
371 log_error(LOG_ARGS, "Could not update header"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
372 return -1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
373 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
374 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
375 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
376 /* free mime types */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
377 if(delmime) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
378 free_strlist(delmime); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
379 myfree(delmime); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
380 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
381 if(denymime) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
382 free_strlist(denymime); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
383 myfree(denymime); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
384 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
385 return 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
386 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
387 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
388 static void print_help(const char *prg) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
389 { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
390 printf("Usage: %s -L /path/to/listdir [-h] [-V] [-P] [-F]\n" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
391 " -h: This help\n" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
392 " -F: Don't fork in the background\n" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
393 " -L: Full path to list directory\n" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
394 " -P: Don't execute mlmmj-process\n" |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
395 " -V: Print version\n", prg); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
396 exit(EXIT_SUCCESS); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
397 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
398 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
399 int main(int argc, char **argv) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
400 { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
401 char *infilename = NULL, *listdir = NULL; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
402 char *randomstr = random_str(); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
403 char *mlmmjprocess, *bindir; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
404 int fd, opt, noprocess = 0, nofork = 0; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
405 struct stat st; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
406 uid_t uid; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
407 pid_t childpid; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
408 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
409 CHECKFULLPATH(argv[0]); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
410 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
411 log_set_name(argv[0]); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
412 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
413 bindir = mydirname(argv[0]); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
414 mlmmjprocess = concatstr(2, bindir, "/mlmmj-process"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
415 myfree(bindir); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
416 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
417 while ((opt = getopt(argc, argv, "hPVL:F")) != -1) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
418 switch(opt) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
419 case 'h': |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
420 print_help(argv[0]); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
421 break; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
422 case 'L': |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
423 listdir = optarg; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
424 break; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
425 case 'P': |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
426 noprocess = 1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
427 break; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
428 case 'F': |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
429 nofork = 1; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
430 break; |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
431 case 'V': |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
432 print_version(argv[0]); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
433 exit(0); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
434 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
435 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
436 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
437 if(listdir == NULL) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
438 fprintf(stderr, "You have to specify -L\n"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
439 fprintf(stderr, "%s -h for help\n", argv[0]); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
440 exit(EXIT_FAILURE); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
441 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
442 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
443 /* Lets make sure no random user tries to send mail to the list */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
444 if(listdir) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
445 if(stat(listdir, &st) == 0) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
446 uid = getuid(); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
447 if(uid && uid != st.st_uid) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
448 log_error(LOG_ARGS, |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
449 "Have to invoke either as root " |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
450 "or as the user owning listdir " |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
451 "Invoked with uid = [%d]", (int)uid); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
452 writen(STDERR_FILENO, |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
453 "Have to invoke either as root " |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
454 "or as the user owning listdir\n", 60); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
455 exit(EXIT_FAILURE); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
456 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
457 } else { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
458 log_error(LOG_ARGS, "Could not stat %s", listdir); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
459 exit(EXIT_FAILURE); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
460 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
461 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
462 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
463 infilename = concatstr(3, listdir, "/incoming/", randomstr); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
464 myfree(randomstr); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
465 fd = open(infilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
466 while(fd < 0 && errno == EEXIST) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
467 myfree(infilename); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
468 randomstr = random_str(); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
469 infilename = concatstr(3, listdir, "/incoming/", randomstr); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
470 myfree(randomstr); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
471 fd = open(infilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
472 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
473 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
474 if(fd < 0) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
475 log_error(LOG_ARGS, "could not create mail file in " |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
476 "%s/incoming directory", listdir); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
477 myfree(infilename); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
478 exit(EXIT_FAILURE); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
479 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
480 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
481 if(dump_mail(fileno(stdin), fd, listdir) != 0) { |
748
dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
Chris Webb
parents:
676
diff
changeset
|
482 log_error(LOG_ARGS, "Could not receive mail"); |
631
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
483 exit(EXIT_FAILURE); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
484 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
485 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
486 #if 0 |
748
dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
Chris Webb
parents:
676
diff
changeset
|
487 log_oper(listdir, OPLOGFNAME, "mlmmj-receive got %s", infilename); |
631
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
488 #endif |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
489 fsync(fd); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
490 close(fd); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
491 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
492 if(noprocess) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
493 myfree(infilename); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
494 exit(EXIT_SUCCESS); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
495 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
496 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
497 /* |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
498 * Now we fork so we can exit with success since it could potentially |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
499 * take a long time for mlmmj-send to finish delivering the mails and |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
500 * returning, making it susceptible to getting a SIGKILL from the |
748
dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
Chris Webb
parents:
676
diff
changeset
|
501 * mailserver invoking mlmmj-receive. |
631
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
502 */ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
503 if (!nofork) { |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
504 childpid = fork(); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
505 if(childpid < 0) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
506 log_error(LOG_ARGS, "fork() failed! Proceeding anyway"); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
507 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
508 if(childpid) |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
509 exit(EXIT_SUCCESS); /* Parent says: "bye bye kids!"*/ |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
510 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
511 close(0); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
512 close(1); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
513 close(2); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
514 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
515 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
516 execlp(mlmmjprocess, mlmmjprocess, |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
517 "-L", listdir, |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
518 "-m", infilename, NULL); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
519 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjprocess); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
520 |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
521 exit(EXIT_FAILURE); |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
522 } |
44021d2ebe92
Added contrib/recievestrip/ MIME processor (Sascha Sommer)
mortenp
parents:
diff
changeset
|
523 |