rev |
line source |
meillo@0
|
1 /* smtp_out.c, Copyright (C) 1999-2001 Oliver Kurth,
|
meillo@0
|
2 *
|
meillo@0
|
3 * This program is free software; you can redistribute it and/or modify
|
meillo@0
|
4 * it under the terms of the GNU General Public License as published by
|
meillo@0
|
5 * the Free Software Foundation; either version 2 of the License, or
|
meillo@0
|
6 * (at your option) any later version.
|
meillo@0
|
7 *
|
meillo@0
|
8 * This program is distributed in the hope that it will be useful,
|
meillo@0
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
meillo@0
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
meillo@0
|
11 * GNU General Public License for more details.
|
meillo@0
|
12 *
|
meillo@0
|
13 * You should have received a copy of the GNU General Public License
|
meillo@0
|
14 * along with this program; if not, write to the Free Software
|
meillo@0
|
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
meillo@0
|
16 */
|
meillo@0
|
17
|
meillo@0
|
18 /*
|
meillo@0
|
19 send bugs to: kurth@innominate.de
|
meillo@0
|
20 */
|
meillo@0
|
21
|
meillo@0
|
22 /*
|
meillo@0
|
23 I always forget these rfc numbers:
|
meillo@0
|
24 RFC 821 (SMTP)
|
meillo@0
|
25 RFC 1869 (ESMTP)
|
meillo@0
|
26 RFC 1870 (ESMTP SIZE)
|
meillo@0
|
27 RFC 2197 (ESMTP PIPELINE)
|
meillo@0
|
28 RFC 2554 (ESMTP AUTH)
|
meillo@0
|
29 */
|
meillo@0
|
30
|
meillo@0
|
31 #include "masqmail.h"
|
meillo@0
|
32 #include "smtp_out.h"
|
meillo@0
|
33 #include "readsock.h"
|
meillo@0
|
34
|
meillo@0
|
35 #ifdef ENABLE_AUTH
|
meillo@0
|
36
|
meillo@0
|
37 #ifdef USE_LIB_CRYPTO
|
meillo@0
|
38 #include <openssl/hmac.h>
|
meillo@0
|
39 #include <openssl/md5.h>
|
meillo@0
|
40 #include <openssl/evp.h>
|
meillo@0
|
41 #else
|
meillo@0
|
42 #include "md5/global.h"
|
meillo@0
|
43 #include "md5/md5.h"
|
meillo@0
|
44 #include "md5/hmac_md5.h"
|
meillo@0
|
45 #endif
|
meillo@0
|
46
|
meillo@0
|
47 #include "base64/base64.h"
|
meillo@0
|
48 #endif
|
meillo@0
|
49
|
meillo@0
|
50 void destroy_smtpbase(smtp_base *psb)
|
meillo@0
|
51 {
|
meillo@0
|
52 fclose(psb->in);
|
meillo@0
|
53 fclose(psb->out);
|
meillo@0
|
54
|
meillo@0
|
55 close(psb->sock);
|
meillo@0
|
56
|
meillo@0
|
57 if(psb->helo_name) g_free(psb->helo_name);
|
meillo@0
|
58 if(psb->buffer) g_free(psb->buffer);
|
meillo@0
|
59 if(psb->auth_names) g_strfreev(psb->auth_names);
|
meillo@0
|
60
|
meillo@0
|
61 if(psb->auth_name) g_free(psb->auth_name);
|
meillo@0
|
62 if(psb->auth_login) g_free(psb->auth_login);
|
meillo@0
|
63 if(psb->auth_secret) g_free(psb->auth_secret);
|
meillo@0
|
64 }
|
meillo@0
|
65
|
meillo@0
|
66 gchar *set_heloname(smtp_base *psb, gchar *default_name, gboolean do_correct)
|
meillo@0
|
67 {
|
meillo@0
|
68 struct sockaddr_in sname;
|
meillo@0
|
69 int len = sizeof(struct sockaddr_in);
|
meillo@0
|
70 struct hostent *host_entry;
|
meillo@0
|
71
|
meillo@0
|
72 if(do_correct){
|
meillo@0
|
73 getsockname(psb->sock, (struct sockaddr *)(&sname), &len);
|
meillo@0
|
74 DEBUG(5) debugf("socket: name.sin_addr = %s\n", inet_ntoa(sname.sin_addr));
|
meillo@0
|
75 host_entry =
|
meillo@0
|
76 gethostbyaddr((const char *)&(sname.sin_addr),
|
meillo@0
|
77 sizeof(sname.sin_addr), AF_INET);
|
meillo@0
|
78 if(host_entry){
|
meillo@0
|
79 psb->helo_name = g_strdup(host_entry->h_name);
|
meillo@0
|
80 }else{
|
meillo@0
|
81 /* we failed to look up our own name. Instead of giving our local hostname,
|
meillo@0
|
82 we may give our IP number to show the server that we are at least
|
meillo@0
|
83 willing to be honest. For the really picky ones.*/
|
meillo@0
|
84 DEBUG(5) debugf("failed to look up own host name.\n");
|
meillo@0
|
85 psb->helo_name = g_strdup_printf("[%s]", inet_ntoa(sname.sin_addr));
|
meillo@0
|
86 }
|
meillo@0
|
87 DEBUG(5) debugf("helo_name = %s\n", psb->helo_name);
|
meillo@0
|
88 }
|
meillo@0
|
89 if(psb->helo_name == NULL){
|
meillo@0
|
90 psb->helo_name = g_strdup(default_name);
|
meillo@0
|
91 }
|
meillo@0
|
92 return psb->helo_name;
|
meillo@0
|
93 }
|
meillo@0
|
94
|
meillo@0
|
95 #ifdef ENABLE_AUTH
|
meillo@0
|
96
|
meillo@0
|
97 gboolean set_auth(smtp_base *psb, gchar *name, gchar *login, gchar *secret)
|
meillo@0
|
98 {
|
meillo@0
|
99 if((strcasecmp(name, "CRAM-MD5") == 0) ||
|
meillo@0
|
100 (strcasecmp(name, "LOGIN") == 0)) {
|
meillo@0
|
101 psb->auth_name = g_strdup(name);
|
meillo@0
|
102 psb->auth_login = g_strdup(login);
|
meillo@0
|
103 psb->auth_secret = g_strdup(secret);
|
meillo@0
|
104
|
meillo@0
|
105 return TRUE;
|
meillo@0
|
106 }
|
meillo@0
|
107 return FALSE;
|
meillo@0
|
108 }
|
meillo@0
|
109
|
meillo@0
|
110 #endif
|
meillo@0
|
111
|
meillo@0
|
112 static
|
meillo@0
|
113 smtp_base *create_smtpbase(gint sock)
|
meillo@0
|
114 {
|
meillo@0
|
115 gint dup_sock;
|
meillo@0
|
116
|
meillo@0
|
117 smtp_base *psb = (smtp_base *)g_malloc(sizeof(smtp_base));
|
meillo@0
|
118
|
meillo@0
|
119 psb->sock = sock;
|
meillo@0
|
120
|
meillo@0
|
121 psb->use_esmtp = FALSE;
|
meillo@0
|
122 psb->use_size = FALSE;
|
meillo@0
|
123 psb->use_pipelining = FALSE;
|
meillo@0
|
124 psb->use_auth = FALSE;
|
meillo@0
|
125
|
meillo@0
|
126 psb->max_size = 0;
|
meillo@0
|
127 psb->auth_names = NULL;
|
meillo@0
|
128
|
meillo@0
|
129 psb->buffer = (gchar *)g_malloc(SMTP_BUF_LEN);
|
meillo@0
|
130
|
meillo@0
|
131 dup_sock = dup(sock);
|
meillo@0
|
132 psb->out = fdopen(sock, "w");
|
meillo@0
|
133 psb->in = fdopen(dup_sock, "r");
|
meillo@0
|
134
|
meillo@0
|
135 psb->error = smtp_ok;
|
meillo@0
|
136
|
meillo@0
|
137 psb->helo_name = NULL;
|
meillo@0
|
138
|
meillo@0
|
139 psb->auth_name = psb->auth_login = psb->auth_secret = NULL;
|
meillo@0
|
140
|
meillo@0
|
141 return psb;
|
meillo@0
|
142 }
|
meillo@0
|
143
|
meillo@0
|
144 static
|
meillo@0
|
145 gboolean read_response(smtp_base *psb, int timeout)
|
meillo@0
|
146 {
|
meillo@0
|
147 gint buf_pos = 0;
|
meillo@0
|
148 gchar code[5];
|
meillo@0
|
149 gint i, len;
|
meillo@0
|
150
|
meillo@0
|
151 do{
|
meillo@0
|
152 len = read_sockline(psb->in, &(psb->buffer[buf_pos]),
|
meillo@0
|
153 SMTP_BUF_LEN - buf_pos, timeout, READSOCKL_CHUG);
|
meillo@0
|
154 if(len == -3){
|
meillo@0
|
155 psb->error = smtp_timeout;
|
meillo@0
|
156 return FALSE;
|
meillo@0
|
157 }
|
meillo@0
|
158 else if(len == -2){
|
meillo@0
|
159 psb->error = smtp_syntax;
|
meillo@0
|
160 return FALSE;
|
meillo@0
|
161 }
|
meillo@0
|
162 else if(len == -1){
|
meillo@0
|
163 psb->error = smtp_eof;
|
meillo@0
|
164 return FALSE;
|
meillo@0
|
165 }
|
meillo@0
|
166 for(i = 0; i < 4; i++)
|
meillo@0
|
167 code[i] = psb->buffer[buf_pos+i];
|
meillo@0
|
168 code[i] = 0;
|
meillo@0
|
169 psb->last_code = atoi(code);
|
meillo@0
|
170
|
meillo@0
|
171 buf_pos += len;
|
meillo@0
|
172
|
meillo@0
|
173 }while(code[3] == '-');
|
meillo@0
|
174
|
meillo@0
|
175 return TRUE;
|
meillo@0
|
176 }
|
meillo@0
|
177
|
meillo@0
|
178 static
|
meillo@0
|
179 gboolean check_response(smtp_base *psb, gboolean after_data)
|
meillo@0
|
180 {
|
meillo@0
|
181 char c = psb->buffer[0];
|
meillo@0
|
182
|
meillo@0
|
183 if(((c == '2') && !after_data) || ((c == '3') && after_data)){
|
meillo@0
|
184 psb->error = smtp_ok;
|
meillo@0
|
185 DEBUG(6) debugf("response OK:'%s' after_date = %d\n", psb->buffer, (int)after_data);
|
meillo@0
|
186 return TRUE;
|
meillo@0
|
187 }else{
|
meillo@0
|
188 if(c == '4')
|
meillo@0
|
189 psb->error = smtp_trylater;
|
meillo@0
|
190 else if(c == '5')
|
meillo@0
|
191 psb->error = smtp_fail;
|
meillo@0
|
192 else
|
meillo@0
|
193 psb->error = smtp_syntax;
|
meillo@0
|
194 DEBUG(6) debugf("response failure:'%s' after_date = %d\n", psb->buffer, (int)after_data);
|
meillo@0
|
195 return FALSE;
|
meillo@0
|
196 }
|
meillo@0
|
197 }
|
meillo@0
|
198
|
meillo@0
|
199 static
|
meillo@0
|
200 gboolean check_init_response(smtp_base *psb)
|
meillo@0
|
201 {
|
meillo@0
|
202 if(check_response(psb, FALSE)){
|
meillo@0
|
203 psb->use_esmtp = (strstr(psb->buffer, "ESMTP") != NULL);
|
meillo@0
|
204
|
meillo@0
|
205 DEBUG(4) debugf(psb->use_esmtp ? "uses esmtp\n" : "no esmtp\n");
|
meillo@0
|
206
|
meillo@0
|
207 return TRUE;
|
meillo@0
|
208 }
|
meillo@0
|
209 return FALSE;
|
meillo@0
|
210 }
|
meillo@0
|
211
|
meillo@0
|
212 static
|
meillo@0
|
213 gchar *get_response_arg(gchar *response)
|
meillo@0
|
214 {
|
meillo@0
|
215 gchar buf[SMTP_BUF_LEN];
|
meillo@0
|
216 gchar *p = response, *q = buf;
|
meillo@0
|
217
|
meillo@0
|
218 while(*p && (*p != '\n') && isspace(*p)) p++;
|
meillo@0
|
219 if(*p && (*p != '\n')){
|
meillo@0
|
220 while(*p && (*p != '\n') && (*p != '\r') && (q < buf+SMTP_BUF_LEN-1)) *(q++) = *(p++);
|
meillo@0
|
221 *q = 0;
|
meillo@0
|
222 return g_strdup(buf);
|
meillo@0
|
223 }
|
meillo@0
|
224 return NULL;
|
meillo@0
|
225 }
|
meillo@0
|
226
|
meillo@0
|
227 static
|
meillo@0
|
228 gboolean check_helo_response(smtp_base *psb)
|
meillo@0
|
229 {
|
meillo@0
|
230 gchar *ptr = psb->buffer;
|
meillo@0
|
231
|
meillo@0
|
232 if(!check_response(psb, FALSE))
|
meillo@0
|
233 return FALSE;
|
meillo@0
|
234
|
meillo@0
|
235 while(*ptr){
|
meillo@0
|
236 if(strncasecmp(&(ptr[4]), "SIZE", 4) == 0){
|
meillo@0
|
237 gchar *arg;
|
meillo@0
|
238 psb->use_size = TRUE;
|
meillo@0
|
239 arg = get_response_arg(&(ptr[8]));
|
meillo@0
|
240 if(arg){
|
meillo@0
|
241 psb->max_size = atoi(arg);
|
meillo@0
|
242 g_free(arg);
|
meillo@0
|
243 }
|
meillo@0
|
244 }
|
meillo@0
|
245
|
meillo@0
|
246 if(strncasecmp(&(ptr[4]), "PIPELINING", 10) == 0)
|
meillo@0
|
247 psb->use_pipelining = TRUE;
|
meillo@0
|
248
|
meillo@0
|
249 if(strncasecmp(&(ptr[4]), "AUTH", 4) == 0){
|
meillo@0
|
250 if((ptr[8] == ' ') || (ptr[8] == '=') || (ptr[8] == '\t')){ /* not sure about '\t' */
|
meillo@0
|
251 gchar *arg;
|
meillo@0
|
252 psb->use_auth = TRUE;
|
meillo@0
|
253 arg = get_response_arg(&(ptr[9])); /* after several years I finally learnt to count */
|
meillo@0
|
254 if(arg){
|
meillo@0
|
255 psb->auth_names = g_strsplit(arg, " " , 0);
|
meillo@0
|
256 g_free(arg);
|
meillo@0
|
257
|
meillo@0
|
258 DEBUG(4){
|
meillo@0
|
259 gint i = 0;
|
meillo@0
|
260 while(psb->auth_names[i]){
|
meillo@0
|
261 debugf("offered AUTH %s\n", psb->auth_names[i]);
|
meillo@0
|
262 i++;
|
meillo@0
|
263 }
|
meillo@0
|
264 }
|
meillo@0
|
265 }
|
meillo@0
|
266 }
|
meillo@0
|
267 }
|
meillo@0
|
268
|
meillo@0
|
269 while(*ptr != '\n') ptr++;
|
meillo@0
|
270 ptr++;
|
meillo@0
|
271 }
|
meillo@0
|
272
|
meillo@0
|
273 DEBUG(4){
|
meillo@0
|
274 debugf(psb->use_size ? "uses SIZE\n" : "no size\n");
|
meillo@0
|
275 debugf(psb->use_pipelining ? "uses PIPELINING\n" : "no pipelining\n");
|
meillo@0
|
276 debugf(psb->use_auth ? "uses AUTH\n" : "no auth\n");
|
meillo@0
|
277 }
|
meillo@0
|
278
|
meillo@0
|
279 return TRUE;
|
meillo@0
|
280 }
|
meillo@0
|
281
|
meillo@0
|
282 static
|
meillo@0
|
283 gboolean smtp_helo(smtp_base *psb, gchar *helo)
|
meillo@0
|
284 {
|
meillo@0
|
285 while(TRUE){
|
meillo@0
|
286 if(psb->use_esmtp){
|
meillo@0
|
287 fprintf(psb->out, "EHLO %s\r\n", helo); fflush(psb->out);
|
meillo@0
|
288
|
meillo@0
|
289 DEBUG(4) debugf("EHLO %s\r\n", helo);
|
meillo@0
|
290
|
meillo@0
|
291 }else{
|
meillo@0
|
292 fprintf(psb->out, "HELO %s\r\n", helo); fflush(psb->out);
|
meillo@0
|
293
|
meillo@0
|
294 DEBUG(4) debugf("HELO %s\r\n", helo);
|
meillo@0
|
295
|
meillo@0
|
296 }
|
meillo@0
|
297
|
meillo@0
|
298 if(!read_response(psb, SMTP_CMD_TIMEOUT))
|
meillo@0
|
299 return FALSE;
|
meillo@0
|
300
|
meillo@0
|
301 if(check_helo_response(psb))
|
meillo@0
|
302 return TRUE;
|
meillo@0
|
303 else{
|
meillo@0
|
304 if(psb->error == smtp_fail){
|
meillo@0
|
305 if(psb->use_esmtp){
|
meillo@0
|
306 /* our guess that server understands EHLO was wrong,
|
meillo@0
|
307 try again with HELO
|
meillo@0
|
308 */
|
meillo@0
|
309 psb->use_esmtp = FALSE;
|
meillo@0
|
310 }else{
|
meillo@0
|
311 /* what sort of server ist THAT ?!
|
meillo@0
|
312 give up...
|
meillo@0
|
313 */
|
meillo@0
|
314 return FALSE;
|
meillo@0
|
315 }
|
meillo@0
|
316 }else
|
meillo@0
|
317 return FALSE;
|
meillo@0
|
318 }
|
meillo@0
|
319 }
|
meillo@0
|
320 }
|
meillo@0
|
321
|
meillo@0
|
322 static
|
meillo@0
|
323 void smtp_cmd_mailfrom(smtp_base *psb, address *return_path, guint size)
|
meillo@0
|
324 {
|
meillo@0
|
325 if(psb->use_size){
|
meillo@0
|
326 fprintf(psb->out, "MAIL FROM:%s SIZE=%d\r\n",
|
meillo@0
|
327 addr_string(return_path), size);
|
meillo@0
|
328 fflush(psb->out);
|
meillo@0
|
329
|
meillo@0
|
330 DEBUG(4) debugf("MAIL FROM:%s SIZE=%d\r\n",
|
meillo@0
|
331 addr_string(return_path), size);
|
meillo@0
|
332
|
meillo@0
|
333 }else{
|
meillo@0
|
334 fprintf(psb->out, "MAIL FROM:%s\r\n", addr_string(return_path));
|
meillo@0
|
335 fflush(psb->out);
|
meillo@0
|
336
|
meillo@0
|
337 DEBUG(4) debugf("MAIL FROM:%s\r\n", addr_string(return_path));
|
meillo@0
|
338 }
|
meillo@0
|
339 }
|
meillo@0
|
340
|
meillo@0
|
341 static
|
meillo@0
|
342 void smtp_cmd_rcptto(smtp_base *psb, address *rcpt)
|
meillo@0
|
343 {
|
meillo@0
|
344 fprintf(psb->out, "RCPT TO:%s\r\n", addr_string(rcpt));
|
meillo@0
|
345 fflush(psb->out);
|
meillo@0
|
346 DEBUG(4) debugf("RCPT TO:%s\n", addr_string(rcpt));
|
meillo@0
|
347 }
|
meillo@0
|
348
|
meillo@0
|
349 static
|
meillo@0
|
350 void send_data_line(smtp_base *psb, gchar *data)
|
meillo@0
|
351 {
|
meillo@0
|
352 /* According to RFC 821 each line should be terminated with CRLF.
|
meillo@0
|
353 Since a dot on a line itself marks the end of data, each line
|
meillo@0
|
354 beginning with a dot is prepended with another dot.
|
meillo@0
|
355 */
|
meillo@0
|
356 gchar *ptr;
|
meillo@0
|
357 gboolean new_line = TRUE; /* previous versions assumed that each item was
|
meillo@0
|
358 exactly one line. This is no longer the case */
|
meillo@0
|
359
|
meillo@0
|
360 ptr = data;
|
meillo@0
|
361 while(*ptr){
|
meillo@0
|
362 int c = (int)(*ptr);
|
meillo@0
|
363 if(c == '.')
|
meillo@0
|
364 if(new_line)
|
meillo@0
|
365 putc('.', psb->out);
|
meillo@0
|
366 if(c == '\n'){
|
meillo@0
|
367 putc('\r', psb->out);
|
meillo@0
|
368 putc('\n', psb->out);
|
meillo@0
|
369 new_line = TRUE;
|
meillo@0
|
370 }else{
|
meillo@0
|
371 putc(c, psb->out);
|
meillo@0
|
372 new_line = FALSE;
|
meillo@0
|
373 }
|
meillo@0
|
374 ptr++;
|
meillo@0
|
375 }
|
meillo@0
|
376 }
|
meillo@0
|
377
|
meillo@0
|
378 static
|
meillo@0
|
379 void send_header(smtp_base *psb, GList *hdr_list)
|
meillo@0
|
380 {
|
meillo@0
|
381 GList *node;
|
meillo@0
|
382 gint num_hdrs = 0;
|
meillo@0
|
383
|
meillo@0
|
384 /* header */
|
meillo@0
|
385 if(hdr_list){
|
meillo@0
|
386 foreach(hdr_list, node){
|
meillo@0
|
387 if(node->data){
|
meillo@0
|
388 header *hdr = (header *)(node->data);
|
meillo@0
|
389 if(hdr->header){
|
meillo@0
|
390 send_data_line(psb, hdr->header);
|
meillo@0
|
391 num_hdrs++;
|
meillo@0
|
392 }
|
meillo@0
|
393 }
|
meillo@0
|
394 }
|
meillo@0
|
395 }
|
meillo@0
|
396
|
meillo@0
|
397 /* empty line separating headers from data: */
|
meillo@0
|
398 putc('\r', psb->out);
|
meillo@0
|
399 putc('\n', psb->out);
|
meillo@0
|
400
|
meillo@0
|
401 DEBUG(4) debugf("sent %d headers\n", num_hdrs);
|
meillo@0
|
402 }
|
meillo@0
|
403
|
meillo@0
|
404 static
|
meillo@0
|
405 void send_data(smtp_base *psb, message *msg)
|
meillo@0
|
406 {
|
meillo@0
|
407 GList *node;
|
meillo@0
|
408 gint num_lines = 0;
|
meillo@0
|
409
|
meillo@0
|
410 /* data */
|
meillo@0
|
411 if(msg->data_list){
|
meillo@0
|
412 for(node = g_list_first(msg->data_list); node; node = g_list_next(node)){
|
meillo@0
|
413 if(node->data){
|
meillo@0
|
414 send_data_line(psb, node->data);
|
meillo@0
|
415 num_lines++;
|
meillo@0
|
416 }
|
meillo@0
|
417 }
|
meillo@0
|
418 }
|
meillo@0
|
419
|
meillo@0
|
420 DEBUG(4) debugf("sent %d lines of data\n", num_lines);
|
meillo@0
|
421
|
meillo@0
|
422 fprintf(psb->out, ".\r\n");
|
meillo@0
|
423 fflush(psb->out);
|
meillo@0
|
424 }
|
meillo@0
|
425
|
meillo@0
|
426 void smtp_out_mark_rcpts(smtp_base *psb, GList *rcpt_list)
|
meillo@0
|
427 {
|
meillo@0
|
428 GList *rcpt_node;
|
meillo@0
|
429 for(rcpt_node = g_list_first(rcpt_list);
|
meillo@0
|
430 rcpt_node;
|
meillo@0
|
431 rcpt_node = g_list_next(rcpt_node)){
|
meillo@0
|
432 address *rcpt = (address *)(rcpt_node->data);
|
meillo@0
|
433
|
meillo@0
|
434 addr_unmark_delivered(rcpt);
|
meillo@0
|
435
|
meillo@0
|
436 if((psb->error == smtp_trylater) || (psb->error == smtp_timeout) ||
|
meillo@0
|
437 (psb->error == smtp_eof)){
|
meillo@0
|
438 addr_mark_defered(rcpt);
|
meillo@0
|
439 }else{
|
meillo@0
|
440 addr_mark_failed(rcpt);
|
meillo@0
|
441 }
|
meillo@0
|
442 }
|
meillo@0
|
443 }
|
meillo@0
|
444
|
meillo@0
|
445 void smtp_out_log_failure(smtp_base *psb, message *msg)
|
meillo@0
|
446 {
|
meillo@0
|
447 gchar *err_str;
|
meillo@0
|
448
|
meillo@0
|
449 if(psb->error == smtp_timeout)
|
meillo@0
|
450 err_str = g_strdup("connection timed out.");
|
meillo@0
|
451 else if(psb->error == smtp_eof)
|
meillo@0
|
452 err_str = g_strdup("connection terminated prematurely.");
|
meillo@0
|
453 else if(psb->error == smtp_syntax)
|
meillo@0
|
454 err_str = g_strdup_printf("got unexpected response: %s", psb->buffer);
|
meillo@0
|
455 else if(psb->error == smtp_cancel)
|
meillo@0
|
456 err_str = g_strdup("delivery was canceled.\n");
|
meillo@0
|
457 else
|
meillo@0
|
458 /* error message should still be in the buffer */
|
meillo@0
|
459 err_str = g_strdup_printf("failed: %s\n", psb->buffer);
|
meillo@0
|
460
|
meillo@0
|
461 if(msg == NULL)
|
meillo@0
|
462 logwrite(LOG_NOTICE, "host=%s %s\n",
|
meillo@0
|
463 psb->remote_host, err_str);
|
meillo@0
|
464 else
|
meillo@0
|
465 logwrite(LOG_NOTICE, "%s == host=%s %s\n",
|
meillo@0
|
466 msg->uid, psb->remote_host, err_str);
|
meillo@0
|
467
|
meillo@0
|
468 g_free(err_str);
|
meillo@0
|
469 }
|
meillo@0
|
470
|
meillo@0
|
471 smtp_base *smtp_out_open(gchar *host, gint port, GList *resolve_list)
|
meillo@0
|
472 {
|
meillo@0
|
473 smtp_base *psb;
|
meillo@0
|
474 gint sock;
|
meillo@0
|
475 mxip_addr *addr;
|
meillo@0
|
476
|
meillo@0
|
477 DEBUG(5) debugf("smtp_out_open entered, host = %s\n", host);
|
meillo@0
|
478
|
meillo@0
|
479 if((addr = connect_resolvelist(&sock, host, port, resolve_list))){
|
meillo@0
|
480 /* create structure to hold status data: */
|
meillo@0
|
481 psb = create_smtpbase(sock);
|
meillo@0
|
482 psb->remote_host = addr->name;
|
meillo@0
|
483
|
meillo@0
|
484 DEBUG(5){
|
meillo@0
|
485 struct sockaddr_in name;
|
meillo@0
|
486 int len = sizeof(struct sockaddr);
|
meillo@0
|
487 getsockname(sock, (struct sockaddr *)(&name), &len);
|
meillo@0
|
488 debugf("socket: name.sin_addr = %s\n", inet_ntoa(name.sin_addr));
|
meillo@0
|
489 }
|
meillo@0
|
490 return psb;
|
meillo@0
|
491 }else{
|
meillo@0
|
492 DEBUG(5) debugf("connect_resolvelist failed: %s %s\n", strerror(errno), hstrerror(h_errno));
|
meillo@0
|
493 }
|
meillo@0
|
494
|
meillo@0
|
495 return NULL;
|
meillo@0
|
496 }
|
meillo@0
|
497
|
meillo@0
|
498 smtp_base *smtp_out_open_child(gchar *cmd)
|
meillo@0
|
499 {
|
meillo@0
|
500 smtp_base *psb;
|
meillo@0
|
501 gint sock;
|
meillo@0
|
502
|
meillo@0
|
503 DEBUG(5) debugf("smtp_out_open_child entered, cmd = %s\n", cmd);
|
meillo@0
|
504
|
meillo@0
|
505 sock = child(cmd);
|
meillo@0
|
506
|
meillo@0
|
507 if(sock > 0){
|
meillo@0
|
508 psb = create_smtpbase(sock);
|
meillo@0
|
509 psb->remote_host = NULL;
|
meillo@0
|
510
|
meillo@0
|
511 return psb;
|
meillo@0
|
512 }
|
meillo@0
|
513
|
meillo@0
|
514 return NULL;
|
meillo@0
|
515 }
|
meillo@0
|
516
|
meillo@0
|
517 gboolean smtp_out_rset(smtp_base *psb)
|
meillo@0
|
518 {
|
meillo@0
|
519 gboolean ok;
|
meillo@0
|
520
|
meillo@0
|
521 fprintf(psb->out, "RSET\r\n"); fflush(psb->out);
|
meillo@0
|
522 DEBUG(4) debugf("RSET\n");
|
meillo@0
|
523
|
meillo@0
|
524 if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
|
meillo@0
|
525 if(check_response(psb, FALSE))
|
meillo@0
|
526 return TRUE;
|
meillo@0
|
527
|
meillo@0
|
528 smtp_out_log_failure(psb, NULL);
|
meillo@0
|
529
|
meillo@0
|
530 return FALSE;
|
meillo@0
|
531 }
|
meillo@0
|
532
|
meillo@0
|
533 #ifdef ENABLE_AUTH
|
meillo@0
|
534
|
meillo@0
|
535 static
|
meillo@0
|
536 gboolean smtp_out_auth_cram_md5(smtp_base *psb)
|
meillo@0
|
537 {
|
meillo@0
|
538 gboolean ok = FALSE;
|
meillo@0
|
539
|
meillo@0
|
540 fprintf(psb->out, "AUTH CRAM-MD5\r\n"); fflush(psb->out);
|
meillo@0
|
541 DEBUG(4) debugf("AUTH CRAM-MD5\n");
|
meillo@0
|
542 if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
|
meillo@0
|
543 if((ok = check_response(psb, TRUE))){
|
meillo@0
|
544 gchar *chall64 = get_response_arg(&(psb->buffer[4]));
|
meillo@0
|
545 gint chall_size;
|
meillo@0
|
546 gchar *chall = base64_decode(chall64, &chall_size);
|
meillo@0
|
547 guchar digest[16], *reply64, *reply;
|
meillo@0
|
548 gchar digest_string[33];
|
meillo@0
|
549 gint i;
|
meillo@0
|
550 #ifdef USE_LIB_CRYPTO
|
meillo@0
|
551 unsigned int digest_len;
|
meillo@0
|
552 #endif
|
meillo@0
|
553
|
meillo@0
|
554 DEBUG(5) debugf("encoded challenge = %s\n", chall64);
|
meillo@0
|
555 DEBUG(5) debugf("decoded challenge = %s, size = %d\n", chall, chall_size);
|
meillo@0
|
556
|
meillo@0
|
557 DEBUG(5) debugf("secret = %s\n", psb->auth_secret);
|
meillo@0
|
558
|
meillo@0
|
559 #ifdef USE_LIB_CRYPTO
|
meillo@0
|
560 HMAC(EVP_md5(), psb->auth_secret, strlen(psb->auth_secret), chall, chall_size, digest, &digest_len);
|
meillo@0
|
561 #else
|
meillo@0
|
562 hmac_md5(chall, chall_size, psb->auth_secret, strlen(psb->auth_secret), digest);
|
meillo@0
|
563 #endif
|
meillo@0
|
564
|
meillo@0
|
565 for(i = 0; i < 16; i++)
|
meillo@0
|
566 sprintf(&(digest_string[i+i]), "%02x", (unsigned int)(digest[i]));
|
meillo@0
|
567 digest_string[32] = 0;
|
meillo@0
|
568
|
meillo@0
|
569 DEBUG(5) debugf("digest = %s\n", digest_string);
|
meillo@0
|
570
|
meillo@0
|
571 reply = g_strdup_printf("%s %s", psb->auth_login, digest_string);
|
meillo@0
|
572 DEBUG(5) debugf("unencoded reply = %s\n", reply);
|
meillo@0
|
573
|
meillo@0
|
574 reply64 = base64_encode(reply, strlen(reply));
|
meillo@0
|
575 DEBUG(5) debugf("encoded reply = %s\n", reply64);
|
meillo@0
|
576
|
meillo@0
|
577 fprintf(psb->out, "%s\r\n", reply64); fflush(psb->out);
|
meillo@0
|
578 DEBUG(4) debugf("%s\n", reply64);
|
meillo@0
|
579
|
meillo@0
|
580 if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
|
meillo@0
|
581 ok = check_response(psb, FALSE);
|
meillo@0
|
582
|
meillo@0
|
583 g_free(reply64);
|
meillo@0
|
584 g_free(reply);
|
meillo@0
|
585 g_free(chall);
|
meillo@0
|
586 g_free(chall64);
|
meillo@0
|
587 }
|
meillo@0
|
588 }
|
meillo@0
|
589 return ok;
|
meillo@0
|
590 }
|
meillo@0
|
591
|
meillo@0
|
592 static
|
meillo@0
|
593 gboolean smtp_out_auth_login(smtp_base *psb)
|
meillo@0
|
594 {
|
meillo@0
|
595 gboolean ok = FALSE;
|
meillo@0
|
596 fprintf(psb->out, "AUTH LOGIN\r\n"); fflush(psb->out);
|
meillo@0
|
597 if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
|
meillo@0
|
598 if((ok = check_response(psb, TRUE))){
|
meillo@0
|
599 gchar *resp64;
|
meillo@0
|
600 guchar *resp;
|
meillo@0
|
601 gint resp_size;
|
meillo@0
|
602 gchar *reply64;
|
meillo@0
|
603
|
meillo@0
|
604 resp64 = get_response_arg(&(psb->buffer[4]));
|
meillo@0
|
605 DEBUG(5) debugf("encoded response = %s\n", resp64);
|
meillo@0
|
606 resp = base64_decode(resp64, &resp_size);
|
meillo@0
|
607 g_free(resp64);
|
meillo@0
|
608 DEBUG(5) debugf("decoded response = %s, size = %d\n",
|
meillo@0
|
609 resp, resp_size);
|
meillo@0
|
610 g_free(resp);
|
meillo@0
|
611 reply64 = base64_encode(psb->auth_login,
|
meillo@0
|
612 strlen(psb->auth_login));
|
meillo@0
|
613 fprintf(psb->out, "%s\r\n", reply64); fflush(psb->out);
|
meillo@0
|
614 g_free(reply64);
|
meillo@0
|
615 if((ok = read_response(psb, SMTP_CMD_TIMEOUT))) {
|
meillo@0
|
616 if ((ok = check_response(psb, TRUE))) {
|
meillo@0
|
617 resp64 = get_response_arg(&(psb->buffer[4]));
|
meillo@0
|
618 DEBUG(5) debugf("encoded response = %s\n", resp64);
|
meillo@0
|
619 resp = base64_decode(resp64, &resp_size);
|
meillo@0
|
620 g_free(resp64);
|
meillo@0
|
621 DEBUG(5) debugf("decoded response = %s, size = %d\n",
|
meillo@0
|
622 resp, resp_size);
|
meillo@0
|
623 g_free(resp);
|
meillo@0
|
624 reply64 = base64_encode(psb->auth_secret,
|
meillo@0
|
625 strlen(psb->auth_secret));
|
meillo@0
|
626 fprintf(psb->out, "%s\r\n", reply64); fflush(psb->out);
|
meillo@0
|
627 g_free(reply64);
|
meillo@0
|
628 if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
|
meillo@0
|
629 ok = check_response(psb, FALSE);
|
meillo@0
|
630 }
|
meillo@0
|
631 }
|
meillo@0
|
632 }
|
meillo@0
|
633 }
|
meillo@0
|
634 return ok;
|
meillo@0
|
635 }
|
meillo@0
|
636
|
meillo@0
|
637 gboolean smtp_out_auth(smtp_base *psb)
|
meillo@0
|
638 {
|
meillo@0
|
639 gboolean ok = FALSE;
|
meillo@0
|
640 gint i = 0;
|
meillo@0
|
641 while(psb->auth_names[i]){
|
meillo@0
|
642 if(strcasecmp(psb->auth_names[i], psb->auth_name) == 0)
|
meillo@0
|
643 break;
|
meillo@0
|
644 i++;
|
meillo@0
|
645 }
|
meillo@0
|
646 if(psb->auth_names[i]){
|
meillo@0
|
647 if(strcasecmp(psb->auth_name, "cram-md5") == 0){
|
meillo@0
|
648 smtp_out_auth_cram_md5(psb);
|
meillo@0
|
649 }else if(strcasecmp(psb->auth_name, "login") == 0){
|
meillo@0
|
650 smtp_out_auth_login(psb);
|
meillo@0
|
651 }else{
|
meillo@0
|
652 logwrite(LOG_ERR, "auth method %s not supported\n", psb->auth_name);
|
meillo@0
|
653 }
|
meillo@0
|
654 }else{
|
meillo@0
|
655 logwrite(LOG_ERR, "no auth method %s found.\n", psb->auth_name);
|
meillo@0
|
656 }
|
meillo@0
|
657 return ok;
|
meillo@0
|
658 }
|
meillo@0
|
659
|
meillo@0
|
660 #endif
|
meillo@0
|
661
|
meillo@0
|
662 gboolean smtp_out_init(smtp_base *psb)
|
meillo@0
|
663 {
|
meillo@0
|
664 gboolean ok;
|
meillo@0
|
665
|
meillo@0
|
666 if((ok = read_response(psb, SMTP_INITIAL_TIMEOUT))){
|
meillo@0
|
667 if((ok = check_init_response(psb))){
|
meillo@0
|
668
|
meillo@0
|
669 if((ok = smtp_helo(psb, psb->helo_name))){
|
meillo@0
|
670 #ifdef ENABLE_AUTH
|
meillo@0
|
671 if(psb->auth_name && psb->use_auth){
|
meillo@0
|
672 /* we completely disregard the response of server here. If
|
meillo@0
|
673 authentication fails, the server will complain later
|
meillo@0
|
674 anyway. I know, this is not polite... */
|
meillo@0
|
675 smtp_out_auth(psb);
|
meillo@0
|
676 }
|
meillo@0
|
677 #endif
|
meillo@0
|
678 }
|
meillo@0
|
679 }
|
meillo@0
|
680 }
|
meillo@0
|
681 if(!ok)
|
meillo@0
|
682 smtp_out_log_failure(psb, NULL);
|
meillo@0
|
683 return ok;
|
meillo@0
|
684 }
|
meillo@0
|
685
|
meillo@0
|
686 gint smtp_out_msg(smtp_base *psb,
|
meillo@0
|
687 message *msg, address *return_path, GList *rcpt_list,
|
meillo@0
|
688 GList *hdr_list)
|
meillo@0
|
689 {
|
meillo@0
|
690 gint i, size;
|
meillo@0
|
691 gboolean ok = TRUE;
|
meillo@0
|
692 int rcpt_cnt;
|
meillo@0
|
693 int rcpt_accept = 0;
|
meillo@0
|
694
|
meillo@0
|
695 DEBUG(5) debugf("smtp_out_msg entered\n");
|
meillo@0
|
696
|
meillo@0
|
697 /* defaults: */
|
meillo@0
|
698 if(return_path == NULL)
|
meillo@0
|
699 return_path = msg->return_path;
|
meillo@0
|
700 if(hdr_list == NULL)
|
meillo@0
|
701 hdr_list = msg->hdr_list;
|
meillo@0
|
702 if(rcpt_list == NULL)
|
meillo@0
|
703 rcpt_list = msg->rcpt_list;
|
meillo@0
|
704 rcpt_cnt = g_list_length(rcpt_list);
|
meillo@0
|
705
|
meillo@0
|
706 size = msg_calc_size(msg, TRUE);
|
meillo@0
|
707
|
meillo@0
|
708 /* respect maximum size given by server: */
|
meillo@0
|
709 if((psb->max_size > 0) && (size > psb->max_size)){
|
meillo@0
|
710 logwrite(LOG_WARNING,
|
meillo@0
|
711 "%s == host=%s message size (%d) > fixed maximum message size of server (%d)",
|
meillo@0
|
712 msg->uid, psb->remote_host, size, psb->max_size);
|
meillo@0
|
713 psb->error = smtp_cancel;
|
meillo@0
|
714 ok = FALSE;
|
meillo@0
|
715 }
|
meillo@0
|
716
|
meillo@0
|
717 if(ok){
|
meillo@0
|
718 smtp_cmd_mailfrom(psb, return_path,
|
meillo@0
|
719 psb->use_size ?
|
meillo@0
|
720 size + SMTP_SIZE_ADD : 0);
|
meillo@0
|
721
|
meillo@0
|
722 if(!psb->use_pipelining){
|
meillo@0
|
723 if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
|
meillo@0
|
724 ok = check_response(psb, FALSE);
|
meillo@0
|
725 }
|
meillo@0
|
726 }
|
meillo@0
|
727 if(ok){
|
meillo@0
|
728 GList *rcpt_node;
|
meillo@0
|
729 rcpt_accept = 0;
|
meillo@0
|
730
|
meillo@0
|
731 for(rcpt_node = g_list_first(rcpt_list);
|
meillo@0
|
732 rcpt_node != NULL;
|
meillo@0
|
733 rcpt_node = g_list_next(rcpt_node)){
|
meillo@0
|
734 address *rcpt = (address *)(rcpt_node->data);
|
meillo@0
|
735 smtp_cmd_rcptto(psb, rcpt);
|
meillo@0
|
736 if(!psb->use_pipelining){
|
meillo@0
|
737 if((ok = read_response(psb, SMTP_CMD_TIMEOUT)))
|
meillo@0
|
738 if(check_response(psb, FALSE)){
|
meillo@0
|
739 rcpt_accept++;
|
meillo@0
|
740 addr_mark_delivered(rcpt);
|
meillo@0
|
741 }
|
meillo@0
|
742 else{
|
meillo@0
|
743 /* if server returned an error for one recp. we
|
meillo@0
|
744 may still try the others. But if it is a timeout, eof
|
meillo@0
|
745 or unexpected response, it is more serious and we should
|
meillo@0
|
746 give up. */
|
meillo@0
|
747 if((psb->error != smtp_trylater) &&
|
meillo@0
|
748 (psb->error != smtp_fail)){
|
meillo@0
|
749 ok = FALSE;
|
meillo@0
|
750 break;
|
meillo@0
|
751 }else{
|
meillo@0
|
752 logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s",
|
meillo@0
|
753 msg->uid, addr_string(rcpt),
|
meillo@0
|
754 psb->remote_host, psb->buffer);
|
meillo@0
|
755 if(psb->error == smtp_trylater){
|
meillo@0
|
756 addr_mark_defered(rcpt);
|
meillo@0
|
757 }else{
|
meillo@0
|
758 addr_mark_failed(rcpt);
|
meillo@0
|
759 }
|
meillo@0
|
760 }
|
meillo@0
|
761 }
|
meillo@0
|
762 else
|
meillo@0
|
763 break;
|
meillo@0
|
764 }
|
meillo@0
|
765 }
|
meillo@0
|
766
|
meillo@0
|
767 /* There is no point in going on if no recp.s were accpted.
|
meillo@0
|
768 But we can check that at this point only if not pipelining: */
|
meillo@0
|
769 ok = (ok && (psb->use_pipelining || (rcpt_accept > 0)));
|
meillo@0
|
770 if(ok){
|
meillo@0
|
771
|
meillo@0
|
772 fprintf(psb->out, "DATA\r\n"); fflush(psb->out);
|
meillo@0
|
773
|
meillo@0
|
774 DEBUG(4) debugf("DATA\r\n");
|
meillo@0
|
775
|
meillo@0
|
776 if(psb->use_pipelining){
|
meillo@0
|
777 /* the first pl'ed command was MAIL FROM
|
meillo@0
|
778 the last was DATA, whose response can be handled by the 'normal' code
|
meillo@0
|
779 all in between were RCPT TO:
|
meillo@0
|
780 */
|
meillo@0
|
781 /* response to MAIL FROM: */
|
meillo@0
|
782 if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
|
meillo@0
|
783 if((ok = check_response(psb, FALSE))){
|
meillo@0
|
784
|
meillo@0
|
785 /* response(s) to RCPT TO:
|
meillo@0
|
786 this is very similar to the sequence above for no pipeline
|
meillo@0
|
787 */
|
meillo@0
|
788 for(i = 0; i < rcpt_cnt; i++){
|
meillo@0
|
789 if((ok = read_response(psb, SMTP_CMD_TIMEOUT))){
|
meillo@0
|
790 address *rcpt = g_list_nth_data(rcpt_list, i);
|
meillo@0
|
791 if(check_response(psb, FALSE)){
|
meillo@0
|
792 rcpt_accept++;
|
meillo@0
|
793 addr_mark_delivered(rcpt);
|
meillo@0
|
794 }
|
meillo@0
|
795 else{
|
meillo@0
|
796 /* if server returned an error 4xx or 5xx for one recp. we
|
meillo@0
|
797 may still try the others. But if it is a timeout, eof
|
meillo@0
|
798 or unexpected response, it is more serious and we
|
meillo@0
|
799 should give up. */
|
meillo@0
|
800 if((psb->error != smtp_trylater) &&
|
meillo@0
|
801 (psb->error != smtp_fail)){
|
meillo@0
|
802 ok = FALSE;
|
meillo@0
|
803 break;
|
meillo@0
|
804 }else{
|
meillo@0
|
805 logwrite(LOG_NOTICE, "%s == %s host=%s failed: %s",
|
meillo@0
|
806 msg->uid, addr_string(rcpt),
|
meillo@0
|
807 psb->remote_host, psb->buffer);
|
meillo@0
|
808 if(psb->error == smtp_trylater){
|
meillo@0
|
809 addr_mark_defered(rcpt);
|
meillo@0
|
810 }else{
|
meillo@0
|
811 addr_mark_failed(rcpt);
|
meillo@0
|
812 }
|
meillo@0
|
813 }
|
meillo@0
|
814 }
|
meillo@0
|
815 }else{
|
meillo@0
|
816 DEBUG(5) debugf("check_response failed after RCPT TO\n");
|
meillo@0
|
817 break;
|
meillo@0
|
818 }
|
meillo@0
|
819 }
|
meillo@0
|
820 if(rcpt_accept == 0)
|
meillo@0
|
821 ok = FALSE;
|
meillo@0
|
822 }else{
|
meillo@0
|
823 DEBUG(5) debugf("check_response failed after MAIL FROM\n");
|
meillo@0
|
824 }
|
meillo@0
|
825 }else{
|
meillo@0
|
826 DEBUG(5) debugf("read_response failed after MAIL FROM\n");
|
meillo@0
|
827 }
|
meillo@0
|
828 } /* if(psb->use_pipelining) */
|
meillo@0
|
829
|
meillo@0
|
830 /* response to the DATA cmd */
|
meillo@0
|
831 if(ok){
|
meillo@0
|
832 if(read_response(psb, SMTP_DATA_TIMEOUT)){
|
meillo@0
|
833 if(check_response(psb, TRUE)){
|
meillo@0
|
834 send_header(psb, hdr_list);
|
meillo@0
|
835 send_data(psb, msg);
|
meillo@0
|
836
|
meillo@0
|
837 if(read_response(psb, SMTP_FINAL_TIMEOUT))
|
meillo@0
|
838 ok = check_response(psb, FALSE);
|
meillo@0
|
839 }
|
meillo@0
|
840 }
|
meillo@0
|
841 }
|
meillo@0
|
842 }
|
meillo@0
|
843 }
|
meillo@0
|
844
|
meillo@0
|
845 DEBUG(5){
|
meillo@0
|
846 debugf("psb->error = %d\n", psb->error);
|
meillo@0
|
847 debugf("ok = %d\n", ok);
|
meillo@0
|
848 debugf("rcpt_accept = %d\n", rcpt_accept);
|
meillo@0
|
849 }
|
meillo@0
|
850
|
meillo@0
|
851 if(psb->error == smtp_ok){
|
meillo@0
|
852 GList *rcpt_node;
|
meillo@0
|
853 for(rcpt_node = g_list_first(rcpt_list);
|
meillo@0
|
854 rcpt_node;
|
meillo@0
|
855 rcpt_node = g_list_next(rcpt_node)){
|
meillo@0
|
856 address *rcpt = (address *)(rcpt_node->data);
|
meillo@0
|
857 if(addr_is_delivered(rcpt))
|
meillo@0
|
858 logwrite(LOG_NOTICE, "%s => %s host=%s with %s\n",
|
meillo@0
|
859 msg->uid, addr_string(rcpt), psb->remote_host,
|
meillo@0
|
860 psb->use_esmtp ? "esmtp" : "smtp");
|
meillo@0
|
861 }
|
meillo@0
|
862 }else{
|
meillo@0
|
863 /* if something went wrong,
|
meillo@0
|
864 we have to unmark the rcpts prematurely marked as delivered
|
meillo@0
|
865 and mark the status */
|
meillo@0
|
866 smtp_out_mark_rcpts(psb, rcpt_list);
|
meillo@0
|
867
|
meillo@0
|
868 /* log the failure: */
|
meillo@0
|
869 smtp_out_log_failure(psb, msg);
|
meillo@0
|
870 }
|
meillo@0
|
871 return rcpt_accept;
|
meillo@0
|
872 }
|
meillo@0
|
873
|
meillo@0
|
874 gboolean smtp_out_quit(smtp_base *psb)
|
meillo@0
|
875 {
|
meillo@0
|
876 fprintf(psb->out, "QUIT\r\n"); fflush(psb->out);
|
meillo@0
|
877
|
meillo@0
|
878 DEBUG(4) debugf("QUIT\n");
|
meillo@0
|
879
|
meillo@0
|
880 signal(SIGALRM, SIG_DFL);
|
meillo@0
|
881
|
meillo@0
|
882 return TRUE;
|
meillo@0
|
883 }
|
meillo@0
|
884
|
meillo@0
|
885 gint smtp_deliver(gchar *host, gint port, GList *resolve_list,
|
meillo@0
|
886 message *msg,
|
meillo@0
|
887 address *return_path,
|
meillo@0
|
888 GList *rcpt_list)
|
meillo@0
|
889 {
|
meillo@0
|
890 smtp_base *psb;
|
meillo@0
|
891 smtp_error err;
|
meillo@0
|
892
|
meillo@0
|
893 DEBUG(5) debugf("smtp_deliver entered\n");
|
meillo@0
|
894
|
meillo@0
|
895 if(return_path == NULL)
|
meillo@0
|
896 return_path = msg->return_path;
|
meillo@0
|
897
|
meillo@0
|
898 if((psb = smtp_out_open(host, port, resolve_list))){
|
meillo@0
|
899 set_heloname(psb, return_path->domain, TRUE);
|
meillo@0
|
900 /* initiate connection, send message and quit: */
|
meillo@0
|
901 if(smtp_out_init(psb)){
|
meillo@0
|
902 smtp_out_msg(psb, msg, return_path, rcpt_list, NULL);
|
meillo@0
|
903 if(psb->error == smtp_ok ||
|
meillo@0
|
904 (psb->error == smtp_fail) ||
|
meillo@0
|
905 (psb->error == smtp_trylater) ||
|
meillo@0
|
906 (psb->error == smtp_syntax) ||
|
meillo@0
|
907 (psb->error == smtp_cancel))
|
meillo@0
|
908
|
meillo@0
|
909 smtp_out_quit(psb);
|
meillo@0
|
910 }
|
meillo@0
|
911
|
meillo@0
|
912 err = psb->error;
|
meillo@0
|
913 destroy_smtpbase(psb);
|
meillo@0
|
914
|
meillo@0
|
915 return err;
|
meillo@0
|
916 }
|
meillo@0
|
917 return -1;
|
meillo@0
|
918 }
|