Mercurial > masqmail
comparison src/fail_msg.c @ 406:8518fe2b0f36
Refactoring.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Wed, 29 Feb 2012 10:34:27 +0100 |
parents | b27f66555ba8 |
children |
comparison
equal
deleted
inserted
replaced
405:0dd84c8f2524 | 406:8518fe2b0f36 |
---|---|
32 | 32 |
33 /* do not bounce bounces, send to postmaster instead */ | 33 /* do not bounce bounces, send to postmaster instead */ |
34 if (msg->return_path->local_part[0] == '\0') { | 34 if (msg->return_path->local_part[0] == '\0') { |
35 GList *node; | 35 GList *node; |
36 | 36 |
37 ret_path = create_address_qualified("postmaster", TRUE, conf.host_name); | 37 ret_path = create_address_qualified("postmaster", TRUE, |
38 conf.host_name); | |
38 foreach(failed_rcpts, node) { | 39 foreach(failed_rcpts, node) { |
39 address *addr = (address *) (node->data); | 40 address *addr = (address *) (node->data); |
40 | 41 |
41 if (addr_isequal_parent(addr, ret_path, strcasecmp)) { | 42 if (addr_isequal_parent(addr, ret_path, strcasecmp)) { |
42 logwrite(LOG_ALERT, "%s == %s: postmaster address failed\n", msg->uid, addr_string(ret_path)); | 43 logwrite(LOG_ALERT, "%s == %s: postmaster " |
44 "address failed\n", msg->uid, | |
45 addr_string(ret_path)); | |
43 return FALSE; | 46 return FALSE; |
44 } | 47 } |
45 } | 48 } |
46 } else | 49 } else |
47 ret_path = copy_address(msg->return_path); | 50 ret_path = copy_address(msg->return_path); |
48 | 51 |
49 DEBUG(1) debugf("sending failure notice to %s.\n", addr_string(ret_path)); | 52 DEBUG(1) debugf("sending failure notice to %s.\n", |
53 addr_string(ret_path)); | |
50 | 54 |
51 if (template) { | 55 if (template) { |
52 FILE *file; | 56 FILE *file; |
53 GList *var_table = var_table_conf(var_table_msg(NULL, msg)); | 57 GList *var_table = var_table_conf(var_table_msg(NULL, msg)); |
54 gchar *err_msg = g_strdup_vprintf(err_fmt, args); | 58 gchar *err_msg = g_strdup_vprintf(err_fmt, args); |
55 | 59 |
56 var_table = g_list_prepend(var_table, create_pair_string("err_msg", err_msg)); | 60 var_table = g_list_prepend(var_table, |
61 create_pair_string("err_msg", err_msg)); | |
57 g_free(err_msg); | 62 g_free(err_msg); |
58 | 63 |
59 if ((file = fopen(template, "r"))) { | 64 if ((file = fopen(template, "r"))) { |
60 FILE *out; | 65 FILE *out; |
61 gchar *cmd; | 66 gchar *cmd; |
62 pid_t pid; | 67 pid_t pid; |
63 | 68 |
64 cmd = g_strdup_printf(SBINDIR "/masqmail -oi -f <> %s@%s", ret_path->local_part, ret_path->domain); | 69 cmd = g_strdup_printf(SBINDIR "/masqmail -oi -f <> %s@%s", ret_path->local_part, ret_path->domain); |
65 if ((out = peidopen(cmd, "w", environ, &pid, conf.mail_uid, conf.mail_gid))) { | 70 if (!(out = peidopen(cmd, "w", environ, &pid, |
71 conf.mail_uid, conf.mail_gid))) { | |
72 logwrite(LOG_ERR, "peopen failed: %s\n", | |
73 strerror(errno)); | |
74 } else { | |
66 gchar fmt[256], line[256]; | 75 gchar fmt[256], line[256]; |
67 int status, ret; | 76 int status, ret; |
68 | 77 |
69 while ((ret = read_sockline(file, fmt, 256, 0, 0)) > 0) { | 78 while ((ret = read_sockline(file, fmt, 256, 0, 0)) > 0) { |
70 if (fmt[0] == '@') { | 79 if (fmt[0] == '@') { |
100 } | 109 } |
101 } | 110 } |
102 | 111 |
103 fclose(out); | 112 fclose(out); |
104 waitpid(pid, &status, 0); | 113 waitpid(pid, &status, 0); |
105 if ((WEXITSTATUS(status) != 0) || WIFSIGNALED(status)) { | 114 if ((WEXITSTATUS(status) != 0) || |
106 if (WEXITSTATUS(status) != 0) | 115 WIFSIGNALED(status)) { |
116 if (WEXITSTATUS(status)) { | |
107 logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status)); | 117 logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status)); |
108 if (WIFSIGNALED(status)) | 118 } |
119 if (WIFSIGNALED(status)) { | |
109 logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status)); | 120 logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status)); |
110 } else | 121 } |
122 } else { | |
111 ok = TRUE; | 123 ok = TRUE; |
112 } else { | 124 } |
113 logwrite(LOG_ERR, "peopen failed: %s\n", strerror(errno)); | |
114 } | 125 } |
115 g_free(cmd); | 126 g_free(cmd); |
116 fclose(file); | 127 fclose(file); |
117 } else | 128 } else { |
118 logwrite(LOG_ALERT, "could not open failure message template %s: %s\n", conf.errmsg_file, strerror(errno)); | 129 logwrite(LOG_ALERT, "could not open failure message " |
130 "template %s: %s\n", | |
131 conf.errmsg_file, strerror(errno)); | |
132 } | |
119 | 133 |
120 destroy_table(var_table); | 134 destroy_table(var_table); |
121 } | 135 } |
122 | 136 |
123 destroy_address(ret_path); | 137 destroy_address(ret_path); |
134 warn_msg_is_due(message *msg) | 148 warn_msg_is_due(message *msg) |
135 { | 149 { |
136 time_t now = time(NULL); | 150 time_t now = time(NULL); |
137 | 151 |
138 GList *node; | 152 GList *node; |
139 for (node = g_list_last(conf.warn_intervals); node; node = g_list_previous(node)) { | 153 for (node = g_list_last(conf.warn_intervals); node; |
154 node = g_list_previous(node)) { | |
140 gchar *str_ival = (gchar *) (node->data); | 155 gchar *str_ival = (gchar *) (node->data); |
141 gint ival = time_interval(str_ival); | 156 gint ival = time_interval(str_ival); |
142 if (ival >= 0) { | 157 if (ival < 0) { |
158 logwrite(LOG_WARNING, "invalid time interval: %s\n", | |
159 str_ival); | |
160 } else { | |
143 DEBUG(5) debugf("ival = %d\n", ival); | 161 DEBUG(5) debugf("ival = %d\n", ival); |
144 DEBUG(5) debugf("now - msg->received_time = %d\n", now - msg->received_time); | 162 DEBUG(5) debugf("now - msg->received_time = %d\n", |
163 now - msg->received_time); | |
145 if ((now - msg->received_time) > ival) { | 164 if ((now - msg->received_time) > ival) { |
146 if (msg->warned_time != 0) { | 165 if (msg->warned_time == 0) { |
147 if ((msg->warned_time - msg->received_time) < ival) | |
148 return TRUE; | |
149 } else | |
150 return TRUE; | 166 return TRUE; |
167 } | |
168 if ((msg->warned_time - msg->received_time) < | |
169 ival) { | |
170 return TRUE; | |
171 } | |
151 } | 172 } |
152 } else | 173 } |
153 logwrite(LOG_WARNING, "invalid time interval: %s\n", str_ival); | |
154 } | 174 } |
155 return FALSE; | 175 return FALSE; |
156 } | 176 } |
157 | 177 |
158 gboolean | 178 gboolean |
163 | 183 |
164 if (warn_msg_is_due(msg)) { | 184 if (warn_msg_is_due(msg)) { |
165 if (fail_msg(msg, template, defered_rcpts, err_fmt, args)) { | 185 if (fail_msg(msg, template, defered_rcpts, err_fmt, args)) { |
166 msg->warned_time = now; | 186 msg->warned_time = now; |
167 return TRUE; | 187 return TRUE; |
168 } else | 188 } else { |
169 return FALSE; | 189 return FALSE; |
190 } | |
170 } | 191 } |
171 return TRUE; | 192 return TRUE; |
172 } | 193 } |