imapext-2007

annotate src/osdep/unix/unix.h @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
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
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 ti = 0; \
yuuji@0 52 if ((*s == 'F') && (s[1] == 'r') && (s[2] == 'o') && (s[3] == 'm') && \
yuuji@0 53 (s[4] == ' ')) { \
yuuji@0 54 for (x = s + 5; *x && *x != '\012'; x++); \
yuuji@0 55 if (*x) { \
yuuji@0 56 if (x[-1] == '\015') --x; \
yuuji@0 57 if (x - s >= 41) { \
yuuji@0 58 for (zn = -1; x[zn] != ' '; zn--); \
yuuji@0 59 if ((x[zn-1] == 'm') && (x[zn-2] == 'o') && (x[zn-3] == 'r') && \
yuuji@0 60 (x[zn-4] == 'f') && (x[zn-5] == ' ') && (x[zn-6] == 'e') && \
yuuji@0 61 (x[zn-7] == 't') && (x[zn-8] == 'o') && (x[zn-9] == 'm') && \
yuuji@0 62 (x[zn-10] == 'e') && (x[zn-11] == 'r') && (x[zn-12] == ' '))\
yuuji@0 63 x += zn - 12; \
yuuji@0 64 } \
yuuji@0 65 if (x - s >= 27) { \
yuuji@0 66 if (x[-5] == ' ') { \
yuuji@0 67 if (x[-8] == ':') zn = 0,ti = -5; \
yuuji@0 68 else if (x[-9] == ' ') ti = zn = -9; \
yuuji@0 69 else if ((x[-11] == ' ') && ((x[-10]=='+') || (x[-10]=='-'))) \
yuuji@0 70 ti = zn = -11; \
yuuji@0 71 } \
yuuji@0 72 else if (x[-4] == ' ') { \
yuuji@0 73 if (x[-9] == ' ') zn = -4,ti = -9; \
yuuji@0 74 } \
yuuji@0 75 else if (x[-6] == ' ') { \
yuuji@0 76 if ((x[-11] == ' ') && ((x[-5] == '+') || (x[-5] == '-'))) \
yuuji@0 77 zn = -6,ti = -11; \
yuuji@0 78 } \
yuuji@0 79 if (ti && !((x[ti - 3] == ':') && \
yuuji@0 80 (x[ti -= ((x[ti - 6] == ':') ? 9 : 6)] == ' ') && \
yuuji@0 81 (x[ti - 3] == ' ') && (x[ti - 7] == ' ') && \
yuuji@0 82 (x[ti - 11] == ' '))) ti = 0; \
yuuji@0 83 } \
yuuji@0 84 } \
yuuji@0 85 } \
yuuji@0 86 }
yuuji@0 87
yuuji@0 88 /* You are not expected to understand this macro, but read the next page if
yuuji@0 89 * you are not faint of heart.
yuuji@0 90 *
yuuji@0 91 * Known formats to the VALID macro are:
yuuji@0 92 * From user Wed Dec 2 05:53 1992
yuuji@0 93 * BSD From user Wed Dec 2 05:53:22 1992
yuuji@0 94 * SysV From user Wed Dec 2 05:53 PST 1992
yuuji@0 95 * rn From user Wed Dec 2 05:53:22 PST 1992
yuuji@0 96 * From user Wed Dec 2 05:53 -0700 1992
yuuji@0 97 * emacs From user Wed Dec 2 05:53:22 -0700 1992
yuuji@0 98 * From user Wed Dec 2 05:53 1992 PST
yuuji@0 99 * From user Wed Dec 2 05:53:22 1992 PST
yuuji@0 100 * From user Wed Dec 2 05:53 1992 -0700
yuuji@0 101 * Solaris From user Wed Dec 2 05:53:22 1992 -0700
yuuji@0 102 *
yuuji@0 103 * Plus all of the above with `` remote from xxx'' after it. Thank you very
yuuji@0 104 * much, smail and Solaris, for making my life considerably more complicated.
yuuji@0 105 */
yuuji@0 106
yuuji@0 107 /*
yuuji@0 108 * What? You want to understand the VALID macro anyway? Alright, since you
yuuji@0 109 * insist. Actually, it isn't really all that difficult, provided that you
yuuji@0 110 * take it step by step.
yuuji@0 111 *
yuuji@0 112 * Line 1 Initializes the return ti value to failure (0);
yuuji@0 113 * Lines 2-3 Validates that the 1st-5th characters are ``From ''.
yuuji@0 114 * Lines 4-6 Validates that there is an end of line and points x at it.
yuuji@0 115 * Lines 7-14 First checks to see if the line is at least 41 characters long.
yuuji@0 116 * If so, it scans backwards to find the rightmost space. From
yuuji@0 117 * that point, it scans backwards to see if the string matches
yuuji@0 118 * `` remote from''. If so, it sets x to point to the space at
yuuji@0 119 * the start of the string.
yuuji@0 120 * Line 15 Makes sure that there are at least 27 characters in the line.
yuuji@0 121 * Lines 16-21 Checks if the date/time ends with the year (there is a space
yuuji@0 122 * five characters back). If there is a colon three characters
yuuji@0 123 * further back, there is no timezone field, so zn is set to 0
yuuji@0 124 * and ti is set in front of the year. Otherwise, there must
yuuji@0 125 * either to be a space four characters back for a three-letter
yuuji@0 126 * timezone, or a space six characters back followed by a + or -
yuuji@0 127 * for a numeric timezone; in either case, zn and ti become the
yuuji@0 128 * offset of the space immediately before it.
yuuji@0 129 * Lines 22-24 Are the failure case for line 14. If there is a space four
yuuji@0 130 * characters back, it is a three-letter timezone; there must be a
yuuji@0 131 * space for the year nine characters back. zn is the zone
yuuji@0 132 * offset; ti is the offset of the space.
yuuji@0 133 * Lines 25-28 Are the failure case for line 20. If there is a space six
yuuji@0 134 * characters back, it is a numeric timezone; there must be a
yuuji@0 135 * space eleven characters back and a + or - five characters back.
yuuji@0 136 * zn is the zone offset; ti is the offset of the space.
yuuji@0 137 * Line 29-32 If ti is valid, make sure that the string before ti is of the
yuuji@0 138 * form www mmm dd hh:mm or www mmm dd hh:mm:ss, otherwise
yuuji@0 139 * invalidate ti. There must be a colon three characters back
yuuji@0 140 * and a space six or nine characters back (depending upon
yuuji@0 141 * whether or not the character six characters back is a colon).
yuuji@0 142 * There must be a space three characters further back (in front
yuuji@0 143 * of the day), one seven characters back (in front of the month),
yuuji@0 144 * and one eleven characters back (in front of the day of week).
yuuji@0 145 * ti is set to be the offset of the space before the time.
yuuji@0 146 *
yuuji@0 147 * Why a macro? It gets invoked a *lot* in a tight loop. On some of the
yuuji@0 148 * newer pipelined machines it is faster being open-coded than it would be if
yuuji@0 149 * subroutines are called.
yuuji@0 150 *
yuuji@0 151 * Why does it scan backwards from the end of the line, instead of doing the
yuuji@0 152 * much easier forward scan? There is no deterministic way to parse the
yuuji@0 153 * ``user'' field, because it may contain unquoted spaces! Yes, I tested it to
yuuji@0 154 * see if unquoted spaces were possible. They are, and I've encountered enough
yuuji@0 155 * evil mail to be totally unwilling to trust that ``it will never happen''.
yuuji@0 156 */
yuuji@0 157
yuuji@0 158 /* Build parameters */
yuuji@0 159
yuuji@0 160 #define KODRETRY 15 /* kiss-of-death retry in seconds */
yuuji@0 161 #define LOCKTIMEOUT 5 /* lock timeout in minutes */

UW-IMAP'd extensions by yuuji