comparison src/masqmail.c @ 266:ab39047ffe44

refactored mode_accept()
author markus schnalke <meillo@marmaro.de>
date Fri, 03 Dec 2010 11:30:24 -0300
parents 1e5e457dea18
children 8be687c06c20
comparison
equal deleted inserted replaced
265:409552c5647f 266:ab39047ffe44
206 { 206 {
207 /* accept message on stdin */ 207 /* accept message on stdin */
208 accept_error err; 208 accept_error err;
209 message *msg = create_message(); 209 message *msg = create_message();
210 gint i; 210 gint i;
211 pid_t pid;
211 212
212 if (return_path && !is_privileged_user(conf.orig_uid)) { 213 if (return_path && !is_privileged_user(conf.orig_uid)) {
213 fprintf(stderr, "must be root, %s or in group %s for setting return path.\n", DEF_MAIL_USER, DEF_MAIL_GROUP); 214 fprintf(stderr, "must be root, %s or in group %s for setting return path.\n", DEF_MAIL_USER, DEF_MAIL_GROUP);
214 exit(1); 215 exit(1);
215 } 216 }
221 222
222 DEBUG(5) debugf("accepting message on stdin\n"); 223 DEBUG(5) debugf("accepting message on stdin\n");
223 224
224 msg->received_prot = PROT_LOCAL; 225 msg->received_prot = PROT_LOCAL;
225 for (i = 0; i < addr_cnt; i++) { 226 for (i = 0; i < addr_cnt; i++) {
226 if (addresses[i][0] == '|') 227 if (addresses[i][0] == '|') {
227 logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]); 228 logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]);
228 exit(1); 229 exit(1);
229 } 230 }
230 msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(addresses[i], TRUE, conf.host_name)); 231 msg->rcpt_list = g_list_append(msg->rcpt_list, create_address_qualified(addresses[i], TRUE, conf.host_name));
231 } 232 }
234 msg->return_path = return_path; 235 msg->return_path = return_path;
235 236
236 /* -F option */ 237 /* -F option */
237 msg->full_sender_name = full_sender_name; 238 msg->full_sender_name = full_sender_name;
238 239
239 if ((err = accept_message(stdin, msg, accept_flags)) == AERR_OK) { 240 err = accept_message(stdin, msg, accept_flags);
240 if (spool_write(msg, TRUE)) { 241
241 pid_t pid; 242 switch (err) {
242 logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]); 243 case AERR_OK:
243 244 /* to continue; all other cases exit */
244 if (!conf.do_queue) { 245 break;
245 if ((pid = fork()) == 0) { 246 case AERR_EOF:
246 conf.do_verbose = FALSE; 247 fprintf(stderr, "unexpected EOF.\n");
247 fclose(stdin); 248 exit(1);
248 fclose(stdout); 249 case AERR_NORCPT:
249 fclose(stderr); 250 fprintf(stderr, "no recipients.\n");
250 if (deliver(msg)) { 251 exit(1);
251 exit(0); 252 case AERR_SIZE:
252 } else 253 fprintf(stderr, "max message size exceeded.\n");
253 exit(1); 254 exit(1);
254 } else if (pid < 0) { 255 default:
255 logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", msg->uid); 256 /* should never happen: */
256 } 257 fprintf(stderr, "Unknown error (%d)\r\n", err);
257 } 258 exit(1);
259 }
260
261 if (!spool_write(msg, TRUE)) {
262 fprintf(stderr, "Could not write spool file\n");
263 exit(1);
264 }
265
266 logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]);
267
268 if (conf.do_queue) {
269 /* we're finished as we only need to queue it */
270 return;
271 }
272
273 /* deliver at once */
274 if ((pid = fork()) < 0) {
275 logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", msg->uid);
276 } else if (pid == 0) {
277 conf.do_verbose = FALSE;
278 fclose(stdin);
279 fclose(stdout);
280 fclose(stderr);
281 if (deliver(msg)) {
282 exit(0);
258 } else { 283 } else {
259 fprintf(stderr, "Could not write spool file\n");
260 exit(1); 284 exit(1);
261 } 285 }
262 } else {
263 switch (err) {
264 case AERR_EOF:
265 fprintf(stderr, "unexpected EOF.\n");
266 exit(1);
267 case AERR_NORCPT:
268 fprintf(stderr, "no recipients.\n");
269 exit(1);
270 case AERR_SIZE:
271 fprintf(stderr, "max message size exceeded.\n");
272 exit(1);
273 default:
274 /* should never happen: */
275 fprintf(stderr, "Unknown error (%d)\r\n", err);
276 exit(1);
277 }
278 exit(1);
279 } 286 }
280 } 287 }
281 288
282 /* 289 /*
283 if -Mrm is given 290 if -Mrm is given