masqmail

changeset 270:0c44b239c7fe

refactoring in the small
author markus schnalke <meillo@marmaro.de>
date Fri, 03 Dec 2010 13:02:45 -0300
parents fd1d77e5a5da
children 899175e8dff0
files src/accept.c
diffstat 1 files changed, 73 insertions(+), 65 deletions(-) [+]
line diff
     1.1 --- a/src/accept.c	Fri Dec 03 12:55:44 2010 -0300
     1.2 +++ b/src/accept.c	Fri Dec 03 13:02:45 2010 -0300
     1.3 @@ -48,10 +48,10 @@
     1.4  	address *addr2 = (address *) b;
     1.5  	int ret;
     1.6  
     1.7 -	if ((ret = strcasecmp(addr1->domain, addr2->domain)) == 0)
     1.8 +	if ((ret = strcasecmp(addr1->domain, addr2->domain)) == 0) {
     1.9  		return strcmp(addr1->local_part, addr2->local_part);
    1.10 -	else
    1.11 -		return ret;
    1.12 +	}
    1.13 +	return ret;
    1.14  }
    1.15  
    1.16  /* accept message from anywhere.
    1.17 @@ -88,70 +88,76 @@
    1.18  			line1++;
    1.19  		}
    1.20  
    1.21 -		if (len <= 0) {
    1.22 -			if ((len == -1) && (flags & (ACC_DOT_IGNORE | ACC_NODOT_RELAX))) {
    1.23 -				/* we got an EOF, and the last line was not terminated by a CR */
    1.24 -				gint len1 = strlen(line1);
    1.25 -				if (len1 > 0) {  /* == 0 is 'normal' (EOF after a CR) */
    1.26 -					if (line1[len1 - 1] != '\n') {  /* some mail clients allow unterminated lines */
    1.27 -						line1[len1] = '\n';
    1.28 -						line1[len1 + 1] = '\0';
    1.29 -						msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
    1.30 -						data_size += strlen(line1);
    1.31 -						line_cnt++;
    1.32 -					}
    1.33 +		if ((len == -1) && (flags & (ACC_DOT_IGNORE | ACC_NODOT_RELAX))) {
    1.34 +			/* we got an EOF, and the last line was not terminated by a CR */
    1.35 +			gint len1 = strlen(line1);
    1.36 +			if (len1 > 0) {  /* == 0 is 'normal' (EOF after a CR) */
    1.37 +				if (line1[len1 - 1] != '\n') {  /* some mail clients allow unterminated lines */
    1.38 +					line1[len1] = '\n';
    1.39 +					line1[len1 + 1] = '\0';
    1.40 +					msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
    1.41 +					data_size += strlen(line1);
    1.42 +					line_cnt++;
    1.43  				}
    1.44 -				break;
    1.45 +			}
    1.46 +			break;
    1.47 +
    1.48 +		} else if (len == -1) {
    1.49 +			g_free(line);
    1.50 +			return AERR_EOF;
    1.51 +
    1.52 +		} else if (len == -2) {
    1.53 +			/* should not happen any more */
    1.54 +			g_free(line);
    1.55 +			return AERR_OVERFLOW;
    1.56 +
    1.57 +		} else if (len == -3) {
    1.58 +			g_free(line);
    1.59 +			return AERR_TIMEOUT;
    1.60 +
    1.61 +		} else if (len <= 0) {
    1.62 +			/* does not happen */
    1.63 +			g_free(line);
    1.64 +			DEBUG(5) debugf("read_sockline returned %d\n", len);
    1.65 +			return AERR_UNKNOWN;
    1.66 +
    1.67 +		}
    1.68 +
    1.69 +		if (in_headers) {
    1.70 +
    1.71 +			/* some pop servers send the 'From ' line, skip it: */
    1.72 +			if (!msg->hdr_list && strncmp(line1, "From ", 5) == 0) {
    1.73 +				continue;
    1.74 +			}
    1.75 +
    1.76 +			if (line1[0] == ' ' || line1[0] == '\t') {
    1.77 +				/* continuation of 'folded' header: */
    1.78 +				if (hdr) {
    1.79 +					hdr->header = g_strconcat(hdr->header, line1, NULL);
    1.80 +				}
    1.81 +
    1.82 +			} else if (line1[0] == '\n') {
    1.83 +				/* an empty line marks end of headers */
    1.84 +				in_headers = FALSE;
    1.85  			} else {
    1.86 -				g_free(line);
    1.87 -				if (len == -1) {
    1.88 -					return AERR_EOF;
    1.89 -				} else if (len == -2) {
    1.90 -					/* should not happen any more */
    1.91 -					return AERR_OVERFLOW;
    1.92 -				} else if (len == -3) {
    1.93 -					return AERR_TIMEOUT;
    1.94 +				/* in all other cases we expect another header */
    1.95 +				if ((hdr = get_header(line1))) {
    1.96 +					msg->hdr_list = g_list_append(msg->hdr_list, hdr);
    1.97  				} else {
    1.98 -					/* does not happen */
    1.99 -					DEBUG(5) debugf("read_sockline returned %d\n", len);
   1.100 -					return AERR_UNKNOWN;
   1.101 +					/* if get_header() returns NULL, no header was recognized,
   1.102 +					   so this seems to be the first data line of a broken mailer
   1.103 +					   which does not send an empty line after the headers */
   1.104 +					in_headers = FALSE;
   1.105 +					msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.106  				}
   1.107  			}
   1.108  		} else {
   1.109 -			if (in_headers) {
   1.110 +			/* message body */
   1.111 +			msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.112 +			data_size += strlen(line1);
   1.113 +			line_cnt++;
   1.114 +		}
   1.115  
   1.116 -				/* some pop servers send the 'From ' line, skip it: */
   1.117 -				if (msg->hdr_list == NULL)
   1.118 -					if (strncmp(line1, "From ", 5) == 0)
   1.119 -						continue;
   1.120 -
   1.121 -				if (line1[0] == ' ' || line1[0] == '\t') {
   1.122 -					/* continuation of 'folded' header: */
   1.123 -					if (hdr) {
   1.124 -						hdr->header = g_strconcat(hdr->header, line1, NULL);
   1.125 -					}
   1.126 -
   1.127 -				} else if (line1[0] == '\n') {
   1.128 -					/* an empty line marks end of headers */
   1.129 -					in_headers = FALSE;
   1.130 -				} else {
   1.131 -					/* in all other cases we expect another header */
   1.132 -					if ((hdr = get_header(line1)))
   1.133 -						msg->hdr_list = g_list_append(msg->hdr_list, hdr);
   1.134 -					else {
   1.135 -						/* if get_header() returns NULL, no header was recognized,
   1.136 -						   so this seems to be the first data line of a broken mailer
   1.137 -						   which does not send an empty line after the headers */
   1.138 -						in_headers = FALSE;
   1.139 -						msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.140 -					}
   1.141 -				}
   1.142 -			} else {
   1.143 -				msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1));
   1.144 -				data_size += strlen(line1);
   1.145 -				line_cnt++;
   1.146 -			}
   1.147 -		}
   1.148  		if (conf.max_msg_size && (data_size > conf.max_msg_size)) {
   1.149  			DEBUG(4) debugf("accept_message_stream(): "
   1.150  					"received %d bytes (conf.max_msg_size=%d)\n",
   1.151 @@ -161,13 +167,14 @@
   1.152  
   1.153  	}
   1.154  
   1.155 -	if (msg->data_list != NULL)
   1.156 -		msg->data_list = g_list_reverse(msg->data_list);
   1.157 -	else
   1.158 +	DEBUG(4) debugf("received %d lines of data (%d bytes)\n", line_cnt, data_size);
   1.159 +
   1.160 +	if (!msg->data_list) {
   1.161  		/* make sure data list is not NULL: */
   1.162  		msg->data_list = g_list_append(NULL, g_strdup(""));
   1.163 +	}
   1.164 +	msg->data_list = g_list_reverse(msg->data_list);
   1.165  
   1.166 -	DEBUG(4) debugf("received %d lines of data (%d bytes)\n", line_cnt, data_size);
   1.167  	/* we get here after we succesfully received the mail data */
   1.168  
   1.169  	msg->data_size = data_size;
   1.170 @@ -421,8 +428,9 @@
   1.171  	accept_error err;
   1.172  
   1.173  	err = accept_message_stream(in, msg, flags);
   1.174 -	if (err == AERR_OK)
   1.175 +	if (err == AERR_OK) {
   1.176  		err = accept_message_prepare(msg, flags);
   1.177 +	}
   1.178  
   1.179  	return err;
   1.180  }