home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / bm332c.zip / BMUTIL.C < prev    next >
C/C++ Source or Header  |  1993-02-24  |  17KB  |  770 lines

  1. /* bmutil.c */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <time.h>
  6.  
  7. #define        SETVBUF
  8.  
  9. #include <sys/stat.h>
  10. #include <fcntl.h>
  11.  
  12. #include "bm.h"
  13. #include "header.h"
  14.  
  15. char *getname();
  16. static unsigned long    mboxsize;
  17. static int    anyread;
  18.  
  19. #ifdef SETVBUF
  20. #define        MYBUF    4096
  21. char    *inbuf = NULLCHAR;    /* the stdio buffer for the mail file */
  22. char    *outbuf = NULLCHAR;    /* the stdio file io buffer for the temp file */
  23. #endif
  24.  
  25. int
  26. initnotes()
  27. {
  28.     FILE    *tmpfile();
  29.     FILE    *ifile;
  30.     register struct    let *cmsg;
  31.     int     i, ret;
  32.     struct stat mstat;
  33.  
  34.     if (!stat(mfilename,&mstat))
  35.         mboxsize = mstat.st_size;
  36.     if ((ifile = fopen(mfilename,"r")) == NULLFILE) {
  37.         printf(nomail);
  38.         mfile = NULLFILE;
  39.         return 0;
  40.     } 
  41. #ifdef    SETVBUF
  42.     if (inbuf == NULLCHAR)
  43.         inbuf = malloc(MYBUF);
  44.     setvbuf(ifile, inbuf, _IOFBF, MYBUF);
  45. #endif
  46.     if ((mfile = tmpfile()) == NULLFILE) {
  47.         printf("Unable to create tmp file\n");
  48.         (void) fclose(ifile);
  49.         return -1;
  50.     }
  51. #ifdef SETVBUF
  52.     if (outbuf == NULLCHAR)
  53.         outbuf = malloc(MYBUF);
  54.     setvbuf(mfile, outbuf, _IOFBF, MYBUF);
  55. #endif
  56.     nmsgs = 0;
  57.     current = 0;
  58.     change = 0;
  59.     newmsgs = 0;
  60.     anyread = 0;
  61.     ret = readnotes(ifile);
  62.     (void) fclose(ifile);
  63.     if (ret != 0)
  64.         return -1;
  65. #ifdef SETVBUF
  66.     if (inbuf != NULLCHAR) {
  67.         (void) free(inbuf);
  68.         inbuf = NULLCHAR;
  69.     }
  70. #endif
  71.     for (cmsg = &mbox[1],i = 1; i <= nmsgs; i++, cmsg++)  
  72.         if ((cmsg->status & READ) == 0) {
  73.             newmsgs++;
  74.             if (current == 0)
  75.                 current = i;
  76.         }
  77.     /* start at one if no new messages */
  78.     if (current == 0)
  79.         current++;
  80.  
  81.     return 0;
  82.  
  83. }
  84.  
  85. /* readnotes assumes that ifile is pointing to the first
  86.  * message that needs to be read.  For initial reads of a
  87.  * notesfile, this will be the beginning of the file.  For
  88.  * rereads when new mail arrives, it will be the first new
  89.  * message.
  90.  */
  91. readnotes(ifile)
  92. FILE *ifile ;
  93. {
  94.     char     tstring[LINELEN];
  95.     long    cpos;
  96.     register struct    let *cmsg;
  97.     register char *line;
  98.     long    ftell();
  99.  
  100.     cmsg = (struct let *)NULL;
  101.     line = tstring;
  102.     while(!feof(ifile)) {
  103.         fgets(line,LINELEN,ifile);
  104.         /* scan for begining of a message */
  105.         if(strncmp(line,"From ",5) == 0) {
  106.             cpos = ftell(mfile);
  107.             fputs(line,mfile);
  108.             if (nmsgs == maxlet) {
  109.                 printf("Mail box full: > %d messages\n",maxlet);
  110.                 (void) fclose(mfile);
  111.                 return -1;
  112.             }
  113.             nmsgs++;
  114.             cmsg = &mbox[nmsgs];
  115.             cmsg->start = cpos;
  116.             cmsg->status = 0;
  117.             cmsg->size = strlen(line);
  118.             while (!feof(ifile)) {
  119.                 if (fgets(line,LINELEN,ifile) == NULLCHAR)
  120.                     break;
  121.                 if (*line == '\n') { /* done header part */
  122.                     cmsg->size++;
  123.                     putc(*line, mfile);
  124.                     break;
  125.                 }
  126.                 if (htype(line) == STATUS) {
  127.                     if (line[8] == 'R') 
  128.                         cmsg->status |= READ;
  129.                     continue;
  130.                 }
  131.                 cmsg->size += strlen(line);
  132.                 if (fputs(line,mfile) == EOF) {
  133.                     perror("tmp file");
  134.                     (void) fclose(mfile);
  135.                     return -1;
  136.                 }
  137.  
  138.             }
  139.         } else if (cmsg) {
  140.             cmsg->size += strlen(line);
  141.             fputs(line,mfile);
  142.         }
  143.     }
  144.     return 0;
  145. }
  146.  
  147. /* list headers of a notesfile a message */
  148. listnotes()
  149. {
  150.     register struct    let *cmsg;
  151.     register char    *p, *s;
  152.     char    smtp_date[SLINELEN];
  153.     char    smtp_from[SLINELEN];
  154.     char    smtp_subject[SLINELEN]; 
  155.     char    tstring[LINELEN];
  156.     int    i,c;
  157.     int    lines;
  158.     long    size;
  159.  
  160.     if (mfile == NULLFILE)
  161.         return;
  162.  
  163.     cls();
  164.     setrawmode();
  165.     printf("Mailbox %s - %d messages %d new\n\n",mfilename,nmsgs,newmsgs);
  166.     lines = 2;
  167.     for (cmsg = &mbox[1],i = 1; i <= nmsgs; i++, cmsg++) {
  168.         *smtp_date = '\0';
  169.         *smtp_from = '\0';
  170.         *smtp_subject = '\0';
  171.         fseek(mfile,cmsg->start,0);
  172.         size = cmsg->size;
  173.         while (!feof(mfile) && size > 0) {
  174.             fgets(tstring,sizeof(tstring),mfile);
  175.             if (*tstring == '\n')    /* end of header */
  176.                 break;
  177.             size -= strlen(tstring);
  178.             rip(tstring);
  179.             /* handle continuation later */
  180.             if (*tstring == ' '|| *tstring == '\t')
  181.                 continue;
  182.             switch(htype(tstring)) {
  183.             case FROM:
  184.                 if((p = getname(tstring)) == NULLCHAR) {
  185.                     p = &tstring[6];
  186.                     while(*p && *p != ' ' && *p != '(')
  187.                         p++;
  188.                     *p = '\0';
  189.                     p = &tstring[6];
  190.                 }
  191.                 sprintf(smtp_from,"%.30s",p);
  192.                 break;
  193.             case SUBJECT:
  194.                 sprintf(smtp_subject,"%.34s",&tstring[9]);
  195.                 break;
  196.             case DATE:
  197.                 if ((p = strchr(tstring,',')) == NULLCHAR)
  198.                     p = &tstring[6];
  199.                 else
  200.                     p++;
  201.                 /* skip spaces */
  202.                 while (*p == ' ') p++;
  203.                 if(strlen(p) < 17)
  204.                     break;     /* not a valid length */
  205.                 s = smtp_date;
  206.                 /* copy day */
  207.                 if (atoi(p) < 10 && *p != '0') {
  208.                     *s++ = ' ';
  209.                 } else
  210.                     *s++ = *p++;
  211.                 *s++ = *p++;
  212.  
  213.                 *s++ = ' ';
  214.                 while (*p == ' ')
  215.                     p++;
  216.                 /* copy month */
  217.                 *s++ = *p++;
  218.                 *s++ = *p++;
  219.                 *s++ = *p++;
  220.                 while (*p == ' ')
  221.                     p++;
  222.                 /* skip year */
  223.                 while (isdigit(*p))
  224.                     p++;
  225.                 /* copy time */
  226.                 *s++ = *p++;    /* space */
  227.                 *s++ = *p++;    /* hour */
  228.                 *s++ = *p++;
  229.                 *s++ = *p++;    /* : */
  230.                 *s++ = *p++;    /* min */
  231.                 *s++ = *p++;
  232.                 *s = '\0';
  233.                 break;
  234.             case NOHEADER:
  235.                 break;
  236.             }
  237.         }
  238.         printf("%c%c%c%3d %-27.27s %-12.12s %5ld %.25s\n",
  239.             (i == current ? '>' : ' '),
  240.             (cmsg->status & DELETE ? 'D' : ' '),
  241.             (cmsg->status & READ ? 'Y' : 'N'),
  242.             i, smtp_from, smtp_date,
  243.             cmsg->size, smtp_subject);
  244.         if ((++lines % (MAXROWS - 1)) == 0) {
  245.             printf("- more -");
  246.             c = getrch();
  247.             printf("\r         \r");
  248.             if( c == EOF || c == 'q')
  249.                 break;
  250.             cls();
  251.             lines = 0;
  252.         }
  253.     }
  254.     setcookedmode();
  255. }
  256.  
  257. /*  save msg on stream - if noheader set don't output the header */
  258. int
  259. msgtofile(msg,tfile,noheader)
  260. int msg;
  261. FILE *tfile;   /* already open for write */
  262. int noheader;
  263. {
  264.     char    tstring[LINELEN];
  265.     long     size;
  266.  
  267.     if (mfile == NULLFILE) {
  268.         printf(nomail);
  269.         return -1;
  270.     }
  271.     fseek(mfile,mbox[msg].start,0);
  272.     size = mbox[msg].size;
  273.     if ((mbox[msg].status & READ) == 0) {
  274.         mbox[msg].status |= READ;
  275.         change = 1;
  276.     }
  277.  
  278.     if (noheader) {
  279.         /* skip header */
  280.         while (!feof(mfile) && size > 0) {
  281.             fgets(tstring,sizeof(tstring),mfile);
  282.             size -= strlen(tstring);
  283.             if (*tstring == '\n')
  284.                 break;
  285.         }
  286.     }
  287.     while (!feof(mfile) && size > 0) {
  288.         fgets(tstring,sizeof(tstring),mfile);
  289.         size -= strlen(tstring);
  290.         fputs(tstring,tfile);
  291.         if (ferror(tfile)) {
  292.             printf("Error writing mail file\n");
  293.             (void) fclose(tfile);
  294.             return -1;
  295.         }
  296.     }
  297.     return 0;
  298. }
  299.  
  300. /*  delmsg - delete message in current notesfile */
  301. delmsg(msg)
  302. int msg;
  303. {
  304.     if (mfile == NULLFILE) {
  305.         printf(nomail);
  306.         return;
  307.     }
  308.     mbox[msg].status |= DELETE;
  309.     change = 1;
  310. }
  311.  
  312. /*  reply - to a message  */
  313. reply(msg)
  314. int msg;
  315. {
  316.     char     to[SLINELEN];
  317.     char    subject[LINELEN];
  318.     char    tstring[LINELEN];
  319.     char     *p,*s;
  320.     char    *toarg[1];
  321.     long    size;
  322.  
  323.     if (mfile == NULLFILE) {
  324.         printf(nomail);
  325.         return;
  326.     }
  327.     *to = '\0';
  328.     *subject = '\0';
  329.     fseek(mfile,mbox[msg].start,0);
  330.     size = mbox[msg].size;
  331.     while (!feof(mfile) && size > 0) {
  332.         fgets(tstring,sizeof(tstring),mfile);
  333.         size -= strlen(tstring);
  334.         if (*tstring == '\n')     /* end of header */
  335.             break;
  336.         rip(tstring);
  337.         if ((*to == '\0' && htype(tstring) == FROM)
  338.             || htype(tstring) == REPLYTO) {
  339.             s = getname(tstring);
  340.             if (s == NULLCHAR) {
  341.                 p = strchr(tstring,':');
  342.                 p += 2;
  343.                 s = p;
  344.                 while(*p && *p != ' ' && *p != '(')
  345.                     p++;
  346.                 *p = '\0';
  347.             }
  348.             *to = '\0';
  349.             strncat(to,s,sizeof(to));
  350.         } else if (htype(tstring) == SUBJECT) {
  351.             if (strncmp(&tstring[9], "Re:", 3))  /* No Re: yet? */
  352.                 sprintf(subject,"Re: %s\n",&tstring[9]);
  353.             else    /* there's an Re:, let's not add another */
  354.                 sprintf(subject,"%s\n",&tstring[9]) ;
  355.         }
  356.     }
  357.     if (*to == '\0')
  358.         printf("No reply address in message\n");
  359.     else {
  360.         toarg[0] = to;
  361.         dosmtpsend(NULLFILE,toarg,1,subject);
  362.     }
  363. }
  364.  
  365.  
  366. /* close the temp file while coping mail back to the mailbox */
  367. int
  368. closenotes()
  369. {
  370.     register struct    let *cmsg;
  371.     register char *line;
  372.     char tstring[LINELEN];
  373.     long size;
  374.     int i;
  375.     int ret;
  376.     FILE    *nfile;
  377.     struct stat mstat;
  378.  
  379.     if (mfile == NULLFILE)
  380.         return 0;
  381.     if (!change) {
  382.         (void) fclose(mfile);
  383.         return 0;
  384.     }
  385.     line = tstring;
  386.     fseek(mfile,0L,2);
  387.     if (isnewmail()) {
  388.         if ((nfile = fopen(mfilename,"r")) == NULLFILE)
  389.             perror(mfilename);
  390.         else {
  391.             /* seek to end of old msgs */
  392.             fseek(nfile,mboxsize,0);
  393.             /* seek to end of tempfile */
  394.             fseek(mfile,0L,2);
  395.             ret = readnotes(nfile);   /* get the new mail */
  396.             (void) fclose(nfile);
  397.             if (ret != 0) {
  398.                 printf("Error updating mail file\n");
  399.                 return -1;
  400.             }
  401.         }
  402.     }
  403.  
  404.     if ((nfile = fopen(mfilename,"w")) == NULLFILE) {
  405.         printf("Unable to open %s\n",mfilename);
  406.         return -1;
  407.     }
  408.     /* copy tmp file back to notes file */
  409.     for (cmsg = &mbox[1],i = 1; i <= nmsgs; i++, cmsg++) {
  410.         fseek(mfile,cmsg->start,0);
  411.         size = cmsg->size;
  412.         if ((cmsg->status & DELETE))
  413.             continue;
  414.         /* copy the header */
  415.         while (!feof(mfile) && size > 0) {
  416.             fgets(line,LINELEN,mfile);
  417.             size -= strlen(line);
  418.             if (*line == '\n') {
  419.                 if ((cmsg->status & READ) != 0)
  420.                     fprintf(nfile,"Status: R\n");
  421.                 fprintf(nfile,"\n");
  422.                 break;
  423.             }
  424.             fputs(line,nfile);
  425.         }
  426.         while (!feof(mfile) && size > 0) {
  427.             fgets(line,LINELEN,mfile);
  428.             fputs(line,nfile);
  429.             size -= strlen(line);
  430.             if (ferror(nfile)) {
  431.                 printf("Error writing mail file\n");
  432.                 (void) fclose(nfile);
  433.                 (void) fclose(mfile);
  434.                 return -1;
  435.             }
  436.         }
  437.     }
  438.     nmsgs = 0;
  439.     (void) fclose(nfile);
  440.     (void) fclose(mfile);
  441.     mfile = NULLFILE;
  442.  
  443.     /* remove a zero length file */
  444.     if (stat(mfilename,&mstat) == 0  && mstat.st_size == 0)
  445.         (void) unlink(mfilename);
  446.     return 0;
  447. }
  448.  
  449. /* get a message id from the sequence file */
  450. long 
  451. get_msgid()
  452. {
  453.     char sfilename[SLINELEN];
  454.     char s[20];
  455.     long sequence = 0L;
  456.     FILE *sfile;
  457.     long atol();
  458.  
  459.     sprintf(sfilename,"%s/sequence.seq", mqueue);
  460.     sfile = fopen(sfilename,"r");
  461.  
  462.     /* if sequence file exists, get the value, otherwise set it */
  463.     if (sfile != NULLFILE) {
  464.         fgets(s,sizeof(s),sfile);
  465.         sequence = atol(s);
  466.     /* Keep it in range of and 8 digit number to use for dos name prefix. */
  467.         if (sequence < 0L || sequence > 99999999L )
  468.             sequence = 0L;
  469.         (void) fclose(sfile);
  470.     }
  471.  
  472.     /* increment sequence number, and write to sequence file */
  473.     sfile = fopen(sfilename,"w");
  474.     fprintf(sfile,"%ld",++sequence);
  475.     (void) fclose(sfile);
  476.     return sequence;
  477. }
  478.  
  479. /* Given a string of the form <user@host>, extract the part inside the
  480.  * brackets and return a pointer to it.
  481.  */
  482. char *
  483. getname(cp)
  484. register char *cp;
  485. {
  486.     char *cp1;
  487.  
  488.     if((cp = strchr(cp,'<')) == NULLCHAR)
  489.         return NULLCHAR;
  490.     cp++;    /* cp -> first char of name */
  491.     if((cp1 = strchr(cp,'>')) == NULLCHAR)
  492.         return NULLCHAR;
  493.     *cp1 = '\0';
  494.     return cp;
  495. }
  496.  
  497. /* create mail lockfile */
  498. int
  499. mlock(dir,id)
  500. char *dir;
  501. char *id;
  502. {
  503.     char lockname[SLINELEN];
  504.     int fd;
  505.     /* Try to create the lock file in an atomic operation */
  506.     sprintf(lockname,"%s/%.8s.lck",dir,id);
  507.     if((fd = open(lockname, O_WRONLY|O_EXCL|O_CREAT,0600)) == -1)
  508.         return -1;
  509.     (void) close(fd);
  510.     return 0;
  511. }
  512.  
  513. /* remove mail lockfile */
  514. int
  515. rmlock(dir,id)
  516. char *dir;
  517. char *id;
  518. {
  519.     char lockname[SLINELEN];
  520.     sprintf(lockname,"%s/%.8s.lck",dir,id);
  521.     (void) unlink(lockname);
  522. }
  523.  
  524. /* parse a line into argv array. Return argc */
  525. int
  526. parse(line,argv,maxargs)
  527. register char *line;
  528. char *argv[];
  529. int maxargs;
  530. {
  531.     int argc;
  532.     int qflag;
  533.     register char *cp;
  534.  
  535.     for(argc = 0; argc < maxargs; argc++)
  536.         argv[argc] = NULLCHAR;
  537.  
  538.     for(argc = 0; argc < maxargs;){
  539.         qflag = 0;
  540.         /* Skip leading white space */
  541.         while(*line == ' ' || *line == '\t')
  542.             line++;
  543.         if(*line == '\0')
  544.             break;
  545.         /* Check for quoted token */
  546.         if(*line == '"'){
  547.             line++;    /* Suppress quote */
  548.             qflag = 1;
  549.         }
  550.         argv[argc++] = line;    /* Beginning of token */
  551.         /* Find terminating delimiter */
  552.         if(qflag){
  553.             /* Find quote, it must be present */
  554.             if((line = strchr(line,'"')) == NULLCHAR){
  555.                 return -1;
  556.             }
  557.             *line++ = '\0';
  558.         } else {
  559.             /* Find space or tab. If not present,
  560.              * then we've already found the last
  561.              * token.
  562.              */
  563.             if((cp = strchr(line,' ')) == NULLCHAR
  564.                 && (cp = strchr(line,'\t')) == NULLCHAR){
  565.                 break;
  566.             }
  567.             *cp++ = '\0';
  568.             line = cp;
  569.         }
  570.     }
  571.     return argc;
  572. }
  573.  
  574. lockit()
  575. {
  576.     char line[SLINELEN];
  577.     while(mlock(maildir,notename)) {
  578.         printf("Mail file is busy, Abort or Retry ? ");
  579.         gets(line);
  580.         if (*line == 'A' || *line == 'a') {
  581.             if ( mfile != NULLFILE)
  582.                 (void) fclose(mfile);
  583.             mfile = NULLFILE;
  584.             return 1;
  585.         }
  586.     }
  587.     return 0;
  588. }
  589.  
  590. /* print the next message or the current on of new */
  591. printnext()
  592. {
  593.     if (mfile == NULLFILE)
  594.         return;
  595.     if ((mbox[current].status & READ) != 0) {
  596.         if (current == 1 && anyread == 0)
  597.             ;
  598.         else if (current < nmsgs) {
  599.             current++;
  600.         } else {
  601.             printf("Last message\n");
  602.             return;
  603.         }
  604.     }
  605.     displaymsg(current);
  606.     anyread = 1;
  607. }
  608.  
  609. /*  display message on the crt given msg number */
  610. displaymsg(msg)
  611. int msg;
  612. {
  613.     register int c;
  614.     register int col;
  615.     char    buf[MAXCOL+2];        /* line buffer */
  616.     int    lines;
  617.     int    cnt;
  618.     long     tsize, size;
  619.  
  620.     if (mfile == NULLFILE) {
  621.         printf(nomail);
  622.         return;
  623.     }
  624.     if( msg < 0 || msg > nmsgs) {
  625.         printf(badmsg,msg);
  626.         return;
  627.     }
  628.     setrawmode();
  629.     cls();
  630.     fseek(mfile,mbox[msg].start,0);
  631.     size = mbox[msg].size;
  632.     tsize = size;
  633.  
  634.     printf("Message #%d %s\n",
  635.         msg, mbox[msg].status & DELETE ? "[Deleted]" : "");
  636.     if ((mbox[msg].status & READ) == 0) {
  637.         mbox[msg].status |= READ;
  638.         change = 1;
  639.     }
  640.     lines = 1;
  641.     col = 0;
  642.     while (!feof(mfile) && size > 0) {
  643.         for (col = 0;  col < MAXCOL-2;) {
  644.             c = getc(mfile);
  645.             size--;
  646.             if (feof(mfile) || size == 0)    /* end this line */
  647.                 break;
  648.             if (c == '\t') {
  649.                 cnt = col + 8 - (col & 7);
  650.                 if (cnt >= MAXCOL)    /* end this line */
  651.                     break;
  652.                 while (col < cnt)
  653.                     buf[col++] = ' ';
  654.             } else if (c == '\n')
  655.                 break;
  656.             else
  657.                 buf[col++] = c;
  658.         }
  659.         buf[col++] = '\r';
  660.         buf[col++] = '\n';
  661.         buf[col] = '\0';
  662.         cputs(buf);
  663.         col = 0;
  664.         if ((++lines == (MAXROWS-1))) {
  665.             printf("- more -(%d%%)",(tsize-size)*100/tsize);
  666.             c = getrch();
  667.             printf("\r               \r");
  668.             if( c == EOF || c == 'q')
  669.                 break;
  670.             cls();
  671.             lines = 0;
  672.         }
  673.     }
  674.     setcookedmode();
  675. }
  676.  
  677. /* list jobs wating to be sent in the mqueue */
  678. listqueue()
  679. {
  680.     char tstring[80];
  681.     char workfile[80];
  682.     char line[20];
  683.     char host[SLINELEN];
  684.     char to[SLINELEN];
  685.     char from[SLINELEN];
  686.     char *p;
  687.     char    status;
  688.     struct stat stbuf;
  689.     struct tm *tminfo, *localtime();
  690.     FILE *fp;
  691.  
  692.     printf("S     Job    Size Date  Time  Host                 From\n");
  693.     sprintf(workfile,"%s/%s",mqueue,WORK);
  694.     filedir(workfile,0,line);
  695.     while(line[0] != '\0') {
  696.         sprintf(tstring,"%s/%s",mqueue,line);
  697.         if ((fp = fopen(tstring,"r")) == NULLFILE) {
  698.             perror(tstring);
  699.             continue;
  700.         }
  701.         if ((p = strrchr(line,'.')) != NULLCHAR)
  702.             *p = '\0';
  703.         sprintf(tstring,"%s/%s.lck",mqueue,line);
  704.         if (access(tstring,0))
  705.             status = ' ';
  706.         else
  707.             status = 'L';
  708.         sprintf(tstring,"%s/%s.txt",mqueue,line);
  709.         stat(tstring,&stbuf);
  710.         tminfo = localtime(&stbuf.st_ctime);
  711.         fgets(host,sizeof(host),fp);
  712.         rip(host);
  713.         fgets(from,sizeof(from),fp);
  714.         rip(from);
  715.         printf("%c %7s %7ld %02d/%02d %02d:%02d %-20s %s\n      ",
  716.             status, line, stbuf.st_size,
  717.             tminfo ->tm_mon+1,
  718.             tminfo->tm_mday,
  719.             tminfo->tm_hour,
  720.             tminfo->tm_min,
  721.             host,from);
  722.         while (fgets(to,sizeof(to),fp) != NULLCHAR) {
  723.             rip(to);
  724.             printf("%s ",to);
  725.         }
  726.         printf("\n");
  727.         (void) fclose(fp);
  728.         filedir(workfile,1,line);
  729.     }
  730. }
  731.  
  732. /* kill a job in the mqueue */
  733. killjob(j)
  734. char *j;
  735. {
  736.     char s[SLINELEN];
  737.     char tbuf[SLINELEN];
  738.     char *p;
  739.     sprintf(s,"%s/%s.lck",mqueue,j);
  740.     p = strrchr(s,'.');
  741.     if (!access(s,0)) {
  742.         printf("Warning Job %s is locked by SMTP. Remove (y/n)? ",j);
  743.         gets(tbuf);
  744.         if (*tbuf != 'y')
  745.             return;
  746.         (void) unlink(s);
  747.     }
  748.     strcpy(p,".wrk");
  749.     if (unlink(s))
  750.         printf("Job id %s not found\n",j);
  751.     strcpy(p,".txt");
  752.     (void) unlink(s);
  753. }
  754.  
  755. /* check the current mailbox to see if new mail has arrived.
  756. * checks to see if the file has increased in size.
  757. * returns true if new mail has arrived.
  758. */
  759. isnewmail()
  760. {
  761.     struct stat mstat;
  762.     if (mfile == NULLFILE)
  763.         return 0;
  764.     if (stat(mfilename,&mstat))
  765.         printf("unable to stat %s\n",mfilename);
  766.     else if (mstat.st_size > mboxsize)
  767.             return 1;
  768.     return 0;
  769. }
  770.