annotate src/smtp_in.c @ 172:cd38f10532e7

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