masqmail
view src/fail_msg.c @ 246:4cff8638dd9b
SMTP client: tries EHLO now always first
Changed the behavior of the SMTP client. Now always an EHLO greeting
is sent, no matter what kind of greeting text the server had sent. If
the EHLO failed, an HELO greeting is tried as fall back. This is the
behavior RFC 2821 requires (section 3.2).
This change will fix setups that were not possible to sent to a
server because that requires AUTH but hadn't said ``ESMTP'' in its
greeting message.
See also: Debian bug #349211
Thanks to Steffen (inne)
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 28 Oct 2010 16:40:02 -0300 |
parents | dcb315792513 |
children | 82d168dd52fd |
line source
1 /* MasqMail
2 Copyright (C) 2000-2001 Oliver Kurth
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
19 #include <sys/wait.h>
21 #include "masqmail.h"
22 #include "peopen.h"
23 #include "readsock.h"
25 gboolean
26 fail_msg(message * msg, gchar * template, GList * failed_rcpts, gchar * err_fmt, va_list args)
27 {
28 gboolean ok = FALSE;
29 address *ret_path = NULL;
31 /* do not bounce bounces, send to postmaster instead */
32 if (msg->return_path->local_part[0] == '\0') {
33 GList *node;
35 ret_path = create_address_qualified("postmaster", TRUE, conf.host_name);
36 foreach(failed_rcpts, node) {
37 address *addr = (address *) (node->data);
39 if (addr_isequal_parent(addr, ret_path, strcasecmp)) {
40 logwrite(LOG_ALERT, "%s == %s: postmaster address failed\n", msg->uid, addr_string(ret_path));
41 return FALSE;
42 }
43 }
44 } else
45 ret_path = copy_address(msg->return_path);
47 DEBUG(1) debugf("sending failure notice to %s.\n", addr_string(ret_path));
49 if (template) {
50 FILE *file;
51 GList *var_table = var_table_conf(var_table_msg(NULL, msg));
52 gchar *err_msg = g_strdup_vprintf(err_fmt, args);
54 var_table = g_list_prepend(var_table, create_pair_string("err_msg", err_msg));
55 g_free(err_msg);
57 if ((file = fopen(template, "r"))) {
58 FILE *out;
59 gchar *cmd;
60 pid_t pid;
62 cmd = g_strdup_printf(SBINDIR "/masqmail -oi -f <> %s@%s", ret_path->local_part, ret_path->domain);
63 if ((out = peidopen(cmd, "w", environ, &pid, conf.mail_uid, conf.mail_gid))) {
64 gchar fmt[256], line[256];
65 int status, ret;
67 while ((ret = read_sockline(file, fmt, 256, 0, 0)) > 0) {
68 if (fmt[0] == '@') {
69 GList *node;
70 if (strncmp(fmt, "@failed_rcpts", 13) == 0) {
71 foreach(failed_rcpts, node) {
72 address *rcpt = (address *) (node->data);
73 fprintf(out, "\t%s\n", addr_string(rcpt));
74 }
75 } else if (strncmp(fmt, "@msg_headers", 12) == 0) {
76 foreach(msg->hdr_list, node) {
77 header *hdr = (header *) (node->data);
78 fputs(hdr->header, out);
79 }
80 } else if (strncmp(fmt, "@msg_body", 9) == 0) {
81 /* we may have to read the data at this point and remember if we did */
82 gboolean flag = (msg->data_list == NULL);
83 if (flag) {
84 if (!spool_read_data(msg)) {
85 logwrite(LOG_ALERT, "could not open data spool file %s\n", msg->uid);
86 }
87 }
88 foreach(msg->data_list, node) {
89 gchar *line = (gchar *) (node->data);
90 fputs(line, out);
91 }
92 if (flag)
93 msg_free_data(msg);
94 }
95 } else {
96 expand(var_table, fmt, line, 256);
97 fputs(line, out);
98 }
99 }
101 fclose(out);
102 waitpid(pid, &status, 0);
103 if ((WEXITSTATUS(status) != EXIT_SUCCESS) || WIFSIGNALED(status)) {
104 if (WEXITSTATUS(status) != EXIT_SUCCESS)
105 logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status));
106 if (WIFSIGNALED(status))
107 logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status));
108 } else
109 ok = TRUE;
110 } else {
111 logwrite(LOG_ERR, "peopen failed: %s\n", strerror(errno));
112 }
113 g_free(cmd);
114 fclose(file);
115 } else
116 logwrite(LOG_ALERT, "could not open failure message template %s: %s\n", conf.errmsg_file, strerror(errno));
118 destroy_table(var_table);
119 }
121 destroy_address(ret_path);
123 return ok;
124 }
126 /*
127 ival : |--|--|----|--------|--------|
128 warned: |-------W-------------W------
129 result: |nnnyyyynnnnyyyyyyyyyynnnnnnn
130 */
132 static gboolean
133 warn_msg_is_due(message * msg)
134 {
135 time_t now = time(NULL);
136 gint dummy;
138 GList *node;
139 for (node = g_list_last(conf.warn_intervals); node; node = g_list_previous(node)) {
140 gchar *str_ival = (gchar *) (node->data);
141 gint ival = time_interval(str_ival, &dummy);
142 if (ival >= 0) {
143 DEBUG(5) debugf("ival = %d\n", ival);
144 DEBUG(5) debugf("now - msg->received_time = %d\n", now - msg->received_time);
145 if ((now - msg->received_time) > ival) {
146 if (msg->warned_time != 0) {
147 if ((msg->warned_time - msg->received_time) < ival)
148 return TRUE;
149 } else
150 return TRUE;
151 }
152 } else
153 logwrite(LOG_WARNING, "invalid time interval: %s\n", str_ival);
154 }
155 return FALSE;
156 }
158 gboolean
159 warn_msg(message * msg, gchar * template, GList * defered_rcpts, gchar * err_fmt, va_list args)
160 {
161 time_t now = time(NULL);
163 if (warn_msg_is_due(msg)) {
164 if (fail_msg(msg, template, defered_rcpts, err_fmt, args)) {
165 msg->warned_time = now;
166 return TRUE;
167 } else
168 return FALSE;
169 }
170 return TRUE;
171 }