masqmail

diff src/queue.c @ 82:83a182793503

refactoring
author meillo@marmaro.de
date Sat, 19 Jun 2010 12:35:08 +0200
parents ac0233b5f6f8
children a80ebfa16cd5
line diff
     1.1 --- a/src/queue.c	Sat Jun 19 11:14:34 2010 +0200
     1.2 +++ b/src/queue.c	Sat Jun 19 12:35:08 2010 +0200
     1.3 @@ -140,48 +140,50 @@
     1.4  
     1.5  	msg_list = read_queue(FALSE);
     1.6  
     1.7 -	if (msg_list != NULL) {
     1.8 -		foreach(msg_list, msg_node) {
     1.9 -			message *msg = (message *) (msg_node->data);
    1.10 -			GList *rcpt_node;
    1.11 -			gchar *size_str = NULL;
    1.12 -			gchar *time_str = NULL;
    1.13 -			gchar *host_str = NULL;
    1.14 -			gchar *ident_str = NULL;
    1.15 +	if (msg_list == NULL) {
    1.16 +		printf("mail queue is empty.\n");
    1.17 +		return;
    1.18 +	}
    1.19  
    1.20 -			if (msg->data_size >= 0)
    1.21 -				size_str = g_strdup_printf(" size=%d", msg->data_size);
    1.22 -			if (msg->received_time > 0) {
    1.23 -				gchar *tmp_str;
    1.24 -				time_str = g_strdup_printf(" age=%s", tmp_str = format_difftime(difftime(time(NULL), msg->received_time)));
    1.25 -				g_free(tmp_str);
    1.26 -			}
    1.27 -			if (msg->received_host != NULL)
    1.28 -				host_str = g_strdup_printf(" host=%s", msg->received_host);
    1.29 -			if (msg->ident != NULL)
    1.30 -				ident_str = g_strdup_printf(" ident=%s", msg->ident);
    1.31 +	foreach(msg_list, msg_node) {
    1.32 +		message *msg = (message *) (msg_node->data);
    1.33 +		GList *rcpt_node;
    1.34 +		gchar *size_str = NULL;
    1.35 +		gchar *time_str = NULL;
    1.36 +		gchar *host_str = NULL;
    1.37 +		gchar *ident_str = NULL;
    1.38  
    1.39 -			printf("%s <= %s%s%s%s%s\n", msg->uid, addr_string(msg->return_path), size_str ? size_str : "",
    1.40 -			       time_str ? time_str : "", host_str ? host_str : "", ident_str ? ident_str : "");
    1.41 +		if (msg->data_size >= 0)
    1.42 +			size_str = g_strdup_printf(" size=%d", msg->data_size);
    1.43 +		if (msg->received_time > 0) {
    1.44 +			gchar *tmp_str;
    1.45 +			time_str = g_strdup_printf(" age=%s", tmp_str = format_difftime(difftime(time(NULL), msg->received_time)));
    1.46 +			g_free(tmp_str);
    1.47 +		}
    1.48 +		if (msg->received_host != NULL)
    1.49 +			host_str = g_strdup_printf(" host=%s", msg->received_host);
    1.50 +		if (msg->ident != NULL)
    1.51 +			ident_str = g_strdup_printf(" ident=%s", msg->ident);
    1.52  
    1.53 -			if (size_str)
    1.54 -				g_free(size_str);
    1.55 -			if (time_str)
    1.56 -				g_free(time_str);
    1.57 -			if (host_str)
    1.58 -				g_free(host_str);
    1.59 -			if (ident_str)
    1.60 -				g_free(ident_str);
    1.61 +		printf("%s <= %s%s%s%s%s\n", msg->uid, addr_string(msg->return_path), size_str ? size_str : "",
    1.62 +		       time_str ? time_str : "", host_str ? host_str : "", ident_str ? ident_str : "");
    1.63  
    1.64 -			foreach(msg->rcpt_list, rcpt_node) {
    1.65 -				address *rcpt = (address *) (rcpt_node->data);
    1.66 +		if (size_str)
    1.67 +			g_free(size_str);
    1.68 +		if (time_str)
    1.69 +			g_free(time_str);
    1.70 +		if (host_str)
    1.71 +			g_free(host_str);
    1.72 +		if (ident_str)
    1.73 +			g_free(ident_str);
    1.74  
    1.75 -				printf("              %s %s\n", addr_is_delivered(rcpt) ? "=>" : (addr_is_failed(rcpt) ? "!=" : "=="), addr_string(rcpt));
    1.76 -			}
    1.77 -			g_free(msg);
    1.78 +		foreach(msg->rcpt_list, rcpt_node) {
    1.79 +			address *rcpt = (address *) (rcpt_node->data);
    1.80 +
    1.81 +			printf("              %s %s\n", addr_is_delivered(rcpt) ? "=>" : (addr_is_failed(rcpt) ? "!=" : "=="), addr_string(rcpt));
    1.82  		}
    1.83 -	} else
    1.84 -		printf("mail queue is empty.\n");
    1.85 +		g_free(msg);
    1.86 +	}
    1.87  }
    1.88  
    1.89  gboolean
    1.90 @@ -193,35 +195,32 @@
    1.91  	gchar *dat_name = g_strdup_printf("%s/input/%s-D", conf.spool_dir, uid);
    1.92  	struct stat stat_buf;
    1.93  
    1.94 -	if (spool_lock(uid)) {
    1.95 -
    1.96 -		if (stat(hdr_name, &stat_buf) == 0) {
    1.97 -			if (unlink(hdr_name) != 0) {
    1.98 -				fprintf(stderr, "could not unlink %s: %s\n", hdr_name, strerror(errno));
    1.99 -				hdr_ok = FALSE;
   1.100 -			}
   1.101 -		} else {
   1.102 -			fprintf(stderr, "could not stat file %s: %s\n", hdr_name, strerror(errno));
   1.103 -			hdr_ok = FALSE;
   1.104 -		}
   1.105 -		if (stat(dat_name, &stat_buf) == 0) {
   1.106 -			if (unlink(dat_name) != 0) {
   1.107 -				fprintf(stderr, "could not unlink %s: %s\n", dat_name, strerror(errno));
   1.108 -				dat_ok = FALSE;
   1.109 -			}
   1.110 -		} else {
   1.111 -			fprintf(stderr, "could not stat file %s: %s\n", dat_name, strerror(errno));
   1.112 -			dat_ok = FALSE;
   1.113 -		}
   1.114 -		printf("message %s deleted\n", uid);
   1.115 -
   1.116 -		spool_unlock(uid);
   1.117 -
   1.118 -	} else {
   1.119 -
   1.120 +	if (!spool_lock(uid)) {
   1.121  		fprintf(stderr, "message %s is locked.\n", uid);
   1.122  		return FALSE;
   1.123  	}
   1.124  
   1.125 +	if (stat(hdr_name, &stat_buf) == 0) {
   1.126 +		if (unlink(hdr_name) != 0) {
   1.127 +			fprintf(stderr, "could not unlink %s: %s\n", hdr_name, strerror(errno));
   1.128 +			hdr_ok = FALSE;
   1.129 +		}
   1.130 +	} else {
   1.131 +		fprintf(stderr, "could not stat file %s: %s\n", hdr_name, strerror(errno));
   1.132 +		hdr_ok = FALSE;
   1.133 +	}
   1.134 +	if (stat(dat_name, &stat_buf) == 0) {
   1.135 +		if (unlink(dat_name) != 0) {
   1.136 +			fprintf(stderr, "could not unlink %s: %s\n", dat_name, strerror(errno));
   1.137 +			dat_ok = FALSE;
   1.138 +		}
   1.139 +	} else {
   1.140 +		fprintf(stderr, "could not stat file %s: %s\n", dat_name, strerror(errno));
   1.141 +		dat_ok = FALSE;
   1.142 +	}
   1.143 +	printf("message %s deleted\n", uid);
   1.144 +
   1.145 +	spool_unlock(uid);
   1.146 +
   1.147  	return (dat_ok && hdr_ok);
   1.148  }