masqmail

diff src/address.c @ 389:bc9a7845b53a

Refactoring and code layouting.
author markus schnalke <meillo@marmaro.de>
date Sat, 18 Feb 2012 13:43:30 +0100
parents b27f66555ba8
children 9b93c0a3bd8c
line diff
     1.1 --- a/src/address.c	Sat Feb 18 13:37:40 2012 +0100
     1.2 +++ b/src/address.c	Sat Feb 18 13:43:30 2012 +0100
     1.3 @@ -25,7 +25,7 @@
     1.4  	address *addr;
     1.5  	addr = _create_address(path, NULL, is_rfc821);
     1.6  
     1.7 -	if (addr != NULL) {
     1.8 +	if (addr) {
     1.9  		addr_unmark_delivered(addr);
    1.10  	}
    1.11  	return addr;
    1.12 @@ -36,8 +36,8 @@
    1.13  {
    1.14  	address *addr = create_address(path, is_rfc821);
    1.15  
    1.16 -	if (addr != NULL && addr->domain == NULL) {
    1.17 -			addr->domain = g_strdup(domain);
    1.18 +	if (addr && !addr->domain) {
    1.19 +		addr->domain = g_strdup(domain);
    1.20  	}
    1.21  	return addr;
    1.22  }
    1.23 @@ -52,7 +52,6 @@
    1.24  		memset(addr, 0, sizeof(address));
    1.25  		addr->address = g_strchomp(g_strdup(path));
    1.26  		addr->local_part = g_strdup(addr->address);
    1.27 -
    1.28  		addr->domain = g_strdup("localhost");  /* quick hack */
    1.29  	}
    1.30  	return addr;
    1.31 @@ -62,11 +61,9 @@
    1.32  destroy_address(address *addr)
    1.33  {
    1.34  	DEBUG(6) debugf("destroy_address entered\n");
    1.35 -
    1.36  	g_free(addr->address);
    1.37  	g_free(addr->local_part);
    1.38  	g_free(addr->domain);
    1.39 -
    1.40  	g_free(addr);
    1.41  }
    1.42  
    1.43 @@ -78,23 +75,13 @@
    1.44  	if (!orig) {
    1.45  		return NULL;
    1.46  	}
    1.47 -
    1.48 -	if ((addr = g_malloc(sizeof(address))) == NULL) {
    1.49 +	if (!(addr = g_malloc(sizeof(address)))) {
    1.50  		return NULL;
    1.51  	}
    1.52 -
    1.53  	addr->address = g_strdup(orig->address);
    1.54 -
    1.55 -	if (l_part == NULL)
    1.56 -		addr->local_part = g_strdup(orig->local_part);
    1.57 -	else
    1.58 -		addr->local_part = g_strdup(l_part);
    1.59 -
    1.60 -	if (dom == NULL)
    1.61 -		addr->domain = g_strdup(orig->domain);
    1.62 -	else
    1.63 -		addr->domain = g_strdup(dom);
    1.64 -
    1.65 +	addr->local_part = l_part ? g_strdup(l_part) :
    1.66 +			g_strdup(orig->local_part);
    1.67 +	addr->domain = dom ? g_strdup(dom) : g_strdup(orig->domain);
    1.68  	addr->flags = 0;
    1.69  	addr->children = NULL;
    1.70  	addr->parent = NULL;
    1.71 @@ -102,22 +89,25 @@
    1.72  }
    1.73  
    1.74  gboolean
    1.75 -addr_isequal(address *addr1, address *addr2, int (*cmpfunc) (const char*, const char*))
    1.76 +addr_isequal(address *addr1, address *addr2,
    1.77 +		int (*cmpfunc) (const char*, const char*))
    1.78  {
    1.79 -	return (cmpfunc(addr1->local_part, addr2->local_part) == 0)
    1.80 -	       && (strcasecmp(addr1->domain, addr2->domain) == 0);
    1.81 +	return (cmpfunc(addr1->local_part, addr2->local_part)==0) &&
    1.82 +			(strcasecmp(addr1->domain, addr2->domain)==0);
    1.83  }
    1.84  
    1.85  /* searches in ancestors of addr1 */
    1.86  gboolean
    1.87 -addr_isequal_parent(address *addr1, address *addr2, int (*cmpfunc) (const char*, const char*))
    1.88 +addr_isequal_parent(address *addr1, address *addr2,
    1.89 +		int (*cmpfunc) (const char*, const char*))
    1.90  {
    1.91  	address *addr;
    1.92  
    1.93 -	for (addr = addr1; addr; addr = addr->parent)
    1.94 -		if (addr_isequal(addr, addr2, cmpfunc))
    1.95 +	for (addr = addr1; addr; addr = addr->parent) {
    1.96 +		if (addr_isequal(addr, addr2, cmpfunc)) {
    1.97  			return TRUE;
    1.98 -
    1.99 +		}
   1.100 +	}
   1.101  	return FALSE;
   1.102  }
   1.103  
   1.104 @@ -128,13 +118,14 @@
   1.105  {
   1.106  	GList *addr_node;
   1.107  
   1.108 -	if (addr->children == NULL)
   1.109 +	if (!addr->children) {
   1.110  		return addr_is_delivered(addr);
   1.111 -
   1.112 +	}
   1.113  	foreach(addr->children, addr_node) {
   1.114  		address *addr = (address *) (addr_node->data);
   1.115 -		if (!addr_is_delivered_children(addr))
   1.116 +		if (!addr_is_delivered_children(addr)) {
   1.117  			return FALSE;
   1.118 +		}
   1.119  	}
   1.120  	return TRUE;
   1.121  }
   1.122 @@ -146,13 +137,14 @@
   1.123  {
   1.124  	GList *addr_node;
   1.125  
   1.126 -	if (addr->children == NULL)
   1.127 +	if (!addr->children) {
   1.128  		return (addr_is_failed(addr) || addr_is_delivered(addr));
   1.129 -
   1.130 +	}
   1.131  	foreach(addr->children, addr_node) {
   1.132  		address *addr = (address *) (addr_node->data);
   1.133 -		if (!addr_is_finished_children(addr))
   1.134 +		if (!addr_is_finished_children(addr)) {
   1.135  			return FALSE;
   1.136 +		}
   1.137  	}
   1.138  	return TRUE;
   1.139  }
   1.140 @@ -161,8 +153,9 @@
   1.141  address*
   1.142  addr_find_ancestor(address *addr)
   1.143  {
   1.144 -	while (addr->parent)
   1.145 +	while (addr->parent) {
   1.146  		addr = addr->parent;
   1.147 +	}
   1.148  	return addr;
   1.149  }
   1.150  
   1.151 @@ -171,18 +164,20 @@
   1.152  {
   1.153  	static gchar *buffer = NULL;
   1.154  
   1.155 -	if (addr == NULL) {
   1.156 +	if (!addr) {
   1.157  		g_free(buffer);
   1.158  		buffer = NULL;
   1.159  		return NULL;
   1.160  	}
   1.161 -	if (buffer)
   1.162 +	if (buffer) {
   1.163  		g_free(buffer);
   1.164 -
   1.165 -	if (addr->local_part[0] == '\0') {
   1.166 +	}
   1.167 +	if (!*addr->local_part) {
   1.168  		buffer = g_strdup("<>");
   1.169  	} else {
   1.170 -		buffer = g_strdup_printf("<%s@%s>", addr->local_part ? addr->local_part : "", addr->domain ? addr->domain : "");
   1.171 +		buffer = g_strdup_printf("<%s@%s>",
   1.172 +				addr->local_part ? addr->local_part : "",
   1.173 +				addr->domain ? addr->domain : "");
   1.174  	}
   1.175  	return buffer;
   1.176  }