Mercurial > masqmail-0.2
annotate src/smtp_in.c @ 117:5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
``SIZE 0'' (= unlimited) is currently not supported
client-side support was already implemented
author | meillo@marmaro.de |
---|---|
date | Thu, 01 Jul 2010 13:08:53 +0200 |
parents | 71ce3a1568e9 |
children | cd59a5b4d3dd |
rev | line source |
---|---|
0 | 1 /* MasqMail |
2 Copyright (C) 1999-2001 Oliver Kurth | |
80 | 3 Copyright (C) 2010 markus schnalke <meillo@marmaro.de> |
0 | 4 |
5 This program is free software; you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 2 of the License, or | |
8 (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 */ | |
19 | |
20 #include "masqmail.h" | |
21 #include "readsock.h" | |
22 | |
23 /* | |
24 I always forget these rfc numbers: | |
25 RFC 821 (SMTP) | |
26 RFC 1869 (ESMTP) | |
27 RFC 1870 (ESMTP SIZE) | |
28 RFC 2197 (ESMTP PIPELINE) | |
29 RFC 2554 (ESMTP AUTH) | |
30 */ | |
31 | |
32 #ifdef ENABLE_SMTP_SERVER | |
33 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
34 smtp_cmd smtp_cmds[] = { |
15 | 35 {SMTP_HELO, "HELO",}, |
36 {SMTP_EHLO, "EHLO",}, | |
37 {SMTP_MAIL_FROM, "MAIL FROM:",}, | |
38 {SMTP_RCPT_TO, "RCPT TO:",}, | |
39 {SMTP_DATA, "DATA",}, | |
40 {SMTP_QUIT, "QUIT",}, | |
41 {SMTP_RSET, "RSET",}, | |
42 {SMTP_NOOP, "NOOP",}, | |
43 {SMTP_HELP, "HELP"}, | |
0 | 44 }; |
45 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 static smtp_cmd_id |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
47 get_id(const gchar * line) |
0 | 48 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
49 gint i; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
50 for (i = 0; i < SMTP_NUM_IDS; i++) { |
80 | 51 if (strncasecmp(smtp_cmds[i].cmd, line, strlen(smtp_cmds[i].cmd)) == 0) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
52 return (smtp_cmd_id) i; |
80 | 53 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
54 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
55 return SMTP_ERROR; |
0 | 56 } |
57 | |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
58 static gboolean |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
59 get_size(gchar *line, unsigned long *msize) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
60 gchar *s = NULL; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
61 |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
62 /* hope we need not to handle cases like SiZe= ...*/ |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
63 s = strstr(line, "SIZE="); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
64 if (!s) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
65 /* try it in lowercase too */ |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
66 if (!(s = strstr(line, "size="))) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
67 return FALSE; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
68 } |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
69 } |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
70 s += 5; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
71 *msize = atol(s); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
72 DEBUG(5) debugf("get_size(): line=%s, msize=%ld\n", line, *msize); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
73 |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
74 return TRUE; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
75 } |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
76 |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
77 |
0 | 78 /* this is a quick hack: we expect the address to be syntactically correct |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
79 and containing the mailbox only, though we first check for size in |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
80 smtp_in(). |
0 | 81 */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
82 static gboolean |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
83 get_address(gchar * line, gchar * addr) |
0 | 84 { |
80 | 85 gchar *p = line; |
86 gchar *q = addr; | |
0 | 87 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
88 /* skip MAIL FROM: and RCPT TO: */ |
80 | 89 while (*p && (*p != ':')) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
90 p++; |
80 | 91 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
92 p++; |
0 | 93 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
94 /* skip spaces: */ |
80 | 95 while (*p && isspace(*p)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
96 p++; |
80 | 97 } |
0 | 98 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
99 /* get address: */ |
80 | 100 while (*p && !isspace(*p) && (q < addr + MAX_ADDRESS - 1)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
101 *(q++) = *(p++); |
80 | 102 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
103 *q = 0; |
0 | 104 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
105 return TRUE; |
0 | 106 } |
107 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
108 static smtp_connection* |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
109 create_base(gchar * remote_host) |
0 | 110 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
111 smtp_connection *base = g_malloc(sizeof(smtp_connection)); |
80 | 112 if (!base) { |
113 return NULL; | |
114 } | |
115 | |
116 base->remote_host = g_strdup(remote_host); | |
0 | 117 |
80 | 118 base->prot = PROT_SMTP; |
119 base->next_id = 0; | |
120 base->helo_seen = 0; | |
121 base->from_seen = 0; | |
122 base->rcpt_seen = 0; | |
123 base->msg = NULL; | |
0 | 124 |
80 | 125 return base; |
0 | 126 } |
127 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
128 static void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
129 smtp_printf(FILE * out, gchar * fmt, ...) |
0 | 130 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
131 va_list args; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
132 va_start(args, fmt); |
0 | 133 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
134 DEBUG(4) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
135 gchar buf[256]; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
136 va_list args_copy; |
0 | 137 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
138 va_copy(args_copy, args); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
139 vsnprintf(buf, 255, fmt, args_copy); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
140 va_end(args_copy); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
141 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
142 debugf(">>>%s", buf); |
0 | 143 } |
144 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
145 vfprintf(out, fmt, args); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
146 fflush(out); |
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 va_end(args); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
149 } |
0 | 150 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
151 void |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
152 smtp_in(FILE * in, FILE * out, gchar * remote_host, gchar * ident) |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
153 { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
154 gchar *buffer; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
155 smtp_cmd_id cmd_id; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
156 message *msg = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
157 smtp_connection *psc; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
158 int len; |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
159 unsigned long size, msize; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
160 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
161 DEBUG(5) debugf("smtp_in entered, remote_host = %s\n", remote_host); |
0 | 162 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
163 psc = create_base(remote_host); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
164 psc->msg = msg; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
165 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
166 buffer = (gchar *) g_malloc(BUF_LEN); |
80 | 167 if (!buffer) { |
168 /* this check is actually unneccessary as g_malloc() | |
169 aborts on failure */ | |
170 return; | |
171 } | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
172 |
80 | 173 /* send greeting string, containing ESMTP: */ |
174 smtp_printf(out, "220 %s MasqMail %s ESMTP\r\n", conf.host_name, VERSION); | |
0 | 175 |
80 | 176 while ((len = read_sockline(in, buffer, BUF_LEN, 5 * 60, READSOCKL_CHUG)) >= 0) { |
177 cmd_id = get_id(buffer); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
178 |
80 | 179 switch (cmd_id) { |
180 case SMTP_EHLO: | |
181 psc->prot = PROT_ESMTP; | |
182 /* fall through */ | |
183 case SMTP_HELO: | |
184 psc->helo_seen = TRUE; | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
185 |
80 | 186 if (conf.defer_all) { /* I need this to debug delivery failures */ |
187 smtp_printf(out, "421 %s service temporarily unavailable.\r\n", conf.host_name); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
188 break; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
189 } |
80 | 190 |
191 if (psc->prot == PROT_ESMTP) { | |
192 smtp_printf(out, "250-%s Nice to meet you with ESMTP\r\n", conf.host_name); | |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
193 smtp_printf(out, "250-SIZE %d\r\n", conf.max_msg_size); |
80 | 194 smtp_printf(out, "250-PIPELINING\r\n" "250 HELP\r\n"); |
195 } else { | |
196 smtp_printf(out, "250 %s pretty old mailer, huh?\r\n", conf.host_name); | |
197 } | |
198 break; | |
199 | |
200 case SMTP_MAIL_FROM: | |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
201 if (get_size(buffer, &msize)) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
202 DEBUG(5) debugf("smtp_in(): get_size: msize=%ld, conf.mms=%d\n", |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
203 msize, conf.max_msg_size); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
204 if (msize > conf.max_msg_size) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
205 smtp_printf(out, "552 Message size exceeds fixed limit.\r\n"); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
206 break; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
207 } |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
208 } |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
209 |
80 | 210 { |
211 gchar buf[MAX_ADDRESS]; | |
212 address *addr; | |
213 | |
214 if (!psc->helo_seen) { | |
215 smtp_printf(out, "503 need HELO or EHLO\r\n"); | |
216 break; | |
217 } | |
218 if (psc->from_seen) { | |
219 smtp_printf(out, "503 MAIL FROM: already given.\r\n"); | |
220 break; | |
221 } | |
222 | |
223 msg = create_message(); | |
224 msg->received_host = remote_host ? g_strdup(remote_host) : NULL; | |
225 msg->received_prot = psc->prot; | |
226 msg->ident = ident ? g_strdup(ident) : NULL; | |
227 /* get transfer id and increment for next one */ | |
228 msg->transfer_id = (psc->next_id)++; | |
229 | |
230 get_address(buffer, buf); | |
231 if (remote_host) { | |
232 addr = create_address(buf, TRUE); | |
233 } else { | |
234 addr = create_address_qualified(buf, TRUE, conf.host_name); | |
235 } | |
236 if (!addr) { | |
237 smtp_printf(out, "501 %s: syntax error.\r\n", buf); | |
238 } else if (!addr->domain) { | |
239 smtp_printf(out, "501 return path must be qualified.\r\n", buf); | |
240 } else { | |
241 psc->from_seen = TRUE; | |
242 msg->return_path = addr; | |
243 smtp_printf(out, "250 OK %s is a nice guy.\r\n", addr->address); | |
244 } | |
245 } | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
246 break; |
80 | 247 |
248 case SMTP_RCPT_TO: | |
249 { | |
250 char buf[MAX_ADDRESS]; | |
251 address *addr; | |
252 | |
253 if (!psc->helo_seen) { | |
254 smtp_printf(out, "503 need HELO or EHLO.\r\n"); | |
255 break; | |
256 } | |
257 if (!psc->from_seen) { | |
258 smtp_printf(out, "503 need MAIL FROM: before RCPT TO:\r\n"); | |
259 break; | |
260 } | |
261 | |
262 get_address(buffer, buf); | |
263 if (remote_host) { | |
264 addr = create_address(buf, TRUE); | |
265 } else { | |
266 addr = create_address_qualified(buf, TRUE, conf.host_name); | |
267 } | |
268 if (!addr) { | |
269 smtp_printf(out, "501 %s: syntax error in address.\r\n", buf); | |
270 break; | |
271 } | |
272 if (addr->local_part[0] == '|') { | |
273 smtp_printf(out, "501 %s: no pipe allowed for SMTP connections\r\n", buf); | |
274 break; | |
275 } | |
276 if (!addr->domain) { | |
277 smtp_printf(out, "501 recipient address must be qualified.\r\n", buf); | |
278 break; | |
279 } | |
280 gboolean do_relay = conf.do_relay; | |
281 if (!do_relay) { | |
282 do_relay = addr_is_local(msg->return_path); | |
283 if (!do_relay) { | |
284 do_relay = addr_is_local(addr); | |
285 } | |
286 } | |
287 if (!do_relay) { | |
288 smtp_printf(out, "550 relaying to %s denied.\r\n", addr_string(addr)); | |
289 break; | |
290 } | |
291 psc->rcpt_seen = TRUE; | |
292 msg->rcpt_list = g_list_append(msg->rcpt_list, addr); | |
293 smtp_printf(out, "250 OK %s is our friend.\r\n", addr->address); | |
294 } | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
295 break; |
80 | 296 |
297 case SMTP_DATA: | |
298 if (!psc->helo_seen) { | |
299 smtp_printf(out, "503 need HELO or EHLO.\r\n"); | |
300 break; | |
301 } | |
302 if (!psc->rcpt_seen) { | |
303 smtp_printf(out, "503 need RCPT TO: before DATA\r\n"); | |
304 break; | |
305 } | |
306 accept_error err; | |
307 | |
308 smtp_printf(out, "354 okay, and do not forget the dot\r\n"); | |
309 | |
310 err = accept_message(in, msg, conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0); | |
311 if (err != AERR_OK) { | |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
312 switch (err) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
313 case AERR_TIMEOUT: |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
314 case AERR_EOF: |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
315 return; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
316 case AERR_SIZE: |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
317 smtp_printf(out, "552 Error: message too large.\r\n"); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
318 return; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
319 default: |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
320 /* should never happen: */ |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
321 smtp_printf(out, "451 Unknown error\r\n"); |
80 | 322 return; |
323 } | |
324 } | |
325 | |
326 | |
327 if (!spool_write(msg, TRUE)) { | |
328 smtp_printf(out, "451 Could not write spool file\r\n"); | |
329 return; | |
330 } | |
331 pid_t pid; | |
332 smtp_printf(out, "250 OK id=%s\r\n", msg->uid); | |
333 | |
334 if (remote_host != NULL) { | |
335 logwrite(LOG_NOTICE, "%s <= <%s@%s> host=%s with %s\n", msg->uid, | |
336 msg->return_path->local_part, msg->return_path->domain, | |
337 remote_host, prot_names[psc->prot]); | |
338 } else { | |
339 logwrite(LOG_NOTICE, "%s <= <%s@%s> with %s\n", msg->uid, | |
340 msg->return_path->local_part, msg->return_path->domain, | |
341 prot_names[psc->prot]); | |
342 } | |
343 | |
344 if (conf.do_queue) { | |
345 DEBUG(1) debugf("queuing forced by configuration or option.\n"); | |
346 } else { | |
347 pid = fork(); | |
348 if (pid == 0) { | |
349 _exit(deliver(msg)); | |
350 } else if (pid < 0) { | |
351 logwrite(LOG_ALERT, "could not fork for delivery, id = %s", msg->uid); | |
352 } | |
353 } | |
354 psc->rcpt_seen = psc->from_seen = FALSE; | |
355 destroy_message(msg); | |
356 msg = NULL; | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
357 break; |
80 | 358 |
359 case SMTP_QUIT: | |
360 smtp_printf(out, "221 goodbye\r\n"); | |
81
71ce3a1568e9
moved check for NULL into destroy_message()
meillo@marmaro.de
parents:
80
diff
changeset
|
361 destroy_message(msg); |
71ce3a1568e9
moved check for NULL into destroy_message()
meillo@marmaro.de
parents:
80
diff
changeset
|
362 msg = NULL; |
80 | 363 return; |
364 | |
365 case SMTP_RSET: | |
366 psc->from_seen = psc->rcpt_seen = FALSE; | |
81
71ce3a1568e9
moved check for NULL into destroy_message()
meillo@marmaro.de
parents:
80
diff
changeset
|
367 destroy_message(msg); |
71ce3a1568e9
moved check for NULL into destroy_message()
meillo@marmaro.de
parents:
80
diff
changeset
|
368 msg = NULL; |
80 | 369 smtp_printf(out, "250 OK\r\n"); |
370 break; | |
371 | |
372 case SMTP_NOOP: | |
373 smtp_printf(out, "250 OK\r\n"); | |
374 break; | |
375 | |
376 case SMTP_HELP: | |
377 { | |
378 int i; | |
379 | |
380 smtp_printf(out, "214-supported commands:\r\n"); | |
381 for (i = 0; i < SMTP_NUM_IDS - 1; i++) { | |
382 smtp_printf(out, "214-%s\r\n", smtp_cmds[i].cmd); | |
383 } | |
384 smtp_printf(out, "214 %s\r\n", smtp_cmds[i].cmd); | |
385 } | |
386 break; | |
387 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
388 default: |
80 | 389 smtp_printf(out, "501 command not recognized\r\n"); |
390 DEBUG(1) debugf("command not recognized, was '%s'\n", buffer); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
391 break; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
392 } |
0 | 393 } |
80 | 394 switch (len) { |
395 case -3: | |
396 logwrite(LOG_NOTICE, "connection timed out\n"); | |
397 break; | |
398 case -2: | |
399 logwrite(LOG_NOTICE, "line overflow\n"); | |
400 break; | |
401 case -1: | |
402 logwrite(LOG_NOTICE, "received EOF\n"); | |
403 break; | |
404 default: | |
405 break; | |
406 } | |
0 | 407 } |
408 #endif |