lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

010-fix_message-header.patch (1908B)


      1 --- a/ssmtp.c
      2 +++ b/ssmtp.c
      3 @@ -282,6 +282,7 @@ standardise() -- Trim off '\n's and doub
      4  */
      5  bool_t standardise(char *str, bool_t *linestart)
      6  {
      7 +	size_t sl;
      8  	char *p;
      9  	bool_t leadingdot = False;
     10  
     11 @@ -297,6 +298,12 @@ bool_t standardise(char *str, bool_t *li
     12  	if((p = strchr(str, '\n'))) {
     13  		*p = '\0';
     14  		*linestart = True;
     15 +
     16 +		/* If the line ended in "\r\n", then drop the '\r' too */
     17 +		sl = strlen(str);
     18 +		if(sl >= 1 && str[sl - 1] == '\r') {
     19 +			str[sl - 1] = '\0';
     20 +		}
     21  	}
     22  	return(leadingdot);
     23  }
     24 @@ -690,6 +697,14 @@ void header_parse(FILE *stream)
     25  		}
     26  		len++;
     27  
     28 +		if(l == '\r' && c == '\n') {
     29 +			/* Properly handle input that already has "\r\n"
     30 +			   line endings; see https://bugs.debian.org/584162 */
     31 +			l = (len >= 2 ? *(q - 2) : '\n');
     32 +			q--;
     33 +			len--;
     34 +		}
     35 +
     36  		if(l == '\n') {
     37  			switch(c) {
     38  				case ' ':
     39 @@ -712,8 +727,9 @@ void header_parse(FILE *stream)
     40  						if((q = strrchr(p, '\n'))) {
     41  							*q = '\0';
     42  						}
     43 -						header_save(p);
     44 -
     45 +						if(len > 0) {
     46 +							header_save(p);
     47 +						}
     48  						q = p;
     49  						len = 0;
     50  			}
     51 @@ -722,35 +738,12 @@ void header_parse(FILE *stream)
     52  
     53  		l = c;
     54  	}
     55 -	if(in_header) {
     56 -		if(l == '\n') {
     57 -			switch(c) {
     58 -				case ' ':
     59 -				case '\t':
     60 -						/* Must insert '\r' before '\n's embedded in header
     61 -						   fields otherwise qmail won't accept our mail
     62 -						   because a bare '\n' violates some RFC */
     63 -						
     64 -						*(q - 1) = '\r';	/* Replace previous \n with \r */
     65 -						*q++ = '\n';		/* Insert \n */
     66 -						len++;
     67 -						
     68 -						break;
     69 -
     70 -				case '\n':
     71 -						in_header = False;
     72 -
     73 -				default:
     74 -						*q = '\0';
     75 -						if((q = strrchr(p, '\n'))) {
     76 -							*q = '\0';
     77 -						}
     78 -						header_save(p);
     79 -
     80 -						q = p;
     81 -						len = 0;
     82 -			}
     83 -		}
     84 +	if(in_header && l == '\n') {
     85 +		/* Got EOF while reading the header */
     86 +		if((q = strrchr(p, '\n'))) {
     87 +			*q = '\0';
     88 + 		}
     89 +		header_save(p);
     90  	}
     91  	(void)free(p);
     92  }