14632Seric # include "sendmail.h" 24632Seric # include <sys/stat.h> 38348Seric # include <dir.h> 44634Seric # include <signal.h> 54632Seric # include <errno.h> 64632Seric 75182Seric # ifndef QUEUE 8*10686Seric SCCSID(@(#)queue.c 3.71 02/02/83 (no queueing)); 95182Seric # else QUEUE 104632Seric 11*10686Seric SCCSID(@(#)queue.c 3.71 02/02/83); 125182Seric 134632Seric /* 149377Seric ** Work queue. 159377Seric */ 169377Seric 179377Seric struct work 189377Seric { 199377Seric char *w_name; /* name of control file */ 209377Seric long w_pri; /* priority of message, see below */ 219377Seric struct work *w_next; /* next in queue */ 229377Seric }; 239377Seric 249377Seric typedef struct work WORK; 259377Seric 269377Seric WORK *WorkQ; /* queue of things to be done */ 279377Seric /* 284632Seric ** QUEUEUP -- queue a message up for future transmission. 294632Seric ** 304632Seric ** Parameters: 316980Seric ** e -- the envelope to queue up. 326999Seric ** queueall -- if TRUE, queue all addresses, rather than 336999Seric ** just those with the QQUEUEUP flag set. 349377Seric ** announce -- if TRUE, tell when you are queueing up. 354632Seric ** 364632Seric ** Returns: 374632Seric ** none. 384632Seric ** 394632Seric ** Side Effects: 409377Seric ** The current request are saved in a control file. 414632Seric */ 424632Seric 439377Seric queueup(e, queueall, announce) 446980Seric register ENVELOPE *e; 456999Seric bool queueall; 469377Seric bool announce; 474632Seric { 487812Seric char *tf; 497812Seric char *qf; 507763Seric char buf[MAXLINE]; 517812Seric register FILE *tfp; 524632Seric register HDR *h; 535007Seric register ADDRESS *q; 5410173Seric MAILER nullmailer; 554632Seric 565037Seric /* 575037Seric ** Create control file. 585037Seric */ 594632Seric 607812Seric tf = newstr(queuename(e, 't')); 617812Seric tfp = fopen(tf, "w"); 627812Seric if (tfp == NULL) 634632Seric { 647812Seric syserr("queueup: cannot create temp file %s", tf); 654632Seric return; 664632Seric } 679048Seric (void) chmod(tf, FileMode); 684632Seric 694632Seric # ifdef DEBUG 707677Seric if (tTd(40, 1)) 717812Seric printf("queueing in %s\n", tf); 724632Seric # endif DEBUG 734632Seric 744632Seric /* 756980Seric ** If there is no data file yet, create one. 766980Seric */ 776980Seric 786980Seric if (e->e_df == NULL) 796980Seric { 806980Seric register FILE *dfp; 819389Seric extern putbody(); 826980Seric 837812Seric e->e_df = newstr(queuename(e, 'd')); 846980Seric dfp = fopen(e->e_df, "w"); 856980Seric if (dfp == NULL) 866980Seric { 876980Seric syserr("queueup: cannot create %s", e->e_df); 887812Seric (void) fclose(tfp); 896980Seric return; 906980Seric } 919048Seric (void) chmod(e->e_df, FileMode); 9210173Seric (*e->e_putbody)(dfp, ProgMailer, e); 937009Seric (void) fclose(dfp); 949389Seric e->e_putbody = putbody; 956980Seric } 966980Seric 976980Seric /* 984632Seric ** Output future work requests. 999377Seric ** Priority should be first, since it is read by orderq. 1004632Seric */ 1014632Seric 1029377Seric /* output message priority */ 1039377Seric fprintf(tfp, "P%ld\n", e->e_msgpriority); 1049377Seric 1059630Seric /* output creation time */ 1069630Seric fprintf(tfp, "T%ld\n", e->e_ctime); 1079630Seric 1084632Seric /* output name of data file */ 1097812Seric fprintf(tfp, "D%s\n", e->e_df); 1104632Seric 11110108Seric /* message from envelope, if it exists */ 11210108Seric if (e->e_message != NULL) 11310108Seric fprintf(tfp, "M%s\n", e->e_message); 11410108Seric 1154632Seric /* output name of sender */ 1167812Seric fprintf(tfp, "S%s\n", e->e_from.q_paddr); 1174632Seric 1184632Seric /* output list of recipient addresses */ 1196980Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 1204632Seric { 1217763Seric if (queueall ? !bitset(QDONTSEND, q->q_flags) : 1227763Seric bitset(QQUEUEUP, q->q_flags)) 1238245Seric { 1247812Seric fprintf(tfp, "R%s\n", q->q_paddr); 1259377Seric if (announce) 1269377Seric { 1279377Seric e->e_to = q->q_paddr; 1289377Seric message(Arpa_Info, "queued"); 1299377Seric if (LogLevel > 4) 1309377Seric logdelivery("queued"); 1319377Seric e->e_to = NULL; 1329377Seric } 1339387Seric #ifdef DEBUG 1349387Seric if (tTd(40, 1)) 1359387Seric { 1369387Seric printf("queueing "); 1379387Seric printaddr(q, FALSE); 1389387Seric } 1399387Seric #endif DEBUG 1408245Seric } 1414632Seric } 1424632Seric 1439377Seric /* 1449377Seric ** Output headers for this message. 1459377Seric ** Expand macros completely here. Queue run will deal with 1469377Seric ** everything as absolute headers. 1479377Seric ** All headers that must be relative to the recipient 1489377Seric ** can be cracked later. 14910173Seric ** We set up a "null mailer" -- i.e., a mailer that will have 15010173Seric ** no effect on the addresses as they are output. 1519377Seric */ 1529377Seric 153*10686Seric bzero((char *) &nullmailer, sizeof nullmailer); 15410173Seric nullmailer.m_r_rwset = nullmailer.m_s_rwset = -1; 15510349Seric nullmailer.m_eol = "\n"; 15610173Seric 1579377Seric define('g', "$f", e); 1586980Seric for (h = e->e_header; h != NULL; h = h->h_link) 1594632Seric { 160*10686Seric extern bool bitzerop(); 161*10686Seric 1624632Seric if (h->h_value == NULL || h->h_value[0] == '\0') 1634632Seric continue; 1647812Seric fprintf(tfp, "H"); 165*10686Seric if (!bitzerop(h->h_mflags) && bitset(H_CHECK|H_ACHECK, h->h_flags)) 166*10686Seric { 167*10686Seric int j; 168*10686Seric 169*10686Seric putc('?', tfp); 170*10686Seric for (j = '\0'; j <= '\177'; j++) 171*10686Seric if (bitnset(j, h->h_mflags)) 172*10686Seric putc(j, tfp); 173*10686Seric putc('?', tfp); 174*10686Seric } 1757763Seric if (bitset(H_DEFAULT, h->h_flags)) 1767763Seric { 1777763Seric (void) expand(h->h_value, buf, &buf[sizeof buf], e); 1788236Seric fprintf(tfp, "%s: %s\n", h->h_field, buf); 1797763Seric } 1808245Seric else if (bitset(H_FROM|H_RCPT, h->h_flags)) 1819348Seric { 1829348Seric commaize(h, h->h_value, tfp, bitset(EF_OLDSTYLE, e->e_flags), 18310173Seric &nullmailer); 1849348Seric } 1857763Seric else 1868245Seric fprintf(tfp, "%s: %s\n", h->h_field, h->h_value); 1874632Seric } 1884632Seric 1894632Seric /* 1904632Seric ** Clean up. 1914632Seric */ 1924632Seric 1937812Seric (void) fclose(tfp); 1947812Seric qf = queuename(e, 'q'); 1959377Seric holdsigs(); 1967812Seric (void) unlink(qf); 1977812Seric if (link(tf, qf) < 0) 1987812Seric syserr("cannot link(%s, %s), df=%s", tf, qf, e->e_df); 1996980Seric else 2007812Seric (void) unlink(tf); 2019377Seric rlsesigs(); 2027391Seric 2037677Seric # ifdef LOG 2047677Seric /* save log info */ 2057878Seric if (LogLevel > 15) 2067878Seric syslog(LOG_DEBUG, "%s: queueup, qf=%s, df=%s\n", e->e_id, qf, e->e_df); 2077677Seric # endif LOG 2084632Seric } 2094632Seric /* 2104632Seric ** RUNQUEUE -- run the jobs in the queue. 2114632Seric ** 2124632Seric ** Gets the stuff out of the queue in some presumably logical 2134632Seric ** order and processes them. 2144632Seric ** 2154632Seric ** Parameters: 2164632Seric ** none. 2174632Seric ** 2184632Seric ** Returns: 2194632Seric ** none. 2204632Seric ** 2214632Seric ** Side Effects: 2224632Seric ** runs things in the mail queue. 2234632Seric */ 2244632Seric 2254639Seric runqueue(forkflag) 2264639Seric bool forkflag; 2274632Seric { 2287466Seric /* 2297466Seric ** See if we want to go off and do other useful work. 2307466Seric */ 2314639Seric 2324639Seric if (forkflag) 2334639Seric { 2347943Seric int pid; 2357943Seric 2367943Seric pid = dofork(); 2377943Seric if (pid != 0) 2384639Seric { 2397943Seric /* parent -- pick up intermediate zombie */ 2409377Seric (void) waitfor(pid); 2417690Seric if (QueueIntvl != 0) 2429348Seric (void) setevent(QueueIntvl, runqueue, TRUE); 2434639Seric return; 2444639Seric } 2457943Seric /* child -- double fork */ 2467943Seric if (fork() != 0) 2477943Seric exit(EX_OK); 2484639Seric } 2497876Seric # ifdef LOG 2507876Seric if (LogLevel > 11) 2517943Seric syslog(LOG_DEBUG, "runqueue %s, pid=%d", QueueDir, getpid()); 2527876Seric # endif LOG 2534639Seric 2547466Seric /* 25510205Seric ** Release any resources used by the daemon code. 25610205Seric */ 25710205Seric 25810205Seric # ifdef DAEMON 25910205Seric clrdaemon(); 26010205Seric # endif DAEMON 26110205Seric 26210205Seric /* 2637466Seric ** Start making passes through the queue. 2647466Seric ** First, read and sort the entire queue. 2657466Seric ** Then, process the work in that order. 2667466Seric ** But if you take too long, start over. 2677466Seric */ 2687466Seric 2697943Seric /* order the existing work requests */ 27010070Seric (void) orderq(); 2717690Seric 2727943Seric /* process them once at a time */ 2737943Seric while (WorkQ != NULL) 2744639Seric { 2757943Seric WORK *w = WorkQ; 2767881Seric 2777943Seric WorkQ = WorkQ->w_next; 2787943Seric dowork(w); 2797943Seric free(w->w_name); 2807943Seric free((char *) w); 2814639Seric } 2827943Seric finis(); 2834634Seric } 2844634Seric /* 2854632Seric ** ORDERQ -- order the work queue. 2864632Seric ** 2874632Seric ** Parameters: 2884632Seric ** none. 2894632Seric ** 2904632Seric ** Returns: 29110121Seric ** The number of request in the queue (not necessarily 29210121Seric ** the number of requests in WorkQ however). 2934632Seric ** 2944632Seric ** Side Effects: 2954632Seric ** Sets WorkQ to the queue of available work, in order. 2964632Seric */ 2974632Seric 2984632Seric # define WLSIZE 120 /* max size of worklist per sort */ 2994632Seric 3004632Seric orderq() 3014632Seric { 3026625Sglickman register struct direct *d; 3034632Seric register WORK *w; 3044632Seric register WORK **wp; /* parent of w */ 3056625Sglickman DIR *f; 3064632Seric register int i; 30710121Seric WORK wlist[WLSIZE+1]; 30810070Seric int wn = -1; 3094632Seric extern workcmpf(); 3104632Seric 3114632Seric /* clear out old WorkQ */ 3124632Seric for (w = WorkQ; w != NULL; ) 3134632Seric { 3144632Seric register WORK *nw = w->w_next; 3154632Seric 3164632Seric WorkQ = nw; 3174632Seric free(w->w_name); 3184632Seric free((char *) w); 3194632Seric w = nw; 3204632Seric } 3214632Seric 3224632Seric /* open the queue directory */ 3238148Seric f = opendir("."); 3244632Seric if (f == NULL) 3254632Seric { 3268148Seric syserr("orderq: cannot open \"%s\" as \".\"", QueueDir); 32710070Seric return (0); 3284632Seric } 3294632Seric 3304632Seric /* 3314632Seric ** Read the work directory. 3324632Seric */ 3334632Seric 33410070Seric while ((d = readdir(f)) != NULL) 3354632Seric { 3369377Seric FILE *cf; 3374632Seric char lbuf[MAXNAME]; 3384632Seric 3394632Seric /* is this an interesting entry? */ 3407812Seric if (d->d_name[0] != 'q' || d->d_name[1] != 'f') 3414632Seric continue; 3424632Seric 34310070Seric /* yes -- open control file (if not too many files) */ 34410070Seric if (++wn >= WLSIZE) 34510070Seric continue; 3468148Seric cf = fopen(d->d_name, "r"); 3474632Seric if (cf == NULL) 3484632Seric { 3497055Seric /* this may be some random person sending hir msgs */ 3507055Seric /* syserr("orderq: cannot open %s", cbuf); */ 35110090Seric #ifdef DEBUG 35210090Seric if (tTd(41, 2)) 35310090Seric printf("orderq: cannot open %s (%d)\n", 35410090Seric d->d_name, errno); 35510090Seric #endif DEBUG 3567055Seric errno = 0; 35710090Seric wn--; 3584632Seric continue; 3594632Seric } 3608148Seric wlist[wn].w_name = newstr(d->d_name); 3614632Seric 3624632Seric /* extract useful information */ 3634632Seric while (fgets(lbuf, sizeof lbuf, cf) != NULL) 3644632Seric { 3659377Seric if (lbuf[0] == 'P') 3664632Seric { 3675037Seric (void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri); 3684632Seric break; 3694632Seric } 3704632Seric } 3714632Seric (void) fclose(cf); 3724632Seric } 3736625Sglickman (void) closedir(f); 37410090Seric wn++; 3754632Seric 3764632Seric /* 3774632Seric ** Sort the work directory. 3784632Seric */ 3794632Seric 38010121Seric qsort(wlist, min(wn, WLSIZE), sizeof *wlist, workcmpf); 3814632Seric 3824632Seric /* 3834632Seric ** Convert the work list into canonical form. 3849377Seric ** Should be turning it into a list of envelopes here perhaps. 3854632Seric */ 3864632Seric 3874632Seric wp = &WorkQ; 38810121Seric for (i = min(wn, WLSIZE); --i >= 0; ) 3894632Seric { 3904632Seric w = (WORK *) xalloc(sizeof *w); 3914632Seric w->w_name = wlist[i].w_name; 3924632Seric w->w_pri = wlist[i].w_pri; 3934632Seric w->w_next = NULL; 3944632Seric *wp = w; 3954632Seric wp = &w->w_next; 3964632Seric } 3974632Seric 3984632Seric # ifdef DEBUG 3997677Seric if (tTd(40, 1)) 4004632Seric { 4014632Seric for (w = WorkQ; w != NULL; w = w->w_next) 4025037Seric printf("%32s: pri=%ld\n", w->w_name, w->w_pri); 4034632Seric } 4044632Seric # endif DEBUG 40510070Seric 40610090Seric return (wn); 4074632Seric } 4084632Seric /* 4097677Seric ** WORKCMPF -- compare function for ordering work. 4104632Seric ** 4114632Seric ** Parameters: 4124632Seric ** a -- the first argument. 4134632Seric ** b -- the second argument. 4144632Seric ** 4154632Seric ** Returns: 41610121Seric ** 1 if a < b 4174632Seric ** 0 if a == b 41810121Seric ** -1 if a > b 4194632Seric ** 4204632Seric ** Side Effects: 4214632Seric ** none. 4224632Seric */ 4234632Seric 4244632Seric workcmpf(a, b) 4255037Seric register WORK *a; 4265037Seric register WORK *b; 4274632Seric { 4285037Seric if (a->w_pri == b->w_pri) 4294632Seric return (0); 4305037Seric else if (a->w_pri > b->w_pri) 43110121Seric return (-1); 43210121Seric else 4334632Seric return (1); 4344632Seric } 4354632Seric /* 4364632Seric ** DOWORK -- do a work request. 4374632Seric ** 4384632Seric ** Parameters: 4394632Seric ** w -- the work request to be satisfied. 4404632Seric ** 4414632Seric ** Returns: 4424632Seric ** none. 4434632Seric ** 4444632Seric ** Side Effects: 4454632Seric ** The work request is satisfied if possible. 4464632Seric */ 4474632Seric 4484632Seric dowork(w) 4494632Seric register WORK *w; 4504632Seric { 4514632Seric register int i; 4524632Seric 4534632Seric # ifdef DEBUG 4547677Seric if (tTd(40, 1)) 4555037Seric printf("dowork: %s pri %ld\n", w->w_name, w->w_pri); 4564632Seric # endif DEBUG 4574632Seric 4584632Seric /* 4594632Seric ** Fork for work. 4604632Seric */ 4614632Seric 4624632Seric i = fork(); 4634632Seric if (i < 0) 4644632Seric { 4654632Seric syserr("dowork: cannot fork"); 4664632Seric return; 4674632Seric } 4684632Seric 4694632Seric if (i == 0) 4704632Seric { 4714632Seric /* 4724632Seric ** CHILD 4738148Seric ** Lock the control file to avoid duplicate deliveries. 4748148Seric ** Then run the file as though we had just read it. 4757350Seric ** We save an idea of the temporary name so we 4767350Seric ** can recover on interrupt. 4774632Seric */ 4784632Seric 4797763Seric /* set basic modes, etc. */ 4807356Seric (void) alarm(0); 48110195Seric closexscript(CurEnv); 4829338Seric CurEnv->e_flags &= ~EF_FATALERRS; 4834632Seric QueueRun = TRUE; 4849377Seric ErrorMode = EM_MAIL; 4858148Seric CurEnv->e_id = &w->w_name[2]; 4867876Seric # ifdef LOG 4877876Seric if (LogLevel > 11) 4887881Seric syslog(LOG_DEBUG, "%s: dowork, pid=%d", CurEnv->e_id, 4897881Seric getpid()); 4907876Seric # endif LOG 4917763Seric 4927763Seric /* don't use the headers from sendmail.cf... */ 4937763Seric CurEnv->e_header = NULL; 4949348Seric (void) chompheader("from: $q", TRUE); 4957763Seric 4967763Seric /* create the link to the control file during processing */ 4977812Seric if (link(w->w_name, queuename(CurEnv, 'l')) < 0) 4986980Seric { 4997812Seric /* being processed by another queuer */ 5007881Seric # ifdef LOG 5017881Seric if (LogLevel > 4) 5027881Seric syslog(LOG_DEBUG, "%s: locked", CurEnv->e_id); 5037881Seric # endif LOG 5046980Seric exit(EX_OK); 5056980Seric } 5066980Seric 5076980Seric /* do basic system initialization */ 5084632Seric initsys(); 5096980Seric 5106980Seric /* read the queue control file */ 5119630Seric readqf(CurEnv, TRUE); 5129338Seric CurEnv->e_flags |= EF_INQUEUE; 5139377Seric eatheader(CurEnv); 5146980Seric 5156980Seric /* do the delivery */ 5169338Seric if (!bitset(EF_FATALERRS, CurEnv->e_flags)) 5179282Seric sendall(CurEnv, SM_DELIVER); 5186980Seric 5196980Seric /* finish up and exit */ 5204632Seric finis(); 5214632Seric } 5224632Seric 5234632Seric /* 5244632Seric ** Parent -- pick up results. 5254632Seric */ 5264632Seric 5274632Seric errno = 0; 5289377Seric (void) waitfor(i); 5294632Seric } 5304632Seric /* 5314632Seric ** READQF -- read queue file and set up environment. 5324632Seric ** 5334632Seric ** Parameters: 5349377Seric ** e -- the envelope of the job to run. 5359630Seric ** full -- if set, read in all information. Otherwise just 5369630Seric ** read in info needed for a queue print. 5374632Seric ** 5384632Seric ** Returns: 5394632Seric ** none. 5404632Seric ** 5414632Seric ** Side Effects: 5424632Seric ** cf is read and created as the current job, as though 5434632Seric ** we had been invoked by argument. 5444632Seric */ 5454632Seric 5469630Seric readqf(e, full) 5479377Seric register ENVELOPE *e; 5489630Seric bool full; 5494632Seric { 5504632Seric register FILE *f; 5517785Seric char buf[MAXFIELD]; 5529348Seric extern char *fgetfolded(); 5539377Seric register char *p; 5544632Seric 5554632Seric /* 5564632Seric ** Open the file created by queueup. 5574632Seric */ 5584632Seric 5599377Seric p = queuename(e, 'q'); 5609377Seric f = fopen(p, "r"); 5614632Seric if (f == NULL) 5624632Seric { 5639377Seric syserr("readqf: no control file %s", p); 5644632Seric return; 5654632Seric } 5669377Seric FileName = p; 5679377Seric LineNumber = 0; 5684632Seric 5694632Seric /* 5704632Seric ** Read and process the file. 5714632Seric */ 5724632Seric 5739630Seric if (Verbose && full) 5749377Seric printf("\nRunning %s\n", e->e_id); 5757785Seric while (fgetfolded(buf, sizeof buf, f) != NULL) 5764632Seric { 5774632Seric switch (buf[0]) 5784632Seric { 5794632Seric case 'R': /* specify recipient */ 5809618Seric sendtolist(&buf[1], (ADDRESS *) NULL, &e->e_sendqueue); 5814632Seric break; 5824632Seric 5834632Seric case 'H': /* header */ 5849630Seric if (full) 5859630Seric (void) chompheader(&buf[1], FALSE); 5864632Seric break; 5874632Seric 58810108Seric case 'M': /* message */ 58910108Seric e->e_message = newstr(&buf[1]); 59010108Seric break; 59110108Seric 5924632Seric case 'S': /* sender */ 5934634Seric setsender(newstr(&buf[1])); 5944632Seric break; 5954632Seric 5964632Seric case 'D': /* data file name */ 5979630Seric if (!full) 5989630Seric break; 5999377Seric e->e_df = newstr(&buf[1]); 6009544Seric e->e_dfp = fopen(e->e_df, "r"); 6019544Seric if (e->e_dfp == NULL) 6029377Seric syserr("readqf: cannot open %s", e->e_df); 6034632Seric break; 6044632Seric 6057860Seric case 'T': /* init time */ 6069377Seric (void) sscanf(&buf[1], "%ld", &e->e_ctime); 6074632Seric break; 6084632Seric 6094634Seric case 'P': /* message priority */ 6109377Seric (void) sscanf(&buf[1], "%ld", &e->e_msgpriority); 6115037Seric 6125037Seric /* make sure that big things get sent eventually */ 6139377Seric e->e_msgpriority -= WKTIMEFACT; 6144634Seric break; 6154634Seric 6164632Seric default: 6179377Seric syserr("readqf(%s): bad line \"%s\"", e->e_id, buf); 6184632Seric break; 6194632Seric } 6204632Seric } 6219377Seric 6229377Seric FileName = NULL; 6234632Seric } 6244632Seric /* 6259630Seric ** PRINTQUEUE -- print out a representation of the mail queue 6269630Seric ** 6279630Seric ** Parameters: 6289630Seric ** none. 6299630Seric ** 6309630Seric ** Returns: 6319630Seric ** none. 6329630Seric ** 6339630Seric ** Side Effects: 6349630Seric ** Prints a listing of the mail queue on the standard output. 6359630Seric */ 6365182Seric 6379630Seric printqueue() 6389630Seric { 6399630Seric register WORK *w; 6409630Seric FILE *f; 64110070Seric int nrequests; 6429630Seric char buf[MAXLINE]; 6439630Seric 6449630Seric /* 6459630Seric ** Read and order the queue. 6469630Seric */ 6479630Seric 64810070Seric nrequests = orderq(); 6499630Seric 6509630Seric /* 6519630Seric ** Print the work list that we have read. 6529630Seric */ 6539630Seric 6549630Seric /* first see if there is anything */ 65510070Seric if (nrequests <= 0) 6569630Seric { 65710070Seric printf("Mail queue is empty\n"); 6589630Seric return; 6599630Seric } 6609630Seric 66110096Seric printf("\t\tMail Queue (%d request%s", nrequests, nrequests == 1 ? "" : "s"); 66210070Seric if (nrequests > WLSIZE) 66310070Seric printf(", only %d printed", WLSIZE); 66410070Seric printf(")\n--QID-- --Size-- -----Q-Time----- ------------Sender/Recipient------------\n"); 6659630Seric for (w = WorkQ; w != NULL; w = w->w_next) 6669630Seric { 6679630Seric struct stat st; 66810070Seric auto time_t submittime = 0; 66910070Seric long dfsize = -1; 67010108Seric char lf[20]; 67110108Seric char message[MAXLINE]; 6729630Seric 6739630Seric printf("%7s", w->w_name + 2); 67410070Seric strcpy(lf, w->w_name); 67510070Seric lf[0] = 'l'; 67610070Seric if (stat(lf, &st) >= 0) 67710070Seric printf("*"); 67810070Seric else 67910070Seric printf(" "); 68010070Seric errno = 0; 6819630Seric f = fopen(w->w_name, "r"); 6829630Seric if (f == NULL) 6839630Seric { 6849630Seric printf(" (finished)\n"); 68510070Seric errno = 0; 6869630Seric continue; 6879630Seric } 68810108Seric message[0] = '\0'; 6899630Seric while (fgets(buf, sizeof buf, f) != NULL) 6909630Seric { 6919630Seric fixcrlf(buf, TRUE); 6929630Seric switch (buf[0]) 6939630Seric { 69410108Seric case 'M': /* error message */ 69510108Seric strcpy(message, &buf[1]); 69610108Seric break; 69710108Seric 6989630Seric case 'S': /* sender name */ 69910108Seric if (message[0] != '\0') 70010108Seric { 70110108Seric (void) strcat(buf, " ("); 70210108Seric (void) strcat(buf, message); 70310108Seric (void) strcat(buf, ")"); 70410108Seric } 70510070Seric printf("%8d %.16s %.40s", dfsize, 70610070Seric ctime(&submittime), &buf[1]); 7079630Seric break; 7089630Seric 7099630Seric case 'R': /* recipient name */ 71010070Seric printf("\n\t\t\t\t %.40s", &buf[1]); 7119630Seric break; 7129630Seric 7139630Seric case 'T': /* creation time */ 71410070Seric sscanf(&buf[1], "%ld", &submittime); 7159630Seric break; 71610070Seric 71710070Seric case 'D': /* data file name */ 71810070Seric if (stat(&buf[1], &st) >= 0) 71910070Seric dfsize = st.st_size; 72010070Seric break; 7219630Seric } 7229630Seric } 72310070Seric if (submittime == (time_t) 0) 72410070Seric printf(" (no control file)"); 7259630Seric printf("\n"); 7269630Seric fclose(f); 7279630Seric } 7289630Seric } 7299630Seric 7305182Seric # endif QUEUE 731