home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / pcmail / main / mbox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  6.2 KB  |  222 lines

  1. /*++
  2. /* NAME
  3. /*      mbox 3
  4. /* SUMMARY
  5. /*      display and manipulate one non-work message
  6. /* PROJECT
  7. /*      pc-mail
  8. /* PACKAGE
  9. /*      mail
  10. /* SYNOPSIS
  11. /*      int mbox(meta,msgid)
  12. /*    int meta;
  13. /*    unsigned msgid;
  14. /* DESCRIPTION
  15. /*      mbox() is invoked when the user has selected a non-work mail message.
  16. /*    It instructs the pager to display the selected mail message. 
  17. /*      The user has the usual options for manipulating the message
  18. /*    being displayed.
  19. /*
  20. /*    The meta parameter indicates the message type,
  21. /*    and msgid is the numerical message id. If the message file is being
  22. /*    read for the first time (meta == NEW_META), it will be marked as read
  23. /*    by renaming the meta file.
  24. /*
  25. /*    Message header lines can be suppressed selectively (see setup).
  26. /* FILES
  27. /*      $MAILDIR/?nnnnn, message and meta files
  28. /* SEE ALSO
  29. /*      pager(3), pager(5), kbdinp(3)
  30. /* DIAGNOSTICS
  31. /*      If a selected mail message could not be found an error message
  32. /*      is displayed instead.
  33. /* AUTHOR(S)
  34. /*      W.Z. Venema
  35. /*      Eindhoven University of Technology
  36. /*      Department of Mathematics and Computer Science
  37. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  38. /* CREATION DATE
  39. /*      Sun Apr  5 13:01:12 GMT+1:00 1987
  40. /* LAST MODIFICATION
  41. /*    90/01/22 13:02:11
  42. /* VERSION/RELEASE
  43. /*    2.1
  44. /*--*/
  45.  
  46. #include <stdio.h>
  47. #include <ctype.h>
  48.  
  49. #include "defs.h"
  50. #include "path.h"
  51. #include "pager.h"
  52. #include "screen.h"
  53. #include "mail.h"
  54. #include "ascf.h"
  55. #include "params.h"
  56. #include "ms_parse.h"
  57.  
  58.  /*
  59.   * Storage for header lines to be ignored. Both the strings with header
  60.   * names, and the pointers to these strings, are kept together.
  61.   */
  62.  
  63. struct ignore {
  64.     char    strs[BUFSIZ];        /* null-terminated strings */
  65.     char   *ptrs[BUFSIZ / 2];        /* null-terminated list of pointers */
  66. };
  67.  
  68. hidden void ign_init();            /* forward declarations */
  69. hidden int ign_header();
  70. hidden int mbox_filter();
  71.  
  72. hidden File *letter = 0;        /* pager file */
  73.  
  74. /* show_letter - display selected mail message */
  75.  
  76. hidden int show_letter()
  77. {
  78.     set_pager(letter);                /* select message display */
  79.     ds_pager();                    /* put it on the screen */
  80.     return (0);                    /* say screen is ok */
  81. }
  82.  
  83. /* mbox - user has selected a message file */
  84.  
  85. public int mbox(meta, id)
  86. int     meta;
  87. unsigned id;
  88. {
  89.     static Screen screen[] = {
  90.     'C',    "Close",0,        initscreen,
  91.     'D',    "Delete",delete,    delcurr,
  92.     'M',    "Mail",    mailfile,    "Mail a copy of this message",
  93.     'P',    "Print",print,        printcurr,
  94.     'R',    "Reply",reply,        "Create reply to sender",
  95.     'S',    "Save",    save,        "Save this message to ordinary file",
  96.     'W',    "Work",    makework,    "Save this message to work file",
  97.     '|',    "|",    filter,        "Filter this message through command",
  98.     PGUP,    PgUp,    pu_pager,    pageup,
  99.     PGDN,    PgDn,    pd_pager,    pagedn,
  100.     UP,    "Up",    up_pager,    csrup,
  101.     DOWN,    "Down",    dn_pager,    csrdn,
  102.     0,    0,    show_letter,    "(Reading a mail message)",
  103.     };
  104.     char   *seen;
  105.  
  106.     /* 
  107.      * Mail being read for the first time is renamed to reflect the
  108.      * status change.
  109.      */
  110.  
  111.     if (mbox_filter(letter = open_pager(), message)) {
  112.     mesg_pager(letter, m_msgread);        /* no file or read error */
  113.     } else if (meta != NEW_META) {        /* unread message? */
  114.      /* void */ ;                /* no */
  115.     } else if (rename(comment, seen = old_meta(id)) == 0) {
  116.     strcpy(comment, seen);            /* mark message as read */
  117.     junk_desk();                /* say desk-top outdated */
  118.     }
  119.     kbdinp(screen);                /* look at the screen */
  120.     close_pager(letter), letter = 0;        /* destroy the display */
  121.     return (S_REDRAW);                /* force screen redrawing */
  122. }
  123.  
  124. /* mbox_filter - suppress some message-header lines */
  125.  
  126. hidden int mbox_filter(pp, path)
  127. File   *pp;
  128. char   *path;
  129. {
  130. #if (defined(lint) && defined(iAPX286))
  131.     static
  132. #endif
  133.     struct ignore ignore;
  134.     FILE   *fp;
  135.  
  136.     if ((fp = ascopen(path, "r")) == 0) {
  137.     return (1);
  138.     } else {
  139.     char    buf[BUFSIZ];
  140.     int     ig_flag = 0;
  141.     int     ret;
  142.     int     context = MS_UUCP;
  143.  
  144.     ign_init(&ignore);            /* initialize filter */
  145.  
  146.     /*
  147.      * The header-line suppression algorithm is effective for RFC822-like
  148.      * headers lines only. Its main use is to get rid of the "Received:"
  149.      * lines that frequently show up in non-local mail.
  150.      */
  151.  
  152.     while (ascgets(buf, sizeof(buf), fp)) {
  153.         switch (context = ms_parse(context, buf)) {
  154.         case MS_UUCP:
  155.         app_pager(pp, buf);
  156.         break;
  157.         case MS_HEADER:
  158.         if ((ig_flag = (ign_header(buf, &ignore))) == 0)
  159.             app_pager(pp, buf);
  160.         break;
  161.         case MS_CONT:
  162.         if (ig_flag == 0)
  163.             app_pager(pp, buf);
  164.         break;
  165.         case MS_BODY:
  166.         app_pager(pp, buf);
  167.         break;
  168.         }
  169.     }
  170.     ret = ferror(fp);
  171.     ascclose(fp);
  172.     return (ret);
  173.     }
  174. }
  175.  
  176. /* ign_init - setup header lines to be ignored */
  177.  
  178. hidden void ign_init(ig)
  179. struct ignore *ig;
  180. {
  181.     Info   *ip = getparams() + P_IGNORE;/* what to ignore */
  182.     char   *sp = ":, ";            /* string separators */
  183.     char  **lp = ig->ptrs;        /* separated strings */
  184.  
  185.     /*
  186.      * This function takes, from the pc-mail setup file, a (blank or
  187.      * comma)-separated list with names of mail headers to be ignored when a
  188.      * message is displayed. The list of names is broken up into separate
  189.      * strings. The result, a null-terminated list of string pointers, is
  190.      * stored in the ig argument. We use strtok() for string splitting. Since
  191.      * that function destroys its input, and since the user may change the
  192.      * setup at any time, we keep in the ig argument a copy of the relevant
  193.      * setup information.
  194.      */
  195.  
  196.     if (ip->strval == 0) {            /* nothing to ignore */
  197.     *lp = 0;
  198.     } else {                    /* copy, then split */
  199.     (void) strncpy(ig->strs, ip->strval, sizeof(ig->strs));
  200.     for (*lp = strtok(ig->strs, sp); *lp; *lp = strtok((char *) 0, sp))
  201.         lp++;
  202.     }
  203. }
  204.  
  205. /* ign_header - do we ignore this header line */
  206.  
  207. hidden int ign_header(buf, ig)
  208. register char *buf;
  209. struct ignore *ig;
  210. {
  211.     register int l;            /* header name length */
  212.     register char **list;        /* ptr to ignored header names */
  213.  
  214.     /* Make sure that the header name is followed by a colon */
  215.  
  216.     for (list = ig->ptrs; *list; list++) {
  217.     if (buf[l = strlen(*list)] == ':' && istrncmp(buf, *list, l) == 0)
  218.         return (1);
  219.     }
  220.     return (0);
  221. }
  222.