imapext-2007
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/osdep/amiga/unix.h Mon Sep 14 15:17:45 2009 +0900 1.3 @@ -0,0 +1,219 @@ 1.4 +/* ======================================================================== 1.5 + * Copyright 1988-2006 University of Washington 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * 1.14 + * ======================================================================== 1.15 + */ 1.16 + 1.17 +/* 1.18 + * Program: UNIX mail routines, Amiga version 1.19 + * 1.20 + * Author: Mark Crispin 1.21 + * Networks and Distributed Computing 1.22 + * Computing & Communications 1.23 + * University of Washington 1.24 + * Administration Building, AG-44 1.25 + * Seattle, WA 98195 1.26 + * Internet: MRC@CAC.Washington.EDU 1.27 + * 1.28 + * Date: 20 December 1989 1.29 + * Last Edited: 30 August 2006 1.30 + */ 1.31 + 1.32 + 1.33 +/* DEDICATION 1.34 + * 1.35 + * This file is dedicated to my dog, Unix, also known as Yun-chan and 1.36 + * Unix J. Terwilliker Jehosophat Aloysius Monstrosity Animal Beast. Unix 1.37 + * passed away at the age of 11 1/2 on September 14, 1996, 12:18 PM PDT, after 1.38 + * a two-month bout with cirrhosis of the liver. 1.39 + * 1.40 + * He was a dear friend, and I miss him terribly. 1.41 + * 1.42 + * Lift a leg, Yunie. Luv ya forever!!!! 1.43 + */ 1.44 + 1.45 +/* Validate line 1.46 + * Accepts: pointer to candidate string to validate as a From header 1.47 + * return pointer to end of date/time field 1.48 + * return pointer to offset from t of time (hours of ``mmm dd hh:mm'') 1.49 + * return pointer to offset from t of time zone (if non-zero) 1.50 + * Returns: t,ti,zn set if valid From string, else ti is NIL 1.51 + */ 1.52 + 1.53 +#define VALID(s,x,ti,zn) { \ 1.54 + int remote = 0; \ 1.55 + ti = 0; \ 1.56 + if ((*s == 'F') && (s[1] == 'r') && (s[2] == 'o') && (s[3] == 'm') && \ 1.57 + (s[4] == ' ')) { \ 1.58 + for (x = s + 5; *x && *x != '\012'; x++); \ 1.59 + if (*x) { \ 1.60 + if (x[-1] == '\015') --x; \ 1.61 + if (x - s >= 41) { \ 1.62 + for (zn = -1; x[zn] != ' '; zn--); \ 1.63 + if ((x[zn-1] == 'm') && (x[zn-2] == 'o') && (x[zn-3] == 'r') && \ 1.64 + (x[zn-4] == 'f') && (x[zn-5] == ' ') && (x[zn-6] == 'e') && \ 1.65 + (x[zn-7] == 't') && (x[zn-8] == 'o') && (x[zn-9] == 'm') && \ 1.66 + (x[zn-10] == 'e') && (x[zn-11] == 'r') && (x[zn-12] == ' '))\ 1.67 + { \ 1.68 + while (x[zn-13] == ' ') zn--; \ 1.69 + x += zn - 12; \ 1.70 + remote = 1; \ 1.71 + } \ 1.72 + } \ 1.73 + if (x - s >= 27) { \ 1.74 + if (x[-5] == ' ') { \ 1.75 + if (x[-8] == ':') zn = 0,ti = -5; \ 1.76 + else if (x[-9] == ' ') ti = zn = -9; \ 1.77 + else if ((x[-11] == ' ') && ((x[-10]=='+') || (x[-10]=='-'))) \ 1.78 + ti = zn = -11; \ 1.79 + } \ 1.80 + else if (x[-4] == ' ') { \ 1.81 + if (x[-9] == ' ') zn = -4,ti = -9; \ 1.82 + else if ( (x[-13] == ' ') && (x[-16] == ' ') \ 1.83 + && (x[-20] ==' ') && \ 1.84 + ( ((x[-22] == ' ') && (x[-23] == ',')) || \ 1.85 + ((x[-23] == ' ') && (x[-24] == ',')) ) ) { \ 1.86 + char weekday[4]={0,}, month[4]={0,}, time[11]={0,}; \ 1.87 + char tzone[4]={0,}; \ 1.88 + char realtime[80]; \ 1.89 + int day,year,start=-26; \ 1.90 + if (x[-23] == ' ') x--; \ 1.91 + sscanf(&x[start],"%3c, %d %s %d %s %s", \ 1.92 + weekday,&day,month,&year,time,tzone); \ 1.93 + sprintf(realtime,"%s %s %2d %s %d %s", \ 1.94 + weekday,month,day,time, \ 1.95 + ( (year < 100) ? year+1900 : year),tzone); \ 1.96 + if (remote) \ 1.97 + strcat(realtime," remote from "); \ 1.98 + else \ 1.99 + strcat(realtime,"\n"); \ 1.100 + strncpy(&x[start],realtime,strlen(realtime)); \ 1.101 + zn = -2; \ 1.102 + ti = -7; \ 1.103 + } \ 1.104 + } \ 1.105 + else if (x[-6] == ' ') { \ 1.106 + if ((x[-11] == ' ') && ((x[-5] == '+') || (x[-5] == '-'))) \ 1.107 + zn = -6,ti = -11; \ 1.108 + } \ 1.109 + else if (x[-9] == ' ') { \ 1.110 + if ( ( (x[-12] == ' ') && (x[-16] == ' ') && \ 1.111 + ( ((x[-18] == ' ') && (x[-19] == ',') ) || \ 1.112 + ((x[-19] == ' ') && (x[-20] == ',')) ) \ 1.113 + || \ 1.114 + ((x[-14] == ' ') && (x[-18] == ' ') && \ 1.115 + ( ((x[-20] == ' ') && (x[-21] == ',') ) || \ 1.116 + ((x[-21] == ' ') && (x[-22] == ',')) ) ) ) ) { \ 1.117 + char weekday[4]={0,}, month[4]={0,},time[11]={0,}; \ 1.118 + int day,year,start=-24; \ 1.119 + char realtime[80]; \ 1.120 + if (x[-12] == ' ') x++; \ 1.121 + if (x[-19] == ' ') x++; \ 1.122 + sscanf(&x[start],"%3c, %d %3c %d %s",weekday, \ 1.123 + &day,month,&year,time); \ 1.124 + sprintf(realtime,"%s %s %2d %s %d",weekday,month,day,time,\ 1.125 + ( (year < 100) ? year+1900 : year)); \ 1.126 + if (remote) \ 1.127 + strcat(realtime," remote from "); \ 1.128 + else \ 1.129 + strcat(realtime,"\n"); \ 1.130 + strncpy(&x[start],realtime,strlen(realtime)); \ 1.131 + ti=-5; \ 1.132 + zn=0; \ 1.133 + } \ 1.134 + } \ 1.135 + if (ti && !((x[ti - 3] == ':') && \ 1.136 + (x[ti -= ((x[ti - 6] == ':') ? 9 : 6)] == ' ') && \ 1.137 + (x[ti - 3] == ' ') && (x[ti - 7] == ' ') && \ 1.138 + (x[ti - 11] == ' '))) ti = 0; \ 1.139 + } \ 1.140 + } \ 1.141 + } \ 1.142 +} 1.143 + 1.144 +/* You are not expected to understand this macro, but read the next page if 1.145 + * you are not faint of heart. 1.146 + * 1.147 + * Known formats to the VALID macro are: 1.148 + * From user Wed Dec 2 05:53 1992 1.149 + * BSD From user Wed Dec 2 05:53:22 1992 1.150 + * SysV From user Wed Dec 2 05:53 PST 1992 1.151 + * rn From user Wed Dec 2 05:53:22 PST 1992 1.152 + * From user Wed Dec 2 05:53 -0700 1992 1.153 + * emacs From user Wed Dec 2 05:53:22 -0700 1992 1.154 + * From user Wed Dec 2 05:53 1992 PST 1.155 + * From user Wed Dec 2 05:53:22 1992 PST 1.156 + * From user Wed Dec 2 05:53 1992 -0700 1.157 + * Solaris From user Wed Dec 2 05:53:22 1992 -0700 1.158 + * 1.159 + * Amiga From user Wed, 6 Dec 92 05:53:22 who did this !!! 1.160 + * CHANGED in place to 1.161 + * From user Wed Dec 2 05:53:22 1992 1.162 + * 1.163 + * Plus all of the above with `` remote from xxx'' after it. Thank you very 1.164 + * much, smail and Solaris, for making my life considerably more complicated. 1.165 + */ 1.166 + 1.167 +/* 1.168 + * What? You want to understand the VALID macro anyway? Alright, since you 1.169 + * insist. Actually, it isn't really all that difficult, provided that you 1.170 + * take it step by step. 1.171 + * 1.172 + * Line 1 Initializes the return ti value to failure (0); 1.173 + * Lines 2-3 Validates that the 1st-5th characters are ``From ''. 1.174 + * Lines 4-6 Validates that there is an end of line and points x at it. 1.175 + * Lines 7-14 First checks to see if the line is at least 41 characters long. 1.176 + * If so, it scans backwards to find the rightmost space. From 1.177 + * that point, it scans backwards to see if the string matches 1.178 + * `` remote from''. If so, it sets x to point to the space at 1.179 + * the start of the string. 1.180 + * Line 15 Makes sure that there are at least 27 characters in the line. 1.181 + * Lines 16-21 Checks if the date/time ends with the year (there is a space 1.182 + * five characters back). If there is a colon three characters 1.183 + * further back, there is no timezone field, so zn is set to 0 1.184 + * and ti is set in front of the year. Otherwise, there must 1.185 + * either to be a space four characters back for a three-letter 1.186 + * timezone, or a space six characters back followed by a + or - 1.187 + * for a numeric timezone; in either case, zn and ti become the 1.188 + * offset of the space immediately before it. 1.189 + * Lines 22-24 Are the failure case for line 14. If there is a space four 1.190 + * characters back, it is a three-letter timezone; there must be a 1.191 + * space for the year nine characters back. zn is the zone 1.192 + * offset; ti is the offset of the space. 1.193 + * Lines 25-28 Are the failure case for line 20. If there is a space six 1.194 + * characters back, it is a numeric timezone; there must be a 1.195 + * space eleven characters back and a + or - five characters back. 1.196 + * zn is the zone offset; ti is the offset of the space. 1.197 + * Line 29-32 If ti is valid, make sure that the string before ti is of the 1.198 + * form www mmm dd hh:mm or www mmm dd hh:mm:ss, otherwise 1.199 + * invalidate ti. There must be a colon three characters back 1.200 + * and a space six or nine characters back (depending upon 1.201 + * whether or not the character six characters back is a colon). 1.202 + * There must be a space three characters further back (in front 1.203 + * of the day), one seven characters back (in front of the month), 1.204 + * and one eleven characters back (in front of the day of week). 1.205 + * ti is set to be the offset of the space before the time. 1.206 + * 1.207 + * Why a macro? It gets invoked a *lot* in a tight loop. On some of the 1.208 + * newer pipelined machines it is faster being open-coded than it would be if 1.209 + * subroutines are called. 1.210 + * 1.211 + * Why does it scan backwards from the end of the line, instead of doing the 1.212 + * much easier forward scan? There is no deterministic way to parse the 1.213 + * ``user'' field, because it may contain unquoted spaces! Yes, I tested it to 1.214 + * see if unquoted spaces were possible. They are, and I've encountered enough 1.215 + * evil mail to be totally unwilling to trust that ``it will never happen''. 1.216 + */ 1.217 + 1.218 +/* Build parameters */ 1.219 + 1.220 +#define KODRETRY 15 /* kiss-of-death retry in seconds */ 1.221 +#define LOCKTIMEOUT 5 /* lock timeout in minutes */ 1.222 +#define CHUNK 16384 /* read-in chunk size */