imapext-2007

view src/osdep/amiga/unix.h @ 0:ada5e610ab86

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

UW-IMAP'd extensions by yuuji