home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / pine3.07 / c-client / mail.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-06  |  12.7 KB  |  430 lines

  1. /*
  2.  * Program:    Mailbox Access routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    22 November 1989
  13.  * Last Edited:    6 May 1992
  14.  *
  15.  * Copyright 1992 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36. /* Build parameters */
  37.  
  38. #define CACHEINCREMENT 100    /* cache growth increments */
  39. #define MAILTMPLEN 1024        /* size of a temporary buffer */
  40. #define MAXMESSAGESIZE 65000    /* MS-DOS: maximum text buffer size
  41.                  * other:  initial text buffer size */
  42. #define NUSERFLAGS 30        /* # of user flags (current servers 30 max) */
  43.  
  44.  
  45. /* Constants */
  46.  
  47. #define NIL 0            /* convenient name */
  48. #define T 1            /* opposite of NIL */
  49.  
  50. #define WARN (long) 1        /* mm_log warning type */
  51. #define ERROR (long) 2        /* mm_log error type */
  52. #define PARSE (long) 3        /* mm_log parse error type */
  53.  
  54.  
  55. /* Garbage collection flags */
  56.  
  57. #define GC_ELT (long) 1        /* message cache elements */
  58. #define GC_ENV (long) 2        /* envelopes and bodies */
  59. #define GC_TEXTS (long) 4    /* cached texts */
  60.  
  61. /* Message structures */
  62.  
  63.  
  64. /* Item in an address list */
  65.  
  66. #define ADDRESS struct mail_address
  67. ADDRESS {
  68.   char *personal;        /* personal name phrase */
  69.   char *adl;            /* at-domain-list source route */
  70.   char *mailbox;        /* mailbox name */
  71.   char *host;            /* domain name of mailbox's host */
  72.   char *error;            /* error in address from SMTP module */
  73.   ADDRESS *next;        /* pointer to next address in list */
  74. };
  75.  
  76.  
  77. /* Message envelope */
  78.  
  79. typedef struct mail_envelope {
  80.   char *remail;            /* remail header if any */
  81.   ADDRESS *return_path;        /* error return address */
  82.   char *date;            /* message composition date string */
  83.   ADDRESS *from;        /* originator address list */
  84.   ADDRESS *sender;        /* sender address list */
  85.   ADDRESS *reply_to;        /* reply address list */
  86.   char *subject;        /* message subject string */
  87.   ADDRESS *to;            /* primary recipient list */
  88.   ADDRESS *cc;            /* secondary recipient list */
  89.   ADDRESS *bcc;            /* blind secondary recipient list */
  90.   char *in_reply_to;        /* replied message ID */
  91.   char *message_id;        /* message ID */
  92.   char *newsgroups;        /* USENET newsgroups */
  93. } ENVELOPE;
  94.  
  95. /* Primary body types */
  96. /* If you change any of these you must also change body_types in rfc822.c */
  97.  
  98. extern const char *body_types[];/* defined body type strings */
  99.  
  100. #define TYPETEXT 0        /* unformatted text */
  101. #define TYPEMULTIPART 1        /* multiple part */
  102. #define TYPEMESSAGE 2        /* encapsulated message */
  103. #define TYPEAPPLICATION 3    /* application data */
  104. #define TYPEAUDIO 4        /* audio */
  105. #define TYPEIMAGE 5        /* static image */
  106. #define TYPEVIDEO 6        /* video */
  107. #define TYPEOTHER 7        /* unknown */
  108.  
  109.  
  110. /* Body encodings */
  111. /* If you change any of these you must also change body_encodings in rfc822.c
  112.  */
  113.  
  114.                 /* defined body encoding strings */
  115. extern const char *body_encodings[];
  116.  
  117. #define ENC7BIT 0        /* 7 bit SMTP semantic data */
  118. #define ENC8BIT 1        /* 8 bit SMTP semantic data */
  119. #define ENCBINARY 2        /* 8 bit binary data */
  120. #define ENCBASE64 3        /* base-64 encoded data */
  121. #define ENCQUOTEDPRINTABLE 4    /* human-readable 8-as-7 bit data */
  122. #define ENCOTHER 5        /* unknown */
  123.  
  124.  
  125. /* Body contents */
  126.  
  127. #define BINARY void
  128. #define BODY struct mail_body
  129. #define MESSAGE struct mail_body_message
  130. #define PARAMETER struct mail_body_parameter
  131. #define PART struct mail_body_part
  132.  
  133. /* Message content (ONLY for parsed messages) */
  134.  
  135. MESSAGE {
  136.   ENVELOPE *env;        /* message envelope */
  137.   BODY *body;            /* message body */
  138.   char *text;            /* message in RFC-822 form */
  139.   unsigned long offset;        /* offset of text from header */
  140. };
  141.  
  142.  
  143. /* Parameter list */
  144.  
  145. PARAMETER {
  146.   char *attribute;        /* parameter attribute name */
  147.   char *value;            /* parameter value */
  148.   PARAMETER *next;        /* next parameter in list */
  149. };
  150.  
  151.  
  152. /* Message body structure */
  153.  
  154. BODY {
  155.   unsigned short type;        /* body primary type */
  156.   unsigned short encoding;    /* body transfer encoding */
  157.   char *subtype;        /* subtype string */
  158.   PARAMETER *parameter;        /* parameter list */
  159.   char *id;            /* body identifier */
  160.   char *description;        /* body description */
  161.   union {            /* different ways of accessing contents */
  162.     unsigned char *text;    /* body text (+ enc. message in composing) */
  163.     BINARY *binary;        /* body binary */
  164.     PART *part;            /* body part list */
  165.     MESSAGE msg;        /* body encapsulated message (PARSE ONLY) */
  166.   } contents;
  167.   struct {
  168.     unsigned long lines;    /* size in lines */
  169.     unsigned long bytes;    /* size in bytes */
  170.     unsigned long ibytes;    /* internal size in bytes (drivers ONLY!!) */
  171.   } size;
  172. };
  173.  
  174.  
  175. /* Multipart content list */
  176.  
  177. PART {
  178.   BODY body;            /* body information for this part */
  179.   unsigned long offset;        /* offset from body origin */
  180.   PART *next;            /* next body part */
  181. };
  182.  
  183. /* Entry in the message cache array */
  184.  
  185. typedef struct message_cache {
  186.   unsigned short lockcount;    /* non-zero if multiple references */
  187.   unsigned long msgno;        /* message number */
  188.   unsigned int seen : 1;    /* system Seen flag */
  189.   unsigned int deleted : 1;    /* system Deleted flag */
  190.   unsigned int flagged : 1;     /* system Flagged flag */
  191.   unsigned int answered : 1;    /* system Answered flag */
  192.   unsigned int searched : 1;    /* message was searched */
  193.   unsigned int recent : 1;    /* message is new as of this mailbox open */
  194.   unsigned int sequence : 1;    /* message is in sequence */
  195.   unsigned int spare : 1;    /* reserved for use by main programs */
  196.   unsigned long user_flags;    /* user-assignable flags */
  197.   unsigned long rfc822_size;    /* # of bytes of message as raw RFC822 */
  198.   char *internal_date;        /* date message placed in mailbox */
  199.   ENVELOPE *env;        /* pointer to message envelope */
  200.   BODY *body;            /* pointer to message body */
  201. } MESSAGECACHE;
  202.  
  203. /* Mail Access I/O stream */
  204.  
  205.  
  206. /* Structure for mail driver dispatch */
  207.  
  208. #define DRIVER struct driver    
  209.  
  210.  
  211. /* Mail I/O stream */
  212.  
  213. typedef struct mail_stream {
  214.   DRIVER *dtb;            /* dispatch table for this driver */
  215.   void *local;            /* pointer to driver local data */
  216.   char *mailbox;        /* mailbox name */
  217.   unsigned int lock : 1;    /* stream lock flag */
  218.   unsigned int debug : 1;    /* stream debug flag */
  219.   unsigned int silent : 1;    /* silent stream from Tenex */
  220.   unsigned int readonly : 1;    /* stream read-only flag */
  221.   unsigned int anonymous : 1;    /* stream anonymous access flag */
  222.   unsigned short use;        /* stream use count */
  223.   unsigned short sequence;    /* stream sequence */
  224.   unsigned long gensym;        /* generated tag */
  225.   unsigned long nmsgs;        /* # of associated msgs */
  226.   unsigned long recent;        /* # of recent msgs */
  227.   char *flagstring;        /* buffer of user keyflags */
  228.   char *user_flags[NUSERFLAGS];    /* pointers to user flags in bit order */
  229.   unsigned long cachesize;    /* size of message cache */
  230.   MESSAGECACHE **cache;        /* message cache array */
  231. } MAILSTREAM;
  232.  
  233.  
  234. /* Mail I/O stream handle */
  235.  
  236. typedef struct mail_stream_handle {
  237.   MAILSTREAM *stream;        /* pointer to mail stream */
  238.   unsigned short sequence;    /* sequence of what we expect stream to be */
  239. } MAILHANDLE;
  240.  
  241.  
  242. /* Jacket into external mailgets interface */
  243.  
  244. typedef long (*readfn_t)  ();
  245. typedef char *(*mailgets_t)  ();
  246.  
  247. extern mailgets_t mailgets;
  248.  
  249. /* Mail driver dispatch */
  250.  
  251. DRIVER {
  252.   DRIVER *next;            /* next driver */
  253.                 /* mailbox is valid for us */
  254.   DRIVER *(*valid) ();
  255.                 /* find mailboxes */
  256.   void (*find) ();
  257.                 /* find bboards */
  258.   void (*find_bboard) ();
  259.                 /* open mailbox */
  260.   MAILSTREAM *(*open) ();
  261.                 /* close mailbox */
  262.   void (*close) ();
  263.                 /* fetch message "fast" attributes */
  264.   void (*fetchfast) ();
  265.                 /* fetch message flags */
  266.   void (*fetchflags) ();
  267.                 /* fetch message envelopes */
  268.   ENVELOPE *(*fetchenvelope) ();
  269.                 /* fetch message header only */
  270.   char *(*fetchheader) ();
  271.                 /* fetch message body only */
  272.   char *(*fetchtext) ();
  273.                 /* fetch message body section */
  274.   char *(*fetchbody) ();
  275.                 /* set message flag */
  276.   void (*setflag) ();
  277.                 /* clear message flag */
  278.   void (*clearflag) ();
  279.                 /* search for message based on criteria */
  280.   void (*search) ();
  281.                 /* ping mailbox to see if still alive */
  282.   long (*ping) ();
  283.                 /* check for new messages */
  284.   void (*check) ();
  285.                 /* expunge deleted messages */
  286.   void (*expunge) ();
  287.                 /* copy messages to another mailbox */
  288.   long (*copy) ();
  289.                 /* move messages to another mailbox */
  290.   long (*move) ();
  291.                 /* garbage collect stream */
  292.   void (*gc) ();
  293. };
  294.  
  295. /* Coddle certain compilers' 6-character symbol limitation */
  296.  
  297. #ifdef __COMPILER_KCC__
  298. #define mm_searched mmsrhd
  299. #define mm_exists mmexst
  300. #define mm_expunged mmexpn
  301. #define mm_notify mmntfy
  302. #define mm_mailbox mmmlbx
  303. #define mm_bboard mmbbrd
  304. #define mm_log mmlog
  305. #define mm_dlog mmdlog
  306. #define mm_login mmlogn
  307. #define mm_critical mmcrit
  308. #define mm_nocritical mmncrt
  309. #define mm_diskerror mmderr
  310. #define mm_fatal mmfatl
  311. #define mail_link mllink
  312. #define mail_find mlfind
  313. #define mail_find_bboards mlfndb
  314. #define mail_open mlopen
  315. #define mail_close mlclse
  316. #define mail_makehandle mlmkha
  317. #define mail_free_handle mlfrha
  318. #define mail_stream mlstrm
  319. #define mail_fetchfast mlffst
  320. #define mail_fetchflags mlfflg
  321. #define mail_fetchenvelope mlfenv
  322. #define mail_fetchheader mlfhdr
  323. #define mail_fetchtext mlftxt
  324. #define mail_fetchbody mlfbdy
  325. #define mail_fetchfrom mlffrm
  326. #define mail_fetchsubject mlfsub
  327. #define mail_elt mlelt
  328. #define mail_cache mlcach
  329. #define mail_setflag mlsflg
  330. #define mail_clearflag mlcflg
  331. #define mail_search mlsrch
  332. #define mail_ping mlping
  333. #define mail_check mlchck
  334. #define mail_expunge mlexpn
  335. #define mail_copy mlcopy
  336. #define mail_move mlmove
  337. #define mail_gc mailgc
  338. #define mail_searched mlsrch
  339. #define mail_exists mlexist
  340. #define mail_recent mlrcnt
  341. #define mail_expunged mlexst
  342. #define mail_lock mllock
  343. #define mail_unlock mlulck
  344. #define mail_debug mldbug
  345. #define mail_nodebug mlndbg
  346. #define mail_sequence mlsequ
  347. #define mail_newenvelope mlnenv
  348. #define mail_newaddr mlnadr
  349. #define mail_newbody mlnbod
  350. #define mail_initbody mlibod
  351. #define mail_newbody_parameter mlnbpr
  352. #define mail_newbody_part mlnbpt
  353. #define mail_free_body mlfrbd
  354. #define mail_free_body_data mlfrbt
  355. #define mail_free_body_parameter mlfrbr
  356. #define mail_free_body_part mlfrbp
  357. #define mail_free_cache mlfrch
  358. #define mail_free_elt mlfrel
  359. #define mail_free_envelope mlfren
  360. #define mail_free_address mlfrad
  361. #endif
  362.  
  363. /* Function prototypes */
  364.  
  365. void mm_searched  ();
  366. void mm_exists  ();
  367. void mm_expunged  ();
  368. void mm_notify  ();
  369. void mm_mailbox  ();
  370. void mm_bboard  ();
  371. void mm_log  ();
  372. void mm_dlog  ();
  373. void mm_login  ();
  374. void mm_critical  ();
  375. void mm_nocritical  ();
  376. long mm_diskerror  ();
  377. void mm_fatal  ();
  378. char *mm_gets  ();
  379.  
  380. void mail_link  ();
  381. void mail_find  ();
  382. void mail_find_bboards  ();
  383. MAILSTREAM *mail_open  ();
  384. MAILSTREAM *mail_close  ();
  385. MAILHANDLE *mail_makehandle  ();
  386. void mail_free_handle  ();
  387. MAILSTREAM *mail_stream  ();
  388. void mail_fetchfast  ();
  389. void mail_fetchflags  ();
  390. ENVELOPE *mail_fetchenvelope  ();
  391. char *mail_fetchheader  ();
  392. char *mail_fetchtext  ();
  393. char *mail_fetchbody  ();
  394. void mail_fetchfrom  ();
  395. void mail_fetchsubject  ();
  396. MESSAGECACHE *mail_elt  ();
  397. void mail_cache  ();
  398. void mail_setflag  ();
  399. void mail_clearflag  ();
  400. void mail_search  ();
  401. long mail_ping  ();
  402. void mail_check  ();
  403. void mail_expunge  ();
  404. long mail_copy  ();
  405. long mail_move  ();
  406. void mail_gc  ();
  407. void mail_searched  ();
  408. void mail_exists  ();
  409. void mail_recent  ();
  410. void mail_expunged  ();
  411. void mail_lock  ();
  412. void mail_unlock  ();
  413. void mail_debug  ();
  414. void mail_nodebug  ();
  415. long mail_sequence  ();
  416. ENVELOPE *mail_newenvelope  ();
  417. ADDRESS *mail_newaddr  ();
  418. BODY *mail_newbody  ();
  419. BODY *mail_initbody  ();
  420. PARAMETER *mail_newbody_parameter  ();
  421. PART *mail_newbody_part  ();
  422. void mail_free_body  ();
  423. void mail_free_body_data  ();
  424. void mail_free_body_parameter  ();
  425. void mail_free_body_part  ();
  426. void mail_free_cache  ();
  427. void mail_free_elt  ();
  428. void mail_free_envelope  ();
  429. void mail_free_address  ();
  430.