summaryrefslogtreecommitdiff
path: root/debian/patches/patch.mail.local
blob: d0c8b0dba400e6b4144b9b1a1404ebde1f620b7f (plain)
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
diff -wur ./mail.local/mail.local.c ./debian/patches/mail.local/mail.local.c
--- ./mail.local/mail.local.c	Tue Dec 29 18:42:53 1998
+++ ./debian/patches/mail.local/mail.local.c	Sun May  7 17:30:14 2000
@@ -593,6 +593,7 @@
 	FILE *fp = NULL;
 	time_t tval;
 	int fd, eline;
+	int prevfl, fl = 1;
 	char line[2048];
 	char tmpbuf[sizeof _PATH_LOCTMP + 1];
 
@@ -620,12 +621,13 @@
 	for (eline = 1; fgets(line, sizeof(line), stdin);) {
 		size_t line_len = strlen(line);
 
+		prevfl=fl;
 		if (line_len >= 2 &&
 		    line[line_len - 2] == '\r' &&
 		    line[line_len - 1] == '\n') {
 			strcpy(line + line_len - 2, "\n");
 		}
-		if (lmtprcpts && line[0] == '.') {
+		if (prevfl && lmtprcpts && line[0] == '.') {
 			char *src = line + 1, *dest = line;
 
 			if (line[1] == '\n')
@@ -634,7 +636,39 @@
 				*dest++ = *src++;
 			*dest = '\0';
 		}
-		if (line[0] == '\n')
+
+		fl=0;
+		if (line_len > 0)
+		{
+		    if (line[line_len - 1] == '\n')
+		    {
+			if (line_len >= 2 &&
+				line[line_len - 2] == '\r')
+			{
+			    line[line_len - 2] = '\n';
+			    line[line_len - 1] = '\0';
+			    line_len--;
+			}
+			fl = 1;
+		    }
+		    else if (line[line_len - 1] == '\r')
+		    {
+			int peek;
+			/* Did we just miss the CRLF? */
+			peek = fgetc(stdin);
+			if (peek == '\n')
+			{
+			    line[line_len - 1] = '\n';
+			    fl = 1;
+			}
+			else
+			    (void) ungetc(peek, stdin);
+		    }
+		}
+		else
+		    fl = 1;
+
+		if (prevfl && line[0] == '\n')
 			eline = 1;
 		else {
 			if (eline && line[0] == 'F' &&