home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / network / amigaelm.lzh / f1.c < prev    next >
C/C++ Source or Header  |  1992-03-15  |  22KB  |  881 lines

  1. #include "prefs.h"
  2. #include <proto/dos.h>
  3. #include <proto/exec.h>
  4.  
  5.  
  6. Prototype void sendmail(char *, char *);
  7. Prototype void readmail(int, int);
  8. Prototype void replymail(int,BOOL,BOOL);
  9. Prototype void forwardmail(int,int);
  10. Prototype void bouncemail(int,int);
  11. Prototype BOOL writemail(char *,int,int);
  12. Prototype void pipemail(int);
  13. Prototype void editfile(char *);
  14.  
  15. void PagerCommand(char *);
  16. int lines_len(long);
  17.  
  18.  
  19.  
  20. void
  21. sendmail(char *To, char *Subject)
  22. {
  23.   FILE *fp;
  24.   if (fp=fopen(MailTmp,"w")) {
  25.     CreateHeader(fp,To,Subject);
  26.     fclose(fp);
  27.     editfile(MailTmp);
  28.     send_off(MailTmp,NULL);
  29.   }
  30.   else
  31.     status_msg("error: cannot open temporary file - mail not sent",100L);
  32. }
  33.  
  34.  
  35.  
  36. int
  37. lines_len(long charnum)
  38. {
  39.   if (charnum)
  40.     return(((charnum+Win_Width-1)/Win_Width));
  41.   else
  42.     return(1);
  43. }
  44.  
  45.  
  46.  
  47. int
  48. chars_len(char *string)
  49. {
  50.   long len = 0L;
  51.   while(*string) {
  52.     len++;
  53.     if(*string=='\n') {
  54.       len--;
  55.       while((len-1)%Win_Width)
  56.         len++;
  57.     }
  58.     else if(*string=='\f')
  59.       *string='┐';
  60.     else if(*string=='\t')
  61.       while(len%8)
  62.         len++;
  63.     string++;
  64.   }
  65.   return(len);
  66. }
  67.  
  68.  
  69.  
  70. void HandleReturns(struct MailItem I)
  71. {
  72.   if ((!(I.Status & READ)) && (I.RR_To) && (ReturnReceipt)) {
  73.     FILE *out;
  74.     char String[MAX_LINELENGTH];
  75.  
  76.     if (!(out=fopen(MailTmp,"w"))) {
  77.       status_msg("error: cannot open temporary file - receipt mail not sent",100L);
  78.     }
  79.     else {
  80.       CreateHeader(out,I.RR_To,"received your mail");
  81.       if (SendmailVersion==SM_FEULNER)
  82.         fprintf(out,"From: Mail Delivery Subsystem <MAILER-DAEMON@%s%s>\n",HostName,DomainName);
  83.       fprintf(out,"\nYour mail to   : %s\n",I.To);
  84.       fprintf(out,"with Subject   : %s\n",I.Subject?I.Subject:"(none)");
  85.       fprintf(out,"and Message-Id : %s\n",I.MessageID);
  86.       fprintf(out,"\n ... has been received and read by ...\n\n");
  87.       fprintf(out,"\t%s <%s@%s%s>\n\n",RealName,UserName,HostName,DomainName);
  88.       fclose(out);
  89.  
  90.       putst("\n\n\033[1m Sending receipt message ... Wait ... \033[0m");
  91.       if (SendmailVersion==SM_FEULNER)
  92.         sprintf(String,"sendmail <%s",MailTmp);
  93.       else if (SendmailVersion==SM_DILLON)
  94.         sprintf(String,"sendmail <%s -f %s -R \"%s\"",MailTmp,"MAILER-DAEMON","Mail Delivery Subsystem");
  95.       else if (SendmailVersion==SM_OTHER)
  96.         sprintf(String,"sendmail <%s -f %s",MailTmp,"MAILER-DAEMON");
  97.       Execute(String,NULL,NULL);
  98.     }
  99.   }
  100.  
  101.   if (((I.Status & READ)!=READ) && (I.RV_To) && (ReturnView)) {
  102.     FILE *out;
  103.     char String[MAX_LINELENGTH];
  104.  
  105.     if (!(out=fopen(MailTmp,"w"))) {
  106.       status_msg("error: cannot open temporary file - receipt mail not sent",100L);
  107.     }
  108.     else {
  109.       CreateHeader(out,I.RV_To,"read your mail");
  110.       if (SendmailVersion==SM_FEULNER)
  111.         fprintf(out,"From: Mail Delivery Subsystem <MAILER-DAEMON@%s%s>\n",HostName,DomainName);
  112.       fprintf(out,"\nYour mail to   : %s\n",I.To);
  113.       fprintf(out,"with Subject   : %s\n",I.Subject?I.Subject:"(none)");
  114.       fprintf(out,"and Message-Id : %s\n",I.MessageID);
  115.       fprintf(out,"\n ... has been received and read by ...\n\n");
  116.       fprintf(out,"\t%s <%s@%s%s>\n\n",RealName,UserName,HostName,DomainName);
  117.       fclose(out);
  118.  
  119.       putst("\n\n\033[1m Sending receipt message ... Wait ... \033[0m");
  120.       if (SendmailVersion==SM_FEULNER)
  121.         sprintf(String,"sendmail <%s",MailTmp);
  122.       else if (SendmailVersion==SM_DILLON)
  123.         sprintf(String,"sendmail <%s -f %s -R \"%s\"",MailTmp,"MAILER-DAEMON","Mail Delivery Subsystem");
  124.       else if (SendmailVersion==SM_OTHER)
  125.         sprintf(String,"sendmail <%s -f %s",MailTmp,"MAILER-DAEMON");
  126.       Execute(String,NULL,NULL);
  127.     }
  128.   }
  129. }
  130.  
  131.  
  132.  
  133. void
  134. readmail_ext(int Number,int full_header)
  135. {
  136. #define EXT_PAGER_WIDTH 80
  137.     FILE *in,*out;
  138.     int j,l;
  139.     long r;
  140.     struct MailItem I;
  141.     char Text[MAX_LINELENGTH];
  142.  
  143.     if (Number<1 || Number>MaxArticle)
  144.       return;
  145.  
  146.     I=*i_th(Number);
  147.  
  148.     sprintf(TBuffer,"\fExternal pager: %s, message: %d.\n",Pager,Number);
  149.     outline();
  150.  
  151.     if (!(in=OpenHomeBox())) {
  152.       status_msg("error: cannot open folder - mail not read",100L);
  153.       return;
  154.     }
  155.  
  156.     if (!(out=fopen(MailTmp,"w"))) {
  157.       status_msg("error: cannot open mailfile - mail not read",100L);
  158.       CloseHomeBox(in);
  159.       return;
  160.     }
  161.  
  162.     sprintf(Text,"Message %d/%d  From %.50s",Number,MaxArticle,I.FromName?I.FromName:I.From);
  163.     while ((6+strlen(Text))<EXT_PAGER_WIDTH)  /* +6 (ctrl-chars, see above) -6 (length of date) */
  164.       strcat(Text," ");
  165.     strcat(Text,I.Date);
  166.     fprintf(out,"%s\n\n",Text);
  167.  
  168.     if (I.Urgent)
  169.       fprintf(out,"\n                    \033[1m (** This message is tagged Urgent **) \033[0m\n\n\n");
  170.  
  171.     if (full_header)
  172.       j=I.ArtikelStart;
  173.     else {
  174.       j=I.TextStart;
  175.       fprintf(out,"\033[1mFrom:\033[0m %s\n",I.From);
  176.       if (I.To)
  177.         fprintf(out,"\033[1mTo:\033[0m %s\n",I.To);
  178.       if (I.Cc)
  179.         fprintf(out,"\033[1mCc:\033[0m %s\n",I.Cc);
  180.       if (I.Bcc)
  181.         fprintf(out,"\033[1mBcc:\033[0m %s\n",I.Bcc);
  182.       fprintf(out,"\033[1mSubject:\033[0m \033[7m%s\033[0m\n\n",I.Subject?I.Subject:"(none)");
  183.     }
  184.  
  185.     if (ShowSig)
  186.       l=I.ArtikelEnd;
  187.     else
  188.       l=I.SignatureStart;
  189.     fseek(in,j,0);
  190.  
  191.     while(getline(in,Text,&r) && (r<=l)) {
  192.       fprintf(out,"%s\n",Text);
  193.     }
  194.  
  195.     CloseHomeBox(in);
  196.     fclose(out);
  197.  
  198.     sprintf(Text,"%s %s",Pager,MailTmp);
  199.     WorkbenchToFront();
  200.     Execute(Text,NULL,NULL);
  201.     ElmToFront();
  202.  
  203.     HandleReturns(I);
  204.     i_th(Number)->Status |= READ;
  205. }
  206.  
  207.  
  208.  
  209. void
  210. readmail(int Number,int full_header)
  211. {
  212.     FILE *fp;
  213.     register int k;
  214.     int j,l;
  215.     long r = 0L;      /* position in file */
  216.     long lines,dl;    /* lines of text, displayed lines */
  217.     struct MailItem I;
  218.     char Text[MAX_LINELENGTH];
  219.     BOOL WrongKey;
  220.     BOOL Quit;
  221.  
  222.     if (Pager) {
  223.       readmail_ext(Number,full_header);
  224.       return;
  225.     }
  226.  
  227.     if (Number<1 || Number>MaxArticle)
  228.       return;
  229.  
  230.     I=*i_th(Number);
  231.  
  232. display_page:
  233.  
  234.     if(!(fp=OpenHomeBox())) {
  235.       status_msg("error: cannot open folder - mail not read",100L);
  236.       return;
  237.     }
  238.  
  239.     Quit = FALSE;
  240.     k = 1;
  241.     dl = 0;
  242.  
  243.     sprintf(TBuffer,"\f\033[0 pMessage %d/%d  From %.50s",Number,MaxArticle,I.FromName?I.FromName:I.From);
  244.     while (strlen(TBuffer)<Win_Width)  /* +6 (ctrl-chars, see above) -6 (length of date) */
  245.       strcat(TBuffer," ");
  246.     strcat(TBuffer,I.Date);
  247.     strcat(TBuffer,"\n\n");
  248.     outline();
  249.     k++;
  250.     k++;
  251.  
  252.     if (I.Urgent) {
  253.       putst("\n                    \033[1m (** This message is tagged Urgent **) \033[0m\n\n\n");
  254.       k+=4;
  255.     }
  256.  
  257.     if (full_header) {
  258.       j=I.ArtikelStart;
  259.       lines=I.TotalLines;
  260.     }
  261.     else {
  262.       j=I.TextStart;
  263.       lines=I.Lines;
  264.       sprintf(TBuffer,"\033[1mFrom:\033[0m %.*s\n",Win_Width-7,I.From);
  265.       outline();
  266.       k++;
  267.       if (I.To) {
  268.         long len = chars_len(I.To)+4;
  269.         sprintf(TBuffer,"\033[1mTo:\033[0m %s\n",I.To);
  270.         outline();
  271.         k+=lines_len(len);
  272.       }
  273.       if (I.Cc) {
  274.         long len = chars_len(I.Cc)+4;
  275.         sprintf(TBuffer,"\033[1mCc:\033[0m %s\n",I.Cc);
  276.         outline();
  277.         k+=lines_len(len);
  278.       }
  279.       if (I.Bcc) {
  280.         long len = chars_len(I.Bcc)+5;
  281.         sprintf(TBuffer,"\033[1mBcc:\033[0m %s\n",I.Bcc);
  282.         outline();
  283.         k+=lines_len(len);
  284.       }
  285.       sprintf(TBuffer,"\033[1mSubject:\033[0m \033[7m%.*s\033[0m\n\n",Win_Width-10,I.Subject?I.Subject:"(none)");
  286.       outline();
  287.       k+=2;
  288.     }
  289.  
  290.     if (ShowSig)
  291.       l=I.ArtikelEnd;
  292.     else
  293.       l=I.SignatureStart;
  294.     fseek(fp,j,0);
  295.  
  296.     while(getline(fp,Text,&r) && (r<=l) && !Quit) {
  297.         register long ll = chars_len(Text);  /* line length */
  298.         k+=lines_len(ll);
  299.         if (k/Win_Height) {
  300.             fseek(fp,r,0);   /* re-position pointer, un-read last line */
  301.             sprintf(TBuffer,"\n  \033[7;33;41m--\033[1mMore\033[0;7;33;41m(%d%%)--\033[0m  \033[3m [d)elete,f)orward,h)eader,m)ail,q)uit,g)roup r)eply] \033[0m",(dl*100)/lines);
  302.             outline();
  303.             Quit = TRUE;
  304.             do {
  305.               int c;
  306.               flush_input();
  307.               c = getch();
  308.               WrongKey=FALSE;
  309.               switch (c) {
  310.                   case '^':
  311.                       CloseHomeBox(fp);
  312.                       goto display_page;
  313.                       break;
  314.                   case '\r':
  315.                       k=Win_Height-lines_len(ll)-1;
  316.                       putst("\r\033M\033[J");
  317.                       Quit = FALSE;
  318.                       break;
  319.                   case ' ' :
  320.                       k=2;
  321.                       putst("\r\033M\033[J");
  322.                       Quit = FALSE;
  323.                       break;
  324.                   case 'd':
  325.                       CloseHomeBox(fp);
  326.                       i_th(Number)->Status |= DELETED;
  327.                       break;
  328.                   case 'h':
  329.                       CloseHomeBox(fp);
  330.                       full_header=!full_header;
  331.                       goto display_page;
  332.                       break;
  333.                   case 'f':
  334.                   case 'F':
  335.                       putst("\033[ p");   /* cursor on */
  336.                       CloseHomeBox(fp);
  337.                       PagerCommand("Forward");
  338.                       forwardmail(Number,isupper(c));
  339.                       break;
  340.                   case 'm':
  341.                       putst("\033[ p");   /* cursor on */
  342.                       CloseHomeBox(fp);
  343.                       PagerCommand("Mail");
  344.                       sendmail("","");
  345.                       break;
  346.                   case 'g':
  347.                   case 'G':
  348.                       putst("\033[ p");   /* cursor on */
  349.                       CloseHomeBox(fp);
  350.                       PagerCommand("Group reply");
  351.                       replymail(Number,isupper(c),TRUE);
  352.                       break;
  353.                   case 'r':
  354.                   case 'R':
  355.                       putst("\033[ p");   /* cursor on */
  356.                       CloseHomeBox(fp);
  357.                       PagerCommand("Reply to message");
  358.                       replymail(Number,isupper(c),FALSE);
  359.                       break;
  360.                   case 'i' :
  361.                   case 'q' :
  362.                       CloseHomeBox(fp);
  363.                       break;
  364.                   default:
  365.                       WrongKey=TRUE;
  366.                       break;
  367.               }
  368.             } while(WrongKey);
  369.         }
  370.         else {
  371.           sprintf(TBuffer,"%s\n",Text);
  372.           outline();
  373.           dl++;
  374.         }
  375.     }
  376.     putst("\033[ p");   /* cursor on */
  377.  
  378.     if (Quit) {
  379.       HandleReturns(I);
  380.       i_th(Number)->Status |= READ;
  381.       return;
  382.     }
  383.  
  384.     CloseHomeBox(fp);
  385.  
  386.     putst("\n\033[1;7;33;41m  End of Message  \033[0m  \033[3m [d)elete,f)orward,h)eader,m)ail,q)uit,g)roup r)eply] \033[0m");
  387.  
  388.     do {
  389.       int c;
  390.       flush_input();
  391.       c = getch();
  392.       WrongKey=FALSE;
  393.       switch (c) {
  394.           case '^':
  395.               goto display_page;
  396.               break;
  397.           case '\r':
  398.           case ' ' :
  399.           case 'i' :
  400.           case 'q' :
  401.               break;
  402.           case 'd':
  403.               i_th(Number)->Status |= DELETED;
  404.               break;
  405.           case 'h':
  406.               full_header=!full_header;
  407.               goto display_page;
  408.               break;
  409.           case 'f':
  410.           case 'F':
  411.               PagerCommand("Forward");
  412.               forwardmail(Number,isupper(c));
  413.               break;
  414.           case 'm':
  415.               PagerCommand("Mail");
  416.               sendmail("","");
  417.               break;
  418.           case 'g':
  419.           case 'G':
  420.               PagerCommand("Group reply");
  421.               replymail(Number,isupper(c),TRUE);
  422.               break;
  423.           case 'r':
  424.           case 'R':
  425.               PagerCommand("Reply to message");
  426.               replymail(Number,isupper(c),FALSE);
  427.               break;
  428.           default:
  429.               WrongKey=TRUE;
  430.               break;
  431.       }
  432.     } while(WrongKey);
  433.  
  434.     HandleReturns(I);
  435.     i_th(Number)->Status |= READ;
  436. }
  437.  
  438.  
  439.  
  440. struct AliasItem *list_wo_own(char *str)
  441. {
  442.   struct AliasItem *list,*l;
  443.   char *adr,*p,*e;
  444.  
  445.   list = AdrsToAList(str);
  446.  
  447.   if (adr=malloc(strlen(UserName)+strlen(HostName)+strlen(DomainName)+2)) {
  448.     sprintf(adr,"%s@%s%s",UserName,HostName,DomainName);
  449.     for (l=list; l; l=l->next) {
  450.       if (p=strstr(l->alias,adr)) {
  451.         e = p+strlen(adr);
  452.         if ((p==l->alias && (*e==' ' || *e=='\t' || *e=='\0' || *e=='('))
  453.              ||
  454.             (p>l->alias && *(p-1)=='<' && *e=='>')
  455.            ) {
  456.  
  457.           free(l->alias);
  458.           l->alias = NULL;
  459.  
  460.         }
  461.       }
  462.     }
  463.   }
  464.  
  465.   return(list);
  466. }
  467.  
  468.  
  469.  
  470. void
  471. replymail(int Number,BOOL full_header,BOOL group_reply)
  472. {
  473.     FILE *in,*out;
  474.     char String[MAX_LINELENGTH];
  475.     struct MailItem I;
  476.  
  477.     if (Number<1 || Number>MaxArticle)
  478.       return;
  479.  
  480.     if (!(out=fopen(MailTmp,"w"))) {
  481.       status_msg("error: cannot open temporary file - mail not sent",100L);
  482.       return;
  483.     }
  484.  
  485.     I=*i_th(Number);
  486.  
  487.     if (I.Subject==NULL || strlen(I.Subject)<1) {
  488.       if (I.ReplyTo)
  489.         CreateHeader(out,I.ReplyTo,"Re: your mail");
  490.       else
  491.         CreateHeader(out,I.From,"Re: your mail");
  492.     }
  493.     else if (strnicmp(I.Subject,"Re:",3)==0) {
  494.       if (I.ReplyTo)
  495.         CreateHeader(out,I.ReplyTo,I.Subject);
  496.       else
  497.         CreateHeader(out,I.From,I.Subject);
  498.     }
  499.     else {
  500.       char *subj;
  501.       if (subj=malloc(strlen(I.Subject)+5)) {    /* + "Re: \0" */
  502.         strcpy(subj,"Re: ");
  503.         strcat(subj,I.Subject);
  504.         if (I.ReplyTo)
  505.           CreateHeader(out,I.ReplyTo,subj);
  506.         else
  507.           CreateHeader(out,I.From,subj);
  508.         free(subj);
  509.       }
  510.     }
  511.  
  512.     if (group_reply) {
  513.       struct AliasItem *cc_list,*to_list,*l;
  514.       BOOL erstes = TRUE;
  515.  
  516.       to_list = list_wo_own(I.To);
  517.       cc_list = list_wo_own(I.Cc);
  518.  
  519.       for (l = cc_list; l; l = l->next) {
  520.         if (l->alias) {
  521.           fprintf(out,"%s%s",erstes?"Cc: ":",\n\t",l->alias);
  522.           erstes = FALSE;
  523.         }
  524.       }
  525.  
  526.       for (l = to_list; l; l = l->next) {
  527.         if (l->alias) {
  528.           fprintf(out,"%s%s",erstes?"Cc: ":",\n\t",l->alias);
  529.           erstes = FALSE;
  530.         }
  531.       }
  532.  
  533. /*
  534.       if (I.Cc && I.To)
  535.         fprintf(out,"Cc: %s,\n\t%s\n",I.Cc,I.To);
  536.       else if (I.Cc)
  537.         fprintf(out,"Cc: %s\n",I.Cc);
  538.       else if (I.To)
  539.         fprintf(out,"Cc: %s\n",I.To);
  540. */
  541.  
  542.       if (to_list || cc_list)
  543.         fputc('\n',out);
  544.  
  545.       FreeAliasList(&cc_list);
  546.       FreeAliasList(&to_list);
  547.     }
  548.  
  549. /*
  550.     else
  551.       if (I.Cc)
  552.         fprintf(out,"Cc: %s\n",I.Cc);
  553.  
  554.     if (I.Bcc)
  555.       fprintf(out,"Bcc: %s\n",I.Bcc);
  556. */
  557.  
  558.     fprintf(out,"\n");
  559.  
  560.     do_introduction(out,ReplyIntro,&I);
  561.  
  562.     if((in=OpenHomeBox())==NULL) {
  563.       status_msg("error: cannot open folder - mail not sent",100L);
  564.       fclose(out);
  565.       return;
  566.     }
  567.     else {
  568.         long r;
  569.         if (full_header)
  570.           fseek(in,I.ArtikelStart,0);
  571.         else
  572.           fseek(in,I.TextStart,0);
  573.         while(getline(in,String,&r) && (r<=I.ArtikelEnd)) {
  574.           fprintf(out,"%s%s\n",PrefixString,String);
  575.         }
  576.         CloseHomeBox(in);
  577.         fprintf(out,"\n");
  578.     }
  579.     fclose(out);
  580.     editfile(MailTmp);
  581.     if (send_off(MailTmp,I.MessageID)==1)
  582.       i_th(Number)->Status |= ANSWERED;
  583. }
  584.  
  585.  
  586.  
  587. void
  588. forwardmail(int Number,int full_header)
  589. {
  590.     FILE *in,*out;
  591.     char String[MAX_LINELENGTH];
  592.     char *subj;
  593.     struct MailItem I;
  594.  
  595.     if (Number<1 || Number>MaxArticle)
  596.       return;
  597.  
  598.     if (!(out=fopen(MailTmp,"w"))) {
  599.       status_msg("error: cannot open temporary file - mail not sent",100L);
  600.       return;
  601.     }
  602.  
  603.     I=*i_th(Number);
  604.  
  605.     if (I.Subject==NULL || strlen(I.Subject)<1) {
  606.       CreateHeader(out,"","forwarded mail");
  607.     }
  608.     else if (subj=malloc(strlen(I.Subject)+7)) {      /* + " (fwd)\0" */
  609.       strcpy(subj,I.Subject);
  610.       strcat(subj," (fwd)");
  611.       CreateHeader(out,"",subj);
  612.       free(subj);
  613.     }
  614.     else {
  615.       CreateHeader(out,"","forwarded mail");
  616.     }
  617.  
  618.     fprintf(out,"\n");
  619.  
  620.     do_introduction(out,ForwardIntro,&I);
  621.     fprintf(out,"[-------------------- text of forwarded message follows --------------------]\n\n");
  622.  
  623.     if(!(in=OpenHomeBox())) {
  624.       status_msg("error: cannot open folder - mail not sent",100L);
  625.       fclose(out);
  626.       return;
  627.     }
  628.     else {
  629.         long r;
  630.         if (full_header)
  631.           fseek(in,I.ArtikelStart,0);
  632.         else
  633.           fseek(in,I.TextStart,0);
  634.         while(getline(in,String,&r) && (r<=I.ArtikelEnd))
  635.           fprintf(out,"%s\n",String);
  636.         CloseHomeBox(in);
  637.         fprintf(out,"\n");
  638.     }
  639.  
  640.     fprintf(out,"[------------------------- end of forwarded message ------------------------]\n\n");
  641.     fclose(out);
  642.  
  643.     editfile(MailTmp);
  644.     if (send_off(MailTmp,NULL)==1)
  645.       i_th(Number)->Status |= FORWARDED;
  646. }
  647.  
  648.  
  649.  
  650. void
  651. bouncemail(int Number,int full_header)
  652. {
  653.     FILE *in,*out;
  654.     char String[MAX_LINELENGTH];
  655.     char *subj;
  656.     struct MailItem I;
  657.  
  658.     if (Number<1 || Number>MaxArticle)
  659.       return;
  660.  
  661.     if (!(out=fopen(MailTmp,"w"))) {
  662.       status_msg("error: cannot open temporary file - mail not sent",100L);
  663.       return;
  664.     }
  665.  
  666.     I=*i_th(Number);
  667.  
  668.     if (I.Subject==NULL || strlen(I.Subject)<1) {
  669.       CreateHeader(out,"","bounced mail");
  670.     }
  671.     else if (subj=malloc(strlen(I.Subject)+10)) {      /* + " (bounce)\0" */
  672.       strcpy(subj,I.Subject);
  673.       strcat(subj," (bounce)");
  674.       CreateHeader(out,"",subj);
  675.       free(subj);
  676.     }
  677.     else {
  678.       CreateHeader(out,"","bounced mail");
  679.     }
  680.  
  681.     fprintf(out,"\n");
  682.  
  683.     do_introduction(out,ForwardIntro,&I);
  684.     fprintf(out,"[-------------------- text of forwarded message follows --------------------]\n\n");
  685.  
  686.     if(!(in=OpenHomeBox())) {
  687.       status_msg("error: cannot open folder - mail not sent",100L);
  688.       fclose(out);
  689.       return;
  690.     }
  691.     else {
  692.         long r;
  693.         if (full_header)
  694.           fseek(in,I.ArtikelStart,0);
  695.         else
  696.           fseek(in,I.TextStart,0);
  697.         while(getline(in,String,&r) && (r<=I.ArtikelEnd))
  698.           fprintf(out,"%s\n",String);
  699.         CloseHomeBox(in);
  700.         fprintf(out,"\n");
  701.     }
  702.  
  703.     fprintf(out,"[------------------------- end of forwarded message ------------------------]\n\n");
  704.     fclose(out);
  705.  
  706.     editfile(MailTmp);
  707.     if (send_off(MailTmp,NULL)==1)
  708.       i_th(Number)->Status |= BOUNCED;
  709.  
  710. /*
  711.     else {
  712.         long r;
  713.         fprintf(out,"On %s, %s wrote:\n\n",I.Date,I.From);
  714.         fprintf(out,"[--------------------- text of bounced message follows ---------------------]\n\n");
  715.         if (full_header)
  716.           fseek(in,I.ArtikelStart,0);
  717.         else
  718.           fseek(in,I.TextStart,0);
  719.         while(getline(in,String,&r) && (r<=I.ArtikelEnd)) {
  720.           fprintf(out,"%s\n",String);
  721.         }
  722.         CloseHomeBox(in);
  723.         fprintf(out,"\n");
  724.     }
  725.     fprintf(out,"[-------------------------- end of bounced message -------------------------]\n\n");
  726.     fclose(out);
  727. */
  728. }
  729.  
  730.  
  731.  
  732. BOOL
  733. writemail(char *Name,int mode,int Number)
  734. /* Number: 0 - short, 1 - full, 2 - archive */
  735. {
  736.     FILE *fp,*in;
  737.     char *name=NULL;
  738.     struct MailItem I;
  739.     long r;
  740.     register int c;
  741.  
  742.     if (Number<1 || Number>MaxArticle || !Name || !strlen(Name))
  743.       return(FALSE);
  744.  
  745.     I=*i_th(Number);
  746.  
  747.     if (Name[0]=='=' && Name[1]) {
  748.       name = malloc(strlen(UUMAIL)+strlen(Name));
  749.       strcpy(name,UUMAIL);
  750.       strcat(name,&Name[1]);
  751.     }
  752.  
  753.     if(!(fp=fopen(name?name:Name,"a"))) {
  754.       status_msg("error: cannot open destination file - mail not saved",100L);
  755.       if(name) free(name);
  756.       return(FALSE);
  757.     }
  758.  
  759.     if(!(in=OpenHomeBox())) {
  760.       status_msg("error: cannot open folder - mail not saved",100L);
  761.       fclose(fp);
  762.       if(name) free(name);
  763.       return(FALSE);
  764.     }
  765.  
  766.     if ((mode==0)||(mode==2))       /* write to file or folder */
  767.         r=I.TextStart;
  768.     else
  769.         r=I.ArtikelStart;
  770.     if (mode==2) {
  771.         fprintf(fp,"\nFrom %s (ARCHIVE)\n",I.From);
  772.         fprintf(fp,"From: %s\n",I.From);
  773.         fprintf(fp,"Date: %s\n",I.Date);
  774.         fprintf(fp,"Subject: %s\n",I.Subject);
  775.     }
  776.     fseek(in,r,0);
  777.     while (r<=I.ArtikelEnd) {
  778.         c=getc(in);
  779.         putc(c,fp);
  780.         r++;
  781.     }
  782.     CloseHomeBox(in);
  783.     fclose(fp);
  784.     i_th(Number)->Status |= LOGGED;
  785.     if(name) free(name);
  786.     return(TRUE);
  787. }
  788.  
  789.  
  790.  
  791. void
  792. pipemail(int Number)
  793. {
  794.     FILE *in,*out;
  795.     char exec[256];
  796. /*
  797.     BPTR fh;
  798. */
  799.     struct MailItem I;
  800.  
  801.     if (Number<1 || Number>MaxArticle)
  802.       return;
  803.  
  804. /*
  805.     if (!(fh=Open("con:",MODE_NEWFILE))) {
  806.       status_msg("error: cannot open i/o window - mail not sent",100L);
  807.       return;
  808.     }
  809. */
  810.  
  811.     if (!(out=fopen(MailTmp,"w"))) {
  812.       status_msg("error: cannot open temporary file - mail not sent",100L);
  813. /*
  814.       Close(fh);
  815. */
  816.       return;
  817.     }
  818.  
  819.     I=*i_th(Number);
  820.  
  821.     if(!(in=OpenHomeBox())) {
  822.       status_msg("error: cannot open folder - mail not sent",100L);
  823. /*
  824.       Close(fh);
  825. */
  826.       fclose(out);
  827.       return;
  828.     }
  829.     else {
  830.       long r = I.ArtikelStart;
  831.       char c;
  832.       fseek(in,r,0);
  833.       while (r<=I.ArtikelEnd) {
  834.         c=getc(in);
  835.         putc(c,out);
  836.         r++;
  837.       }
  838.     }
  839.  
  840.     CloseHomeBox(in);
  841.     fclose(out);
  842.  
  843.     sprintf(exec,PipeDefault,MailTmp);
  844.     Execute(exec,NULL,NULL);
  845. /*
  846.     Delay(100L);
  847.     Close(fh);
  848. */
  849.     remove(MailTmp);
  850. }
  851.  
  852.  
  853.  
  854. void PagerCommand(char *cmd_text)
  855. {
  856.   int i;
  857.   sprintf(TBuffer,"\033[%d;1H\033[J",Win_Height-3);
  858.   outline();
  859.   putst("\033[1m");
  860.   for(i=0;i<Win_Width;i++)
  861.     TBuffer[i]='_';
  862.   TBuffer[Win_Width]='\0';
  863.   outline();
  864.   putst("\033[0m");
  865.   sprintf(TBuffer,"\033[%d;1HCommand: %s",Win_Height-1,cmd_text);
  866.   outline();
  867. }
  868.  
  869.  
  870.  
  871. void editfile(char *name)
  872. {
  873.   char *str;
  874.   str=malloc(strlen(MailEditor)+strlen(name)+2);
  875.   sprintf(str,"%s %s",MailEditor,name);
  876.   WorkbenchToFront();
  877.   Execute(str,NULL,NULL);
  878.   ElmToFront();
  879.   free(str);
  880. }
  881.