home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / msq31004.zip / MAINTMSG.C < prev    next >
C/C++ Source or Header  |  1995-07-20  |  8KB  |  378 lines

  1. /* maintmsg.c
  2. **
  3. ** released into the PUBLIC DOMAIN 30 jul 1990 by jim nutt
  4. ** Changes released into the PUBLIC DOMAIN 10 jul 1994 by John Dennis
  5. **
  6. ** Handles message maintenance.
  7. */
  8.  
  9. #define TEXTLEN 256
  10.  
  11. #include "msged.h"
  12. #include "date.h"
  13. #include "main.h"
  14. #include "keys.h"
  15. #include "menu.h"
  16. #include "makemsgn.h"
  17. #include "template.h"
  18.  
  19. extern int direction;
  20. extern int msgederr;
  21.  
  22. static char *formenu[] = {"Move Message",
  23.                           "Copy Message",
  24.                           "Redirect Message",
  25.                           "Forward Message",
  26.                            NULL};
  27.  
  28.  
  29. /*
  30. **
  31. ** Deletes the current message
  32. **
  33. */
  34.                            
  35. void  deletemsg(void)
  36. {
  37.     unsigned long   n    = CurArea.current;
  38.     msg    *from = NULL;
  39.     msg    *to   = NULL;
  40.     int     i;
  41.  
  42.     if (message == NULL)
  43.     {
  44.         if ((message = readmsg(CurArea.current)) == NULL)
  45.             return;
  46.     }
  47.  
  48.     if (!confirm())
  49.         return;                                 /* patch up reply links */
  50.  
  51.     for (i = 0; i < 10; i++)
  52.     {
  53.         if (message->replies[i] != 0)
  54.         {
  55.             from = MsgReadHeader(message->replies[i], RD_HEADER);
  56.             if (from)
  57.             {
  58.                 from->replyto = 0;
  59.                 MsgWriteHeader(from, WR_HEADER);
  60.                 dispose(from);
  61.             }
  62.         }
  63.     }
  64.     to = MsgReadHeader(message->replyto, RD_HEADER);
  65.     if (to)
  66.     {
  67.         for (i = 0; i < 10; i++)
  68.         {
  69.             if (to->replies[i] == n)
  70.             {
  71.                 to->replies[i] = 0;
  72.             }
  73.         }
  74.         MsgWriteHeader(to, WR_HEADER);
  75.         dispose(to);
  76.     }
  77.  
  78.     MsgDelete(message->msgnum);      /* we re-scan the area to be safe */
  79.     MsgAreaClose();
  80.     message          = KillMsg(message);
  81.     CurArea.messages = MsgAreaOpen(&CurArea);
  82.     CurArea.current  = min(max(1, n), CurArea.messages);
  83. }
  84.  
  85.  
  86. /*
  87. **
  88. ** Forwards the current message
  89. **
  90. */
  91.  
  92. void  forward_msg(void)
  93. {
  94.     msg    *m       = NULL;
  95.     msg    *oldm    = NULL;
  96.     int     fr_area = SW->area;
  97.     time_t  now     = time(NULL);
  98.     int     to_area;
  99.  
  100.     to_area = selectarea();
  101.  
  102.     if (msgederr)
  103.         return;
  104.  
  105.     /*
  106.     ** Save the current message and make the global pointer equal
  107.     ** to null (forcing a re-read).
  108.     */
  109.  
  110.     oldm    = duplicatemsg(message);
  111.     m       = message;
  112.     message = NULL;
  113.  
  114.     set_area(to_area);
  115.  
  116.     if (!CurArea.status)
  117.     {
  118.         dispose(oldm);
  119.         dispose(m);
  120.         set_area(fr_area);
  121.         return;
  122.     }
  123.  
  124.     if ((m->reply && (fr_area != to_area)) || CurArea.netmail)
  125.         release(m->reply);
  126.  
  127.     release(m->msgid);
  128.     release(m->isfrom);
  129.     release(m->isto);
  130.     release(m->from.domain);
  131.     release(m->to.domain);
  132.  
  133.     m->from = CurArea.addr;
  134.  
  135.     if (CurArea.addr.domain)
  136.         m->from.domain = strdup(CurArea.addr.domain);
  137.  
  138.     clear_attributes(&m->attrib);
  139.     memset(&m->replies, 0, sizeof(m->replies));
  140.  
  141.     CurArea.new     = 1;
  142.     m->isfrom       = strdup(ST->username);
  143.     m->new          = 1;
  144. //    m->movecopy     = 1;
  145.     m->msgnum       = MsgnToUid(CurArea.messages) + 1;
  146.     m->attrib.local = 1;
  147.     m->attrib.sent  = 0;
  148.     m->timestamp    = now;
  149.     m->scanned      = 0;
  150.     m->replyto      = 0;
  151.     m->attrib.private = CurArea.priv;
  152.  
  153.     if ((EditHeader(m) == Key_Esc) && confirm())
  154.         set_area(fr_area);
  155.     else
  156.     {
  157.         MakeTemplateMsg(m, oldm, fr_area, MT_FOR);
  158.         save(m);
  159.         set_area(fr_area);
  160.     }
  161.     dispose(oldm);
  162.     dispose(m);
  163. }
  164.  
  165.  
  166. /*
  167. **
  168. ** Redirects the current message
  169. **
  170. */
  171.  
  172. void  redirect_msg(void)
  173. {
  174.     msg    *m       = NULL;
  175.     msg    *oldm    = NULL;
  176.     int     fr_area = SW->area;
  177.     int     to_area;
  178.  
  179.     to_area = selectarea();
  180.  
  181.     if (msgederr)
  182.         return;
  183.  
  184.     oldm    = duplicatemsg(message);
  185.     m       = message;
  186.     message = NULL;
  187.     set_area(to_area);
  188.  
  189.     if (!CurArea.status)
  190.     {
  191.         dispose(oldm);
  192.         dispose(m);
  193.         set_area(fr_area);
  194.         return;
  195.     }
  196.  
  197.     memset(&m->replies, 0, sizeof(m->replies));
  198.  
  199.     if ((m->reply && (fr_area != to_area)) || CurArea.netmail)
  200.         release(m->reply);
  201.  
  202.     release(m->msgid);
  203.     release(m->isto);
  204.     clear_attributes(&m->attrib);
  205.  
  206.     CurArea.new     = 1;
  207.     m->new          = 1;
  208.     m->movecopy     = 1;
  209.     m->attrib.local = 1;
  210.     m->attrib.sent  = 0;
  211.     m->msgnum       = MsgnToUid(CurArea.messages) + 1;
  212.     m->scanned      = 0;
  213.     m->replyto      = 0;
  214.     m->attrib.private = CurArea.priv;
  215.  
  216.     if ((EditHeader(m) == Key_Esc) && confirm())
  217.         set_area(fr_area);
  218.     else
  219.     {
  220.         MakeTemplateMsg(m, oldm, fr_area, MT_RED);
  221.         save(m);
  222.         set_area(fr_area);
  223.     }
  224.     dispose(oldm);
  225.     dispose(m);
  226. }
  227.  
  228.  
  229. /*
  230. **
  231. ** Copies the current message
  232. **
  233. */
  234.  
  235. void  copy_msg(void)
  236. {
  237.     msg    *m       = NULL;
  238.     int     fr_area = SW->area;
  239.     int     to_area;
  240.  
  241.     to_area = selectarea();
  242.  
  243.     if (msgederr)
  244.         return;
  245.  
  246.     m       = message;
  247.     message = NULL;
  248.  
  249.     set_area(to_area);
  250.     if (!CurArea.status)
  251.     {
  252.         dispose(m);
  253.         set_area(fr_area);
  254.         return;
  255.     }
  256.  
  257.     clear_attributes(&m->attrib);
  258.     CurArea.new     = 1;
  259.     release(m->from.domain);
  260.     m->from = CurArea.addr;
  261.     if (CurArea.addr.domain)
  262.         m->from.domain = strdup(CurArea.addr.domain);
  263.     m->msgnum       = MsgnToUid(CurArea.messages) + 1;
  264.     m->new          = 1;
  265.     m->movecopy     = 1;
  266.     m->attrib.sent  = 0;
  267.     m->attrib.local = 1;
  268.     m->scanned      = 0;
  269.     m->attrib.private = CurArea.priv;
  270.  
  271.     memset(&m->replies,0,sizeof(m->replies));
  272.     m->replyto = 0; 
  273.  
  274.     writemsg(m);
  275.     set_area(fr_area);
  276.     dispose(m);
  277. }
  278.  
  279.  
  280. /*
  281. **
  282. ** Moves the current message
  283. **
  284. */
  285.  
  286. void  move_msg(void)
  287. {
  288.     msg    *m       = NULL;
  289.     int     fr_area = SW->area;
  290.     int     t       = SW->confirmations;
  291.     int     to_area;
  292.     int     status;
  293.  
  294.     to_area = selectarea();
  295.  
  296.     if (msgederr)
  297.         return;
  298.  
  299.     m                 = message;     /* save the msg so we can write it */
  300.     message           = NULL;
  301.  
  302.     set_area(to_area);
  303.     if (!CurArea.status)
  304.     {
  305.         set_area(fr_area);
  306.         dispose(m);
  307.         return;
  308.     }
  309.  
  310.     clear_attributes(&m->attrib);
  311.     CurArea.new     = 1;
  312.     release(m->from.domain);
  313.     m->from = CurArea.addr;
  314.     if (CurArea.addr.domain)
  315.         m->from.domain = strdup(CurArea.addr.domain);
  316.     m->msgnum       = MsgnToUid(CurArea.messages) + 1;
  317.     m->new          = 1;
  318.     m->movecopy     = 1;
  319.     m->attrib.sent  = 0;
  320.     m->attrib.local = 1;
  321.     m->scanned      = 0;
  322.     m->attrib.private = CurArea.priv;
  323.  
  324.     memset(&m->replies,0,sizeof(m->replies));
  325.     m->replyto = 0; 
  326.  
  327.     status = writemsg(m);
  328.     dispose(m);
  329.     set_area(fr_area);
  330.     
  331.     if (status == TRUE)
  332.     {
  333.         SW->confirmations = 0;           /* delete msg unconditionally */
  334.         deletemsg();
  335.         SW->confirmations = t;
  336.     }
  337. }
  338.  
  339.  
  340. /*
  341. **
  342. ** Allows forwarding, redirecting, moving and copying of msgs.
  343. **
  344. **
  345. */
  346.  
  347. void  movemsg(void)
  348. {
  349.     int     ch;
  350.  
  351.     ch = DoMenu((maxx/2)-8, (maxy/2)-1, (maxx/2)+8, (maxy/2)+2, formenu, 0);
  352.  
  353.     switch (ch)
  354.     {
  355.         case 0:                                      /* Move */
  356.             move_msg();
  357.             return;
  358.  
  359.         case 1:                                      /* Copy */
  360.             copy_msg();
  361.             return;
  362.  
  363.         case 2:    /* Redirect */
  364.             redirect_msg();
  365.             return;
  366.  
  367.         case 3:                                      /* Forward */
  368.             forward_msg();
  369.             return;
  370.  
  371.         case -1:                                     /* Escape */
  372.             return;
  373.  
  374.     }
  375. }
  376.  
  377. /* end of file */
  378.