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

  1. /*++
  2. /* NAME
  3. /*    email 3
  4. /* SUMMARY
  5. /*    manipulate one message in preparation
  6. /* PROJECT
  7. /*    pc-mail
  8. /* PACKAGE
  9. /*    mail
  10. /* SYNOPSIS
  11. /*    #include "mail.h"
  12. /*
  13. /*    int work()
  14. /*
  15. /*    int work_disp(def_addr)
  16. /*    char *def_addr;
  17. /* DESCRIPTION
  18. /*      The functions in this module are responsible for manipulations 
  19. /*    on mail messages in preparation.
  20. /*
  21. /*    work() should be invoked when the user has selected an existing
  22. /*    message in preparation. It does some initializations and invokes
  23. /*    the work_disp() function.
  24. /*
  25. /*      work_disp() allows the user to specify the disposition of a
  26. /*    mail message in preparation. It should be used after the user has
  27. /*    created a message, or after the user has selected a message in 
  28. /*    preparation.
  29. /*
  30. /*    The message file is displayed on the screen and user the 
  31. /*    can choose to print, mail, edit or delete etc. the message.
  32. /*
  33. /*    The def_addr argument contains a default mail destination: for example,
  34. /*    an address extracted from a message being replied to. It should be an
  35. /*    e-mail address or an empty string.
  36. /*
  37. /*    The code in this module is a little tricky, to avoid "orphan" work
  38. /*    files (message file without a metafile).
  39. /* COMMANDS
  40. /*    The program specified in the EDITOR environment variable,
  41. /*    or a system-dependent default.
  42. /* FILES
  43. /*    mail.msg, file being edited in the current directory
  44. /*      $MAILDIR/ennnnn, message file (body)
  45. /*    $MAILDIR/cnnnnn, meta file (summary)
  46. /*    $MAILDIR/header, template mail header file
  47. /*    $MAILDIR/trailer, template signature file
  48. /* SEE ALSO
  49. /*      pager(3), pager(5), kbdinp(3), edit(3)
  50. /* AUTHOR(S)
  51. /*      W.Z. Venema
  52. /*      Eindhoven University of Technology
  53. /*      Department of Mathematics and Computer Science
  54. /*      Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  55. /* CREATION DATE
  56. /*    Tue May 12 15:35:20 GMT+1:00 1987
  57. /* LAST MODIFICATION
  58. /*    90/01/22 13:01:35
  59. /* VERSION/RELEASE
  60. /*    2.1
  61. /*--*/
  62.  
  63. #include <stdio.h>
  64. #include <sys/types.h>
  65. #include <sys/stat.h>
  66.  
  67. #include <errno.h>
  68. #include "defs.h"
  69. #include "path.h"
  70. #include "pager.h"
  71. #include "screen.h"
  72. #include "mail.h"
  73. #include "status.h"
  74.  
  75. /* forward declarations */
  76.  
  77. hidden void junk_work();
  78. hidden int edit_work();
  79. hidden int show_work();
  80. hidden int hold_work();
  81. hidden int send_work();
  82. hidden int queue_work();
  83.  
  84. public char address[MAXLINE];        /* default destination */
  85. hidden File *workfile = 0;        /* pager file */
  86.  
  87. /* work - user selected message in preparation */
  88.  
  89. public int work()
  90. {
  91.     return (work_disp(""));
  92. }
  93.  
  94. /* work_disp - ask disposition of a message in preparation */
  95.  
  96. public int work_disp(def_addr)
  97. char *def_addr;
  98. {
  99.     static Screen screen[] = {
  100.     'C',    "Close",hold_work,"Send message later, return to message-selection menu",
  101. #ifdef    ATTACH
  102.     'A',    "Attach",attach", "Attach file to message",
  103. #endif
  104.     'D',    "Delete",delete,  delcurr,
  105.     'E',    "Edit",    edit_work,"Edit this message",
  106.     'M',    "Mail",    send_work,"Send this message to destination",
  107.     'P',    "Print",print,      printcurr,
  108.     PGUP,    PgUp,    pu_pager, pageup,
  109.     PGDN,    PgDn,    pd_pager, pagedn,
  110.     UP,    "Up",    up_pager, csrup,
  111.     DOWN,    "Down",    dn_pager, csrdn,
  112.     0,    0,    show_work,
  113.     "(Reading a message in preparation)",
  114.     };
  115.     struct stat s;
  116.  
  117.     strcpy(address, def_addr);            /* set up default address */
  118.     kbdinp(screen);                /* ask disposition */
  119.     junk_work();                /* destroy mail pager file */
  120.     return (S_REDRAW);                /* say screen was changed */
  121. }
  122.  
  123. /* show_work - show message in preparation or error message in middle window */
  124.  
  125. hidden int show_work()
  126. {
  127.     if (workfile) {                /* check pager file exists */
  128.     set_pager(workfile);            /* select existing display */
  129.     } else if (rd_pager(workfile = open_pager(), message)) {
  130.     mesg_pager(workfile, m_msgread);    /* cannot display message */
  131.     }
  132.     ds_pager();                    /* (re)draw display */
  133.     return (0);                    /* screen is up-to-date */
  134. }
  135.  
  136. /* junk_work - destroy message in preparation display */
  137.  
  138. hidden void junk_work()
  139. {
  140.     if (workfile) {                /* no-op if no display */
  141.     close_pager(workfile);            /* release memory */
  142.     workfile = 0;                /* say it is gone */
  143.     }
  144. }
  145.  
  146. /* edit_work - edit a message in preparation */
  147.  
  148. hidden int edit_work()
  149. {
  150.     register int stat;
  151.  
  152.     if (stat = edit(message, MAILFILE))        /* try to edit the message */
  153.     errdisp(stat);                /* edit() had a problem */
  154.     junk_work();                /* force new message display */
  155.     return (S_REDRAW);                /* say screen has changed */
  156. }
  157.  
  158. hidden int label_work();
  159.  
  160. /* hold_work - stop editing but do not yet mail a message in preparation */
  161.  
  162. hidden int hold_work()
  163. {
  164.     static Screen screen[] = {
  165.     STRING,    0, label_work, int_error,
  166.     0,    0, 0,
  167.     getsummary,
  168.     };
  169.     struct stat s;
  170.  
  171.     /*
  172.      * The user does not yet want to send the message off. The purpose of the
  173.      * following code is to ask for a one-line summary, but only if such a
  174.      * comment does not yet exist. The summary is used to identify the
  175.      * message in preparation in the message- selection display.
  176.      */
  177.  
  178.     if (stat(message, &s) || !stat(comment, &s)) {
  179.     return (S_BREAK);            /* we are done here */
  180.     } else {
  181.     return (kbdinp(screen) | S_REDRAW);    /* ask for a summary */
  182.     }
  183. }
  184.  
  185. /* label_work - save summary line to meta file */
  186.  
  187. hidden  label_work(string)
  188. char   *string;
  189. {
  190.     register int stat;
  191.  
  192.     if (stat = metafile(comment, string, (char *) 0)) {
  193.     errdisp(stat);                /* oops, notify the user */
  194.     return (S_REDRAW);            /* say screen has changed */
  195.     } else {
  196.     chmod(comment, 0444);            /* make comments read-only */
  197.     junk_desk();                /* say mail box has changed */
  198.     return (S_BREAK);            /* say no more work */
  199.     }
  200. }
  201.  
  202. /* send_work - user wants to send message in preparation, ask for destination */
  203.  
  204. hidden int send_work()
  205. {
  206.     static Screen screen[] = {
  207.     EDIT,    0,    queue_work,    address,
  208.     0,    0,    when,
  209.     "Press ESC to cancel. Send message to:",
  210.     };
  211.  
  212.     return (kbdinp(screen) | S_REDRAW);
  213. }
  214.  
  215. /* queue_work - spool mail, delete message in preparation and meta file */
  216.  
  217. hidden int queue_work(to)
  218. char   *to;
  219. {
  220.     register int stat;
  221.  
  222.     if (stat = submit(message, to)) {
  223.     errdisp(stat);                /* cannot queue message */
  224.     return (S_REDRAW);            /* say screen has changed */
  225.     } else {
  226.     return (unspool() | S_BREAK);        /* remove work and meta file */
  227.     }
  228. }
  229.