masqmail

changeset 272:681863fdafbb

refactoring in the small
author markus schnalke <meillo@marmaro.de>
date Fri, 03 Dec 2010 19:13:25 -0300
parents 899175e8dff0
children 00724782b6c9
files src/rewrite.c
diffstat 1 files changed, 33 insertions(+), 31 deletions(-) [+]
line diff
     1.1 --- a/src/rewrite.c	Fri Dec 03 13:05:59 2010 -0300
     1.2 +++ b/src/rewrite.c	Fri Dec 03 19:13:25 2010 -0300
     1.3 @@ -26,39 +26,38 @@
     1.4  	gchar *p = hdr->value;
     1.5  	gchar *new_hdr = g_strndup(hdr->header, hdr->value - hdr->header);
     1.6  	gint tmp;
     1.7 +	gchar *loc_beg, *loc_end;
     1.8 +	gchar *dom_beg, *dom_end;
     1.9 +	gchar *addr_end;
    1.10 +	gchar *rewr_string;
    1.11 +	gchar *left, *right;
    1.12  
    1.13  	while (*p) {
    1.14 -		gchar *loc_beg, *loc_end;
    1.15 -		gchar *dom_beg, *dom_end;
    1.16 -		gchar *addr_end;
    1.17 -		gchar *rewr_string;
    1.18 +		if (!parse_address_rfc822(p, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) {
    1.19 +			return FALSE;
    1.20 +		}
    1.21  
    1.22 -		if (parse_address_rfc822(p, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) {
    1.23 -			gchar *left, *right;
    1.24 +		if (dom_beg) {
    1.25 +			left = g_strndup(p, dom_beg - p);
    1.26 +			right = g_strndup(dom_end, addr_end - dom_end);
    1.27  
    1.28 -			if (dom_beg != NULL) {
    1.29 -				left = g_strndup(p, dom_beg - p);
    1.30 -				right = g_strndup(dom_end, addr_end - dom_end);
    1.31 +			rewr_string = g_strconcat(left, domain, right, NULL);
    1.32 +		} else {
    1.33 +			left = g_strndup(p, loc_end - p);
    1.34 +			right = g_strndup(loc_end, addr_end - loc_end);
    1.35  
    1.36 -				rewr_string = g_strconcat(left, domain, right, NULL);
    1.37 -			} else {
    1.38 -				left = g_strndup(p, loc_end - p);
    1.39 -				right = g_strndup(loc_end, addr_end - loc_end);
    1.40 +			rewr_string = g_strconcat(left, "@", domain, right, NULL);
    1.41 +		}
    1.42 +		g_free(left);
    1.43 +		g_free(right);
    1.44  
    1.45 -				rewr_string = g_strconcat(left, "@", domain, right, NULL);
    1.46 -			}
    1.47 -			g_free(left);
    1.48 -			g_free(right);
    1.49 +		p = addr_end;
    1.50 +		if (*p == ',') {
    1.51 +			p++;
    1.52 +		}
    1.53 +		new_hdr = g_strconcat(new_hdr, rewr_string, *p != '\0' ? "," : NULL, NULL);
    1.54 +	}
    1.55  
    1.56 -			p = addr_end;
    1.57 -			if (*p == ',')
    1.58 -				p++;
    1.59 -
    1.60 -			new_hdr = g_strconcat(new_hdr, rewr_string, *p != '\0' ? "," : NULL, NULL);
    1.61 -
    1.62 -		} else
    1.63 -			return FALSE;
    1.64 -	}
    1.65  	tmp = (hdr->value - hdr->header);
    1.66  	g_free(hdr->header);
    1.67  	hdr->header = new_hdr;
    1.68 @@ -79,19 +78,22 @@
    1.69  		address *addr = (address *) (addr_node->data);
    1.70  		gchar *rewr_string = (gchar *) table_find_fnmatch(table, addr->local_part);
    1.71  
    1.72 -		if (rewr_string == NULL)
    1.73 +		if (rewr_string) {
    1.74 +			did_change = TRUE;
    1.75 +		} else {
    1.76  			rewr_string = addr->address;
    1.77 -		else
    1.78 -			did_change = TRUE;
    1.79 +		}
    1.80  
    1.81 -		if (rewr_string)
    1.82 +		if (rewr_string) {
    1.83  			new_hdr = g_strconcat(new_hdr, rewr_string, g_list_next(addr_node) ? "," : "\n", NULL);
    1.84 +		}
    1.85  	}
    1.86  	if (did_change) {
    1.87  		g_free(hdr->header);
    1.88  		hdr->header = new_hdr;
    1.89 -	} else
    1.90 +	} else {
    1.91  		g_free(new_hdr);
    1.92 +	}
    1.93  
    1.94  	return did_change;
    1.95  }