home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / pine / c-client / bezerk.h < prev    next >
Text File  |  1994-01-09  |  16KB  |  279 lines

  1. /*
  2.  * Program:    Berkeley mail routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    20 December 1989
  13.  * Last Edited:    21 September 1993
  14.  *
  15.  * Copyright 1993 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36.  
  37. /* Dedication:
  38.  *  This file is dedicated with affection to those Merry Marvels of Musical
  39.  * Madness . . .
  40.  *  ->  The Incomparable Leland Stanford Junior University Marching Band  <-
  41.  * who entertain, awaken, and outrage Stanford fans in the fact of repeated
  42.  * losing seasons and shattered Rose Bowl dreams [Cardinal just don't have
  43.  * HUSKY FEVER!!!].
  44.  *
  45.  */
  46.  
  47. /* Validate line known to start with ``F''
  48.  * Accepts: pointer to candidate string to validate as a From header
  49.  *        return pointer to end of date/time field
  50.  *        return pointer to offset from t of time (hours of ``mmm dd hh:mm'')
  51.  *        return pointer to offset from t of time zone (if non-zero)
  52.  * Returns: T if valid From string, t,ti,zn set; else NIL
  53.  */
  54.  
  55. #define VALID(s,x,ti,zn) \
  56.   (s[1] == 'r') && (s[2] == 'o') && (s[3] == 'm') && (s[4] == ' ') && \
  57.   (x = strchr (s+5,'\n')) && \
  58.   ((x-s < 41) || ((ti = ((x[-2] == ' ') ? -14 : (x[-3] == ' ') ? -15 : \
  59.              (x[-4] == ' ') ? -16 : (x[-5] == ' ') ? -17 : \
  60.              (x[-6] == ' ') ? -18 : (x[-7] == ' ') ? -19 : \
  61.              (x[-8] == ' ') ? -20 : (x[-9] == ' ') ? -21 : \
  62.              (x[-10]== ' ') ? -22 : (x[-11]== ' ') ? -23 : 0)) && \
  63.           (x[ti]   == ' ') && (x[ti+1] == 'r') && (x[ti+2] == 'e') && \
  64.           (x[ti+3] == 'm') && (x[ti+4] == 'o') && (x[ti+5] == 't') && \
  65.           (x[ti+6] == 'e') && (x[ti+7] == ' ') && (x[ti+8] == 'f') && \
  66.           (x[ti+9] == 'r') && (x[ti+10]== 'o') && (x[ti+11]== 'm') && \
  67.           (x += ti)) || T) && \
  68.   (x-s >= 27) && \
  69.   ((x[ti = -5] == ' ') ? ((x[-8] == ':') ? !(zn = 0) : \
  70.               ((x[ti = zn = -9] == ' ') || \
  71.                ((x[ti = zn = -11] == ' ') && \
  72.                 ((x[-10] == '+') || (x[-10] == '-'))))) : \
  73.    ((x[zn = -4] == ' ') ? (x[ti = -9] == ' ') : \
  74.     ((x[zn = -6] == ' ') && ((x[-5] == '+') || (x[-5] == '-')) && \
  75.      (x[ti = -11] == ' ')))) && \
  76.   (x[ti - 3] == ':') && (x[ti -= ((x[ti - 6] == ':') ? 9 : 6)] == ' ') && \
  77.   (x[ti - 3] == ' ') && (x[ti - 7] == ' ') && (x[ti - 11] == ' ')
  78.  
  79.  
  80. /* You are not expected to understand this macro, but read the next page if
  81.  * you are not faint of heart.
  82.  *
  83.  * Known formats to the VALID macro are:
  84.  *         From user Wed Dec  2 05:53 1992
  85.  * BSD        From user Wed Dec  2 05:53:22 1992
  86.  * SysV        From user Wed Dec  2 05:53 PST 1992
  87.  * rn        From user Wed Dec  2 05:53:22 PST 1992
  88.  *        From user Wed Dec  2 05:53 -0700 1992
  89.  *        From user Wed Dec  2 05:53:22 -0700 1992
  90.  *        From user Wed Dec  2 05:53 1992 PST
  91.  *        From user Wed Dec  2 05:53:22 1992 PST
  92.  *        From user Wed Dec  2 05:53 1992 -0700
  93.  * Solaris    From user Wed Dec  2 05:53:22 1992 -0700
  94.  *
  95.  * Plus all of the above with `` remote from xxx'' after it. Thank you very
  96.  * much, smail and Solaris, for making my life considerably more complicated.
  97.  */
  98.  
  99. /*
  100.  * What?  You want to understand the VALID macro anyway?  Alright, since you
  101.  * insist.  Actually, it isn't really all that difficult, provided that you
  102.  * take it step by step.
  103.  *
  104.  * Line 1    Validates that the 2-5th characters are ``rom ''.
  105.  * Line 2    Sets x to point to the end of the line.
  106.  * Lines 3-12    First checks to see if the line is at least 41 characters long.
  107.  *        If so, it scans backwards up to 10 characters (the UUCP system
  108.  *        name length limit due to old versions of UNIX) to find a space.
  109.  *        If one is found, it backs up 12 characters from that point, and
  110.  *        sees if the string from there is `` remote from''.  If so, it
  111.  *        sets x to that position.  The ``|| T'' is there so the parse
  112.  *        will still continue.
  113.  * Line 13    Makes sure that there are at least 27 characters in the line.
  114.  * Lines 14-17    Checks if the date/time ends with the year.  If so, It sees if
  115.  *        there is a colon 3 characters further back; this would mean
  116.  *        that there is no timezone field and zn is set to 0 and ti is
  117.  *        left in front of the year.  If not, then it expects there to
  118.  *        either to be a space four characters back for a three-letter
  119.  *        timezone, or a space six characters back followed by a + or -
  120.  *        for a numeric timezone.  If a timezone is found, both zn and
  121.  *        ti are the offset of the space immediately before it.
  122.  * Lines 18-20    Are the failure case for a date/time not ending with a year in
  123.  *        line 14.  If there is a space four characters back, it is a
  124.  *        three-letter timezone; there must be a space for the year nine
  125.  *        characters back.  Otherwise, there must be a space six
  126.  *        characters back and a + or - five characters back to indicate a
  127.  *        numeric timezone and a space eleven characters back to indicate
  128.  *        a year.  zn and ti are set appropriately.
  129.  * Line 21    Make sure that the string before ti is of the form hh:mm or
  130.  *        hh:mm:ss.  There must be a colon three characters back, and a
  131.  *        space six or nine characters back (depending upon whether or
  132.  *        not the character six characters back is a colon).  ti is set
  133.  *        to be the offset of the space immediately before the time.
  134.  * Line 22    Make sure the string before ti is of the form www mmm dd.
  135.  *        There must be a space three characters back (in front of the
  136.  *        day), one seven characters back (in front of the month), and
  137.  *        one eleven characters back (in front of the day of week).
  138.  *
  139.  * Why a macro?  It gets invoked a *lot* in a tight loop.  On some of the
  140.  * newer pipelined machines it is faster being open-coded than it would be if
  141.  * subroutines are called.
  142.  *
  143.  * Why does it scan backwards from the end of the line, instead of doing the
  144.  * much easier forward scan?  There is no deterministic way to parse the
  145.  * ``user'' field, because it may contain unquoted spaces!  Yes, I tested it to
  146.  * see if unquoted spaces were possible.  They are, and I've encountered enough
  147.  * evil mail to be totally unwilling to trust that ``it will never happen''.
  148.  */
  149.  
  150. /* Build parameters */
  151.  
  152. #define KODRETRY 15        /* kiss-of-death retry in seconds */
  153. #define LOCKTIMEOUT 5        /* lock timeout in minutes */
  154. #define CHUNK 8192        /* read-in chunk size */
  155.  
  156.  
  157. /* Command bits from bezerk_getflags() */
  158.  
  159. #define fSEEN 1
  160. #define fDELETED 2
  161. #define fFLAGGED 4
  162. #define fANSWERED 8
  163.  
  164.  
  165. /* Status string */
  166.  
  167. #define STATUS "Status: RO\nX-Status: DFA\n\n"
  168.  
  169. /* BEZERK per-message cache information */
  170.  
  171. typedef struct file_cache {
  172.   char *header;            /* pointer to RFC 822 header */
  173.   unsigned long headersize;    /* size of RFC 822 header */
  174.   char *body;            /* pointer to message body */
  175.   unsigned long bodysize;    /* size of message body */
  176.   char status[sizeof (STATUS)];    /* status flags */
  177.   char internal[1];        /* start of internal header and data */
  178. } FILECACHE;
  179.  
  180.  
  181. /* BEZERK I/O stream local data */
  182.  
  183. typedef struct bezerk_local {
  184.   unsigned int dirty : 1;    /* disk copy needs updating */
  185.   int ld;            /* lock file descriptor */
  186.   char *name;            /* local file name for recycle case */
  187.   char *lname;            /* lock file name */
  188.   off_t filesize;        /* file size parsed */
  189.   time_t filetime;        /* last file time */
  190.   unsigned long cachesize;    /* size of local cache */
  191.   FILECACHE **msgs;        /* pointers to message-specific information */
  192.   char *buf;            /* temporary buffer */
  193.   unsigned long buflen;        /* current size of temporary buffer */
  194. } BEZERKLOCAL;
  195.  
  196.  
  197. /* Convenient access to local data */
  198.  
  199. #define LOCAL ((BEZERKLOCAL *) stream->local)
  200.  
  201. /* Function prototypes */
  202.  
  203. DRIVER *bezerk_valid  ();
  204. int bezerk_isvalid  ();
  205. void *bezerk_parameters  ();
  206. void bezerk_find  ();
  207. void bezerk_find_bboards  ();
  208. void bezerk_find_all  ();
  209. void bezerk_find_all_bboards  ();
  210. long bezerk_subscribe  ();
  211. long bezerk_unsubscribe  ();
  212. long bezerk_subscribe_bboard  ();
  213. long bezerk_unsubscribe_bboard  ();
  214. long bezerk_create  ();
  215. long bezerk_delete  ();
  216. long bezerk_rename  ();
  217. MAILSTREAM *bezerk_open  ();
  218. void bezerk_close  ();
  219. void bezerk_fetchfast  ();
  220. void bezerk_fetchflags  ();
  221. ENVELOPE *bezerk_fetchstructure  ();
  222. char *bezerk_snarf  ();
  223. char *bezerk_fetchheader  ();
  224. char *bezerk_fetchtext  ();
  225. char *bezerk_fetchbody ();
  226. void bezerk_setflag  ();
  227. void bezerk_clearflag  ();
  228. void bezerk_search  ();
  229. long bezerk_ping  ();
  230. void bezerk_check  ();
  231. void bezerk_expunge  ();
  232. long bezerk_copy  ();
  233. long bezerk_move  ();
  234. long bezerk_append  ();
  235. long bezerk_append_putc  ();
  236. void bezerk_gc  ();
  237.  
  238. void bezerk_abort  ();
  239. char *bezerk_file  ();
  240. int bezerk_lock  ();
  241. void bezerk_unlock  ();
  242. int bezerk_parse  ();
  243. char *bezerk_eom  ();
  244. int bezerk_extend  ();
  245. void bezerk_save  ();
  246. int bezerk_copy_messages  ();
  247. void bezerk_write_message  ();
  248. void bezerk_update_status  ();
  249. short bezerk_getflags  ();
  250. char bezerk_search_all  ();
  251. char bezerk_search_answered  ();
  252. char bezerk_search_deleted  ();
  253. char bezerk_search_flagged  ();
  254. char bezerk_search_keyword  ();
  255. char bezerk_search_new  ();
  256. char bezerk_search_old  ();
  257. char bezerk_search_recent  ();
  258. char bezerk_search_seen  ();
  259. char bezerk_search_unanswered  ();
  260. char bezerk_search_undeleted  ();
  261. char bezerk_search_unflagged  ();
  262. char bezerk_search_unkeyword  ();
  263. char bezerk_search_unseen  ();
  264. char bezerk_search_before  ();
  265. char bezerk_search_on  ();
  266. char bezerk_search_since  ();
  267. char bezerk_search_body  ();
  268. char bezerk_search_subject  ();
  269. char bezerk_search_text  ();
  270. char bezerk_search_bcc  ();
  271. char bezerk_search_cc  ();
  272. char bezerk_search_from  ();
  273. char bezerk_search_to  ();
  274.  
  275. typedef char (*search_t)  ();
  276. search_t bezerk_search_date  ();
  277. search_t bezerk_search_flag  ();
  278. search_t bezerk_search_string  ();