comparison 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
comparison
equal deleted inserted replaced
116:ddc8041fdee1 117:5ec5e6637049
53 } 53 }
54 } 54 }
55 return SMTP_ERROR; 55 return SMTP_ERROR;
56 } 56 }
57 57
58 static gboolean
59 get_size(gchar *line, unsigned long *msize) {
60 gchar *s = NULL;
61
62 /* hope we need not to handle cases like SiZe= ...*/
63 s = strstr(line, "SIZE=");
64 if (!s) {
65 /* try it in lowercase too */
66 if (!(s = strstr(line, "size="))) {
67 return FALSE;
68 }
69 }
70 s += 5;
71 *msize = atol(s);
72 DEBUG(5) debugf("get_size(): line=%s, msize=%ld\n", line, *msize);
73
74 return TRUE;
75 }
76
77
58 /* this is a quick hack: we expect the address to be syntactically correct 78 /* this is a quick hack: we expect the address to be syntactically correct
59 and containing the mailbox only: 79 and containing the mailbox only, though we first check for size in
80 smtp_in().
60 */ 81 */
61 static gboolean 82 static gboolean
62 get_address(gchar * line, gchar * addr) 83 get_address(gchar * line, gchar * addr)
63 { 84 {
64 gchar *p = line; 85 gchar *p = line;
133 gchar *buffer; 154 gchar *buffer;
134 smtp_cmd_id cmd_id; 155 smtp_cmd_id cmd_id;
135 message *msg = NULL; 156 message *msg = NULL;
136 smtp_connection *psc; 157 smtp_connection *psc;
137 int len; 158 int len;
159 unsigned long size, msize;
138 160
139 DEBUG(5) debugf("smtp_in entered, remote_host = %s\n", remote_host); 161 DEBUG(5) debugf("smtp_in entered, remote_host = %s\n", remote_host);
140 162
141 psc = create_base(remote_host); 163 psc = create_base(remote_host);
142 psc->msg = msg; 164 psc->msg = msg;
166 break; 188 break;
167 } 189 }
168 190
169 if (psc->prot == PROT_ESMTP) { 191 if (psc->prot == PROT_ESMTP) {
170 smtp_printf(out, "250-%s Nice to meet you with ESMTP\r\n", conf.host_name); 192 smtp_printf(out, "250-%s Nice to meet you with ESMTP\r\n", conf.host_name);
171 /* not yet: fprintf(out, "250-SIZE\r\n"); */ 193 smtp_printf(out, "250-SIZE %d\r\n", conf.max_msg_size);
172 smtp_printf(out, "250-PIPELINING\r\n" "250 HELP\r\n"); 194 smtp_printf(out, "250-PIPELINING\r\n" "250 HELP\r\n");
173 } else { 195 } else {
174 smtp_printf(out, "250 %s pretty old mailer, huh?\r\n", conf.host_name); 196 smtp_printf(out, "250 %s pretty old mailer, huh?\r\n", conf.host_name);
175 } 197 }
176 break; 198 break;
177 199
178 case SMTP_MAIL_FROM: 200 case SMTP_MAIL_FROM:
201 if (get_size(buffer, &msize)) {
202 DEBUG(5) debugf("smtp_in(): get_size: msize=%ld, conf.mms=%d\n",
203 msize, conf.max_msg_size);
204 if (msize > conf.max_msg_size) {
205 smtp_printf(out, "552 Message size exceeds fixed limit.\r\n");
206 break;
207 }
208 }
209
179 { 210 {
180 gchar buf[MAX_ADDRESS]; 211 gchar buf[MAX_ADDRESS];
181 address *addr; 212 address *addr;
182 213
183 if (!psc->helo_seen) { 214 if (!psc->helo_seen) {
276 307
277 smtp_printf(out, "354 okay, and do not forget the dot\r\n"); 308 smtp_printf(out, "354 okay, and do not forget the dot\r\n");
278 309
279 err = accept_message(in, msg, conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0); 310 err = accept_message(in, msg, conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0);
280 if (err != AERR_OK) { 311 if (err != AERR_OK) {
281 if (err == AERR_TIMEOUT || err == AERR_EOF) { 312 switch (err) {
313 case AERR_TIMEOUT:
314 case AERR_EOF:
282 return; 315 return;
283 } 316 case AERR_SIZE:
284 /* should never happen: */ 317 smtp_printf(out, "552 Error: message too large.\r\n");
285 smtp_printf(out, "451 Unknown error\r\n"); 318 return;
286 return; 319 default:
320 /* should never happen: */
321 smtp_printf(out, "451 Unknown error\r\n");
322 return;
323 }
287 } 324 }
288 325
289 326
290 if (!spool_write(msg, TRUE)) { 327 if (!spool_write(msg, TRUE)) {
291 smtp_printf(out, "451 Could not write spool file\r\n"); 328 smtp_printf(out, "451 Could not write spool file\r\n");