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