Mercurial > masqmail
annotate src/accept.c @ 421:f37384470855
Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup.
Moved the lockdir out of the spool dir. (When /var/lock is a ramdisk
we do well to have the lock files there.) Added the new configure option
--with-lockdir to change that location. Nontheless, if we run_as_user,
then lock files are always stored in the spool dir directly.
Instead of installing the lockdir and piddir at installation time, we
create them on startup time now if they are missing. This is necessary
if lockdir or piddir are a tmpfs.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Wed, 30 May 2012 09:38:38 +0200 |
parents | 9b93c0a3bd8c |
children |
rev | line source |
---|---|
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
1 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
2 ** MasqMail |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
3 ** Copyright (C) 1999-2001 Oliver Kurth |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
4 ** Copyright (C) 2010 markus schnalke <meillo@marmaro.de> |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
5 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
6 ** This program is free software; you can redistribute it and/or modify |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
7 ** it under the terms of the GNU General Public License as published by |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
8 ** the Free Software Foundation; either version 2 of the License, or |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
9 ** (at your option) any later version. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
10 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
11 ** This program is distributed in the hope that it will be useful, |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
14 ** GNU General Public License for more details. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
15 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
16 ** You should have received a copy of the GNU General Public License |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
17 ** along with this program; if not, write to the Free Software |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
18 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
0 | 19 */ |
20 | |
21 #include "masqmail.h" | |
22 #include "readsock.h" | |
23 | |
299
ca2d11aec2a3
fixed compile error; removed PROT_BSMTP; made protocol names ucase
markus schnalke <meillo@marmaro.de>
parents:
298
diff
changeset
|
24 /* must match PROT_* in masqmail.h */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
25 gchar *prot_names[] = { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
26 "local", |
299
ca2d11aec2a3
fixed compile error; removed PROT_BSMTP; made protocol names ucase
markus schnalke <meillo@marmaro.de>
parents:
298
diff
changeset
|
27 "SMTP", |
ca2d11aec2a3
fixed compile error; removed PROT_BSMTP; made protocol names ucase
markus schnalke <meillo@marmaro.de>
parents:
298
diff
changeset
|
28 "ESMTP", |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
29 "(unknown)" /* should not happen, but better than crashing. */ |
0 | 30 }; |
31 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
32 static gchar* |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
362
diff
changeset
|
33 string_base62(gchar *res, guint value, gchar len) |
0 | 34 { |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
35 static gchar base62_chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
36 "abcdefghijklmnopqrstuvwxyz"; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
37 gchar *p = res + len; |
14
a8f3424347dc
replaced number 0 with character \0 where appropriate
meillo@marmaro.de
parents:
13
diff
changeset
|
38 *p = '\0'; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
39 while (p > res) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
40 *(--p) = base62_chars[value % 62]; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
41 value /= 62; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
42 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
43 return res; |
0 | 44 } |
45 | |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
46 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
47 ** accept message from anywhere. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
48 ** A message from local is indicated by msg->recieved_host == NULL |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
49 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
50 ** The -t option: With the ACC_RCPT_FROM_HEAD flag the addrs found found |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
51 ** in To/Cc/Bcc headers are added to the recipient list. |
0 | 52 */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
53 accept_error |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
362
diff
changeset
|
54 accept_message_stream(FILE *in, message *msg, guint flags) |
0 | 55 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
56 gchar *line, *line1; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
57 int line_size = MAX_DATALINE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
58 gboolean in_headers = TRUE; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
59 header *hdr = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
60 gint line_cnt = 0, data_size = 0; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
61 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
62 line = g_malloc(line_size); |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
63 *line = '\0'; |
0 | 64 |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
65 while (1) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
66 int len = read_sockline1(in, &line, &line_size, 5 * 60, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
67 READSOCKL_CVT_CRLF); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
68 line1 = line; |
0 | 69 |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
70 if ((*line == '.') && (!(flags & ACC_DOT_IGNORE))) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
71 if (line[1] == '\n') { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
72 g_free(line); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
73 break; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
74 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
75 line1++; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
76 } |
0 | 77 |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
78 if (len==-1 && (flags & (ACC_DOT_IGNORE | ACC_NODOT_RELAX))) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
79 /* at EOF but last line was not terminated by CR */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
80 /* some MUAs allow unterminated lines */ |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
81 gint len1 = strlen(line1); |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
82 if (len1 > 0 && line1[len1-1] != '\n') { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
83 line1[len1] = '\n'; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
84 line1[len1+1] = '\0'; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
85 msg->data_list = g_list_prepend(msg->data_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
86 g_strdup(line1)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
87 data_size += strlen(line1); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
88 line_cnt++; |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
89 } |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
90 break; |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
91 |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
92 } else if (len == -1) { |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
93 g_free(line); |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
94 return AERR_EOF; |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
95 |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
96 } else if (len == -2) { |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
97 /* should not happen any more */ |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
98 g_free(line); |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
99 return AERR_OVERFLOW; |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
100 |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
101 } else if (len == -3) { |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
102 g_free(line); |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
103 return AERR_TIMEOUT; |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
104 |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
105 } else if (len <= 0) { |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
106 /* does not happen */ |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
107 g_free(line); |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
108 DEBUG(5) debugf("read_sockline returned %d\n", len); |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
109 return AERR_UNKNOWN; |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
110 |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
111 } |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
112 |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
113 if (in_headers) { |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
114 /* some pop servers send the 'From ' line, skip it: */ |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
115 if (!msg->hdr_list && strncmp(line1, "From ", 5)==0) { |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
116 continue; |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
117 } |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
118 |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
119 if (*line1 == ' ' || *line1 == '\t') { |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
120 /* continuation of 'folded' header: */ |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
121 if (hdr) { |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
362
diff
changeset
|
122 char *cp; |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
123 cp = g_strconcat(hdr->header, line1, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
124 NULL); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
125 hdr->value = cp + (hdr->value - |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
126 hdr->header); |
323
29de6a1c4538
Fixed an important bug with folded headers!
meillo@marmaro.de
parents:
304
diff
changeset
|
127 free(hdr->header); |
29de6a1c4538
Fixed an important bug with folded headers!
meillo@marmaro.de
parents:
304
diff
changeset
|
128 hdr->header = cp; |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
129 } |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
130 } else if (*line1 == '\n') { |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
131 /* an empty line marks end of headers */ |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
132 in_headers = FALSE; |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
133 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
134 } else if ((hdr = get_header(line1))) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
135 /* another header */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
136 msg->hdr_list = g_list_append(msg->hdr_list, hdr); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
137 } else { |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
138 /* |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
139 ** Should be another header but none was |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
140 ** recognized, so this seems to be the first |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
141 ** data line of a broken mailer which does |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
142 ** not add an empty line after the headers. |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
143 */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
144 in_headers = FALSE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
145 msg->data_list = g_list_prepend(msg->data_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
146 g_strdup(line1)); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
147 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
148 } else { |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
149 /* message body */ |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
150 msg->data_list = g_list_prepend(msg->data_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
151 g_strdup(line1)); |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
152 data_size += strlen(line1); |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
153 line_cnt++; |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
154 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
155 |
120
cd59a5b4d3dd
added support for SMTP SIZE 0 (unlimited)
meillo@marmaro.de
parents:
117
diff
changeset
|
156 if (conf.max_msg_size && (data_size > conf.max_msg_size)) { |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
111
diff
changeset
|
157 DEBUG(4) debugf("accept_message_stream(): " |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
111
diff
changeset
|
158 "received %d bytes (conf.max_msg_size=%d)\n", |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
111
diff
changeset
|
159 data_size, conf.max_msg_size); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
111
diff
changeset
|
160 return AERR_SIZE; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
111
diff
changeset
|
161 } |
0 | 162 } |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
163 DEBUG(4) debugf("received %d lines of data (%d bytes)\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
164 line_cnt, data_size); |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
165 |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
166 if (!msg->data_list) { |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
167 /* make sure data list is not NULL */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
168 msg->data_list = g_list_append(NULL, g_strdup("")); |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
169 } |
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
170 msg->data_list = g_list_reverse(msg->data_list); |
0 | 171 |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
172 /* we have succesfully received the mail data */ |
0 | 173 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
174 msg->data_size = data_size; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
175 msg->received_time = time(NULL); |
0 | 176 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
177 return AERR_OK; |
0 | 178 } |
179 | |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
180 static void |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
181 ensure_return_path(message *msg) |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
182 { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
183 GList *hdr_list; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
184 header *hdr; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
185 gchar *addr; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
186 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
187 if (msg->return_path) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
188 return; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
189 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
190 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
191 DEBUG(3) debugf("return_path == NULL\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
192 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
193 hdr_list = find_header(msg->hdr_list, HEAD_SENDER, NULL); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
194 if (!hdr_list) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
195 hdr_list = find_header(msg->hdr_list, HEAD_FROM, NULL); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
196 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
197 if (hdr_list) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
198 hdr = (header *) (g_list_first(hdr_list)->data); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
199 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
200 DEBUG(5) debugf("hdr->value = '%s'\n", hdr->value); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
201 |
411
9b93c0a3bd8c
Ensure lvals, rvals and components of address strucs are stripped.
markus schnalke <meillo@marmaro.de>
parents:
388
diff
changeset
|
202 addr = g_strstrip(g_strdup(hdr->value)); |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
203 msg->return_path = create_address_qualified(addr, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
204 FALSE, msg->received_host); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
205 if (msg->return_path) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
206 DEBUG(3) debugf("setting return_path to %s\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
207 addr_string(msg->return_path)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
208 msg->hdr_list = g_list_append(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
209 create_header(HEAD_UNKNOWN, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
210 "X-Warning: return path set from %s " |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
211 "address\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
212 (hdr->id == HEAD_SENDER) ? |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
213 "Sender:" : "From:")); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
214 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
215 g_free(addr); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
216 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
217 if (!msg->return_path) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
218 /* no Sender: or From: or create_address_qualified failed */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
219 msg->return_path = create_address_qualified("postmaster", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
220 TRUE, conf.host_name); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
221 DEBUG(3) debugf("setting return_path to %s\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
222 addr_string(msg->return_path)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
223 msg->hdr_list = g_list_append(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
224 create_header(HEAD_UNKNOWN, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
225 "X-Warning: real return path is unknown\n")); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
226 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
227 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
228 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
229 static accept_error |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
230 scan_headers(message *msg, guint flags) |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
231 { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
232 gboolean has_id = FALSE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
233 gboolean has_date = FALSE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
234 gboolean has_sender = FALSE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
235 gboolean has_from = FALSE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
236 gboolean has_to_or_cc = FALSE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
237 GList *hdr_node, *hdr_node_next; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
238 header *hdr; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
239 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
240 for (hdr_node = g_list_first(msg->hdr_list); hdr_node; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
241 hdr_node = hdr_node_next) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
242 hdr_node_next = g_list_next(hdr_node); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
243 hdr = ((header *) (hdr_node->data)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
244 DEBUG(5) debugf("scanning headers: %s", hdr->header); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
245 switch (hdr->id) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
246 case HEAD_MESSAGE_ID: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
247 has_id = TRUE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
248 break; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
249 case HEAD_DATE: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
250 has_date = TRUE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
251 break; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
252 case HEAD_FROM: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
253 has_from = TRUE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
254 break; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
255 case HEAD_SENDER: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
256 has_sender = TRUE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
257 break; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
258 case HEAD_TO: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
259 case HEAD_CC: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
260 has_to_or_cc = TRUE; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
261 /* fall through */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
262 case HEAD_BCC: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
263 if (flags & ACC_RCPT_FROM_HEAD) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
264 /* -t option (see comment above) */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
265 DEBUG(5) debugf("hdr->value = %s\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
266 hdr->value); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
267 if (hdr->value) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
268 msg->rcpt_list = addr_list_append_rfc822(msg->rcpt_list, hdr->value, conf.host_name); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
269 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
270 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
271 if (hdr->id == HEAD_BCC) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
272 DEBUG(3) debugf("removing 'Bcc' header\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
273 msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
274 g_list_free_1(hdr_node); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
275 destroy_header(hdr); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
276 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
277 break; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
278 case HEAD_ENVELOPE_TO: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
279 if (flags & ACC_SAVE_ENVELOPE_TO) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
280 DEBUG(3) debugf("creating 'X-Orig-Envelope-To' header\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
281 msg->hdr_list = g_list_prepend(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
282 create_header(HEAD_UNKNOWN, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
283 "X-Orig-Envelope-To: %s", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
284 hdr->value)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
285 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
286 DEBUG(3) debugf("removing 'Envelope-To' header\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
287 msg->hdr_list = g_list_remove_link(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
288 hdr_node); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
289 g_list_free_1(hdr_node); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
290 destroy_header(hdr); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
291 break; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
292 case HEAD_RETURN_PATH: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
293 if (flags & ACC_MAIL_FROM_HEAD) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
294 /* usually POP3 accept */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
295 msg->return_path = create_address_qualified(hdr->value, TRUE, msg->received_host); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
296 DEBUG(3) debugf("setting return_path to %s\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
297 addr_string(msg->return_path)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
298 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
299 DEBUG(3) debugf("removing 'Return-Path' header\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
300 msg->hdr_list = g_list_remove_link(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
301 hdr_node); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
302 g_list_free_1(hdr_node); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
303 destroy_header(hdr); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
304 break; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
305 default: |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
306 break; /* make compiler happy */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
307 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
308 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
309 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
310 /* |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
311 ** TODO: do we still need this as we don't fetch |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
312 ** mail anymore? |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
313 ** This can happen for pop3 accept only and if no |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
314 ** Return-Path: header was given |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
315 */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
316 ensure_return_path(msg); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
317 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
318 /* here we should have our recipients, fail if not: */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
319 if (!msg->rcpt_list) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
320 logwrite(LOG_WARNING, "no recipients found in message\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
321 return AERR_NORCPT; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
322 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
323 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
324 if (!has_sender && !has_from) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
325 DEBUG(3) debugf("adding 'From:' header\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
326 if (msg->full_sender_name) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
327 msg->hdr_list = g_list_append(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
328 create_header(HEAD_FROM, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
329 "From: \"%s\" <%s@%s>\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
330 msg->full_sender_name, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
331 msg->return_path->local_part, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
332 msg->return_path->domain)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
333 } else { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
334 msg->hdr_list = g_list_append(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
335 create_header(HEAD_FROM, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
336 "From: <%s@%s>\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
337 msg->return_path->local_part, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
338 msg->return_path->domain)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
339 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
340 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
341 if (!has_to_or_cc) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
342 DEBUG(3) debugf("no To: or Cc: header, hence adding " |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
343 "`To: undisclosed recipients:;'\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
344 msg->hdr_list = g_list_append(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
345 create_header(HEAD_TO, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
346 "To: undisclosed-recipients:;\n")); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
347 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
348 if (!has_date) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
349 DEBUG(3) debugf("adding 'Date:' header\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
350 msg->hdr_list = g_list_append(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
351 create_header(HEAD_DATE, "Date: %s\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
352 rec_timestamp())); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
353 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
354 if (!has_id) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
355 DEBUG(3) debugf("adding 'Message-ID:' header\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
356 msg->hdr_list = g_list_append(msg->hdr_list, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
357 create_header(HEAD_MESSAGE_ID, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
358 "Message-ID: <%s@%s>\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
359 msg->uid, conf.host_name)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
360 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
361 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
362 return AERR_OK; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
363 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
364 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
365 static void |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
366 add_received_hdr(message *msg) |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
367 { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
368 gchar *for_string = NULL; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
369 header *hdr = NULL; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
370 address *addr; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
371 |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
372 DEBUG(3) debugf("adding 'Received:' header\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
373 if (g_list_length(msg->rcpt_list) == 1) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
374 /* The `for' part only if exactly one rcpt is present */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
375 addr = (address *) (g_list_first(msg->rcpt_list)->data); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
376 for_string = g_strdup_printf("\n\tfor %s", addr_string(addr)); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
377 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
378 if (!msg->received_host) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
379 /* received locally */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
380 hdr = create_header(HEAD_RECEIVED, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
381 "Received: by %s (%s %s, from userid %d)\n" |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
382 "\tid %s%s; %s\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
383 conf.host_name, PACKAGE, VERSION, geteuid(), |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
384 msg->uid, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
385 for_string ? for_string : "", rec_timestamp()); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
386 } else { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
387 /* received from remote */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
388 DEBUG(5) debugf("adding 'Received:' header (5)\n"); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
389 hdr = create_header(HEAD_RECEIVED, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
390 "Received: from %s\n" |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
391 "\tby %s with %s (%s %s)\n" |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
392 "\tid %s%s; %s\n", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
393 msg->received_host, conf.host_name, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
394 prot_names[msg->received_prot], PACKAGE, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
395 VERSION, msg->uid, |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
396 for_string ? for_string : "", rec_timestamp()); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
397 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
398 msg->hdr_list = g_list_prepend(msg->hdr_list, hdr); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
399 if (for_string) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
400 g_free(for_string); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
401 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
402 } |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
403 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
404 accept_error |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
362
diff
changeset
|
405 accept_message_prepare(message *msg, guint flags) |
0 | 406 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
407 DEBUG(5) debugf("accept_message_prepare()\n"); |
0 | 408 |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
409 /* generate unique message id */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
410 msg->uid = g_malloc(14); |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
411 string_base62(msg->uid, time(NULL), 6); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
412 msg->uid[6] = '-'; |
298 | 413 string_base62(msg->uid + 7, getpid(), 3); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
414 msg->uid[10] = '-'; |
298 | 415 string_base62(msg->uid + 11, msg->transfer_id, 2); |
416 msg->uid[13] = '\0'; | |
0 | 417 |
298 | 418 /* if local, get password entry and set return path if missing */ |
419 if (!msg->received_host) { | |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
420 struct passwd *passwd = NULL; |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
421 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
422 passwd = g_memdup(getpwuid(geteuid()), sizeof(struct passwd)); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
423 msg->ident = g_strdup(passwd->pw_name); |
298 | 424 if (!msg->return_path) { |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
425 gchar *path = g_strdup_printf("<%s@%s>", |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
426 passwd->pw_name, conf.host_name); |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
427 DEBUG(3) debugf("setting return_path for local " |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
428 "accept: %s\n", path); |
298 | 429 msg->return_path = create_address(path, TRUE); |
430 g_free(path); | |
431 } | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
432 } |
0 | 433 |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
434 if (scan_headers(msg, flags) == AERR_NORCPT) { |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
435 return AERR_NORCPT; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
436 } |
0 | 437 |
388
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
438 /* after the hdrs are scanned because we need to know the rcpts */ |
aa40710f09fe
Refactoring and code layouting.
markus schnalke <meillo@marmaro.de>
parents:
378
diff
changeset
|
439 add_received_hdr(msg); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
440 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
441 return AERR_OK; |
0 | 442 } |
443 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
444 accept_error |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
362
diff
changeset
|
445 accept_message(FILE *in, message *msg, guint flags) |
0 | 446 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
447 accept_error err; |
0 | 448 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
449 err = accept_message_stream(in, msg, flags); |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
450 if (err == AERR_OK) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
451 err = accept_message_prepare(msg, flags); |
270
0c44b239c7fe
refactoring in the small
markus schnalke <meillo@marmaro.de>
parents:
269
diff
changeset
|
452 } |
0 | 453 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
454 return err; |
0 | 455 } |