home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / pine4.10.tar.gz / pine4.10.tar / pine4.10 / imap / docs / internal.txt < prev    next >
Text File  |  1996-08-19  |  115KB  |  2,977 lines

  1.       Documentation of c-client Functions and Interfaces
  2.  
  3. REVISED: 19 August 1996
  4.  
  5.                   Credits
  6.  
  7.      The original version of this document was written by Mark Crispin at
  8. the University of Washington, and described the version of c-client that
  9. supported the IMAP2 (RFC 1176) and IMAP2bis (unpublished) protocols.
  10.  
  11.      This version is a substantial rewrite of that document, and was
  12. written by Mark Crispin with funding from Sun Microsystems, Incorporated.
  13. Sun's generous support of this work is gratefully acknowledged.
  14.  
  15.  
  16.                  Road Map
  17.  
  18.      This document is organized into the following sections.  Except as
  19. noted, an implementor of an application that uses c-client needs to be
  20. familiar with all of these sections.  Someone who plans to write a new
  21. mailbox driver for c-client (or otherwise modify it) needs to be familiar
  22. with all sections, no exception.
  23.  
  24. History
  25.     History of how c-client came about.
  26.  
  27. Overview
  28.     Read this before designing an application that uses c-client.
  29.  
  30. c-client Structures
  31.     Documentation of several important c-client structs which are
  32.     used in, and returned by, c-client calls.
  33.  
  34. String Structures
  35.     Documentation of the concept of a "string structure", which
  36.     provides random access to strings without requiring that the
  37.     string be in memory.
  38.  
  39. c-client Support Functions
  40.     Documentation of support functions for c-client; these deal
  41.     with c-client functionality.
  42.  
  43.     Only mail_parameters() is of interest to most application
  44.     developers.  Advanced application developers, particularly
  45.     for limited memory systems, may also need to know about the
  46.     readfn_t, mailgets_t, mailcache_t, and tcptimeout_t function
  47.     pointer types, and possibly also the mail_valid_net_parse()
  48.     function.
  49.  
  50. Mailbox Access Functions
  51.     Documentation of functions which deal with mailboxes;
  52.     listing, subscribing, creating, deleting, renaming, status
  53.     inquiries, opening, and closing mailboxes.
  54.  
  55. Handle Functions
  56.     Documentation of mail stream handles, which provide protection
  57.     for an advanced application which may have multiple pointers to
  58.     a single mail stream.  If a stream has a handle on it, closing
  59.     the stream does not release its memory, so pointers to it in
  60.     the application remain valid.  Freeing the last handle will free
  61.     the entire stream.
  62.  
  63.     This is only of interest for advanced application developers.
  64.  
  65. Message Data Fetching Functions
  66.     Documentation on message data fetching in an open mailbox,
  67.     including parsed representations of RFC-822 and MIME headers
  68.     and message text.  Also how to fetch message attributes (flags,
  69.     internal date, sizes).
  70.  
  71. Message Status Manipulation Functions
  72.     Documentation on altering message flags in an open mailbox.
  73.  
  74. Mailbox Searching
  75.     Documentation on searching an open mailbox for messages which
  76.     match certain criteria (e.g. "messages sent July 4 from Jones
  77.     with text `Paris'").
  78.  
  79. Miscellaneous Mailbox and Message Functions
  80.     Documentation on other operations that would be used by an
  81.     application but that don't fit into any of the above categories.
  82.  
  83. Date/Time Handling Functions
  84.     Documentation on functions that deal with date/time strings.
  85.  
  86.     This is only of interest for advanced application developers
  87.     and for implementors of new c-client drivers.
  88.  
  89. Utility Functions
  90.     Documentation on internal utility functions.
  91.  
  92.     This is primarily of interest for implementors of new c-client
  93.     drivers, but advanced application developers may also use some
  94.     of these functions.
  95.  
  96. Data Structure Instantiation/Destruction functions
  97.     Documentation on creating and destroy c-client structures.
  98.  
  99.     This is primarily of interest for implementors of new c-client
  100.     drivers.  However, application developers will need some of
  101.     these functions to create and destroy structures which are used
  102.     as arguments to various application functions.
  103.  
  104. Authentication Functions
  105.     Documentation on support for network protocol authentication
  106.     functions.
  107.  
  108.     This is only of interest for implementors of new c-client
  109.     drivers which deal with authentication mechanisms.
  110.  
  111. Network Access Functions
  112.     Documentation on creating and destroy c-client structures.
  113.  
  114.     This is primarily of interest for implementors of new c-client
  115.     drivers which deal with a network.  However, advanced
  116.     application developers may need to use this information if they
  117.     wish to insert their own layer into a network session.
  118.  
  119. Subscription Management Functions
  120.     Documentation on managing the local (client-based) subscription
  121.     database file.
  122.  
  123.     This is primarily of interest to advanced application developers.
  124.  
  125. Miscellaneous Utility Functions
  126.     Documentation on various useful utility functions, such as "make
  127.     a copy of this string."
  128.  
  129. SMTP Functions
  130.     Documentation on posting email messages via SMTP protocol.
  131.  
  132. NNTP Functions
  133.     Documentation on posting netnews messages via NNTP protocol.
  134.  
  135. RFC 822 Support Functions
  136.     Documentation on public RFC-822/MIME functions.
  137.  
  138.     This is primarily of interest for implementors of new c-client
  139.     drivers and advanced application developers.
  140.  
  141. Operating System-Dependent Public Interface
  142.     Documentation on OS-dependent functions.  With the exception of
  143.     fs_get(), fs_give(), and fs_resize(), which should be called
  144.     instead of malloc(), free(), and realloc(), these functions are
  145.     primarily of interest for implementors of new c-client drivers.
  146.  
  147. Main Program Callbacks
  148.     Documentation of functions which the main program must provide
  149.     as callbacks from c-client.
  150.  
  151. Driver Interface
  152.     Documentation of the driver dispatch vector and the functions
  153.     which a driver must supply.
  154.  
  155.     This is primarily of interest for implementors of new c-client
  156.     drivers.
  157.  
  158. Driver Support Functions
  159.     Documentation of support functions which are called by drivers.
  160.  
  161.     This is primarily of interest for implementors of new c-client
  162.     drivers.
  163.                   History
  164.  
  165.      The c-client API was originally written by Mark Crispin at Stanford
  166. University as a set of routines to support IMAP and SMTP from a main
  167. program which would handle the user interface.  In its original form, it
  168. was written as the low-level routines that were to be used as part of a
  169. Macintosh client.
  170.  
  171.      The first IMAP client, MM-D (for "MM on Xerox D machines" -- MM was a
  172. popular DEC-20 mail program) was written in Interlisp for Xerox Lisp
  173. machines.  At that time, there was no name for the embryonic Mac client,
  174. but since it was the first one to be written in C instead of Lisp, it was
  175. given a development name of "C client".  This name became "c-client"
  176. because that is the name of the subdirectory on UNIX where the source files
  177. were stored.
  178.  
  179.      To exercise the routines, a minimal main program which uses c-client,
  180. mtest, was written.  mtest has subsequently been extended so that it runs
  181. on every platform that c-client is ported.
  182.  
  183.      The real Mac client, was eventually written by Frank Gilmurrary and
  184. Bill Yeager at Stanford using the autumn 1988 version of c-client and named
  185. "MacMS".  In the winter of 1988-89, Mark Crispin, who had changed jobs to
  186. the University of Washington, developed MS as an MM-like text-based program
  187. for UNIX and MailManager as a GUI-based program for NeXT machines.
  188.  
  189.      The realization sunk in that this API needed its own name.  As early
  190. as spring 1989, there were at least four programs (mtest, MS, MailManager,
  191. and MacMS) that used it.  The name c-client thus became permanent.
  192.  
  193.      In its history, c-client has undergone two major redesigns, both by
  194. Mark Crispin who is now on the staff at the University of Washington.
  195.  
  196.      The first major redesign added the following:
  197.     1) ANSI C calling conventions throughout to assist in function
  198.        argument type checking.
  199.     2) Vectoring mail access calls through "driver" methods; thus
  200.        providing transparent access to multiple types of mail
  201.        stores with the same call.
  202.     3) MIME support.
  203.  
  204.      The second major redesign was part of the IMAP4 project.  Many
  205. c-client functions were extended with additional arguments and options.
  206. The driver interface was also made simpler, with more work done by
  207. driver-independent code.
  208.  
  209.                    Overview
  210.  
  211.      The most important file for the author of an application using the
  212. c-client is mail.h.  mail.h defines several important structures of
  213. data which are passed between the main program and the c-client.
  214. Although some functions (e.g. mail_fetchtext_body()) return the data
  215. fetched, for certain other data items (e.g. flags) you need to get the
  216. data as a structure reference.  mail.h also defines a large number of
  217. useful constants and structures.
  218.  
  219.      When a function in mail.h exists to reference data, it MUST be
  220. used instead of referencing the structures directly.  This is because
  221. in some cases the data is not actually fetched until a reference (via
  222. the function call) is made.  For example, although the MESSAGECACHE
  223. element for a message can be obtained by indexing the proper cache
  224. element in the stream, there is no guarantee that the item in fact
  225. exists unless mail_fetchstructure_full() is called for that message.
  226. Less costly functions. also exist to create and load a MESSAGECACHE
  227. element.
  228.  
  229.      The main program will probably also need to include smtp.h,
  230. misc.h, and osdep.h, but this usage should be solely to receive
  231. function prototypes.  Any other definitions in those files should be
  232. considered private to that module.
  233.  
  234.      Two important predefined symbols are NIL and T.  NIL is any sort
  235. of "false"; T is any sort of "true".  NIL is also used to null-specify
  236. certain optional arguments.
  237.  
  238.             * * * IMPORTANT * * *
  239.  
  240.      Any multi-threaded application should test stream->lock prior to
  241. calling any c-client stream functions.  Any attempt to call a
  242. mail_xxx() function while one is already in progress on the same
  243. stream will cause the application to fail in unpredictable ways.
  244.  
  245.      Note that this check is insufficient in a preemptive-scheduling
  246. multi-tasking application due to the possibility of a timing race.
  247. Such applications must be written so that only one process accesses
  248. the stream, or to have a higher level lock.
  249.  
  250.      Since MAIL operations will not finish until they are completed, a
  251. single-tasking application does not have to worry about this problem,
  252. except in the callback invoked from MAIL (e.g. mm_exists(), etc.) in which
  253. case the stream is *always* locked.
  254.  
  255.               c-client Structures
  256.  
  257.      c-client has a large number of structures which are used for
  258. multiple functions.  The most important of these are described here.
  259.  
  260.      The MAILSTREAM structure is used to reference open mailboxes.
  261. Applications may reference the following:
  262.  
  263. char *mailbox;            mailbox name
  264. unsigned short use;        stream use count, this is incremented
  265. unsigned short sequence;    stream sequence, this is incremented
  266.                  each time a stream is reused (i.e.
  267.                  mail_open() is called to open a
  268.                  different mailbox on this stream)
  269. unsigned int rdonly : 1;    stream is open read-only
  270. unsigned int anonymous : 1;    stream is open with anonymous access
  271. unsigned int halfopen : 1;    stream is half-open; it can be
  272.                  reopened or used for functions that
  273.                  don't need a open mailbox such as
  274.                  mail_create() but no message data
  275.                  can be fetched
  276. unsigned int perm_seen : 1;    Seen flag can be set permanently
  277. unsigned int perm_deleted : 1;    Deleted flag can be set permanently
  278. unsigned int perm_flagged : 1;    Flagged flag can be set permanently
  279. unsigned int perm_answered :1;    Answered flag can be set permanently
  280. unsigned int perm_draft : 1;    Draft flag can be set permanently
  281. unsigned int kwd_create : 1;    new user flags can be created by
  282.                  referencing then in mail_setflag() or
  283.                  mail_clearflag().  Note: this can
  284.                  change during a session (e.g. if
  285.                  there is a limit on the number of
  286.                  keywords), so check after creating a
  287.                  new flag to see if any more can be
  288.                  created before letting the user try
  289.                  to do so
  290. unsigned long perm_user_flags;    corresponding user flags can be set
  291.                  permanently.  This is a bit mask
  292.                  which matches the entries in
  293.                  stream->user_flags[]
  294. unsigned long gensym;        generated unique value.  Always
  295.                  referenced with stream->gensys++
  296. unsigned long nmsgs;        number of messages in current mailbox
  297. unsigned long recent;        number of recent messages in current
  298.                  mailbox
  299. unsigned long uid_validity;    UID validity value; this is used to
  300.                  verify that recorded UIDs match the
  301.                  UIDs that the stream has.  If the
  302.                  mailbox does not have matching UIDs
  303.                  (e.g. the UIDs were lost or not
  304.                  recorded) then the UID validity value
  305.                  will be different
  306. unsigned long uid_last;        highest currently assigned UID in the
  307.                  current mailbox; a new UID will be
  308.                  assigned with ++stream->uid_last
  309. char *user_flags[NUSERFLAGS];    pointers to user flag names in bit
  310.                  order from stream->perm_user_flags or
  311.                  elt->user_flags
  312.  
  313.      The following MAILSTREAM values are only used internally:
  314.  
  315. DRIVER *dtb;            dispatch table for this driver
  316. void *local;            pointer to driver local data
  317. unsigned int lock : 1;        stream lock flag (an operation is in
  318.                  progress; used as a bug trap to
  319.                  detect recursion back to c-client
  320.                  from callback routines).
  321. unsigned int debug : 1;        debugging information should be logged
  322.                  via mm_dlog().
  323. unsigned int silent : 1;    don't do main program callbacks on
  324.                  this stream (used when a stream is
  325.                  opened internally)
  326. unsigned int scache : 1;    short caching; don't cache information
  327.                  in memory
  328.  
  329.      The following MAILSTREAM values are only used by the cache
  330. manager routine (see the documentation about mailcache_t above):
  331.  
  332. unsigned long cachesize;    size of c-client message cache
  333. union {
  334.   void **c;            to get at the cache in general
  335.   MESSAGECACHE **s;        message cache array
  336.   LONGCACHE **l;        long cache array
  337. } cache;
  338.  
  339.      The following MAILSTREAM values are for the convenience of
  340. drivers that use short caching and want to be able to garbage collect
  341. any values that they returned:
  342.  
  343. unsigned long msgno;        message number of `current' message
  344. ENVELOPE *env;            pointer to `current' message envelope
  345. BODY *body;            pointer to `current' message body
  346. char *text;            pointer to `current' text
  347.  
  348.  
  349.      The MESSAGECACHE structure (commonly called an "elt" as a
  350. nickname for "cache ELemenT") contains information about messages.
  351. Applications may use the following:
  352.  
  353. unsigned long msgno;        message number.  If the elt is locked
  354.                  (by elt->lockcount++), then the elt
  355.                  pointer can be stored (e.g. with the
  356.                  data for a window which draws this
  357.                  message) and elt->msgno will change
  358.                  automatically whenever expunges are
  359.                  done so the window will always view
  360.                  the correct message.  If elt->msgno
  361.                  becomes 0, then the message has been
  362.                  expunged, but the elt won't be freed
  363.                  until the elt lock count is
  364.                  decremented (by mail_free_elt()).
  365. unsigned long uid;        message unique ID
  366. unsigned int hours: 5;        internal date hours (0-23)
  367. unsigned int minutes: 6;    internal date minutes (0-59)
  368. unsigned int seconds: 6;    internal date seconds (0-59)
  369. unsigned int zoccident : 1;    non-zero if internal date time zone is
  370.                  west of UTC
  371. unsigned int zhours : 4;    internal date time zone hours from UTC
  372.                  (0-12)
  373. unsigned int zminutes: 6;    internal date time zone minutes (0-59)
  374. unsigned int seen : 1;        message Seen flag
  375. unsigned int deleted : 1;    message Deleted flag
  376. unsigned int flagged : 1;     message Flagged flag
  377. unsigned int answered : 1;    message Answered glag
  378. unsigned int draft : 1;        message Draft flag
  379. unsigned int valid : 1;        flags are valid in this elt; an elt
  380.                  that was newly created but never
  381.                  loaded with flags won't have this set.
  382. unsigned int recent : 1;    message recent flag
  383. unsigned int searched : 1;    message matches search criteria in
  384.                  most recent mail_search_full() call
  385. unsigned int spare : 1;        reserved for application use
  386. unsigned int spare2 : 1;    reserved for application use
  387. unsigned int spare3 : 1;    reserved for application use
  388. unsigned int lockcount : 8;    non-zero if multiple references to
  389.                  this elt.  Refer to the msgno member
  390.                  for more information.
  391. unsigned int day : 5;        internal date day of month (1-31)
  392. unsigned int month : 4;        internal date month of year (1-12)
  393. unsigned int year : 7;        internal date year since BASEYEAR
  394.                  (currently 1970; was 1969 in older
  395.                  versions so use BASEYEAR instead of
  396.                  having the base year wired in)
  397. unsigned long user_flags;    message user flags; this is a bit mask
  398.                  which matches the entries in
  399.                  stream->user_flags[]
  400. unsigned long rfc822_size;    size of message in octets
  401.  
  402.      The following MESSAGECACHE values are only used internally by
  403. drivers:
  404.  
  405. unsigned int sequence : 1;    message is in sequence from either
  406.                  mail_sequence() or mail_uid_sequence()
  407. unsigned long data1;        first data item
  408. unsigned long data2;        second data item
  409. unsigned long data3;        third data item
  410. unsigned long data4;        fourth data item
  411.  
  412.  
  413.      The ADDRESS structure is a parsed form of a linked list of RFC 822
  414. addresses.  It contains the following information:
  415.  
  416. char *personal;            personal name phrase
  417. char *adl;            at-domain-list (also called "source
  418.                  route")
  419. char *mailbox;            mailbox name
  420. char *host;            domain name of mailbox's host
  421. char *error;            error in address from smtp_mail(); if
  422.                  an error is returned from smtp_mail()
  423.                  for one of the recipient addresses
  424.                  the SMTP server's error text for that
  425.                  recipient can be found here.  If it
  426.                  is null then there was no error (or
  427.                  an error was found with a prior
  428.                  recipient
  429. ADDRESS *next;            pointer to next address in list
  430.  
  431.  
  432.      The ENVELOPE structure is a parsed form of the RFC 822 header.
  433. Its member names correspond to the RFC 822 field names.  It contains
  434. the following information:
  435.  
  436. char *remail;            remail header if any
  437. ADDRESS *return_path;        error return address
  438. char *date;            message composition date string
  439. ADDRESS *from;            from address list
  440. ADDRESS *sender;        sender address list
  441. ADDRESS *reply_to;        reply address list
  442. char *subject;            message subject string
  443. ADDRESS *to;            primary recipient list
  444. ADDRESS *cc;            secondary recipient list
  445. ADDRESS *bcc;            blind secondary recipient list
  446. char *in_reply_to;        replied message ID
  447. char *message_id;        message ID
  448. char *newsgroups;        USENET newsgroups
  449. char *followup_to;        USENET reply newsgroups
  450. char *references;        USENET references
  451.  
  452.  
  453.      The BODY structure is a parsed form of a linked list of the MIME
  454. structure of a message.  It contains the following information.
  455.  
  456. unsigned short type;        body primary type code.  This is an
  457.                  index into the body_types vector of
  458.                  body type names.  The following body
  459.                  types are pre-defined:
  460.     TYPETEXT        unformatted text
  461.     TYPEMULTIPART        multiple part
  462.     TYPEMESSAGE        encapsulated message
  463.     TYPEAPPLICATION        application data
  464.     TYPEAUDIO        audio
  465.     TYPEIMAGE        static image (GIF, JPEG, etc.)
  466.     TYPEVIDEO        video
  467.     TYPEOTHER        unknown
  468.                 Additional types up to TYPEMAX are
  469.                  dynamically defined if they are
  470.                  encountered by c-client.
  471. unsigned short encoding;    body transfer encoding.  This is an
  472.                  index into the body_encodings vector
  473.                  of body encoding names.  The
  474.                  following body encodings are
  475.                  pre-defined:
  476.     ENC7BIT            7 bit SMTP semantic data
  477.     ENC8BIT            8 bit SMTP semantic data
  478.     ENCBINARY        8 bit binary data
  479.     ENCBASE64        base-64 encoded data
  480.     ENCQUOTEDPRINTABLE    human-readable 8-as-7 bit data
  481.     ENCOTHER        unknown
  482.                 Additional encodings up to ENCMAX are
  483.                  dynamically defined if they are
  484.                  encountered by c-client.
  485. char *subtype;            body subtype string
  486. PARAMETER *parameter;        parameter list
  487. char *id;            body content identifier
  488. char *description;        body content description
  489. unsigned char *contents.text;    when composing a message that is NOT
  490.                  of TYPEMULTIPART, non-binary text of
  491.                  the content is stored here.  Note that
  492.                  this happens even when the text is
  493.                  of TYPEMESSAGE.  Text of encoding
  494.                  ENC8BIT may be converted to
  495.                  ENCQUOTEDPRINTABLE when it is sent.
  496.                  This should not be referenced for any
  497.                  other reason; in particular, this is
  498.                  NOT the way for an application to
  499.                  access content data (use
  500.                  mail_fetchbody_full() instead).
  501. BINARY *contents.binary;    when composing a message that is NOT
  502.                  of TYPEMULTIPART, binary content (of
  503.                  encoding ENCBINARY) is stored here.
  504.                  It will be converted to ENCBASE64 when
  505.                  it is sent.
  506.                  This should not be referenced for any
  507.                  other reason; in particular, this is
  508.                  NOT the way for an application to
  509.                  access content data (use
  510.                  mail_fetchbody_full() instead).
  511. PART *contents.part;        for body parts of TYPEMULTIPART, this
  512.                  contains the list of body parts in
  513.                  this multipart
  514. MESSAGE contents.msg;        for body parts of TYPEMESSAGE with
  515.                  subtype "RFC822", this contains the
  516.                  encapsulated message
  517. unsigned long size.lines;    size in lines
  518. unsigned long size.bytes;    size in octets.  This MUST be set when
  519.                 composing a message if the encoding is
  520.                 ENC8BIT or ENCBINARY.
  521. char *md5;            body content MD5 checksum
  522.  
  523.      The following BODY information is used only by c-client
  524. internally.  The use of this data is driver-specific and it can not be
  525. relied-upon by applications.
  526.  
  527. unsigned char *contents.text;    drivers can store a pointer to the
  528.                  body contents as text here.        
  529. unsigned long size.ibytes;    internal size of the body content (prior
  530.                  to newline conversion, etc.) in octets
  531.  
  532.  
  533.      The MESSAGE structure is a parsed form of a MESSAGE/RFC822 MIME
  534. body part.  It contains the following information:
  535.  
  536. ENVELOPE *env;            encapsulated message RFC 822 header
  537. BODY *body;            encapsulated message MIME structure
  538.  
  539.      The following MESSAGE information is used only by c-client
  540. internally.  The use of this data is driver-specific and it can not be
  541. relied-upon by applications.
  542.  
  543. char *hdr;            encapsulated message header
  544. unsigned long hdrsize;        message header size
  545. char *text;            message in RFC 822 form
  546. unsigned long offset;        offset of text from header
  547.  
  548.  
  549.      The PARAMETER structure is a parsed form of a linked list of
  550. attribute/value pairs.  It contains the following information:
  551.  
  552. char *attribute;        attribute name
  553. char *value;            value
  554. PARAMETER *next;        next parameter in list
  555.  
  556.  
  557.      The PART structure is a parsed form of a linked list of MIME body
  558. parts.  It contains the following information:
  559.  
  560. BODY body;            body information for this part
  561. PART *next;            next body part
  562.  
  563.      The following PART information is used only by c-client
  564. internally.  The use of this data is driver-specific and it can not be
  565. relied-upon by applications.
  566.  
  567. unsigned long offset;        offset from body origin
  568.  
  569.  
  570.     The NETMBX structure is a parsed form of a network mailbox name:
  571.  
  572. char host[NETMAXHOST];        remote host name
  573. char user[NETMAXUSER];        remote user name if specified
  574. char mailbox[NETMAXMBX];    remote mailbox name
  575. char service[NETMAXSRV];    remote service name (IMAP4, NNTP, etc.)
  576. unsigned long port;        TCP/IP port number if specified
  577. unsigned int anoflag : 1;    anonymous access requested
  578. unsigned int dbgflag : 1;    protocol debugging telemetry, via
  579.                  mm_dlog(), requested
  580.  
  581.  
  582.      The STRINGLIST structure is a list of strings (which may have
  583. embedded NULs) and their lengths:
  584.  
  585. char *text;            string text
  586. unsigned long size;        string length
  587. STRINGLIST *next;        next string in list
  588.  
  589.               String Structures
  590.  
  591.      A string structure is analogous to a char*, and is used in some
  592. functions as an input argument.  It represents a string of data in a
  593. way that does not necessarily require the entire string to be in
  594. memory at once.  This is essential for small machines with
  595. highly-restricted memory limits (e.g. DOS).
  596.  
  597.                String Structure Access
  598.  
  599.      To use a string structure, the caller needs to know a string
  600. driver and needs to know the driver-dependent data used by that string
  601. structure.  A simple string driver is mail_string, a string driver
  602. that takes an in-memory char* string as the driver-dependent data.
  603. The DOS port uses string drivers that take a struct holding a file
  604. descriptor and a file offset.  Often the user of a string driver is
  605. the same module that defined it, so usually the programmer knows about
  606. its conventions.
  607.  
  608.      The following calls are used to access a string structure:
  609.  
  610. void INIT (STRING *s,STRINGDRIVER *d,void *data,unsigned long size);
  611.     s    pointer to the string structure to be initialized
  612.     d    pointer to the string driver
  613.     data    pointer to driver-dependent data, from which the
  614.          driver can determine string data
  615.     size    size of the string
  616.  This call initializes the string stucture.
  617.  
  618.  
  619. unsigned long SIZE (STRING *s);
  620.     s    pointer to the string structure
  621.  This call returns the number of characters remaining in the string
  622. after the current string character pointer.
  623.  
  624.  
  625. char CHR (STRING *s);
  626.     s    pointer to the string structure
  627.  This call returns the character at the current string character
  628. pointer.
  629.  
  630.  
  631. char SNX (STRING *s);
  632.     s    pointer to the string structure
  633.  This call returns the character at the current string character
  634. pointer, and increments the string character pointer.
  635.  
  636.  
  637. unsigned long GETPOS (STRING *s);
  638.     s    pointer to the string structure
  639.     i    new string pointer value
  640.  This returns the value of the current string character pointer.
  641.  
  642.  
  643. void SETPOS (STRING *s,unsigned long i);
  644.     s    pointer to the string structure
  645.     i    new string pointer value
  646.  This method sets the string character pointer to the given value.
  647.  
  648.  
  649.               String Structure Internals
  650.  
  651.      A string structure holds the following data:
  652.  
  653. void *data;        used by the string driver as it likes
  654. unsigned long data1;    used by the string driver as it likes
  655. unsigned long size;    static, holds the total length of the string
  656.              from the INIT call
  657. char *chunk;        current chunk of in-memory data; this is used
  658.              for buffering to avoid unnecessary calls to
  659.              the string driver's next method.
  660. unsigned long chunksize; size of an in-memory data chunk
  661. unsigned long offset;    position of first character of the chunk in
  662.              the overall string
  663. char *curpos;        current position; this is what CHR() will
  664.              access
  665. unsigned long cursize;    number of characters remaining in the current
  666.              string
  667. STRINGDRIVER *dtb;    the string driver for this string structure
  668.  
  669.  
  670.      A string structure is manipulated by a string driver, which has
  671. the following access methods:
  672.  
  673. void (*init) (STRING *s,void *data,unsigned long size);
  674.     s    pointer to the string structure to be initialized
  675.     data    pointer to driver-dependent data, from which the
  676.          driver can determine string data
  677.     size    size of the string
  678.  This method initializes the string stucture.  It can use the data,
  679. data1, and chunksize values as it likes.  The remaining values must be
  680. set up as follows:
  681.     size        static, copied from the size argument
  682.     chunk        pointer to a buffer loaded with initial data
  683.     chunksize    size of the buffer
  684.     offset        0
  685.     curpos        copied from chunk
  686.     cursize        copied from chunksize
  687.     dtb        STRINGDRIVER identity pointer
  688.  
  689.  
  690. char (*next) (STRING *s);
  691.     s    pointer to the string structure
  692.  This method returns the character at the current string character
  693. pointer, and increments the string character pointer.  This method
  694. is likely to call the setpos method if the desired character is not in
  695. the current chunk.
  696.  
  697.  
  698. void (*setpos) (STRING *s,unsigned long i);
  699.     s    pointer to the string structure
  700.     i    new string pointer value
  701.  This method sets the string character pointer to the given value.  If
  702. the pointer is not in the current chunk, then a new chunk is loaded
  703. and the associated values (chunk, offset, curpos, cursize) are
  704. adjusted accordingly.
  705.  
  706.               c-client Support Functions
  707.  
  708.  
  709. void mail_string_init (STRING *s,void *data,unsigned long size);
  710. char mail_string_next (STRING *s);
  711. void mail_string_setpos (STRING *s,unsigned long i);
  712.  
  713.      These three functions are the init, next, and setpos string
  714. structure access methods for the build-in mail_string string driver.
  715. mail_string is a basic string driver for a char* string.  See the
  716. documentation below on "String Structions" for more information.
  717.  
  718.  
  719. void mail_link (DRIVER *driver);
  720.     driver    pointer to the driver to be added
  721.  
  722.      This function adds the specified driver to the list of mailbox
  723. drivers.  Initially there are no drivers lunk, so all programs which
  724. intend to use c-client need to have at least one call to this function.
  725.  
  726.      A function which uses IMAP4 would have a statement such as:
  727.     mail_link (&imapdriver);    /* link in IMAP driver */
  728. early in the program's initialization.  Normally, this is done by the
  729. statement
  730.     #include "linkage.c"
  731. which will include the "system standard driver linkage" defined when
  732. c-client was built.  By using linkage.c instead of explicit mail_link()
  733. calls, you are guaranteed that you will have a consistant linkage among
  734. all software built on this system.
  735.  
  736.  
  737. void auth_link (AUTHENTICATOR *auth);
  738.     auth    pointer to the authenticator to be added
  739.  
  740.      This function adds the specified authenticator to the list of
  741. authenticators.  Initially there are no authenticators lunk.  Normally,
  742. this is done by linkage.c so you don't need to call this routine
  743. explicitly.
  744.  
  745.  
  746. void *mail_parameters (MAILSTREAM *stream,long function,void *value);
  747.     stream    stream to poll or NIL
  748.     function function code
  749.     value    new value for function codes that change a parameter
  750.  
  751.      This function fetches or changes the settings of various c-client
  752. operational parameters depending upon the function.  If the stream is
  753. specified, only the action for the underlying driver for that stream is
  754. taken; however, the scope of the operational parameters is global so
  755. there is generally no reason for the stream argument ever to be
  756. non-NIL.
  757.  
  758.      The function codes ENABLE_DRIVER and DISABLE_DRIVER take a driver
  759. pointer as a value.  These functions enable and disable mailbox
  760. processing by that driver.  By default, all drivers are enabled.
  761.  
  762.      The remaining the function codes are in a pair named GET_xxx to
  763. fetch an operational parameter and SET_xxx to set the parameter:
  764.  
  765.  GET_DRIVERS / SET_DRIVERS
  766.      The list of currently lunk drivers.
  767.  
  768.  GET_GETS / SET_GETS
  769.      If non-NIL, points to a function for reading message text.
  770.     Defaults to NIL.
  771.      This function is called with three arguments; a function
  772.     pointer to a "reading function", a stream for the reading
  773.     function, and a size in octets.  The reading function is
  774.     in turn called with the stream, a size in octets, and a
  775.     pointer to a readin buffer.
  776.      This function returns with a char* string, which will be
  777.     returned by the mail_fetchheader(), mail_fetchtext(), or
  778.     mail_fetchbody() function which triggered the message text
  779.     reading.
  780.      The purpose is to permit reading of large strings, without
  781.     requiring an in-memory buffer for the entire string.  The idea
  782.     is that this function can store the data in some form other
  783.     than a char* (e.g. a temporary file) and the main program will
  784.     recognize that it should get the text from there instead of
  785.     from the results from mail_fetch....().
  786.      This is only supported on DOS and Win16; on other platforms it
  787.     is inconsistant whether or not it works.
  788.  
  789.  GET_CACHE / SET_CACHE
  790.      Points to the c-client cache manager function.  Defaults to
  791.     mm_cache().
  792.  
  793.  GET_SMTPVERBOSE / SET_SMTPVERBOSE
  794.      If non-NIL, points to a function that accepts a char* string.
  795.     This function is called any time the SMTP routines receive a
  796.     response code less than 100.  The argument is the text of the
  797.     response code
  798.  
  799.  GET_RFC822OUTPUT / SET_RFC822OUTPUT
  800.      If non-NIL, points to an alternate rfc822_output() function.
  801.     rfc822_output() will call this function and return instead of
  802.     doing its normal action.  See the description of
  803.     rfc822_output() for more information.    
  804.  
  805.  GET_USERNAME / SET_USERNAME
  806.      The logged-in user name.
  807.  
  808.  GET_HOMEDIR / SET_HOMEDIR
  809.      The home directory path name.
  810.  
  811.  GET_LOCALHOST / SET_LOCALHOST
  812.      The local host name.
  813.  
  814.  GET_SYSINBOX / SET_SYSINBOX
  815.      The "system INBOX" (where mail is delivered) path name.
  816.  
  817.  GET_OPENTIMEOUT / SET_OPENTIMEOUT
  818.      TCP/IP open timeout in seconds.  Defaults to 0 (system
  819.     default timeout, usually 75 seconds on Unix).
  820.     
  821.  GET_READTIMEOUT / SET_READTIMEOUT
  822.      TCP/IP read timeout in seconds.  Defaults to 0 (no timeout).
  823.  
  824.  GET_WRITETIMEOUT / SET_WRITETIMEOUT
  825.      TCP/IP write timeout in seconds.  Defaults to 0 (no timeout).
  826.  
  827.  GET_CLOSETIMEOUT / SET_CLOSETIMEOUT
  828.      TCP/IP close timeout in seconds.  Defaults to 0 (no timeout).
  829.  
  830.  GET_TIMEOUT / SET_TIMEOUT
  831.      If non-NIL, points to the function called when a TCP/IP
  832.     timeout occurs.  This function is called with the number of
  833.     seconds since the start of the TCP operation.  If it returns
  834.     non-zero, the TCP/IP operation is continued; if it returns
  835.     non-zero, the TCP/IP connection is aborted.
  836.  
  837.  GET_RSHTIMEOUT / SET_RSHTIMEOUT
  838.      rsh connection timeout in seconds.  Defaults to 15 seconds.
  839.  
  840.  GET_MAXLOGINTRIALS / SET_MAXLOGINTRIALS
  841.      The maximum number of login attempts permitted in an IMAP or
  842.     POP connection.  Defaults to 3.
  843.  
  844.  GET_LOOKAHEAD / SET_LOOKAHEAD
  845.      The number of subsequent envelopes prefetched in IMAP when an
  846.     envelope is fetched.  Defaults to 20.
  847.  
  848.  GET_IMAPPORT / SET_IMAPPORT
  849.      The IMAP port number.  Defaults to 143.
  850.  
  851.  GET_PREFETCH / SET_PREFETCH
  852.      The number of envelopes prefetched in IMAP from the results
  853.     of a SEARCH.  Defaults to 20.
  854.  
  855.  GET_CLOSEONERROR / SET_CLOSEONERROR
  856.      If non-NIL, close an opening IMAP connection if the SELECT
  857.     command fails instead of returning a half-open stream.
  858.     Defaults to NIL.
  859.  
  860.  GET_POP3PORT / SET_POP3PORT
  861.      The POP3 port number.  Defaults to 110.
  862.  
  863.  GET_UIDLOOKAHEAD / SET_UIDLOOKAHEAD
  864.      The number of UIDs premapped when a message number is
  865.     translated to a UID.  Defaults to 1000.
  866.  
  867.  GET_MBXPROTECTION / SET_MBXPROTECTION
  868.      Default file protection for newly created mailboxes.
  869.     Defaults to 0600.
  870.  
  871.  GET_DIRPROTECTION / SET_DIRPROTECTION
  872.      Default file protection for newly created directories.
  873.     Defaults to 0700.
  874.  
  875.  GET_LOCKPROTECTION / SET_LOCKPROTECTION
  876.      Default file protection for locks.  Defaults to 0666.
  877.     WARNING: don't blithely change this.  If other processes
  878.     can't get access to a lock then they will have trouble in
  879.     locking properly.
  880.  
  881.  GET_FROMWIDGET / SET_FROMWIDGET
  882.      If non-NIL, APPEND in the Unix mbox format will insert a
  883.     ">" character in front of all lines which begin with the
  884.     string "From ".  If NIL, it will only do so if the entire
  885.     line looks like a message delimiter (that is, the date is
  886.     also in correct format).  Defaults to T.
  887.  
  888.  GET_NEWSACTIVE / SET_NEWSACTIVE
  889.      Netnews active file path name.
  890.  
  891.  GET_NEWSSPOOL / SET_NEWSSPOOL
  892.      Netnews spool directory path name.
  893.  
  894.  GET_NEWSRC / SET_NEWSRC
  895.      Netnews newsgroup reading status file (.newsrc) path name.
  896.  
  897.  GET_EXTENSION / SET_EXTENSION
  898.      If non-NIL, points to a string holding the extension for all
  899.     mailbox files.  This is only supported on DOS and Win16.
  900.  
  901.  GET_DISABLEFCNTLLOCK / SET_DISABLEFCNTLLOCK
  902.      If non-NIL, disables fcntl() locking on SVR4.  This is done
  903.     if fcntl() tends to hang for no good reason.  Now that the
  904.     fcntl() code checks for NFS files and no-ops the locking,
  905.     this problem usually doesn't happen much any more.  Defaults
  906.     to NIL.
  907.  
  908.  GET_LOCKEACCESERROR / SET_LOCKEACCESERROR
  909.      If non-NIL, give a warning if an attempt to create a .lock
  910.     file gets an EACCES ("Permission denied") error.  This usually
  911.     means that somebody protected the system inbox directory (e.g.
  912.     /var/mail) instead of making it public-write with the sticky
  913.     bit.  Defaults to non-NIL, since this is usually bad news.
  914.  
  915.  GET_LISTMAXLEVEL / SET_LISTMAXLEVEL
  916.      The maximum depth of recusion that LIST will go on a *
  917.     wildcard.  Defaults to 20.
  918.  
  919.  GET_ANONYMOUSHOME / SET_ANONYMOUSHOME
  920.      The anonymous use home directory name.
  921.  
  922.  
  923. typedef long (*readfn_t) (void *stream,unsigned long size,char *buffer);
  924.     stream    a designator suitable
  925.     size    a number of octets to read
  926.     buffer    a buffer of at least size octets for readin
  927.  
  928.      This function reads the given number of octets into the buffer,
  929. using the given stream.  What sort of object the stream is depends upon
  930. the function and its caller, so you must make sure that the readfn is
  931. suitable for the caller's purpose.  Common uses include support of the
  932. mailgets function (see below) and of reading from local files on systems
  933. with limited address apce.
  934.  
  935.  
  936. typedef char *(*mailgets_t) (readfn_t f,void *stream,unsigned long size);
  937.     f    the readfn to use
  938.     stream    stream argument for the readfn
  939.     size    total number of octets to read
  940.  
  941.      This is the argument to the SET_GETS mail_parameter() call.  This
  942. function must read size octets from the stream, using the readfn f.  It
  943. may call f multiple times to accomplish this; this will read the data in
  944. a serial fashion.  So, for example, if size is a megabyte and there is
  945. only 4K of available buffer space, it can call f 256 times to satisfy
  946. the request.  There is no way to back up in the reading, so any
  947. processing or saving of the data must be done when it is read.
  948.  
  949.      The function mm_gets() in mail.c is a sample mailgets function; it
  950. reads the first MAXMESSAGESIZE of data into memory and discards the
  951. rest.
  952.  
  953.  
  954. typedef void *(*mailcache_t) (MAILSTREAM *stream,unsigned long msgno,long op);
  955.     stream    stream to cache manage
  956.     msgno    message to cache manage in the stream
  957.     op    cache management operation
  958.  
  959.      This function manages the c-client cache.  Normally, a program will
  960. use the default c-client cache manager routine mm_cache().  However, a
  961. main program may want to supply its own cache manager, e.g. it may want
  962. to store the data on a disk file instead of in memory on DOS and Win16
  963. where memory is tight.
  964.  
  965.      If you write your own cache manager, you need to examine the
  966. default mm_cache() manager closely, as well as paying close attention to
  967. what goes into an elt (a MESSAGECACHE element).  It is highly likely
  968. that if you roll elts out to disk, you will want to set stream->scache
  969. and *NOT* use long elts (because long elts have ENVELOPE and BODY
  970. pointers that you would have to know how to write to disk and read back).
  971.  
  972.      The cache management functions are one of the following:
  973.  
  974.  CH_INIT     Initialize the entire cache for the stream.  This is
  975.         called only when creating a new stream or when freeing
  976.         it.  The msgno argument is ignored.
  977.  
  978.  CH_SIZE     Make sure that the cache is at least large enough to
  979.         support msgno.  This is a request to grow the cache if
  980.         necessary, not shrink it.
  981.  
  982.  CH_MAKELELT     Return a long elt for msgno, creating it if necessary.
  983.         This is the underlying support function for mail_lelt().
  984.  
  985.  CH_LELT     Return the long elt for msgno, or NIL if it does not
  986.         already exist.
  987.  
  988.  CH_MAKEELT     Return an elt for msgno, creating it if necessary.
  989.         This is the underlying support function for mail_elt().
  990.  
  991.  CH_ELT         Return the elt for msgno, or NIL if it does not already
  992.         exist.
  993.  
  994.  CH_FREE     Free the [l]elt for msgno.
  995.  
  996.  CH_EXPUNGE     Free the [l]elt for msgno, and reclaim its position.
  997.         All subsequent elts are renumbered with their elt->msgno
  998.         decremented by 1.  [Hence msgno+1 becomes msgno, etc.]
  999.         This supports message expunging from the cache.
  1000.  
  1001.  
  1002. typedef long (*tcptimeout_t) (long time);
  1003.     time    total time spent since TCP operation started
  1004.  
  1005.      This function is called when a TCP operation times out.  It is set
  1006. by the SET_TIMEOUT mail_parameter().  The function can return non-zero
  1007. to continue the TCP operation (e.g. after outputting a "do you still
  1008. want to wait" prompt) or zero if it wants the TCP operation to abort and
  1009. close.  If the TCP operation aborts, it will likely cause the upper
  1010. level IMAP, SMTP, etc. stream to abort and close as well.
  1011.  
  1012.  
  1013. DRIVER *mail_valid (MAILSTREAM *stream,char *mailbox,char *purpose);
  1014.     stream    if non-NIL, stream to use for validation
  1015.     mailbox    mailbox name to validate
  1016.     purpose    filled in as xxx in "Can't xxx" in error messages
  1017.  
  1018.      This function validates the given mailbox name.  It successful, it
  1019. returns the driver that can open that name if successful, otherwise it
  1020. returns NIL.  If stream is non-NIL, the mailbox name must be valid for
  1021. the type of mailbox associated with that stream (e.g. an NNTP name can
  1022. not be used with an IMAP stream).  If purpose is non-NIL, an error
  1023. message is passed via mm_log() when an error occurs.
  1024.  
  1025.  
  1026. DRIVER *mail_valid_net (char *name,DRIVER *drv,char *host,char *mailbox);
  1027.     name    mailbox name to validate
  1028.     drv    driver name to validate against
  1029.     host    buffer to return host name if non-NIL
  1030.     mailbox    buffer to return remote mailbox name if non-NIL
  1031.  
  1032.      This function is an alternative to mail_valid_net_parse().  It
  1033. validates the given mailbox name as a network name and makes sure that
  1034. its service name is the same as the driver in drv.  If successful, it
  1035. returns drv, and copies the host and mailbox strings as needed.
  1036. Otherwise it returns NIL.
  1037.  
  1038.  
  1039. long mail_valid_net_parse (char *name,NETMBX *mb);
  1040.     name    mailbox name to parse
  1041.     mb    pointer to NETMBX structure to return
  1042.  
  1043.      This function parses a network mailbox name.  If the name is a
  1044. network mailbox name, it returns non-NIL, with the NETMBX structure
  1045. loaded with the results form the parse.
  1046.  
  1047.                Mailbox Access Functions
  1048.  
  1049. void mail_list (MAILSTREAM *stream,char *ref,char *pat);
  1050. void mail_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents);
  1051.     stream    if non-NIL, stream to use
  1052.     ref    mailbox reference string
  1053.     pat    mailbox pattern string
  1054.     contents contents to search
  1055.  
  1056.      This function returns a list of mailboxes via the mm_list()
  1057. callback.  The reference is applied to the pattern in an implementation
  1058. dependent fashion, and the resulting string is used to search for
  1059. matching mailbox names.  "*" is a wildcard which matches zero or more
  1060. characters; "%" is a variant which does not descend a hierarchy level.
  1061. Read the IMAP specification for more information.
  1062.  
  1063.      mail_scan() is a variant which takes a string to search for in the
  1064. text of the mailbox.  The string is a free-text string, without regard
  1065. for message boundaries, and thus the choice of strings must be made
  1066. with care.
  1067.  
  1068.  
  1069. void mail_lsub (MAILSTREAM *stream,char *ref,char *pat);
  1070.     stream    if non-NIL, stream to use
  1071.     ref    mailbox reference string
  1072.     pat    mailbox pattern string
  1073.  
  1074.      This function returns a list of subscribed mailboxes via the
  1075. mm_lsub() callback.  The reference is applied to the pattern in an
  1076. implementation dependent fashion, and the resulting string is used to
  1077. search for matching mailbox names in the subscription list.  "*" is a
  1078. wildcard which matches zero or more characters; "%" is a variant which
  1079. does not descend a hierarchy level.  Read the IMAP specification for
  1080. more information.
  1081.  
  1082.  
  1083. long mail_subscribe (MAILSTREAM *stream,char *mailbox);
  1084.     stream    if non-NIL, stream to use
  1085.     mailbox    mailbox name
  1086.  
  1087.      This function adds the given name to the subscription list.  It
  1088. returns T if successful, NIL if unsuccessful.  If unsuccessful, an
  1089. error message is returned via the mm_log() callback.
  1090.  
  1091.  
  1092. long mail_unsubscribe (MAILSTREAM *stream,char *mailbox);
  1093.     stream    if non-NIL, stream to use
  1094.     mailbox    mailbox name
  1095.  
  1096.      This function removes the given name from the subscription list.
  1097. It returns T if successful, NIL if unsuccessful.  If unsuccessful, an
  1098. error message is returned via the mm_log() callback.
  1099.  
  1100.  
  1101. long mail_create (MAILSTREAM *stream,char *mailbox);
  1102.     stream    if non-NIL, stream to use
  1103.     mailbox    mailbox name
  1104.  
  1105.      This function creates a mailbox with the given name.  It returns T
  1106. if successful, NIL if unsuccessful.  If unsuccessful, an error message
  1107. is returned via the mm_log() callback.
  1108.  
  1109.      It is an error to create INBOX or a mailbox name which already
  1110. exists.
  1111.  
  1112.  
  1113. long mail_delete (MAILSTREAM *stream,char *mailbox);
  1114.     stream    if non-NIL, stream to use
  1115.     mailbox    mailbox name
  1116.  
  1117.      This function deletes the named mailbox.  It returns T if
  1118. successful, NIL if unsuccessful.  If unsuccessful, an error message is
  1119. returned via the mm_log() callback.
  1120.  
  1121.      It is an error to delete INBOX or a mailbox name which does not
  1122. already exist.
  1123.  
  1124.  
  1125. long mail_rename (MAILSTREAM *stream,char *old,char *newname);
  1126.     stream    if non-NIL, stream to use
  1127.     old    existing mailbox name
  1128.     newname    new (not yet existing) mailbox name
  1129.  
  1130.      This function renames the old mailbox to the new mailbox name.
  1131. It returns T if successful, NIL if unsuccessful.  If unsuccessful, an
  1132. error message is returned via the mm_log() callback.
  1133.  
  1134.      It is an error to reanme a mailbox that does not exist, or rename
  1135. a mailbox to a name that already exists.  It is permitted to rename
  1136. INBOX; a new empty INBOX is created in its place.
  1137.  
  1138.  
  1139. long mail_status (MAILSTREAM *stream,char *mbx,long flags);
  1140.     stream    if non-NIL, stream to use
  1141.     mbx    mailbox name
  1142.     flags    option flags
  1143.  
  1144.      This function returns the status of the given mailbox name via the
  1145. mm_status() callback.  It returns T if successful, NIL if unsuccessful.
  1146. If unsuccessful, an error message is returned via the mm_log()
  1147. callback.
  1148.  
  1149.      The options are a bit mask with one or more of the following,
  1150. indicating the data which should be returned.
  1151.     SA_MESSAGES    number of messages in the mailbox
  1152.     SA_RECENT    number of recent messages in the mailbox
  1153.     SA_UNSEEN    number of unseen messages in the mailbox
  1154.     SA_UIDNEXT    next UID value to be assigned
  1155.     SA_UIDVALIDITY    UID validity value
  1156.  
  1157.      Note that, depending upon implementation, some of these values may
  1158. be more costly to get than others.  For example, calculating the
  1159. number of unseen messages may require opening the mailbox and scanning
  1160. all of the message flags.  A mail_status() call should thus be used
  1161. with option flags specifying only the data that is actually needed.
  1162.  
  1163.  
  1164. MAILSTREAM *mail_open (MAILSTREAM *oldstream,char *name,long options);
  1165.     oldstream if non-NIL, stream to recycle
  1166.     name    mailbox name to open
  1167.     options    option flags.
  1168.  
  1169.      This function opens the mailbox and if successful returns a stream
  1170. suitable for use by the other MAIL functions.
  1171.  
  1172.      If oldstream is non-NIL, an attempt is made to reuse oldstream as
  1173. the stream for this mailbox; this is useful when you want to open
  1174. another mailbox to the same IMAP or NNTP server without having to open
  1175. a new connection.  Doing this will close the previously open mailbox.
  1176.  
  1177.      The options are a bit mask with one or more of the following:
  1178.     OP_DEBUG    Log IMAP protocol telemetry through mm_debug()
  1179.     OP_READONLY    Open mailbox read-only.
  1180.     OP_ANONYMOUS    Don't use or update a .newsrc file for news.
  1181.     OP_SHORTCACHE    Don't cache envelopes or body structures
  1182.     OP_SILENT    Don't pass mailbox events (internal use only)
  1183.     OP_PROTOTYPE    Return the "prototype stream" for the driver
  1184.              associated with this mailbox instead of
  1185.              opening the stream
  1186.     OP_HALFOPEN    For IMAP and NNTP names, open a connection
  1187.              to the server but don't open a mailbox.
  1188.     OP_EXPUNGE    Silently expunge the oldstream before recycling
  1189.  
  1190.  NIL is returned if this function fails for any reason.
  1191.  
  1192.  
  1193. MAILSTREAM *mail_close (MAILSTREAM *stream);
  1194. MAILSTREAM *mail_close_full (MAILSTREAM *stream,long options);
  1195.     stream    stream to close
  1196.     options    option flags
  1197.      This function closes the MAIL stream and frees all resources
  1198. associated with it that it may have created (subject to any handles
  1199. existing).
  1200.  
  1201.      The options for mail_close_full() are a bit mask with one or more
  1202. of the following:
  1203.     CL_EXPUNGE    Silently expunge before closing
  1204.  
  1205.      This function always returns NIL, so it can be used as:
  1206.     stream = mail_close (stream);
  1207.  
  1208.                Handle Functions
  1209.  
  1210.      Handles are used when an entity that wishes to access the stream
  1211. may survive the stream without knowing that it outlived it.  For
  1212. example, an object reading a message may have a handle to a stream,
  1213. but the message selection object that spawned it (and which owns the
  1214. stream) may have gone away.  A stream can be closed or recycled while
  1215. handles are pointing at it, but it is not completely freed until all
  1216. handles are gone.  A stream may have an arbitrary number of handles.
  1217.  
  1218.  
  1219. MAILHANDLE *mail_makehandle (MAILSTREAM *stream);
  1220.     stream    stream to make handle to
  1221.  
  1222.      This function creates and returns a handle to the stream.
  1223.  
  1224.  
  1225. void mail_free_handle (MAILHANDLE **handle);
  1226.     handle    pointer to handle to release
  1227.  
  1228.      This function frees the handle and notifies the stream that it has
  1229. one fewer handle.  If this is the last handle on the stream and the
  1230. stream has been closed, then the stream is freed.
  1231.  
  1232.  
  1233. MAILSTREAM *mail_stream (MAILHANDLE *handle);
  1234.     handle    handle to look up
  1235.  
  1236.      This function returns the stream associated with the handle if and
  1237. only if the stream still represents the same MAIL connection associated
  1238. with the handle.  Otherwise, NIL is returned (meaning that there is no
  1239. active stream associated with this handle).
  1240.  
  1241.             Message Data Fetching Functions
  1242.  
  1243. [Note!!  There is an important difference between a "sequence" and a
  1244.  "msgno".  A sequence is a string representing one or more messages in
  1245.  IMAP4-style sequence format ("n", "n:m", or combination of these
  1246.  delimited by commas), whereas a msgno is an int representing a single
  1247.  message.] 
  1248.  
  1249. void mail_fetchfast (MAILSTREAM *stream,char *sequence);
  1250. void mail_fetchfast_full (MAILSTREAM *stream,char *sequence,long flags);
  1251.     stream    stream to fetch on
  1252.     sequence IMAP-format set of message sequence numbers
  1253.     flags    option flags
  1254.  
  1255.      This function causes a cache load of all the "fast" information
  1256. (internal date, RFC 822 size, and flags) for the given sequence.  Since
  1257. all this information is also fetched by mail_fetchstructure(), this
  1258. function is generally not used unless the OP_SHORTCACHE option in the
  1259. mail_open() call is used.
  1260.  
  1261.      The options for mail_fetchfast_full() are a bit mask with one or
  1262. more of the following:
  1263.     FT_UID        The sequence argument contains UIDs instead of
  1264.              sequence numbers
  1265.  
  1266.  
  1267. void mail_fetchflags (MAILSTREAM *stream,char *sequence);
  1268. void mail_fetchflags_full (MAILSTREAM *stream,char *sequence,long flags);
  1269.  
  1270.      This function causes a fetch of the flags for the given sequence.
  1271. This main reason for using this function is to update the flags in the
  1272. local cache in case some other process changed the flags (multiple
  1273. simultaneous write access is allowed to the flags) as part of a "check
  1274. entire mailbox" (as opposed to "check for new messages") operation.
  1275.  
  1276.  The options for mail_fetchflags_full() are a bit mask with one or more
  1277. of the following:
  1278.     FT_UID        The sequence argument contains UIDs instead of
  1279.              sequence numbers
  1280.  
  1281.  
  1282. ENVELOPE *mail_fetchenvelope (MAILSTREAM *stream,unsigned long msgno);
  1283. ENVELOPE *mail_fetchstructure (MAILSTREAM *stream,unsigned long msgno,
  1284.                    BODY **body);
  1285. ENVELOPE *mail_fetchstructure_full (MAILSTREAM *stream,unsigned long msgno,
  1286.                     BODY **body,long flags);
  1287.     stream    stream to fetch on
  1288.     msgno    message sequence number
  1289.     body    pointer to where to return BODY structure if non-NIL
  1290.     flags    option flags
  1291.      This function causes a fetch of all the structured information
  1292. (envelope, internal date, RFC 822 size, flags, and body structure) for
  1293. the given msgno and, in the case of IMAP, up to MAPLOOKAHEAD (a
  1294. parameter in IMAP2.H) subsequent messages which are not yet in the
  1295. cache.  No fetch is done if the envelope for the given msgno is already
  1296. in the cache.  The ENVELOPE and the BODY for this msgno is returned.
  1297. It is possible for the BODY to be NIL, in which case no information is
  1298. available about the structure of the message body.
  1299.  
  1300.      The options for mail_fetchstructure_full() are a bit mask with one
  1301. or more of the following:
  1302.     FT_UID        The msgno argument is a UID 
  1303.  
  1304.      This is the primary function for fetching non-text information
  1305. about messages, and should be called before any attempt to reference
  1306. cache information about this message via mail_elt().
  1307.  
  1308.  
  1309. char *mail_fetchheader (MAILSTREAM *stream,unsigned long msgno);
  1310. char *mail_fetchheader_full (MAILSTREAM *stream,unsigned long msgno,
  1311.                  STRINGLIST *lines,unsigned long *len,long flags);
  1312.     stream    stream to fetch on
  1313.     msgno    message sequence number
  1314.     lines    list of header lines to fetch
  1315.     len    returned length in octets
  1316.     flags    option flags
  1317.  
  1318.      This function causes a fetch of the complete, unfiltered RFC 822
  1319. format header of the specified message as a text string and returns
  1320. that text string.
  1321.  
  1322.      If the lines argument is non-NIL, it contains a list of header
  1323. field names to use in subsetting the header text.  Only those lines
  1324. which have that header field name are returned, unless FT_NOT is set in
  1325. which case only those lines which do not have that header field name
  1326. are returned.
  1327.  
  1328.      If the len argument is non-NIL, it holds a pointer in which the
  1329. length of the string in octets is returned.  This is useful in cases
  1330. where there may be an embedded null in the string.
  1331.  
  1332.      This function always returns a valid string pointer; if no header
  1333. exists or if it can not be fetched (e.g. by a deceased IMAP stream) an
  1334. empty string is returned.
  1335.  
  1336.      The options for mail_fetchheader_full() are a bit mask with one or
  1337. more of the following:
  1338.     FT_UID        The msgno argument is a UID 
  1339.     FT_NOT        The returned header lines are those that are
  1340.              not in the lines argument
  1341.     FT_INTERNAL    The return string is in "internal" format,
  1342.              without any attempt to canonicalize to CRLF
  1343.               newlines
  1344.     FT_PREFETCHTEXT    The RFC822.TEXT should be pre-fetched at the
  1345.              same time.  This avoids an extra RTT on an
  1346.              IMAP connection if a full message text is
  1347.              desired (e.g. in a "save to local file"
  1348.              operation)
  1349.          
  1350.  
  1351. char *mail_fetchtext (MAILSTREAM *stream,unsigned long msgno);
  1352. char *mail_fetchtext_full (MAILSTREAM *stream,unsigned long msgno,
  1353.                unsigned long *len,long flags);
  1354.     stream    stream to fetch on
  1355.     msgno    message sequence number
  1356.     len    returned length in octets
  1357.     flags    option flags
  1358.  
  1359.      This function causes a fetch of the non-header text of the
  1360. specified message as a text string and returns that text string.  No
  1361. attempt is made to segregate individual body parts.
  1362.  
  1363.      If the len argument is non-NIL, it holds a pointer in which the
  1364. length of the string in octets is returned.  This is useful in cases
  1365. where there may be an embedded null in the string.
  1366.  
  1367.      This function always returns a valid string pointer; if no header
  1368. exists or if it can not be fetched (e.g. by a deceased IMAP stream) an
  1369. empty string is returned.
  1370.  
  1371.       The options for mail_fetchtext_full() are a bit mask with one or
  1372. more of the following:
  1373.     FT_UID        The msgno argument is a UID 
  1374.     FT_PEEK        Do not set the \Seen flag if it not already set
  1375.     FT_INTERNAL    The return string is in "internal" format,
  1376.              without any attempt to canonicalize to CRLF
  1377.               newlines
  1378.  
  1379.  
  1380. char *mail_fetchbody (MAILSTREAM *stream,unsigned long msgno,char *sec,
  1381.               unsigned long *len);
  1382. char *mail_fetchbody_full (MAILSTREAM *stream,unsigned long msgno,char *sec,
  1383.                unsigned long *len,long flags);
  1384.     stream    stream to fetch on
  1385.     msgno    message sequence number
  1386.     sec    section specifier
  1387.     len    returned length in octets
  1388.     flags    option flags
  1389.  
  1390.       This function causes a fetch of the particular section of the
  1391. body of the specified message as a text string and returns that text
  1392. string.  The section specification is a string of integers delimited by
  1393. period which index into a body part list as per the IMAP4
  1394. specification.  Body parts are not decoded by this function; see
  1395. rfc822_base64() and rfc822_quotedprintable().
  1396.  
  1397.      If the len argument is non-NIL, it holds a pointer in which the
  1398. length of the string in octets is returned.  This is useful in cases
  1399. where there may be an embedded null in the string.
  1400.  
  1401.       This function may return NIL on error.
  1402.  
  1403.       The options for mail_fetchbody_full() are a bit mask with one or
  1404. more of the following:
  1405.     FT_UID        The msgno argument is a UID 
  1406.     FT_PEEK        Do not set the \Seen flag if it not already set
  1407.     FT_INTERNAL    The return string is in "internal" format,
  1408.              without any attempt to canonicalize to CRLF
  1409.               newlines
  1410.  
  1411.  
  1412. unsigned long mail_uid (MAILSTREAM *stream,unsigned long msgno);
  1413.     stream    stream to fetch on
  1414.     msgno    message sequence number
  1415.  
  1416.       This function returns the UID for the given message sequence
  1417. number.
  1418.  
  1419.  
  1420. void mail_fetchfrom (char *s,MAILSTREAM *stream,unsigned long msgno,
  1421.              long length);
  1422.     s    destination string
  1423.     stream    stream to fetch on
  1424.     msgno    message sequence number
  1425.     length    maximum field length
  1426.  
  1427.      This function writes a "from" string of the specified length for
  1428. the specified message, suitable for display to the user in a menu line,
  1429. into the string pointed to by s.
  1430.  
  1431.       If the personal name of the first address in the envelope's from
  1432. item is non-NIL, it is used; otherwise a string is created by appending
  1433. the mailbox of the first address, an "@", and the host of the first
  1434. address.  The string is trimmed or padded with trailing spaces as
  1435. necessary to make its length match the length argument.
  1436.  
  1437.  
  1438. void mail_fetchsubject (char *s,MAILSTREAM *stream,unsigned long msgno,
  1439.             long length);
  1440.     s    destination string
  1441.     stream    stream to fetch on
  1442.     msgno    message sequence number
  1443.     length    maximum field length
  1444.  
  1445.       This function returns a "subject" string of the specified length
  1446. for the specified message, suitable for display to the user in a menu
  1447. line.
  1448.  
  1449.        The envelope's subject item is copied and trimmed as necessary
  1450. to make its length be no more what the caller requested.  Unlike
  1451. mail_fetchfrom(), this function can return a string of shorter length
  1452. than what the caller requested.
  1453.  
  1454.  
  1455. LONGCACHE *mail_lelt (MAILSTREAM *stream,unsigned long msgno);
  1456. MESSAGECACHE *mail_elt (MAILSTREAM *stream,unsigned long msgno);
  1457.     stream    stream to access
  1458.     msgno    message sequence number
  1459.  
  1460.      This function returns the cache entry for the specified message.
  1461. Although it will create a cache entry if it does not already exist,
  1462. that functionality is for internal use only.  This function should
  1463. never be called without having first called mail_fetchfast() or
  1464. mail_fetchstructure() on the message first.
  1465.  
  1466.      A cache entry holds the internal date/time, flags, and RFC 822
  1467. size of a message.  It holds other data as well, but that is for
  1468. internal use only.
  1469.  
  1470.      mail_lelt() is a variant that returns a `long' cache entry, which
  1471. consists of an cache entry (as a structure, not a pointer), an envelope
  1472. pointer, and a body pointer.  This is used in conjunction with the elt
  1473. lock count functionality, to allow an application to associate the
  1474. cached envelope and body of a message with an open window even if the
  1475. message is subsequently expunged or if the stream is closed.
  1476.  
  1477.      Unless your application wants to look at cached envelopes and
  1478. bodies even after the message is expunged or the stream is closed, it
  1479. should not use mail_lelt().  Instead, it should use a returned elt from
  1480. mail_elt() and use the elt->msgsno as the argument to
  1481. mail_fetchstructure().
  1482.  
  1483.     BEWARE: the behavior of mail_lelt() is undefined if the
  1484.     stream is open with OP_SHORTCACHE.  mail_lelt() is extremely
  1485.     special purpose, and should only be used in sophisticated
  1486.     special purpose applications after discussing its use with
  1487.     the c-client author.  If you think you need this function,
  1488.     you are probably mistaken.  In almost all cases, you should
  1489.     use mail_elt() and mail_fetchstructure() instead.
  1490.  
  1491.          Message Status Manipulation Functions
  1492.  
  1493. void mail_setflag (MAILSTREAM *stream,char *sequence,char *flag);
  1494. void mail_setflag_full (MAILSTREAM *stream,char *sequence,char *flag,
  1495.             long flags);
  1496.     stream    stream to use
  1497.     sequence IMAP-format set of message sequence numbers
  1498.     flag    IMAP-format flag string
  1499.     flags    option flags
  1500.  
  1501.     This function causes a store to add the specified flag to the flags
  1502. set for the messages in the specified sequence.  If there is any
  1503. problem in setting flags, a message will be passed to the application
  1504. via the mm_log() facility.
  1505.  
  1506.      The options for mail_setflag_full() are a bit mask with one or
  1507. more of the following:
  1508.     ST_UID        The sequence argument contains UIDs instead of
  1509.              sequence numbers
  1510.     ST_SILENT    Do not update the local cache with the new
  1511.              value of the flags.  This is useful to save
  1512.              network bandwidth, at the cost of invalidating
  1513.              the cache.
  1514.  
  1515.  
  1516. void mail_clearflag (MAILSTREAM *stream,char *sequence,char *flag);
  1517. void mail_clearflag_full (MAILSTREAM *stream,char *sequence,char *flag,
  1518.               long flags);
  1519.     stream    stream to use
  1520.     sequence IMAP-format set of message sequence numbers
  1521.     flag    IMAP-format flag string
  1522.     flags    option flags
  1523.  
  1524.      This function causes a store to delete the specified flag from the
  1525. flags set for the messages in the specified sequence.  If there is any
  1526. problem in clearing flags, a message will be passed to the application
  1527. via the mm_log() facility.
  1528.  
  1529.      The options for mail_setflag_full() are a bit mask with one or
  1530. more of the following:
  1531.     ST_UID        The sequence argument contains UIDs instead of
  1532.              sequence numbers
  1533.     ST_SILENT    Do not update the local cache with the new
  1534.              value of the flags.  This is useful to save
  1535.              network bandwidth, at the cost of invalidating
  1536.              the cache.
  1537.  
  1538.                Mailbox Searching
  1539.  
  1540. void mail_search (MAILSTREAM *stream,char *criteria);
  1541. void mail_search_full (MAILSTREAM *stream,char *charset,SEARCHPGM *pgm,
  1542.                long flags);
  1543.     stream    stream to search
  1544.     charset    MIME character set to use when searching strings
  1545.     pgm    search program
  1546.     flags    option flags
  1547.  
  1548.      This function causes a mailbox search, using the given MIME
  1549. charset (NIL means the default, US-ASCII) and the given search program.
  1550. A search program is a structure that holds the following data:
  1551.  
  1552. SEARCHSET *msgno;    a set of message sequence numbers
  1553. SEARCHSET *uid;        a set of unique identifiers
  1554. SEARCHOR *or;        OR result of two search programs
  1555. SEARCHPGMLIST *not;    AND result of list of NOT'ed search programs
  1556. SEARCHHEADER *header;    message headers
  1557. STRINGLIST *bcc;    string(s) appear in bcc list
  1558. STRINGLIST *body;    string(s) appear in message body text
  1559. STRINGLIST *cc;        string(s) appear in cc list
  1560. STRINGLIST *from;    string(s) appear in from
  1561. STRINGLIST *keyword;    user flag string(s) set
  1562. STRINGLIST *unkeyword;    user flag strings() not set
  1563. STRINGLIST *subject;    string(s) appear in subject
  1564. STRINGLIST *text;    string(s) appear in message header or body
  1565. STRINGLIST *to;        string(s) appear in to list
  1566. unsigned long larger;    larger than this many octets
  1567. unsigned long smaller;    smaller than this many octes
  1568.     The following dates are in form:
  1569.         ((year - BASEYEAR) << 9) + (month << 5) + day
  1570. unsigned short sentbefore;
  1571.             sent before this date
  1572. unsigned short senton;    sent on this date
  1573. unsigned short sentsince;
  1574.             sent since this date
  1575. unsigned short before;    received before this date
  1576. unsigned short on;    received on this date
  1577. unsigned short since;    received since this date
  1578. unsigned int answered : 1;
  1579.             message answered
  1580. unsigned int unanswered : 1;
  1581.             message not answered
  1582. unsigned int deleted : 1;
  1583.             message deleted
  1584. unsigned int undeleted : 1;
  1585.             message not deleted
  1586. unsigned int draft : 1;    message is a draft
  1587. unsigned int undraft : 1;
  1588.             message is not a draft
  1589. unsigned int flagged : 1;
  1590.             message flagged as urgent
  1591. unsigned int unflagged : 1;
  1592.             message not flagged as urgent
  1593. unsigned int recent : 1;
  1594.             message recent since last parse of mailbox
  1595. unsigned int old : 1;    message not recent since last parse of mailbox
  1596. unsigned int seen : 1;    message read
  1597. unsigned int unseen : 1;
  1598.             message not read
  1599.  
  1600.      The following auxillary structures are used by search programs:
  1601.     SEARCHHEADER:    header line searching
  1602. char *line;        header line field name
  1603. char *text;        text header line
  1604. SEARCHHEADER *next;    next SEARCHHEADER in list (AND'ed)
  1605.  
  1606.     SEARCHSET:    message number set
  1607. unsigned long first;    first number in set
  1608. unsigned long last;    if non-zero, last number in set
  1609. SEARCHSET *next;    next SEARCHSET in list (AND'ed)
  1610.  
  1611.     SEARCHOR:    two search programs, OR'ed together
  1612. SEARCHPGM *first;    first program
  1613. SEARCHPGM *second;    second program
  1614. SEARCHOR *next;        next SEARCHOR in list
  1615.  
  1616.     SEARCHPGMLIST:    list of search programs
  1617. SEARCHPGM *pgm;        search program (AND'd with others in list)
  1618. SEARCHPGMLIST *next;    next SEARCHPGM in list
  1619.  
  1620.      mail_search(), the older interface, accepts a search criteria
  1621. argument as a character string in IMAP2 (RFC-1176) format.  Do not try
  1622. to use any IMAP4 search criteria with this interface.
  1623.  
  1624.      The application's mm_searched() function is called for each
  1625. message that matches the search criteria.  In addition, after the
  1626. search is completed, the "fast" information (see mail_fetchfast_full()
  1627. and envelopes of the searched messages are fetched (this is called
  1628. pre-fetching).
  1629.  
  1630.      If there is any problem in searching, a message will be passed to
  1631. the application via the mm_log() facility.
  1632.  
  1633.      The flags for mail_search_full() are a bit mask with one or more
  1634. of the following:
  1635.     SE_UID        Return UIDs instead of sequence numbers
  1636.     SE_FREE        Return the search program to free storage after
  1637.              finishing
  1638.     SE_NOPREFETCH    Don't prefetch searched messages.
  1639.  
  1640.  
  1641. unsigned long *mail_sort (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
  1642.               SORTPGM *pgm,long flags);
  1643.     stream    stream to sort
  1644.     charset    MIME character set to use when sorting strings
  1645.     spg    search program
  1646.     pgm    sort program
  1647.     flags    option flags
  1648.  
  1649.  
  1650.      This function is a variant of mail_search_full().  It accepts an
  1651. additional argument, a sort program, which specifies one or more sort
  1652. rules to be applied to the result.  If the searching and sorting are
  1653. successful, it returns a 0-terminated vector of message sequence
  1654. numbers (or UIDs if SE_UID is set).  This vector is created out of
  1655. free storage, and must be freed with fs_give() when finished with it.
  1656.  
  1657.      A sort program is a structure that holds the following data:
  1658. unsigned int reverse : 1;
  1659.             reverse sorting of this key
  1660. short function;        sort rule, one of the following:
  1661.         SORTDATE    message Date
  1662.         SORTARRIVAL    arrival date
  1663.         SORTFROM    mailbox in first From address
  1664.         SORTSUBJECT    message Subject
  1665.         SORTTO        mailbox in first To address 
  1666.         SORTCC        mailbox in first cc address 
  1667.         SORTSIZE    size of message in octets
  1668. SORTPGM *next;        next sort program to be applied if two or more
  1669.              messages collate identically with this rule
  1670.  
  1671.      The flags for mail_search_full() are a bit mask with one or more
  1672. of the following:
  1673.     SE_UID        Return UIDs instead of sequence numbers
  1674.     SE_FREE        Return the search program to free storage after
  1675.              finishing
  1676.     SE_NOPREFETCH    Don't prefetch searched messages.
  1677.     SO_FREE        Return the sort program to free storage after
  1678.              finishing
  1679.  
  1680.           Miscellaneous Mailbox and Message Functions
  1681.  
  1682. long mail_ping (MAILSTREAM *stream);
  1683.     stream    string to ping
  1684.  
  1685.      The function pings the stream to see if it is still active.  It may
  1686. discover new mail; this is the preferred method for a periodic "new mail
  1687. check" as well as a "keep alive" for servers which have an inactivity
  1688. timeout.  It returns T if the stream is still alive, NIL otherwise.
  1689.  
  1690.      If new mail is found, the application's mm_exists() function is
  1691. called with the newly-determined number of messages in the mailbox.
  1692.  
  1693.  
  1694. void mail_check (MAILSTREAM *stream);
  1695.     stream    stream to checkpoint
  1696.  
  1697.       This function causes a mailstore-defined checkpoint of the
  1698. mailbox.  This may include such things as a writeback to disk, a check
  1699. for flag changes in a shared mailbox, etc.  It is not a "check for new
  1700. mail"; mail_ping() performs this function (as potentially does any other
  1701. function).  The status of the check is passed to the application via the
  1702. mm_log() facility.
  1703.  
  1704.  
  1705. void mail_expunge (MAILSTREAM *stream);
  1706.     stream    string to expunge
  1707.  
  1708.      This function causes an expunge (permanent removal of messages
  1709. which are marked as deleted) of the mailbox.  The application's
  1710. mm_expunged() function is called for each message that has been
  1711. expunged.  The application's mm_exists() function is called at the start
  1712. and end of the expunge to ensure synchronization.  The status of the
  1713. expunge is passed to the application via the mm_log() facility.
  1714.  
  1715.       Note that the decrementing of msgno's for subsequent messages
  1716. happens immediately; for example, if three consequtive messages starting
  1717. at msgno 5 are expunged, mm_expunged() will be called with a msgno of 5
  1718. three times.
  1719.  
  1720.  
  1721. long mail_copy (MAILSTREAM *stream,char *sequence,char *mailbox);
  1722. long mail_move (MAILSTREAM *stream,char *sequence,char *mailbox);
  1723. long mail_copy_full (MAILSTREAM *stream,char *sequence,char *mailbox,
  1724.              long options);
  1725.     stream    stream to copy
  1726.     sequence IMAP-format set of message numbers
  1727.     mailbox    destination mailbox name
  1728.     options    option flags
  1729.  
  1730.      This function causes the messages in the specified sequence to be
  1731. copied to the specified mailbox.  T is returned if the copy is
  1732. successful.  mail_move() is equivalent to setting CP_MOVE in the options.
  1733.  
  1734.      If there is any problem in copying, a message will be passed to
  1735. the application via the mm_log() facility and the function returns NIL.
  1736. No copying is actually done in this case.
  1737.  
  1738.       Note that the mailbox must be on the same host as the stream and
  1739. is a mailbox of the type of the source mailbox only.
  1740.  
  1741.      The flags for mail_search_full() are a bit mask with one or more
  1742. of the following:
  1743.     CP_UID        The sequence argument contains UIDs instead of
  1744.              sequence numbers
  1745.     CP_MOVE        Delete the messages from the current mailbox
  1746.              after copying to the destination.
  1747.  
  1748.  
  1749. long mail_append (MAILSTREAM *stream,char *mailbox,STRING *message);
  1750. long mail_append_full (MAILSTREAM *stream,char *mailbox,char *flags,char *date,
  1751.                STRING *message);
  1752.     stream    stream to use if non-NIL (in the IMAP case)
  1753.     mailbox    destination mailbox name
  1754.     flags    flags to set on message if non-NIL
  1755.     date    internal date (received date) to set on message if non-NIL
  1756.     message    string structure of message to write
  1757.  
  1758.      This function writes the message in the string structure to the
  1759. destination mailbox, along with the flags and date if specified.  This
  1760. is useful in those cases where you can't use mail_copy(), e.g. when
  1761. copying from one server to another; you can always fetch the message
  1762. and then mail_append() it to the destination.  It may also be useful
  1763. for maintaining an outbox of your outgoing mail.
  1764.  
  1765.  
  1766. void mail_gc (MAILSTREAM *stream,long gcflags);
  1767.     stream    stream to GC if non-NIL (else GC's all streams)
  1768.     flags    option flags
  1769.  
  1770.       This function garbage collects (purges) the cache of entries of
  1771. a specific type.  Some drivers do not allow purging of particular
  1772. cache types, and an attempt to do so is ignored.
  1773.  
  1774.       The flags for mail_gc() are a bit mask with one or more of the
  1775. following:
  1776.     GC_ELT        message cache elements
  1777.     GC_ENV        ENVELOPEs and BODYs
  1778.     GC_TEXTS    cached texts
  1779.  
  1780.              Date/Time Handling Functions
  1781.  
  1782.  
  1783. char *mail_date (char *string,MESSAGECACHE *elt);
  1784.     string    destination string
  1785.     elt    message cache element containing date
  1786.  
  1787.       This function accepts a message cache element that contains date
  1788. information, and writes an IMAP-4 date string, that is, one in form:
  1789.     dd-mmm-yyyy hh:mm:ss +zzzz
  1790. based upon the data in the elt.  The destination string must be large
  1791. enough to hold this string.
  1792.  
  1793.  
  1794. char *mail_cdate (char *string,MESSAGECACHE *elt);
  1795.     string    destination string
  1796.     elt    message cache element containing date
  1797.  
  1798.       This function accepts a message cache element that contains date
  1799. information, and writes a ctime() format date string, that is, one in
  1800. form:
  1801.     www mmm dd hh:mm:ss yyyy\n
  1802. based upon the data in the elt.  The destination string must be large
  1803. enough to hold this string.
  1804.  
  1805.  
  1806. long mail_parse_date (MESSAGECACHE *elt,char *string);
  1807.     elt    message cache element to store parsed date
  1808.     string    source date string
  1809.  
  1810.       This function parses the date/time stored in the given string,
  1811. in format:
  1812.     [www,] date [[hh:mm[:ss][-zzz| +zzzz]
  1813. where the date can be any of:
  1814.     mm/dd/yy, mm/dd/yyyy, dd-mmm-yy, dd-mmm-yyyy, dd mmm yy, dd mmm yyyy
  1815. and stores the result of the parse in the elt.  If the parse is
  1816. successful, T is returned, else NIL.
  1817.  
  1818.  
  1819. unsigned long mail_longdate (MESSAGECACHE *elt);
  1820.     elt    message cache element containing date.
  1821.  
  1822.       This function accepts a message cache element that contains date
  1823. information, and returns the number of days since the base time of the
  1824. imap-4 toolkit.  At present, this is the same as the Unix time() value
  1825. for that date/time, and hence can be used for functions such as utime().
  1826.  
  1827.               Utility Functions
  1828.  
  1829. void mail_debug (MAILSTREAM *stream);
  1830.     stream    stream to debug
  1831.  
  1832.       This function enables telemetry logging for this stream.  All
  1833. telemetry is passed to the application via the mm_dlog() facility.
  1834.  
  1835.  
  1836. void mail_nodebug (MAILSTREAM *stream);
  1837.     stream    stream to disable debugging
  1838.  
  1839.      This function disables telemetry logging for this stream.
  1840.  
  1841.  
  1842. long mail_sequence (MAILSTREAM *stream,char *sequence);
  1843.     stream    stream to set the sequence bits
  1844.     sequence IMAP-format message set string
  1845.  
  1846.      This function parses the given sequence string for message
  1847. numbers, sets the sequence bit in the stream's message cache element
  1848. of all messages in the sequence (and turns it off in all other message
  1849. cache elements).  If the parse is successful, T is returned, else NIL.
  1850.  
  1851.  
  1852. long mail_uid_sequence (MAILSTREAM *stream,char *sequence);
  1853.     stream    stream to set the sequence bits
  1854.     sequence IMAP-format message set string
  1855.  
  1856.      This function parses the given sequence string for unique
  1857. identifiers, sets the sequence bit in the stream's message cache
  1858. element of all messages in the sequence (and turns it off in all other
  1859. message cache elements).  If the parse is successful, T is returned,
  1860. else NIL.
  1861.  
  1862.  
  1863. long mail_parse_flags (MAILSTREAM *stream,char *flag,unsigned long *uf);
  1864.     stream    stream (used to get user flags)
  1865.     flag    IMAP-format flag string to parse
  1866.     uf    returned location of user flags
  1867.  
  1868.      The function parses the given flag string, and returns the system
  1869. flags as its return value and the user flags in the location pointed
  1870. to by the uf argument.  If there is an error in parse, a log message
  1871. is issued via mm_log() and this function returns NIL.
  1872.  
  1873.  
  1874. unsigned long mail_filter (char *text,unsigned long len,STRINGLIST *lines,
  1875.                long flags);
  1876.     text    RFC 822 text to filter
  1877.     len    length in octets in the text argument
  1878.     lines    string list of header file names to filter
  1879.     flags    option flags
  1880.  
  1881.      This function supports the header lines filtering function of
  1882. mail_fetchheader_full().  The lines argument contains a list of header
  1883. field names to use in subsetting the header text.  Only those lines
  1884. which have that header field name are returned, unless FT_NOT is set
  1885. in which case only those lines which do not have that header field
  1886. name are returned.
  1887.  
  1888.      The options for mail_filter() are a bit mask with one or more of
  1889. the following:
  1890.     FT_NOT        The returned header lines are those that are
  1891.              not in the lines argument
  1892.  
  1893.  
  1894. long mail_search_msg (MAILSTREAM *stream,unsigned long msgno,char *charset,
  1895.               SEARCHPGM *pgm);
  1896.     stream    stream to search
  1897.     msgno    message number of message to inspect
  1898.     charset    character set of search strings
  1899.     pgm    search program to test
  1900.  
  1901.      This function implements mail_search_full() locally in cases when
  1902. it is not done by a server (e.g. local mail files, NNTP/POP).  It
  1903. inspects the given message on that stream to see if it matches the
  1904. criteria or not.  If it matches, T is returned, else NIL.
  1905.  
  1906.  
  1907. SEARCHPGM *mail_criteria (char *criteria);
  1908.     criteria IMAP2-format search criteria string
  1909.  
  1910.      This function accepts an IMAP2-format search criteria string and
  1911. parses it.  If the parse is successful, it returns a search program
  1912. suitable for use in mail_search_full().
  1913.     WARNING: This function does not accept IMAP4 search criteria.
  1914.     The source string must be writeable (this restriction was also
  1915.     in the old IMAP2 c-client).
  1916.  
  1917.        Data Structure Instantiation/Destruction functions
  1918.  
  1919.      These functions are used to obtain structures from free storage and
  1920. to release them.
  1921.  
  1922. ENVELOPE *mail_newenvelope (void);
  1923. ADDRESS *mail_newaddr (void);
  1924. BODY *mail_newbody (void);
  1925. BODY *mail_initbody (BODY *body);
  1926. PARAMETER *mail_newbody_parameter (void);
  1927. PART *mail_newbody_part (void);
  1928. STRINGLIST *mail_newstringlist (void);
  1929. SEARCHPGM *mail_newsearchpgm (void);
  1930. SEARCHHEADER *mail_newsearchheader (char *line);
  1931. SEARCHSET *mail_newsearchset (void);
  1932. SEARCHOR *mail_newsearchor (void);
  1933. SEARCHPGMLIST *mail_newsearchpgmlist (void);
  1934. SORTPGM *mail_newsortpgm (void);
  1935.  
  1936.      These functions, all named mail_new...(), create a new structure of
  1937. the given type and initialize all of its elements to zero or empty.
  1938.  
  1939. void mail_free_body (BODY **body);
  1940. void mail_free_body_parameter (PARAMETER **parameter);
  1941. void mail_free_body_part (PART **part);
  1942. void mail_free_cache (MAILSTREAM *stream);
  1943. void mail_free_elt (MESSAGECACHE **elt);
  1944. void mail_free_lelt (LONGCACHE **lelt);
  1945. void mail_free_envelope (ENVELOPE **env);
  1946. void mail_free_address (ADDRESS **address);
  1947. void mail_free_stringlist (STRINGLIST **string);
  1948. void mail_free_searchpgm (SEARCHPGM **pgm);
  1949. void mail_free_searchheader (SEARCHHEADER **hdr);
  1950. void mail_free_searchset (SEARCHSET **set);
  1951. void mail_free_searchor (SEARCHOR **orl);
  1952. void mail_free_searchpgmlist (SEARCHPGMLIST **pgl);
  1953. void mail_free_sortpgm (SORTPGM **pgm);
  1954.  
  1955.      These functions, all named mail_free_...(), take a pointer to a
  1956. structure pointer, free all contained strings and structures within the
  1957. structure, and finally free the structure itself and set its pointer to
  1958. NIL.  For example, mail_free_envelope() frees all the ADDRESS structures
  1959. contained in the envelope.
  1960.  
  1961.      Normally, mail_free_elt() and mail_free_lelt() are used only if the
  1962. main program has a private pointer to cache elements.  If so, it is
  1963. expected to increment the cache element's lockcount when it makes a
  1964. private pointer, and to call this function when it is finished with it.
  1965.  
  1966.                Authentication Functions
  1967.  
  1968. char *mail_auth (char *mechanism,authresponse_t resp,int argc,char *argv[]);
  1969.     mechanism authentication mechanism name
  1970.     resp    callback function for providing responses
  1971.     argc    main() function argc value
  1972.     argv    main() function argv value
  1973.  
  1974.      This server function searches the list of authenticators that was
  1975. established by auth_link() for an authenticator with the given name.  If
  1976. an authenticator is found, authentication is initialized.  The function
  1977. pointed to by resp is called as the authenticator requires responses.
  1978.  
  1979.  
  1980. AUTHENTICATOR *mail_lookup_auth (unsigned int i);
  1981.     i    position in authenticator list
  1982.  
  1983.      This function returns the nth authenticator in the list, where n is
  1984. the value of it.
  1985.  
  1986.  
  1987. unsigned int mail_lookup_auth_name (char *mechanism);
  1988.     mechanism authentication mechanism name
  1989.  
  1990.      This function searches the list of authenticators for an
  1991. authenticator with the given name, and returns its position in the
  1992. authenticator list.
  1993.  
  1994.  
  1995.      The functions below are provided by c-client client drivers or by
  1996. servers to support the protocol-dependent parts of authentication.
  1997.  
  1998. typedef void *(*authchallenge_t) (void *stream,unsigned long *len);
  1999.     stream    stream to read challenge
  2000.     len    pointer to returned length in octets
  2001.  
  2002.      This driver function is called by an authenticator to read a
  2003. challenge from the given protocol stream in a protocol-dependent way.
  2004. It returns that challenge in binary and its length in octets to the
  2005. authenticator.
  2006.  
  2007.  
  2008. typedef long (*authrespond_t) (void *stream,char *s,unsigned long size);
  2009.     stream    stream to send response
  2010.     s    response string
  2011.     size    length of response string in octets
  2012.  
  2013.      This driver function is called by an authenticator to send a
  2014. challenge response to the given stream in a protocol-dependent way.
  2015. It returns T if successful, NIL if failure.
  2016.  
  2017.  
  2018. typedef char *(*authresponse_t) (void *challenge,unsigned long clen,
  2019.                  unsigned long *rlen);
  2020.     challenge challenge string
  2021.     clen    length of challenge string in octets
  2022.     rlen    pointer to returned length of response string
  2023.  
  2024.      This server function is called with a challenge string of clen
  2025. octets.  It sends, according to whatever protocol (IMAP, POP, etc.) it
  2026. uses, and returns the received response and response length in octets.
  2027.  
  2028.  
  2029. typedef long (*authclient_t) (authchallenge_t challenger,
  2030.                   authrespond_t responder,NETMBX *mb,void *s,
  2031.                   unsigned long trial);
  2032.     challenger pointer to protocol-dependent challenge reader function
  2033.     responder pointer to protocol-dependent response sender function
  2034.     mb    NETMBX struct of the mailbox desired to open
  2035.     s    stream for protocol-dependent routines to use
  2036.     trial    number of authentication attempts remaining
  2037.  
  2038.      This client authenticator function negotiates reading challenges
  2039. and sending responses for a particular authenticator (Kerberos, etc.)
  2040. over the protocol, and returns T if authenticated or NIL if failed.
  2041.  
  2042.  
  2043. typedef char *(*authserver_t) (authresponse_t responder,int argc,char *argv[]);
  2044.     responder pointer to protocol-dependent responder function
  2045.     argc    main() function argc value
  2046.     argv    main() function argv value
  2047.  
  2048.     This server authenticator function negotiates sending challenges and
  2049. reading responses for a particular authenticator (Kerberos, etc.), and
  2050. returns either the authenticated user name or NIL if authentication
  2051. failed.
  2052.  
  2053.                Network Access Functions
  2054.  
  2055.      These functions provide a layer of indirection between the TCP
  2056. routines and upper level routines.  This makes it possible to insert
  2057. additional code (e.g. privacy or checksum handling).
  2058.  
  2059. NETSTREAM *net_open (char *host,char *service,unsigned long port);
  2060.     host    host name
  2061.     service    contact service name
  2062.     port    contact port number
  2063.  
  2064.      This function opens a TCP connection to the given host and service
  2065. or port.
  2066.  
  2067.  
  2068. NETSTREAM *net_aopen (NETMBX *mb,char *service,char *usrbuf);
  2069.     NETMBX    parsed mailbox specification
  2070.     service    stream to open (at present, only /etc/rimapd is used)
  2071.     usrbuf    buffer to return login user name
  2072.  
  2073.      This function attempts to open a preauthenticated connection to the
  2074. given mailbox and service.  It will return the login user name of the
  2075. preauthenticated connection, as well as an open network stream, if
  2076. successful.
  2077.  
  2078.  
  2079. char *net_getline (NETSTREAM *stream);
  2080.     stream    network stream to read
  2081.  
  2082.      This routine reads a text line from the stream.  It calls
  2083. stream->dtb->getline, which normally points to tcp_getline() but can be
  2084. set to some other function.
  2085.  
  2086.  
  2087. long net_getbuffer (void *stream,unsigned long size,char *buffer);
  2088.     stream    network stream to read
  2089.     size    length of data in octets
  2090.     buffer    buffer of at least size octets
  2091.  
  2092.      This routine reads data from the stream.  It calls
  2093. stream->dtb->getbuffer, which normally points to tcp_getbuffer() but can
  2094. be set to some other function.
  2095.  
  2096.  
  2097. long net_soutr (NETSTREAM *stream,char *string);
  2098.     stream    network stream to write
  2099.     string    null-terminated string to output
  2100.  
  2101.      This routine writes a null-terminated string to the stream.  It
  2102. calls stream->dtb->soutr, which normally points to tcp_soutr() but can
  2103. be set to some other function.
  2104.  
  2105.  
  2106. long net_sout (NETSTREAM *stream,char *string,unsigned long size);
  2107.     stream    network stream to write
  2108.     string    string to output
  2109.     size    length of string in octets
  2110.  
  2111.      This routine writes a string of length size to the stream.  It
  2112. calls stream->dtb->sout, which normally points to tcp_sout() but can be
  2113. set to some other function.
  2114.  
  2115.  
  2116. void net_close (NETSTREAM *stream);
  2117.     stream    stream to close
  2118.  
  2119.      This routine closes the stream.  It calls stream->dtb->close, which
  2120. normally points to tcp_close() but can point to some other function.
  2121.  
  2122.  
  2123. char *net_host (NETSTREAM *stream);
  2124.     stream    stream to inspect
  2125.  
  2126.      This routine returns the remote host name of the stream.  It calls
  2127. stream->dtb->host, which normally points to tcp_host() but can point
  2128. to some other function.
  2129.  
  2130.  
  2131. unsigned long net_port (NETSTREAM *stream);
  2132.     stream    stream to inspect
  2133.  
  2134.      This routine returns the remote port number of the stream.  It calls
  2135. stream->dtb->port, which normally points to tcp_port() but can point
  2136. to some other function.
  2137.  
  2138.  
  2139. char *net_localhost (NETSTREAM *stream);
  2140.     stream    stream to inspect
  2141.  
  2142.      This routine returns the local host name of the stream.  It calls
  2143. stream->dtb->localhost, which normally points to tcp_localhost() but can
  2144. point to some other function.
  2145.  
  2146.           Subscription Management Functions
  2147.  
  2148. long sm_subscribe (char *mailbox);
  2149.     mailbox    mailbox name to subscribe
  2150.  
  2151.      This function adds the given mailbox name to the local subscription
  2152. list, and returns T if successful, NIL if failure.
  2153.  
  2154.  
  2155. long sm_unsubscribe (char *mailbox);
  2156.     mailbox    mailbox name to unsubscribe
  2157.  
  2158.      This function removes the given mailbox name from the local
  2159. subscription list, and returns T if successful, NIL if failure.
  2160.  
  2161. char *sm_read (void **sdb);
  2162.     sdb    data to use in subsequent calls, or NIL if first call
  2163.  
  2164.      This function returns the local subscription list as null
  2165. terminated strings.  Each call returns the next element in the list.
  2166. The first call should be with sdb pointing to a NIL pointer; this will
  2167. be filled in for subsequent calls.  At the last call, NIL will be
  2168. returned.
  2169.  
  2170.             Miscellaneous Utility Functions
  2171.  
  2172. char *ucase (char *string);
  2173.     string    string to convert
  2174.  
  2175.      This function converts each lowercase character of the specified
  2176. string to uppercase and returns the string.
  2177.  
  2178.  
  2179. char *lcase (char *string);
  2180.     string    string to convert
  2181.  
  2182.      This function converts each uppercase character of the specified
  2183. string to lowercase and returns the string.
  2184.  
  2185.  
  2186. char *cpystr (char *string);
  2187.     string    string to copy
  2188.  
  2189.  This function makes a copy of the string from free storage and returns
  2190. the copy.
  2191.  
  2192.  
  2193. long find_rightmost_bit (long *valptr);
  2194.     valptr    pointer to value to search
  2195.  
  2196.       This function returns -1 if the 32-bit value pointed to by valptr
  2197. is non-zero, otherwise it returns the bit number (0 = LSB, 31 = MSB) of
  2198. the right-most bit in that value.  This is used to convert from the bits
  2199. in the cache's userflags item to an index into the stream's userFlags
  2200. array of flag texts.
  2201.  
  2202.  
  2203. long min (long i,long j);
  2204.     i    first argument
  2205.     j    second argument
  2206.  
  2207.       This function returns the minimum of the two integers.
  2208.  
  2209. long max (long i,long j);
  2210.     i    first argument
  2211.     j    second argument
  2212.  
  2213.      This function returns the maximum of the two integers.
  2214.  
  2215. long search (char *s,long c,char *pat,long patc);
  2216.     s    string to search
  2217.     c    size of string
  2218.     pat    pattern to search in string
  2219.     patc    size of pattern
  2220.  
  2221.       This function does a fast case-independent search for the given
  2222. pattern in pat (length patc) in base string s, and returns T if the
  2223. pattern is found in the string.
  2224.  
  2225.  
  2226. long pmatch (char *s,char *pat,delim);
  2227. long pmatch_full (char *s,char *pat,delim);
  2228.     s    string to match
  2229.     pat    wildcard (* and %) to match in pattern
  2230.     delim    hierarchy delimiter
  2231.  
  2232.       This function returns T if the given wildcard pattern matches the
  2233. string in s with hierarchy delimiter delim.  Otherwise NIL is returned.
  2234.  
  2235.  
  2236. long dmatch (char *s,char *pat,char delim);
  2237.     s    string to match
  2238.     pat    wildcard (* and %) to match in pattern
  2239.     delim    hierarchy delimiter
  2240.  
  2241.      This function returns T if the given wildcard pattern matches the
  2242. directory.  If not, then none of the elements in the directory are
  2243. considered for recursive checking with pmatch_full().
  2244.  
  2245.                  SMTP Functions
  2246.  
  2247. SMTPSTREAM *smtp_open (char **hostlist,long debug);
  2248.     hostlist vector of SMTP server host names to try
  2249.     debug    non-zero if want protocol telemetry debugging
  2250.  
  2251.       This function opens an SMTP connection to a one of the hosts in the
  2252. host list and if successful returns a stream suitable for use by the
  2253. other SMTP functions.  The hosts are tried in order until a connection is
  2254. successfully opened.  If debug is non-NIL, protocol telemetry is logged
  2255. via mm_dlog().  NIL is returned if this function fails to open a
  2256. connection to any of the hosts in the list.
  2257.  
  2258. void smtp_close (SMTPSTREAM *stream);
  2259.     stream    stream to close
  2260.  
  2261.      This function closes the SMTP stream and frees all resources
  2262. associated with it that it may have created.
  2263.  
  2264. long smtp_mail (SMTPSTREAM *stream,char *type,ENVELOPE *msg,BODY *body);
  2265.     stream    stream to transmit mail
  2266.     type    mail type (MAIL, SEND, SAML, SOML)
  2267.     msg    message envelope
  2268.     body    message body
  2269.  
  2270.       This function negotiates an SMTP transaction of the specified type
  2271. (one of "MAIL", "SEND", "SAML", or "SOML") to deliver the specified
  2272. message.  This function returns T if success or NIL if there is any
  2273. failure.  The text reason for the failure is in stream->reply item; if
  2274. it is associated with a recipient it is also in that address'
  2275. address->error item.
  2276.  
  2277.  
  2278. void smtp_debug (SMTPSTREAM *stream);
  2279.     stream    stream to enable debugging telemetry
  2280.  
  2281.       This function enables SMTP protocol telemetry logging for this
  2282. stream.  All SMTP protocol operations are passed to the application via
  2283. the mm_dlog() facility.
  2284.  
  2285.  
  2286. void smtp_nodebug (SMTPSTREAM *stream);
  2287.     stream    stream to disable debugging telemetry
  2288.  
  2289.       This function disables SMTP protocol telemetry logging for this
  2290. stream.
  2291.  
  2292.  
  2293. typedef void (*smtpverbose_t) (char *buffer);
  2294.     buffer    pointer to verbose reply buffer
  2295.  
  2296.      This is the argument to the SET_SMTPVERBOSE mail_parmameter() call.
  2297. If this function pointer is non-NIL, then if a verbose SMTP response
  2298. (with SMTP code less than 100) is received, this function is called with
  2299. that response text as its argument.
  2300.  
  2301.                  NNTP Functions
  2302.  
  2303. NNTPSTREAM *nntp_open (char **hostlist,long debug);
  2304.     hostlist vector of NNTP server host names to try
  2305.     debug    non-zero if want protocol telemetry debugging
  2306.  
  2307.       This function opens an NNTP connection to a one of the hosts in the
  2308. host list and if successful returns a stream suitable for use by the
  2309. other MTP functions.  The hosts are tried in order until a connection is
  2310. successfully opened.  If debug is non-NIL, protocol telemetry is logged
  2311. via mm_dlog().  NIL is returned if this function fails to open a
  2312. connection to any of the hosts in the list.
  2313.  
  2314.  
  2315. void nntp_close (NNTPSTREAM *stream);
  2316.     stream    stream to close
  2317.  
  2318.      This function closes the NNTP stream and frees all resources
  2319. associated with it that it may have created.
  2320.  
  2321.  
  2322. long nntp_mail (NNTPSTREAM *stream,ENVELOPE *msg,BODY *body);
  2323.     stream    stream to transmit mail
  2324.     msg    message envelope
  2325.     body    message body
  2326.  
  2327.       This function negotiates an NNTP posting transaction to deliver
  2328. the specified news message.  This function returns T if success or NIL
  2329. if there is any failure.  The text reason for the failure is in
  2330. stream->reply item; if it is associated with a recipient it is also in
  2331. that address' address->error item.
  2332.  
  2333.               RFC 822 Support Functions
  2334.  
  2335.      Although rfc822.c contains several additional functions besides
  2336. these, only the functions documented here should be used by
  2337. applications.  The other functions are for internal use only.
  2338.  
  2339.  
  2340. void rfc822_header (char *header,ENVELOPE *env,BODY *body);
  2341.     header    buffer to write RFC 822 header
  2342.     env    message ENVELOPE (used to obtain RFC 822 information)
  2343.     body    message BODY (used to obtain MIME information)
  2344.  
  2345.      This function writes an RFC 822 format header into header based
  2346. on the information in the envelope and body.  The header buffer must
  2347. be large enough to contain the full text of the resulting header.
  2348.  
  2349.  
  2350. void rfc822_write_address (char *dest,ADDRESS *adr);
  2351.     dest    buffer to write address list
  2352.     adr    RFC 822 ADDRESS list
  2353.  
  2354.      This function writes an RFC 822 format address list into dest
  2355. based on the information in adr.  The dest buffer must be large enough
  2356. to contain the full text of the resulting address list.
  2357.  
  2358. void rfc822_parse_msg (ENVELOPE **en,BODY **bdy,char *s,unsigned long i,
  2359.                STRING *b,char *host,char *tmp);
  2360.     en    destination pointer where message ENVELOPE will be stored
  2361.     bdy    destination pointer where message BODY will be stored
  2362.     s    RFC 822 header to parse (character string)
  2363.     i    length of RFC 822 header
  2364.     b    stringstruct of message body
  2365.     host    default host name if an address lacks an @host.
  2366.     temp    scratch buffer, must be long enough to hold unwound
  2367.          header lines (a buffer that is i octets long is OK)
  2368.  
  2369.      This function parses the RFC 822 header pointed to by s with body
  2370. pointed to by string structure b into the specified destination
  2371. envelope and body pointers, using host as the default host name and
  2372. tmp as a scratch buffer.  New ENVELOPE and BODY structures are
  2373. created; when finished with them the application must free them with
  2374. mail_free_envelope() and mail_free_body().  Any parsing errors are
  2375. noted via the mm_log() mechanism using log type PARSE.
  2376.  
  2377.  
  2378. void rfc822_parse_adrlist (ADDRESS **lst,char *string,char *host);
  2379.     lst    destination pointer where ADDRESS will be stored
  2380.     string    string of addresses to parse
  2381.     host    default host name if an address lacks an @host.
  2382.  
  2383.      This function parses the address list in the given string into an
  2384. address list in lst.  Any addresses missing a host name are have the
  2385. host name defaulted from the host argument.  If the destination list
  2386. is non-empty it appends the new addresses to the list.  Any parsing
  2387. errors are noted via the mm_log() mechanism using log type PARSE.
  2388.  
  2389. long rfc822_output (char *t,ENVELOPE *env,BODY *body,soutr_t f,void *s,
  2390.             long ok8bit);
  2391.     t    scratch buffer, large enough to hold message header
  2392.     env    message ENVELOPE
  2393.     body    message BODY
  2394.     f    I/O function to write to
  2395.     s    stream for I/O function f
  2396.     ok8bit    non-zero if OK to output 8-bit data
  2397.  
  2398.      This function writes the message described with the given
  2399. envelope and body.  Any body part contents of type ENCBINARY is
  2400. converted to ENCBASE64 before sending.  If ok8bit is NIL, any message
  2401. data of type ENC8BIT is converted to ENCQUOTEDPRINTABLE before
  2402. sending; if ok8bit is non-NIL then ENC8BIT data is sent as-is.  T is
  2403. returned if the function succeeds, else NIL is returned.
  2404.  
  2405.      The function f is typically net_soutr(), but it can be any
  2406. function which matches
  2407.   typedef long (*soutr_t) (void *stream,char *string);
  2408. where stream holds sufficient information to enable the output routine
  2409. to know where to output to, and the string is a null-terminated string
  2410. to output.  This function returns either T or NIL, and that value is
  2411. passed up to rfc822_output() for its return.
  2412.  
  2413.  
  2414. void *rfc822_base64 (char *src,unsigned long srcl,unsigned long *len);
  2415.     src    source string
  2416.     srcl    size of source string in octets
  2417.     len    pointer to where destination string length in octets
  2418.          will be returned
  2419.  
  2420.      This function decodes a BASE64 body part given a source string
  2421. and its length.  The decoded body part as a sequence of binary octets
  2422. is returned, and its length is returned in len.
  2423.  
  2424.  
  2425. char *rfc822_qprint (char *src,unsigned long srcl,unsigned long *len);
  2426.     src    source string
  2427.     srcl    size of source string in octets
  2428.     len    pointer to where destination string length in octets
  2429.          will be returned
  2430.  
  2431.      This function decodes a QUOTED-PRINTABLE body part given a source
  2432. string and its length.  The decoded body part as an 8-bit character
  2433. string is returned, and its length is returned in len.
  2434.  
  2435.          Operating System-Dependent Public Interface
  2436.  
  2437.      These functions are in OS-dependent code, and are rewritten each
  2438. time c-client is ported to a new operating system.
  2439.  
  2440.  
  2441. void rfc822_date (char *date);
  2442.     date    buffer to write the date, must be large enough
  2443.  
  2444.      This function is called to get the current date and time in an
  2445. RFC 822 format string into the given buffer.
  2446.  
  2447.  
  2448. void *fs_get (size_t size);
  2449.     size    number of octets requested
  2450.  
  2451.       This function allocates and returns a block of free storage of
  2452. the specified size.  Unlike malloc(), there is no failure return; this
  2453. function must return with the requested storage.
  2454.  
  2455.  
  2456. void fs_resize (void **block,size_t size);
  2457.     block    pointer to pointer to block to be resized
  2458.     size    new size in octets
  2459.  
  2460.      This function resizes the free storage block, updating the
  2461. pointer if necessary.  Unlike realloc(), there is no failure return;
  2462. this function must return with the requested storage.
  2463.  
  2464.  
  2465. void fs_give (void **block);
  2466.     block    pointer to pointer to block to free
  2467.  
  2468.       This function releases a block of free storage allocated by
  2469. fs_get().  It also erases the block pointer, so it isn't necessary to
  2470. do this in the application.
  2471.  
  2472.  
  2473. void fatal (char *string);
  2474.     string    message string
  2475.  
  2476.       This function is called when an "impossible" error is detected
  2477. and the client wishes to crash.  The string should contain a reason.
  2478.  
  2479.  
  2480. char *strcrlfcpy (char **dst,long *dstl,char *src,long srcl);
  2481.     dst    pointer to destination string pointer
  2482.     dstl    pointer to destination string size
  2483.     src    source strin
  2484.     srcl    source string size
  2485.  
  2486.       This function is called to copy into a destination string dst of
  2487. size dstl (resized if necessary), a CRLF newline form string from
  2488. local format string src of size srcl.
  2489.  
  2490.  
  2491. TCPSTREAM *tcp_open (char *host,long port);
  2492. TCPSTREAM *tcp_aopen (char *host,char *service);
  2493. char *tcp_getline (TCPSTREAM *stream);
  2494. long tcp_getbuffer (TCPSTREAM *stream,long size,char *buffer);
  2495. long tcp_soutr (TCPSTREAM *stream,char *string);
  2496. void tcp_close (TCPSTREAM *stream);
  2497. char *tcp_host (TCPSTREAM *stream);
  2498. unsigned long tcp_port (TCPSTREAM *stream);
  2499. char *tcp_localhost (TCPSTREAM *stream);
  2500.  
  2501.      These functions are TCP-specific versions of the more general
  2502. net_xxx() functions.  These should not be called directly by
  2503. applications.
  2504.  
  2505.  
  2506. char *tcp_clienthost (char *dst);
  2507.     dst    destination string buffer
  2508.  
  2509.      This function should be called only by a server called by inetd
  2510. or similar mechanism which maps standard input to a network socket.
  2511. It returns the host name of the other end (e.g. the client of a
  2512. server) using the given string buffer, or NIL if it can't get this
  2513. information.
  2514.  
  2515.             Main Program Callbacks
  2516.  
  2517.      All applications which use the c-client must have the following
  2518. callbacks to handle events from c-client.  Note that in any callback
  2519. which involves a mail stream, the stream is locked and you can not
  2520. recursively call c-client from the callback.  This may also be true in
  2521. callbacks which do not have a stream; in general, the rule is "do not
  2522. call c-client, especially any mail_xxx() function, from a c-client
  2523. callback".
  2524.  
  2525.  
  2526. void mm_flags (MAILSTREAM *stream,unsigned long number);
  2527.     stream    stream where event happened
  2528.     number    message number
  2529.  
  2530.      This function is called when c-client manipulates the flags for
  2531. the given message number.  This alerts the application that it may
  2532. need to inspect that message's flags to see if there are any
  2533. interesting changes.
  2534.  
  2535.  
  2536. void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status);
  2537.     stream    stream where event happened
  2538.     mailbox    mailbox name for this status
  2539.     status    MAILSTATUS structure with message status
  2540.  
  2541.      This function is called when c-client reports status of a mailbox
  2542. (generally as the result of a mail_status() function call).  The
  2543. returned MAILSTATUS structure has the following members:
  2544.  
  2545. long flags;            validity flags.  These are the same as
  2546.                  the SA_xxx option flags in the
  2547.                  mail_status() call, and they indicate
  2548.                  which of the other members of the
  2549.                  MAILSTATUS structure have usable data
  2550.                  (i.e. if SA_MESSAGES is not set, do
  2551.                  not believe status->messages!!).
  2552. unsigned long messages;        number of messages if SA_MESSAGES
  2553. unsigned long recent;        number of recent messages if SA_RECENT
  2554. unsigned long unseen;        number of unseen messages if SA_UNSEEN
  2555. unsigned long uidnext;        next UID to be assigned if SA_UIDNEXT
  2556. unsigned long uidvalidity;    UID validity value if SA_UIDVALIDITY
  2557.  
  2558.  
  2559. void mm_searched (MAILSTREAM *stream,unsigned long number);
  2560.     stream    stream where event happened
  2561.     number    message number
  2562.  
  2563.      This function is called to notify the main program that this
  2564. message number matches a search (generally as the result of a
  2565. mail_search_full() function call).
  2566.  
  2567.  
  2568. void mm_exists (MAILSTREAM *stream,unsigned long number);
  2569.     stream    stream where event happened
  2570.     number    message number
  2571.  
  2572.      This function is called to notify the main program that there are
  2573. this many messages in the mailbox.  It is also used to notify the main
  2574. program of new mail, by announcing a higher number than the main
  2575. program was previously aware.
  2576.  
  2577.  
  2578. void mm_expunged (MAILSTREAM *stream,unsigned long number);
  2579.     stream    stream where event happened
  2580.     number    message number
  2581.  
  2582.      This function is called to notify the main program that this
  2583. message number has been expunged from the mail file and that all
  2584. subsequent messages are now referenced by a message number one less
  2585. than before.  This implicitly decrements the number of messages in the
  2586. mailbox.
  2587.  
  2588.  
  2589. void mm_list (MAILSTREAM *stream,char delim,char *name,long attrib);
  2590.     stream    stream where event happened
  2591.     delim    hierarchy delimiter
  2592.     name    mailbox name
  2593.     attrib    mailbox attributes
  2594.  
  2595.      This function is called to notify the main program that this
  2596. mailbox name matches a mailbox listing request (generally as the
  2597. result of a mail_list() function call).  The hierarchy delimiter is a
  2598. character that separates out levels of hierarchy in mailbox names.
  2599. The attributes are a bit mask with one of the following:
  2600.     LATT_NOINFERIORS
  2601.             it is not possible for there to be any
  2602.              hierarchy inferiors to this name (that is,
  2603.              this name followed by the hierarchy delimiter
  2604.              and additional name characters).
  2605.     LATT_NOSELECT    this is not a mailbox name, just a hierarchy
  2606.              level, and it may not be opened by mail_open()
  2607.     LATT_MARKED    this mailbox may have recent messages
  2608.     LATT_UNMARKED    this mailbox does not have any recent messages
  2609.  
  2610.  
  2611. void mm_lsub (MAILSTREAM *stream,char delim,char *name,long attrib);
  2612.     stream    stream where event happened
  2613.     delim    hierarchy delimiter
  2614.     name    mailbox name
  2615.     attrib    mailbox attributes
  2616.  
  2617.  
  2618.      This function is called to notify the main program that this
  2619. mailbox name matches a subscribed mailbox listing request (generally
  2620. as the result of a mail_lsub() function call).  The hierarchy
  2621. delimiter is a character that separates out levels of hierarchy in
  2622. mailbox names.  The attributes are a bit mask with one of the
  2623. following:
  2624.     LATT_NOINFERIORS
  2625.             it is not possible for there to be any
  2626.              hierarchy inferiors to this name (that is,
  2627.              this name followed by the hierarchy delimiter
  2628.              and additional name characters).
  2629.     LATT_NOSELECT    this is not a mailbox name, just a hierarchy
  2630.              level, and it may not be opened by mail_open()
  2631.     LATT_MARKED    this mailbox may have recent messages
  2632.     LATT_UNMARKED    this mailbox does not have any recent messages
  2633.  
  2634.  
  2635. void mm_notify (MAILSTREAM *stream,char *string,long errflg);
  2636.     stream    stream where event happened
  2637.     string    message string
  2638.     errflg    message error level
  2639.  
  2640.      This function is called to deliver a stream-oriented message
  2641. event.  This is the mechanism by which any IMAP response codes for any
  2642. application (e.g. TRYCREATE) are delivered to the application.
  2643. No newline is included in the string, so this function has to output
  2644. its own.
  2645.  
  2646.      The message error level is one of the following:
  2647.  
  2648.     NIL    normal operation.  The text is `babble' that may be
  2649.         interesting to the user, e.g. the greeting message
  2650.         from a server.
  2651.  
  2652.     WARN    A warning event.  This event should be displayed to
  2653.         the user.  Examples: a mailbox rewrite failed because
  2654.         of disk full, but the previous mailbox contents were
  2655.         recovered.
  2656.  
  2657.     ERROR    An error event.  This event should be displayed to
  2658.         the user, or at least logged someplace.  This type of
  2659.         error shouldn't happen, and so should be called to the
  2660.         attention of support staff.  Whatever happened has
  2661.         probably disrupted the user's work.  Examples: an
  2662.         untagged BAD from an IMAP server.
  2663.  
  2664.  
  2665. void mm_log (char *string,long errflg);
  2666.     string    message string
  2667.     errflg    message error level
  2668.  
  2669.       This function is called to deliver a log message.  No newline is
  2670. included in the string, so this function has to output its own.  In
  2671. general, it is intended that these messages are logged someplace, and
  2672. possibly shown to the user.
  2673.  
  2674.      The message error level is one of the following:
  2675.  
  2676.     NIL    normal operation.  The text is `babble' that may be
  2677.         interesting to the user, e.g. "Expunged 3 messages".
  2678.  
  2679.     PARSE    An RFC 822 parsing error.  Since bogus headers are
  2680.         all-too-common in the real world, these can often be
  2681.         ignored on the "garbage in, garbage out" princple.
  2682.         However, since surprising results can be yielded when
  2683.         trying to parse garbage, this message should be logged
  2684.         somewhere so it can be figured out what happened.
  2685.  
  2686.     WARN    A warning event.  This event should be displayed to
  2687.         the user.  It occurs when an error condition has
  2688.         happened, but c-client knows what to do to recover.
  2689.         Examples: "Can't open read-write, so opening
  2690.         read-only", "Empty mailbox", "Login failed, try
  2691.         again", "Waiting for mailbox to become unlocked",
  2692.         "IMAP protocol error".  Although a user should be
  2693.         told about a warning, it's generally not necessary
  2694.         to interrupt the flow of her work (e.g. it's alright
  2695.         to display the warning in a scrolling window, but
  2696.         not necessary to require the user to do anything).
  2697.  
  2698.     ERROR    An error event.  This event should be displayed to
  2699.         the user, or at least logged someplace.  This is a
  2700.         serious error condition occured that aborted the
  2701.         requested operation and possibly also aborted the mail
  2702.         stream.  This ranges from normal error conditions such
  2703.         as "Can't open mailbox", "too many login failures, go
  2704.         away" to bizarre conditions such as "Apparent new mail
  2705.         appeared in the mailbox that doesn't look like mail,
  2706.         program aborting".  Errors must be called to the
  2707.         user's attention, and probably should require some
  2708.         sort of acknowledgement (e.g. answering a modal panel)
  2709.         before the application proceeds.
  2710.  
  2711.  
  2712. void mm_dlog (char *string);
  2713.     string message string
  2714.  
  2715.       This function is called to deliver a debugging telemetry
  2716. message.  No newline is included in the string, so this function has
  2717. to output its own.  This is called only when debugging is enabled.
  2718.  
  2719.  
  2720. void mm_login (NETMBX *mb,char *user,char *pwd,long trial);
  2721.     mb    parsed mailbox specification
  2722.     user    pointer to where to return user name
  2723.     pwd    pointer to where to return password
  2724.     trial    number of prior login attempts
  2725.  
  2726.       This function is called to get a user name and password for the
  2727. given network mailbox.  It stores the user name and password in the
  2728. strings pointed to by the appropriate arguments.  The trial argument
  2729. is the number of attempts to perform the login and is initially zero
  2730. (e.g. for a default username and password login functionality).  It is
  2731. incremented for each subsequent trial until the maximum number of
  2732. trials are made.
  2733.  
  2734.  
  2735. void mm_critical (MAILSTREAM *stream);
  2736.     stream    stream where event happened
  2737.  
  2738.       This function is called to alert the application that c-client
  2739. is about to run some critical code on that stream that may result in a
  2740. clobbered mail file if it is interrupted.  It may be desirable to
  2741. disable CTRL/C, etc. during this time.
  2742.  
  2743.  
  2744. void mm_nocritical (MAILSTREAM *stream);
  2745.     stream    stream where event happened
  2746.  
  2747.       This function is called to alert the application that c-client
  2748. is no longer running critical code on that stream that may result in a
  2749. clobbered mail file if it is interrupted.
  2750.  
  2751.  
  2752. long mm_diskerror (MAILSTREAM *stream,long errcode,long serious);
  2753.     stream    stream where event happened
  2754.     errcode    OS error code for disk error
  2755.     serious    non-zero if c-client can not undo the operation (and
  2756.          thus must retry to avoid mail file damage)
  2757.  
  2758.       This function is called to alert the application that the
  2759. c-client has encountered an unrecoverable write error when trying to
  2760. update the mail file.  errcode contains the system error code.  If
  2761. serious is non-zero, then it is probable that the disk copy of the
  2762. mailbox has been damaged.
  2763.  
  2764.      The return value from this function is the abort flag; if serious
  2765. is zero and the abort flag is non-zero, the operation is aborted.  If
  2766. the abort flag is zero or if serious was non-zero, a return from this
  2767. function will retry the failing operation.
  2768.  
  2769.  
  2770. void mm_fatal (char *string);
  2771.     string    message string
  2772.  
  2773.       This function is called from the fatal() routine in the
  2774. operating system code to notify the main program that it is about to
  2775. crash.  The string contains a reason.  At the very minimum, the main
  2776. program should do something like
  2777.  mm_log (string,ERROR);
  2778. and then return.  No newline is included in the string, so this
  2779. function has to output its own.
  2780.  
  2781.                  Driver interface
  2782.  
  2783.      When writing a new driver for the c-client, you must provide a
  2784. DRIVER stucture giving a dispatch vector between MAIL and the driver.
  2785. The DRIVER dispatch vector is described in mail.h.
  2786.  
  2787. char *name;
  2788.      Name by which the driver is known to c-client.
  2789.  
  2790. unsigned long flags;
  2791.      Attribute flags for this driver:
  2792.     DR_DISABLE    This driver is currently disabled.
  2793.     DR_LOCAL    This driver deals with local mailboxes; if
  2794.              this is off it deals with mailboxes over a
  2795.              network.
  2796.     DR_MAIL        This driver supports e-mail messages.
  2797.     DR_NEWS        This driver supports netnews messages
  2798.     DR_READONLY    This driver only allows read-only access;
  2799.              mail_setflag(), mail_expunge(), etc. are
  2800.              no-ops.
  2801.     DR_NOFAST    This driver does not implement mail_fetchfast()
  2802.              in a fast way (e.g. it may have to fetch the
  2803.              entire message text over a network to
  2804.              calculate sizes).
  2805.     DR_NAMESPACE    This driver accepts and uses namespace format
  2806.              names.
  2807.     DR_LOWMEM    This driver is designed for systems with very
  2808.              limited amounts of memory (e.g. DOS) and
  2809.              support routines called by this driver should
  2810.              try not to use much memory.
  2811.  
  2812. DRIVER *next;
  2813.      Pointer to the next driver which this application supports (or NIL if
  2814. this is the last driver).  Drivers are lunk together via the mail_link()
  2815. function.
  2816.  
  2817. DRIVER *driver_valid (char *mailbox);
  2818.      This function returns a pointer to the driver's DRIVER dispatch
  2819. vector iff this driver accepts the given name as a valid mailbox for this
  2820. driver.  Otherwise, it returns the value of the next driver's
  2821. driver_valid() or NIL if there is no next driver.  In other words, calling
  2822. driver_valid() for the first driver will return the driver dispatch vector
  2823. for the driver which supports this type of mailbox.
  2824.  
  2825. void *driver_parameters (long function,void *value);
  2826.      This function implements mail_parameters() for this driver.
  2827.  
  2828. void driver_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents);
  2829.      This function implements mail_scan() for this driver.
  2830.  
  2831. void driver_list (MAILSTREAM *stream,char *ref,char *pat);
  2832.      This function implements mail_list() for this driver.
  2833.  
  2834. void driver_lsub (MAILSTREAM *stream,char *ref,char *pat);
  2835.      This function implements mail_lsub() for this driver.
  2836.  
  2837. long driver_subscribe (MAILSTREAM *stream,char *mailbox);
  2838.      This function implements mail_subscribe() for this driver.
  2839.  
  2840. long driver_unsubscribe (MAILSTREAM *stream,char *mailbox);
  2841.      This function implements mail_unsubscribe() for this driver.
  2842.  
  2843. long driver_create (MAILSTREAM *stream,char *mailbox);
  2844.      This function implements mail_create() for this driver.
  2845.  
  2846. long driver_delete (MAILSTREAM *stream,char *mailbox);
  2847.      This function implements mail_delete() for this driver.
  2848.  
  2849. long driver_rename (MAILSTREAM *stream,char *old,char *new);
  2850.      This function implements mail_rename() for this driver.
  2851.  
  2852. long driver_status (MAILSTREAM *stream,char *mailbox,long flags);
  2853.      This function implements mail_status() for this driver.
  2854.  
  2855. MAILSTREAM *driver_open (MAILSTREAM *stream);
  2856.      This function opens the mailbox identified by the given stream.  It
  2857. may use the data on the stream and create additional data on stream->local
  2858. as necessary.  It should return the given stream unless it failed to open
  2859. the mailbox, in which case it should return NIL.
  2860.  
  2861. void driver_close (MAILSTREAM *stream,long options);
  2862.      This function implements mail_close() for this driver.
  2863.  
  2864. void driver_fetchfast (MAILSTREAM *stream,char *sequence,long flags);
  2865.      This function implements mail_fetchfast() for this driver.
  2866.  
  2867. void driver_fetchflags (MAILSTREAM *stream,char *sequence,long flags);
  2868.      This function implements mail_fetchflags() for this driver.
  2869.  
  2870. ENVELOPE *driver_fetchstructure (MAILSTREAM *stream,unsigned long msgno,
  2871.                  BODY **body,long flags);
  2872.      This function implements mail_fetchstructure() for this driver.
  2873.  
  2874. char *driver_fetchheader (MAILSTREAM *stream,unsigned long msgno,
  2875.               STRINGLIST *lines,unsigned long *len,long flags);
  2876.      This function implements mail_fetchheader() for this driver.
  2877.  
  2878. char *driver_fetchtext (MAILSTREAM *stream,unsigned long msgno,
  2879.             unsigned long *len,long flags);
  2880.      This function implements mail_fetchtext() for this driver.
  2881.  
  2882. char *driver_fetchbody (MAILSTREAM *stream,unsigned long msgno,char *section,
  2883.             unsigned long *len,long flags);
  2884.      This function implements mail_fetchbody() for this driver.
  2885.  
  2886. void driver_setflag (MAILSTREAM *stream,char *sequence,char *flag,long flags);
  2887.      This function implements mail_setflag() for this driver.
  2888.  
  2889. void driver_clearflag (MAILSTREAM *stream,char *sequence,char *flag,
  2890.                long flags);
  2891.      This function implements mail_clearflag() for this driver.
  2892.  
  2893. void driver_search (MAILSTREAM *stream,char *charset,SEARCHPGM *pgm,
  2894.             long flags);
  2895.      This function implements mail_search() for this driver.
  2896.  
  2897. unsigned long *driver_sort (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
  2898.                 SORTPGM *pgm,long flags);
  2899.      This function implements mail_sort() for this driver.
  2900.  
  2901. void *driver_thread (MAILSTREAM *stream,char *seq,long function,long flag);
  2902.      This dispatch is reserved for a future threading capability.
  2903.  
  2904. long driver_ping (MAILSTREAM *stream);
  2905.       This function implements mail_ping() for this driver.
  2906.  
  2907. void driver_check (MAILSTREAM *stream);
  2908.       This function implements mail_check() for this driver.
  2909.  
  2910. void driver_expunge (MAILSTREAM *stream);
  2911.       This function implements mail_expunge() for this driver.
  2912.  
  2913. long driver_copy (MAILSTREAM *stream,char *sequence,char *mailbox,
  2914.           long options);
  2915.       This function implements mail_copy() for this driver.
  2916.  
  2917. long driver_append (MAILSTREAM *stream,char *mailbox,char *flags,char *date,
  2918.             STRING *message);
  2919.       This function implements mail_append() for this driver.
  2920.  
  2921. void driver_gc (MAILSTREAM *stream,long gcflags);
  2922.       This function implements mail_gc() for this driver.
  2923.  
  2924.              Driver Support Functions
  2925.  
  2926. void mail_searched (MAILSTREAM *stream,unsigned long msgno);
  2927.     stream    stream where event happened
  2928.     msgno    message number
  2929.  
  2930.      This function is called by the driver to notify c-client that this
  2931. message number matches a search.  It invokes the main program's
  2932. mm_searched() function.
  2933.  
  2934. void mail_exists (MAILSTREAM *stream,unsigned long nmsgs);
  2935.     stream    stream where event happened
  2936.     nmsgs    number of messages
  2937.  
  2938.      This function is called by the driver to notify c-client that this
  2939. message number exists (i.e. there are this many messages in the mailbox).
  2940. It invokes the main program's mm_exists() function.
  2941.  
  2942. void mail_recent (MAILSTREAM *stream,unsigned long recent);
  2943.     stream    stream where event happened
  2944.     recent    number of messages
  2945.  
  2946.       This function is called by the driver to notify c-client that this
  2947. many messages are "recent" (i.e. arrived in the mailbox since the previous
  2948. time the mailbox was opened).
  2949.  
  2950. void mail_expunged (MAILSTREAM *stream,unsigned long msgno);
  2951.     stream    stream where event happened
  2952.     msgno    number of messages
  2953.  
  2954.       This function is called by the driver to notify MAIL that this
  2955. message number has been expunged from the mail file and that all subsequent
  2956. messages are no references by a message number one less than before.  It
  2957. invokes the main program's mm_expunged() function.
  2958.  
  2959. void mail_lock (MAILSTREAM *stream);
  2960.     stream    stream where event happened
  2961.       This function sets the stream lock.  It is an error to set the stream
  2962. lock if the stream is already locked.
  2963.  
  2964.       This is mainly used to catch errors due to a callback function
  2965. (e.g. mm_exists) inadvertantly recursing back to the MAIL routines and
  2966. establishing an infinite recursion.  Normally, drivers will set the lock
  2967. prior to calling one of the callback functions above or, more likely, in
  2968. the beginning of the driver's non-reentrant "do operation" section.  In the
  2969. IMAP4 driver, the stream lock is set when entering imap_send() and cleared
  2970. on exit.
  2971.  
  2972. void mail_unlock (MAILSTREAM *stream);
  2973.     stream    stream where event happened
  2974.  
  2975.      This function releases the stream lock.  It is an error to release the
  2976. stream lock if the stream is not locked.
  2977.