rev |
line source |
yuuji@0
|
1 /* ========================================================================
|
yuuji@0
|
2 * Copyright 1988-2006 University of Washington
|
yuuji@0
|
3 *
|
yuuji@0
|
4 * Licensed under the Apache License, Version 2.0 (the "License");
|
yuuji@0
|
5 * you may not use this file except in compliance with the License.
|
yuuji@0
|
6 * You may obtain a copy of the License at
|
yuuji@0
|
7 *
|
yuuji@0
|
8 * http://www.apache.org/licenses/LICENSE-2.0
|
yuuji@0
|
9 *
|
yuuji@0
|
10 *
|
yuuji@0
|
11 * ========================================================================
|
yuuji@0
|
12 */
|
yuuji@0
|
13
|
yuuji@0
|
14 /*
|
yuuji@0
|
15 * Program: UNIX mail routines, Amiga version
|
yuuji@0
|
16 *
|
yuuji@0
|
17 * Author: Mark Crispin
|
yuuji@0
|
18 * Networks and Distributed Computing
|
yuuji@0
|
19 * Computing & Communications
|
yuuji@0
|
20 * University of Washington
|
yuuji@0
|
21 * Administration Building, AG-44
|
yuuji@0
|
22 * Seattle, WA 98195
|
yuuji@0
|
23 * Internet: MRC@CAC.Washington.EDU
|
yuuji@0
|
24 *
|
yuuji@0
|
25 * Date: 20 December 1989
|
yuuji@0
|
26 * Last Edited: 30 August 2006
|
yuuji@0
|
27 */
|
yuuji@0
|
28
|
yuuji@0
|
29
|
yuuji@0
|
30 /* DEDICATION
|
yuuji@0
|
31 *
|
yuuji@0
|
32 * This file is dedicated to my dog, Unix, also known as Yun-chan and
|
yuuji@0
|
33 * Unix J. Terwilliker Jehosophat Aloysius Monstrosity Animal Beast. Unix
|
yuuji@0
|
34 * passed away at the age of 11 1/2 on September 14, 1996, 12:18 PM PDT, after
|
yuuji@0
|
35 * a two-month bout with cirrhosis of the liver.
|
yuuji@0
|
36 *
|
yuuji@0
|
37 * He was a dear friend, and I miss him terribly.
|
yuuji@0
|
38 *
|
yuuji@0
|
39 * Lift a leg, Yunie. Luv ya forever!!!!
|
yuuji@0
|
40 */
|
yuuji@0
|
41
|
yuuji@0
|
42 /* Validate line
|
yuuji@0
|
43 * Accepts: pointer to candidate string to validate as a From header
|
yuuji@0
|
44 * return pointer to end of date/time field
|
yuuji@0
|
45 * return pointer to offset from t of time (hours of ``mmm dd hh:mm'')
|
yuuji@0
|
46 * return pointer to offset from t of time zone (if non-zero)
|
yuuji@0
|
47 * Returns: t,ti,zn set if valid From string, else ti is NIL
|
yuuji@0
|
48 */
|
yuuji@0
|
49
|
yuuji@0
|
50 #define VALID(s,x,ti,zn) { \
|
yuuji@0
|
51 int remote = 0; \
|
yuuji@0
|
52 ti = 0; \
|
yuuji@0
|
53 if ((*s == 'F') && (s[1] == 'r') && (s[2] == 'o') && (s[3] == 'm') && \
|
yuuji@0
|
54 (s[4] == ' ')) { \
|
yuuji@0
|
55 for (x = s + 5; *x && *x != '\012'; x++); \
|
yuuji@0
|
56 if (*x) { \
|
yuuji@0
|
57 if (x[-1] == '\015') --x; \
|
yuuji@0
|
58 if (x - s >= 41) { \
|
yuuji@0
|
59 for (zn = -1; x[zn] != ' '; zn--); \
|
yuuji@0
|
60 if ((x[zn-1] == 'm') && (x[zn-2] == 'o') && (x[zn-3] == 'r') && \
|
yuuji@0
|
61 (x[zn-4] == 'f') && (x[zn-5] == ' ') && (x[zn-6] == 'e') && \
|
yuuji@0
|
62 (x[zn-7] == 't') && (x[zn-8] == 'o') && (x[zn-9] == 'm') && \
|
yuuji@0
|
63 (x[zn-10] == 'e') && (x[zn-11] == 'r') && (x[zn-12] == ' '))\
|
yuuji@0
|
64 { \
|
yuuji@0
|
65 while (x[zn-13] == ' ') zn--; \
|
yuuji@0
|
66 x += zn - 12; \
|
yuuji@0
|
67 remote = 1; \
|
yuuji@0
|
68 } \
|
yuuji@0
|
69 } \
|
yuuji@0
|
70 if (x - s >= 27) { \
|
yuuji@0
|
71 if (x[-5] == ' ') { \
|
yuuji@0
|
72 if (x[-8] == ':') zn = 0,ti = -5; \
|
yuuji@0
|
73 else if (x[-9] == ' ') ti = zn = -9; \
|
yuuji@0
|
74 else if ((x[-11] == ' ') && ((x[-10]=='+') || (x[-10]=='-'))) \
|
yuuji@0
|
75 ti = zn = -11; \
|
yuuji@0
|
76 } \
|
yuuji@0
|
77 else if (x[-4] == ' ') { \
|
yuuji@0
|
78 if (x[-9] == ' ') zn = -4,ti = -9; \
|
yuuji@0
|
79 else if ( (x[-13] == ' ') && (x[-16] == ' ') \
|
yuuji@0
|
80 && (x[-20] ==' ') && \
|
yuuji@0
|
81 ( ((x[-22] == ' ') && (x[-23] == ',')) || \
|
yuuji@0
|
82 ((x[-23] == ' ') && (x[-24] == ',')) ) ) { \
|
yuuji@0
|
83 char weekday[4]={0,}, month[4]={0,}, time[11]={0,}; \
|
yuuji@0
|
84 char tzone[4]={0,}; \
|
yuuji@0
|
85 char realtime[80]; \
|
yuuji@0
|
86 int day,year,start=-26; \
|
yuuji@0
|
87 if (x[-23] == ' ') x--; \
|
yuuji@0
|
88 sscanf(&x[start],"%3c, %d %s %d %s %s", \
|
yuuji@0
|
89 weekday,&day,month,&year,time,tzone); \
|
yuuji@0
|
90 sprintf(realtime,"%s %s %2d %s %d %s", \
|
yuuji@0
|
91 weekday,month,day,time, \
|
yuuji@0
|
92 ( (year < 100) ? year+1900 : year),tzone); \
|
yuuji@0
|
93 if (remote) \
|
yuuji@0
|
94 strcat(realtime," remote from "); \
|
yuuji@0
|
95 else \
|
yuuji@0
|
96 strcat(realtime,"\n"); \
|
yuuji@0
|
97 strncpy(&x[start],realtime,strlen(realtime)); \
|
yuuji@0
|
98 zn = -2; \
|
yuuji@0
|
99 ti = -7; \
|
yuuji@0
|
100 } \
|
yuuji@0
|
101 } \
|
yuuji@0
|
102 else if (x[-6] == ' ') { \
|
yuuji@0
|
103 if ((x[-11] == ' ') && ((x[-5] == '+') || (x[-5] == '-'))) \
|
yuuji@0
|
104 zn = -6,ti = -11; \
|
yuuji@0
|
105 } \
|
yuuji@0
|
106 else if (x[-9] == ' ') { \
|
yuuji@0
|
107 if ( ( (x[-12] == ' ') && (x[-16] == ' ') && \
|
yuuji@0
|
108 ( ((x[-18] == ' ') && (x[-19] == ',') ) || \
|
yuuji@0
|
109 ((x[-19] == ' ') && (x[-20] == ',')) ) \
|
yuuji@0
|
110 || \
|
yuuji@0
|
111 ((x[-14] == ' ') && (x[-18] == ' ') && \
|
yuuji@0
|
112 ( ((x[-20] == ' ') && (x[-21] == ',') ) || \
|
yuuji@0
|
113 ((x[-21] == ' ') && (x[-22] == ',')) ) ) ) ) { \
|
yuuji@0
|
114 char weekday[4]={0,}, month[4]={0,},time[11]={0,}; \
|
yuuji@0
|
115 int day,year,start=-24; \
|
yuuji@0
|
116 char realtime[80]; \
|
yuuji@0
|
117 if (x[-12] == ' ') x++; \
|
yuuji@0
|
118 if (x[-19] == ' ') x++; \
|
yuuji@0
|
119 sscanf(&x[start],"%3c, %d %3c %d %s",weekday, \
|
yuuji@0
|
120 &day,month,&year,time); \
|
yuuji@0
|
121 sprintf(realtime,"%s %s %2d %s %d",weekday,month,day,time,\
|
yuuji@0
|
122 ( (year < 100) ? year+1900 : year)); \
|
yuuji@0
|
123 if (remote) \
|
yuuji@0
|
124 strcat(realtime," remote from "); \
|
yuuji@0
|
125 else \
|
yuuji@0
|
126 strcat(realtime,"\n"); \
|
yuuji@0
|
127 strncpy(&x[start],realtime,strlen(realtime)); \
|
yuuji@0
|
128 ti=-5; \
|
yuuji@0
|
129 zn=0; \
|
yuuji@0
|
130 } \
|
yuuji@0
|
131 } \
|
yuuji@0
|
132 if (ti && !((x[ti - 3] == ':') && \
|
yuuji@0
|
133 (x[ti -= ((x[ti - 6] == ':') ? 9 : 6)] == ' ') && \
|
yuuji@0
|
134 (x[ti - 3] == ' ') && (x[ti - 7] == ' ') && \
|
yuuji@0
|
135 (x[ti - 11] == ' '))) ti = 0; \
|
yuuji@0
|
136 } \
|
yuuji@0
|
137 } \
|
yuuji@0
|
138 } \
|
yuuji@0
|
139 }
|
yuuji@0
|
140
|
yuuji@0
|
141 /* You are not expected to understand this macro, but read the next page if
|
yuuji@0
|
142 * you are not faint of heart.
|
yuuji@0
|
143 *
|
yuuji@0
|
144 * Known formats to the VALID macro are:
|
yuuji@0
|
145 * From user Wed Dec 2 05:53 1992
|
yuuji@0
|
146 * BSD From user Wed Dec 2 05:53:22 1992
|
yuuji@0
|
147 * SysV From user Wed Dec 2 05:53 PST 1992
|
yuuji@0
|
148 * rn From user Wed Dec 2 05:53:22 PST 1992
|
yuuji@0
|
149 * From user Wed Dec 2 05:53 -0700 1992
|
yuuji@0
|
150 * emacs From user Wed Dec 2 05:53:22 -0700 1992
|
yuuji@0
|
151 * From user Wed Dec 2 05:53 1992 PST
|
yuuji@0
|
152 * From user Wed Dec 2 05:53:22 1992 PST
|
yuuji@0
|
153 * From user Wed Dec 2 05:53 1992 -0700
|
yuuji@0
|
154 * Solaris From user Wed Dec 2 05:53:22 1992 -0700
|
yuuji@0
|
155 *
|
yuuji@0
|
156 * Amiga From user Wed, 6 Dec 92 05:53:22 who did this !!!
|
yuuji@0
|
157 * CHANGED in place to
|
yuuji@0
|
158 * From user Wed Dec 2 05:53:22 1992
|
yuuji@0
|
159 *
|
yuuji@0
|
160 * Plus all of the above with `` remote from xxx'' after it. Thank you very
|
yuuji@0
|
161 * much, smail and Solaris, for making my life considerably more complicated.
|
yuuji@0
|
162 */
|
yuuji@0
|
163
|
yuuji@0
|
164 /*
|
yuuji@0
|
165 * What? You want to understand the VALID macro anyway? Alright, since you
|
yuuji@0
|
166 * insist. Actually, it isn't really all that difficult, provided that you
|
yuuji@0
|
167 * take it step by step.
|
yuuji@0
|
168 *
|
yuuji@0
|
169 * Line 1 Initializes the return ti value to failure (0);
|
yuuji@0
|
170 * Lines 2-3 Validates that the 1st-5th characters are ``From ''.
|
yuuji@0
|
171 * Lines 4-6 Validates that there is an end of line and points x at it.
|
yuuji@0
|
172 * Lines 7-14 First checks to see if the line is at least 41 characters long.
|
yuuji@0
|
173 * If so, it scans backwards to find the rightmost space. From
|
yuuji@0
|
174 * that point, it scans backwards to see if the string matches
|
yuuji@0
|
175 * `` remote from''. If so, it sets x to point to the space at
|
yuuji@0
|
176 * the start of the string.
|
yuuji@0
|
177 * Line 15 Makes sure that there are at least 27 characters in the line.
|
yuuji@0
|
178 * Lines 16-21 Checks if the date/time ends with the year (there is a space
|
yuuji@0
|
179 * five characters back). If there is a colon three characters
|
yuuji@0
|
180 * further back, there is no timezone field, so zn is set to 0
|
yuuji@0
|
181 * and ti is set in front of the year. Otherwise, there must
|
yuuji@0
|
182 * either to be a space four characters back for a three-letter
|
yuuji@0
|
183 * timezone, or a space six characters back followed by a + or -
|
yuuji@0
|
184 * for a numeric timezone; in either case, zn and ti become the
|
yuuji@0
|
185 * offset of the space immediately before it.
|
yuuji@0
|
186 * Lines 22-24 Are the failure case for line 14. If there is a space four
|
yuuji@0
|
187 * characters back, it is a three-letter timezone; there must be a
|
yuuji@0
|
188 * space for the year nine characters back. zn is the zone
|
yuuji@0
|
189 * offset; ti is the offset of the space.
|
yuuji@0
|
190 * Lines 25-28 Are the failure case for line 20. If there is a space six
|
yuuji@0
|
191 * characters back, it is a numeric timezone; there must be a
|
yuuji@0
|
192 * space eleven characters back and a + or - five characters back.
|
yuuji@0
|
193 * zn is the zone offset; ti is the offset of the space.
|
yuuji@0
|
194 * Line 29-32 If ti is valid, make sure that the string before ti is of the
|
yuuji@0
|
195 * form www mmm dd hh:mm or www mmm dd hh:mm:ss, otherwise
|
yuuji@0
|
196 * invalidate ti. There must be a colon three characters back
|
yuuji@0
|
197 * and a space six or nine characters back (depending upon
|
yuuji@0
|
198 * whether or not the character six characters back is a colon).
|
yuuji@0
|
199 * There must be a space three characters further back (in front
|
yuuji@0
|
200 * of the day), one seven characters back (in front of the month),
|
yuuji@0
|
201 * and one eleven characters back (in front of the day of week).
|
yuuji@0
|
202 * ti is set to be the offset of the space before the time.
|
yuuji@0
|
203 *
|
yuuji@0
|
204 * Why a macro? It gets invoked a *lot* in a tight loop. On some of the
|
yuuji@0
|
205 * newer pipelined machines it is faster being open-coded than it would be if
|
yuuji@0
|
206 * subroutines are called.
|
yuuji@0
|
207 *
|
yuuji@0
|
208 * Why does it scan backwards from the end of the line, instead of doing the
|
yuuji@0
|
209 * much easier forward scan? There is no deterministic way to parse the
|
yuuji@0
|
210 * ``user'' field, because it may contain unquoted spaces! Yes, I tested it to
|
yuuji@0
|
211 * see if unquoted spaces were possible. They are, and I've encountered enough
|
yuuji@0
|
212 * evil mail to be totally unwilling to trust that ``it will never happen''.
|
yuuji@0
|
213 */
|
yuuji@0
|
214
|
yuuji@0
|
215 /* Build parameters */
|
yuuji@0
|
216
|
yuuji@0
|
217 #define KODRETRY 15 /* kiss-of-death retry in seconds */
|
yuuji@0
|
218 #define LOCKTIMEOUT 5 /* lock timeout in minutes */
|
yuuji@0
|
219 #define CHUNK 16384 /* read-in chunk size */
|