masqmail

diff 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
line diff
     1.1 --- a/src/fail_msg.c	Wed Feb 29 10:28:23 2012 +0100
     1.2 +++ b/src/fail_msg.c	Wed Feb 29 10:34:27 2012 +0100
     1.3 @@ -34,26 +34,31 @@
     1.4  	if (msg->return_path->local_part[0] == '\0') {
     1.5  		GList *node;
     1.6  
     1.7 -		ret_path = create_address_qualified("postmaster", TRUE, conf.host_name);
     1.8 +		ret_path = create_address_qualified("postmaster", TRUE,
     1.9 +				conf.host_name);
    1.10  		foreach(failed_rcpts, node) {
    1.11  			address *addr = (address *) (node->data);
    1.12  
    1.13  			if (addr_isequal_parent(addr, ret_path, strcasecmp)) {
    1.14 -				logwrite(LOG_ALERT, "%s == %s: postmaster address failed\n", msg->uid, addr_string(ret_path));
    1.15 +				logwrite(LOG_ALERT, "%s == %s: postmaster "
    1.16 +						"address failed\n", msg->uid,
    1.17 +						addr_string(ret_path));
    1.18  				return FALSE;
    1.19  			}
    1.20  		}
    1.21  	} else
    1.22  		ret_path = copy_address(msg->return_path);
    1.23  
    1.24 -	DEBUG(1) debugf("sending failure notice to %s.\n", addr_string(ret_path));
    1.25 +	DEBUG(1) debugf("sending failure notice to %s.\n",
    1.26 +			addr_string(ret_path));
    1.27  
    1.28  	if (template) {
    1.29  		FILE *file;
    1.30  		GList *var_table = var_table_conf(var_table_msg(NULL, msg));
    1.31  		gchar *err_msg = g_strdup_vprintf(err_fmt, args);
    1.32  
    1.33 -		var_table = g_list_prepend(var_table, create_pair_string("err_msg", err_msg));
    1.34 +		var_table = g_list_prepend(var_table,
    1.35 +				create_pair_string("err_msg", err_msg));
    1.36  		g_free(err_msg);
    1.37  
    1.38  		if ((file = fopen(template, "r"))) {
    1.39 @@ -62,7 +67,11 @@
    1.40  			pid_t pid;
    1.41  
    1.42  			cmd = g_strdup_printf(SBINDIR "/masqmail -oi -f <> %s@%s", ret_path->local_part, ret_path->domain);
    1.43 -			if ((out = peidopen(cmd, "w", environ, &pid, conf.mail_uid, conf.mail_gid))) {
    1.44 +			if (!(out = peidopen(cmd, "w", environ, &pid,
    1.45 +					conf.mail_uid, conf.mail_gid))) {
    1.46 +				logwrite(LOG_ERR, "peopen failed: %s\n",
    1.47 +						strerror(errno));
    1.48 +			} else {
    1.49  				gchar fmt[256], line[256];
    1.50  				int status, ret;
    1.51  
    1.52 @@ -102,20 +111,25 @@
    1.53  
    1.54  				fclose(out);
    1.55  				waitpid(pid, &status, 0);
    1.56 -				if ((WEXITSTATUS(status) != 0) || WIFSIGNALED(status)) {
    1.57 -					if (WEXITSTATUS(status) != 0)
    1.58 +				if ((WEXITSTATUS(status) != 0) ||
    1.59 +						WIFSIGNALED(status)) {
    1.60 +					if (WEXITSTATUS(status)) {
    1.61  						logwrite(LOG_WARNING, "child returned %d\n", WEXITSTATUS(status));
    1.62 -					if (WIFSIGNALED(status))
    1.63 +					}
    1.64 +					if (WIFSIGNALED(status)) {
    1.65  						logwrite(LOG_WARNING, "child got signal: %d\n", WTERMSIG(status));
    1.66 -				} else
    1.67 +					}
    1.68 +				} else {
    1.69  					ok = TRUE;
    1.70 -			} else {
    1.71 -				logwrite(LOG_ERR, "peopen failed: %s\n", strerror(errno));
    1.72 +				}
    1.73  			}
    1.74  			g_free(cmd);
    1.75  			fclose(file);
    1.76 -		} else
    1.77 -			logwrite(LOG_ALERT, "could not open failure message template %s: %s\n", conf.errmsg_file, strerror(errno));
    1.78 +		} else {
    1.79 +			logwrite(LOG_ALERT, "could not open failure message "
    1.80 +					"template %s: %s\n",
    1.81 +					conf.errmsg_file, strerror(errno));
    1.82 +		}
    1.83  
    1.84  		destroy_table(var_table);
    1.85  	}
    1.86 @@ -136,21 +150,27 @@
    1.87  	time_t now = time(NULL);
    1.88  
    1.89  	GList *node;
    1.90 -	for (node = g_list_last(conf.warn_intervals); node; node = g_list_previous(node)) {
    1.91 +	for (node = g_list_last(conf.warn_intervals); node;
    1.92 +			node = g_list_previous(node)) {
    1.93  		gchar *str_ival = (gchar *) (node->data);
    1.94  		gint ival = time_interval(str_ival);
    1.95 -		if (ival >= 0) {
    1.96 +		if (ival < 0) {
    1.97 +			logwrite(LOG_WARNING, "invalid time interval: %s\n",
    1.98 +					str_ival);
    1.99 +		} else {
   1.100  			DEBUG(5) debugf("ival = %d\n", ival);
   1.101 -			DEBUG(5) debugf("now - msg->received_time = %d\n", now - msg->received_time);
   1.102 +			DEBUG(5) debugf("now - msg->received_time = %d\n",
   1.103 +					now - msg->received_time);
   1.104  			if ((now - msg->received_time) > ival) {
   1.105 -				if (msg->warned_time != 0) {
   1.106 -					if ((msg->warned_time - msg->received_time) < ival)
   1.107 -						return TRUE;
   1.108 -				} else
   1.109 +				if (msg->warned_time == 0) {
   1.110  					return TRUE;
   1.111 +				}
   1.112 +				if ((msg->warned_time - msg->received_time) <
   1.113 +						ival) {
   1.114 +					return TRUE;
   1.115 +				}
   1.116  			}
   1.117 -		} else
   1.118 -			logwrite(LOG_WARNING, "invalid time interval: %s\n", str_ival);
   1.119 +		}
   1.120  	}
   1.121  	return FALSE;
   1.122  }
   1.123 @@ -165,8 +185,9 @@
   1.124  		if (fail_msg(msg, template, defered_rcpts, err_fmt, args)) {
   1.125  			msg->warned_time = now;
   1.126  			return TRUE;
   1.127 -		} else
   1.128 +		} else {
   1.129  			return FALSE;
   1.130 +		}
   1.131  	}
   1.132  	return TRUE;
   1.133  }