home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mm / mm-0.90 / rd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-18  |  6.9 KB  |  183 lines

  1. /*
  2.  * Copyright (c) 1986, 1990 by The Trustees of Columbia University in
  3.  * the City of New York.  Permission is granted to any individual or
  4.  * institution to use, copy, or redistribute this software so long as it
  5.  * is not sold for profit, provided this copyright notice is retained.
  6.  */
  7.  
  8. #ifdef RCSID
  9. #ifndef lint
  10. static char *rd_rcsid = "$Header: /f/src2/encore.bin/cucca/mm/tarring-it-up/RCS/rd.h,v 2.3 90/10/04 18:25:40 melissa Exp $";
  11. #endif
  12. #endif /* RCSID */
  13.  
  14. /* rd.h: stuff for rd.c, and so file.c understands rd.c */
  15.  
  16. /*
  17.  * structure to handle operations on messages
  18.  */
  19. typedef struct msghandler {
  20.     char *typename;            /* what type is this */
  21.     int (*open)();            /* open a file */
  22.     int (*close)();            /* close the file */
  23.     int (*rd_msg)();            /* read a message */
  24.     int (*wr_msg)();            /* write a message */
  25.     int (*probe)();            /* query the file type */
  26. } msg_handler;
  27.  
  28. /* 
  29.  * some comments about the different routines...  
  30.  */
  31.  
  32. #define OP_APP        0001        /* open for appending */
  33. #define OP_INT        0002        /* interactive errors */
  34. #define OP_PND        0004        /* ignore poundfile */
  35. /*
  36.  * open:
  37.  *
  38.  * Given a msgvec structure (nf) and a flags word, this routine should
  39.  * open the file named in nf->filename (for read-only if nf->flags
  40.  * contains MF_RDONLY and read/write otherwise).  It is responsible for 
  41.  * locking the file (if opening it for writing or appending) to prevent
  42.  * simultaneous access by other processes running mm.  Something like
  43.  * the UNIX flock(2) would be good.
  44.  *
  45.  * If the flags word contains OP_APP, meaning we're just appending to
  46.  * a file, don't read in any messages.  If this is a non-contiguous
  47.  * format, which requires a current message count to do an append,
  48.  * determine that count.
  49.  *
  50.  * If OP_APP is not on, always determine the number of messages in the
  51.  * mail file (reading them in if counting requires that and space
  52.  * allows).  Also determine the size of the file.
  53.  *
  54.  * If OP_INT is on, meaning this file was parsed interactively, give
  55.  * error messages directly to user (with cmerr?), else pass back error.
  56.  *
  57.  * If OP_PND is on, caller acknowledges that there is already a
  58.  * #filename# (pound) backup file, so ignore it.  If OP_PND is not 
  59.  * on and #filename# exists, give an error and make the file read-only.
  60.  * (the #filename# only exists when running update, so indicates an error
  61.  * otherwise -- cras
  62.  *
  63.  * The pointer to FILE goes in nf->filep, and the count of messages
  64.  * goes in nf->count.  A set of message structures (possibly all
  65.  * flagged empty) should be allocated into nf->msgs if append is
  66.  * false.  The size of the file should go into nf->size.
  67.  */
  68.  
  69. /*
  70.  * close: 
  71.  *
  72.  * Given a FILE pointer (fp), this should simply close the
  73.  * corresponding file, closing any sessions (as in POP) as necessary.
  74.  * It should release any locks that were set by the open routine.
  75.  */
  76.  
  77. #define RD_OK        0
  78. #define RD_EOF        1
  79. #define RD_FAIL        2
  80.  
  81. /*
  82.  * rd_msg:
  83.  *
  84.  * Given a msgvec structure (nf) and a message number (n), this should
  85.  * read the nth message from the file into nf->msgs[n].  (This
  86.  * structure is assumed to exist already.)  It should fill in the
  87.  * size, flags, from (possibly with null), date, and text fields of
  88.  * the message structure.  rd_msg is expected to use nf->last_read to
  89.  * keep track of which message it read last, and optimize away any
  90.  * unnecessary rewinding of the file.  The rd_msg routine returns RD_OK
  91.  * if the message was read successfully, RD_EOF if the file ends just
  92.  * before this message (that is, there are exactly n-1 messages in the
  93.  * file), and RD_FAIL otherwise.
  94.  *
  95.  * Note that the from field of the message structure, if non-NULL,
  96.  * should be malloc'ed, since it will be free'd.
  97.  */
  98.  
  99. #define WR_COPY        0001        /* copy to new file */
  100. #define WR_SAVE        0002        /* save to old file */
  101. #define WR_EXP        0004        /* expunge deleted messages */
  102. /*
  103.  * wr_msg:
  104.  *
  105.  * Given ptrs to a msgvec structure (mail) and a message structure
  106.  * (msg), a number (n), and a flags word, this makes sure message is
  107.  * written out to the file associated with mail as the nth message.
  108.  *
  109.  * If WR_COPY is in the flags word, we're copying this message into
  110.  * another file.  n is ignored and message is written to the end of
  111.  * the mail file as the mail->count+1th message (incrementing
  112.  * mail->count).
  113.  *
  114.  * If WR_SAVE is on, we're saving the whole file.  For contiguous
  115.  * formats (like mtxt) this means to write message out at the end of
  116.  * the file (requiring no rewinds or fseeks).  For non-contiguous
  117.  * formats (like mh), the message should only be written out if
  118.  * M_MODIFIED is on for that message.  For either format, we should
  119.  * keep mail->size up to date -- however, this may be left until the
  120.  * last message is written to avoid unnecessary overhead.
  121.  *
  122.  * If WR_EXP is on, it is assumed that WR_SAVE is on as well and we
  123.  * are doing an expunge.  This means that for contiguous files,
  124.  * messages with M_DELETED on in their flags word should not be
  125.  * written out.  For non-contiguous files the message-file should
  126.  * actually be deleted at this time (after being copied to a ~ file).
  127.  *
  128.  * If neither WR_SAVE nor WR_COPY is on, we have modified the text of
  129.  * a message.  For a non-contiguous format file, the message should be
  130.  * written out, but for a contiguous format wr_msg should just flag
  131.  * the fact that the mail file must be written out before the file is
  132.  * closed (by setting MF_DIRTY in mail->flags).
  133.  * 
  134.  * After a message is written out, a fflush (or the equivalent for
  135.  * that format) should be done to make sure it gets written.
  136.  *
  137.  * Whenever any message is written out without WR_COPY on (meaning it
  138.  * is written to its original file), M_MODIFIED should be cleared in
  139.  * its flags word, and if it is a non-contiguous format, the message
  140.  * being overwritten should first be saved to a file of the same name
  141.  * with a ~ appended.
  142.  */
  143.  
  144. #define PR_NAME        0000    /* badly formed name, didn't look at file */
  145. #define PR_NOEX        0001    /* file does not exist */
  146. #define PR_PERM        0002    /* file exists, but couldn't read it */
  147. #define PR_NOTOK    0003    /* file non-empty, but not this format */
  148. #define PR_EMPTY    0004    /* we could read it, but it's empty */
  149. #define PR_OK        0005    /* file is in this format */
  150. /*
  151.  * probe:
  152.  *
  153.  * Given a filename, this should see if the specified file is of this
  154.  * format, any way that works.  Passes back the most exact of the true
  155.  * return codes.  (The maximum of the various return codes is used to
  156.  * determine the true status of the file.)
  157.  *
  158.  * Note that it is VERY IMPORTANT that this routine give the right
  159.  * answer, especially for PR_OK, since mail will be unreadable if the
  160.  * format is incorrect.
  161.  */
  162.  
  163. /*
  164.  * rename:
  165.  */
  166.  
  167. #ifndef MSGOPS
  168. extern msg_handler msg_ops[];
  169. #endif
  170.  
  171. /*
  172.  * keep these in alphabetical order to line up with all the other tables
  173.  * and make sure it matches the stuff in rd.c
  174.  *
  175.  * whenever a type is added here, it must be added to cmds.H as well!!
  176.  */
  177. #define TYPE_BABYL 0
  178. #define TYPE_MBOX  1
  179. #define TYPE_MH    2
  180. #define TYPE_MTXT  3
  181. #define TYPE_POP2  4
  182. #define TYPE_POP3  5
  183.