masqmail

diff 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
line diff
     1.1 --- a/src/masqmail.c	Fri Dec 03 11:30:01 2010 -0300
     1.2 +++ b/src/masqmail.c	Fri Dec 03 11:30:24 2010 -0300
     1.3 @@ -208,6 +208,7 @@
     1.4  	accept_error err;
     1.5  	message *msg = create_message();
     1.6  	gint i;
     1.7 +	pid_t pid;
     1.8  
     1.9  	if (return_path && !is_privileged_user(conf.orig_uid)) {
    1.10  		fprintf(stderr, "must be root, %s or in group %s for setting return path.\n", DEF_MAIL_USER, DEF_MAIL_GROUP);
    1.11 @@ -223,7 +224,7 @@
    1.12  
    1.13  	msg->received_prot = PROT_LOCAL;
    1.14  	for (i = 0; i < addr_cnt; i++) {
    1.15 -		if (addresses[i][0] == '|')
    1.16 +		if (addresses[i][0] == '|') {
    1.17  			logwrite(LOG_ALERT, "no pipe allowed as recipient address: %s\n", addresses[i]);
    1.18  			exit(1);
    1.19  		}
    1.20 @@ -236,46 +237,52 @@
    1.21  	/* -F option */
    1.22  	msg->full_sender_name = full_sender_name;
    1.23  
    1.24 -	if ((err = accept_message(stdin, msg, accept_flags)) == AERR_OK) {
    1.25 -		if (spool_write(msg, TRUE)) {
    1.26 -			pid_t pid;
    1.27 -			logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]);
    1.28 +	err = accept_message(stdin, msg, accept_flags);
    1.29  
    1.30 -			if (!conf.do_queue) {
    1.31 -				if ((pid = fork()) == 0) {
    1.32 -					conf.do_verbose = FALSE;
    1.33 -					fclose(stdin);
    1.34 -					fclose(stdout);
    1.35 -					fclose(stderr);
    1.36 -					if (deliver(msg)) {
    1.37 -						exit(0);
    1.38 -					} else
    1.39 -						exit(1);
    1.40 -				} else if (pid < 0) {
    1.41 -					logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", msg->uid);
    1.42 -				}
    1.43 -			}
    1.44 +	switch (err) {
    1.45 +	case AERR_OK:
    1.46 +		/* to continue; all other cases exit */
    1.47 +		break;
    1.48 +	case AERR_EOF:
    1.49 +		fprintf(stderr, "unexpected EOF.\n");
    1.50 +		exit(1);
    1.51 +	case AERR_NORCPT:
    1.52 +		fprintf(stderr, "no recipients.\n");
    1.53 +		exit(1);
    1.54 +	case AERR_SIZE:
    1.55 +		fprintf(stderr, "max message size exceeded.\n");
    1.56 +		exit(1);
    1.57 +	default:
    1.58 +		/* should never happen: */
    1.59 +		fprintf(stderr, "Unknown error (%d)\r\n", err);
    1.60 +		exit(1);
    1.61 +	}
    1.62 +
    1.63 +	if (!spool_write(msg, TRUE)) {
    1.64 +		fprintf(stderr, "Could not write spool file\n");
    1.65 +		exit(1);
    1.66 +	}
    1.67 +
    1.68 +	logwrite(LOG_NOTICE, "%s <= %s with %s\n", msg->uid, addr_string(msg->return_path), prot_names[PROT_LOCAL]);
    1.69 +
    1.70 +	if (conf.do_queue) {
    1.71 +		/* we're finished as we only need to queue it */
    1.72 +		return;
    1.73 +	}
    1.74 +
    1.75 +	/* deliver at once */
    1.76 +	if ((pid = fork()) < 0) {
    1.77 +		logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", msg->uid);
    1.78 +	} else if (pid == 0) {
    1.79 +		conf.do_verbose = FALSE;
    1.80 +		fclose(stdin);
    1.81 +		fclose(stdout);
    1.82 +		fclose(stderr);
    1.83 +		if (deliver(msg)) {
    1.84 +			exit(0);
    1.85  		} else {
    1.86 -			fprintf(stderr, "Could not write spool file\n");
    1.87  			exit(1);
    1.88  		}
    1.89 -	} else {
    1.90 -		switch (err) {
    1.91 -		case AERR_EOF:
    1.92 -			fprintf(stderr, "unexpected EOF.\n");
    1.93 -			exit(1);
    1.94 -		case AERR_NORCPT:
    1.95 -			fprintf(stderr, "no recipients.\n");
    1.96 -			exit(1);
    1.97 -		case AERR_SIZE:
    1.98 -			fprintf(stderr, "max message size exceeded.\n");
    1.99 -			exit(1);
   1.100 -		default:
   1.101 -			/* should never happen: */
   1.102 -			fprintf(stderr, "Unknown error (%d)\r\n", err);
   1.103 -			exit(1);
   1.104 -		}
   1.105 -		exit(1);
   1.106  	}
   1.107  }
   1.108