~ubuntu-branches/debian/squeeze/alpine/squeeze

« back to all changes in this revision

Viewing changes to imap/src/osdep/nt/unixnt.h

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

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