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*10066Seric SCCSID(@(#)queue.c 3.60 01/01/83 (no queueing)); 95182Seric # else QUEUE 104632Seric 11*10066Seric SCCSID(@(#)queue.c 3.60 01/01/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; 544632Seric 555037Seric /* 565037Seric ** Create control file. 575037Seric */ 584632Seric 597812Seric tf = newstr(queuename(e, 't')); 607812Seric tfp = fopen(tf, "w"); 617812Seric if (tfp == NULL) 624632Seric { 637812Seric syserr("queueup: cannot create temp file %s", tf); 644632Seric return; 654632Seric } 669048Seric (void) chmod(tf, FileMode); 674632Seric 684632Seric # ifdef DEBUG 697677Seric if (tTd(40, 1)) 707812Seric printf("queueing in %s\n", tf); 714632Seric # endif DEBUG 724632Seric 734632Seric /* 746980Seric ** If there is no data file yet, create one. 756980Seric */ 766980Seric 776980Seric if (e->e_df == NULL) 786980Seric { 796980Seric register FILE *dfp; 809389Seric extern putbody(); 816980Seric 827812Seric e->e_df = newstr(queuename(e, 'd')); 836980Seric dfp = fopen(e->e_df, "w"); 846980Seric if (dfp == NULL) 856980Seric { 866980Seric syserr("queueup: cannot create %s", e->e_df); 877812Seric (void) fclose(tfp); 886980Seric return; 896980Seric } 909048Seric (void) chmod(e->e_df, FileMode); 91*10066Seric (*e->e_putbody)(dfp, ProgMailer, FALSE, e, FALSE); 927009Seric (void) fclose(dfp); 939389Seric e->e_putbody = putbody; 946980Seric } 956980Seric 966980Seric /* 974632Seric ** Output future work requests. 989377Seric ** Priority should be first, since it is read by orderq. 994632Seric */ 1004632Seric 1019377Seric /* output message priority */ 1029377Seric fprintf(tfp, "P%ld\n", e->e_msgpriority); 1039377Seric 1049630Seric /* output creation time */ 1059630Seric fprintf(tfp, "T%ld\n", e->e_ctime); 1069630Seric 1074632Seric /* output name of data file */ 1087812Seric fprintf(tfp, "D%s\n", e->e_df); 1094632Seric 1104632Seric /* output name of sender */ 1117812Seric fprintf(tfp, "S%s\n", e->e_from.q_paddr); 1124632Seric 1134632Seric /* output list of recipient addresses */ 1146980Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 1154632Seric { 1167763Seric if (queueall ? !bitset(QDONTSEND, q->q_flags) : 1177763Seric bitset(QQUEUEUP, q->q_flags)) 1188245Seric { 1197812Seric fprintf(tfp, "R%s\n", q->q_paddr); 1209377Seric if (announce) 1219377Seric { 1229377Seric e->e_to = q->q_paddr; 1239377Seric message(Arpa_Info, "queued"); 1249377Seric if (LogLevel > 4) 1259377Seric logdelivery("queued"); 1269377Seric e->e_to = NULL; 1279377Seric } 1289387Seric #ifdef DEBUG 1299387Seric if (tTd(40, 1)) 1309387Seric { 1319387Seric printf("queueing "); 1329387Seric printaddr(q, FALSE); 1339387Seric } 1349387Seric #endif DEBUG 1358245Seric } 1364632Seric } 1374632Seric 1389377Seric /* 1399377Seric ** Output headers for this message. 1409377Seric ** Expand macros completely here. Queue run will deal with 1419377Seric ** everything as absolute headers. 1429377Seric ** All headers that must be relative to the recipient 1439377Seric ** can be cracked later. 1449377Seric */ 1459377Seric 1469377Seric define('g', "$f", e); 1476980Seric for (h = e->e_header; h != NULL; h = h->h_link) 1484632Seric { 1494632Seric if (h->h_value == NULL || h->h_value[0] == '\0') 1504632Seric continue; 1517812Seric fprintf(tfp, "H"); 1524632Seric if (h->h_mflags != 0 && bitset(H_CHECK|H_ACHECK, h->h_flags)) 1537812Seric mfdecode(h->h_mflags, tfp); 1547763Seric if (bitset(H_DEFAULT, h->h_flags)) 1557763Seric { 1567763Seric (void) expand(h->h_value, buf, &buf[sizeof buf], e); 1578236Seric fprintf(tfp, "%s: %s\n", h->h_field, buf); 1587763Seric } 1598245Seric else if (bitset(H_FROM|H_RCPT, h->h_flags)) 1609348Seric { 1619348Seric commaize(h, h->h_value, tfp, bitset(EF_OLDSTYLE, e->e_flags), 162*10066Seric (MAILER *) NULL, FALSE); 1639348Seric } 1647763Seric else 1658245Seric fprintf(tfp, "%s: %s\n", h->h_field, h->h_value); 1664632Seric } 1674632Seric 1684632Seric /* 1694632Seric ** Clean up. 1704632Seric */ 1714632Seric 1727812Seric (void) fclose(tfp); 1737812Seric qf = queuename(e, 'q'); 1749377Seric holdsigs(); 1757812Seric (void) unlink(qf); 1767812Seric if (link(tf, qf) < 0) 1777812Seric syserr("cannot link(%s, %s), df=%s", tf, qf, e->e_df); 1786980Seric else 1797812Seric (void) unlink(tf); 1809377Seric rlsesigs(); 1817391Seric 1827677Seric # ifdef LOG 1837677Seric /* save log info */ 1847878Seric if (LogLevel > 15) 1857878Seric syslog(LOG_DEBUG, "%s: queueup, qf=%s, df=%s\n", e->e_id, qf, e->e_df); 1867677Seric # endif LOG 1874632Seric } 1884632Seric /* 1894632Seric ** RUNQUEUE -- run the jobs in the queue. 1904632Seric ** 1914632Seric ** Gets the stuff out of the queue in some presumably logical 1924632Seric ** order and processes them. 1934632Seric ** 1944632Seric ** Parameters: 1954632Seric ** none. 1964632Seric ** 1974632Seric ** Returns: 1984632Seric ** none. 1994632Seric ** 2004632Seric ** Side Effects: 2014632Seric ** runs things in the mail queue. 2024632Seric */ 2034632Seric 2044639Seric runqueue(forkflag) 2054639Seric bool forkflag; 2064632Seric { 2077466Seric /* 2087466Seric ** See if we want to go off and do other useful work. 2097466Seric */ 2104639Seric 2114639Seric if (forkflag) 2124639Seric { 2137943Seric int pid; 2147943Seric 2157943Seric pid = dofork(); 2167943Seric if (pid != 0) 2174639Seric { 2187943Seric /* parent -- pick up intermediate zombie */ 2199377Seric (void) waitfor(pid); 2207690Seric if (QueueIntvl != 0) 2219348Seric (void) setevent(QueueIntvl, runqueue, TRUE); 2224639Seric return; 2234639Seric } 2247943Seric /* child -- double fork */ 2257943Seric if (fork() != 0) 2267943Seric exit(EX_OK); 2274639Seric } 2287876Seric # ifdef LOG 2297876Seric if (LogLevel > 11) 2307943Seric syslog(LOG_DEBUG, "runqueue %s, pid=%d", QueueDir, getpid()); 2317876Seric # endif LOG 2324639Seric 2337466Seric /* 2347466Seric ** Start making passes through the queue. 2357466Seric ** First, read and sort the entire queue. 2367466Seric ** Then, process the work in that order. 2377466Seric ** But if you take too long, start over. 2387466Seric */ 2397466Seric 2407943Seric /* order the existing work requests */ 2417943Seric orderq(); 2427690Seric 2437943Seric /* process them once at a time */ 2447943Seric while (WorkQ != NULL) 2454639Seric { 2467943Seric WORK *w = WorkQ; 2477881Seric 2487943Seric WorkQ = WorkQ->w_next; 2497943Seric dowork(w); 2507943Seric free(w->w_name); 2517943Seric free((char *) w); 2524639Seric } 2537943Seric finis(); 2544634Seric } 2554634Seric /* 2564632Seric ** ORDERQ -- order the work queue. 2574632Seric ** 2584632Seric ** Parameters: 2594632Seric ** none. 2604632Seric ** 2614632Seric ** Returns: 2624632Seric ** none. 2634632Seric ** 2644632Seric ** Side Effects: 2654632Seric ** Sets WorkQ to the queue of available work, in order. 2664632Seric */ 2674632Seric 2684632Seric # define WLSIZE 120 /* max size of worklist per sort */ 2694632Seric 2704632Seric orderq() 2714632Seric { 2726625Sglickman register struct direct *d; 2734632Seric register WORK *w; 2744632Seric register WORK **wp; /* parent of w */ 2756625Sglickman DIR *f; 2764632Seric register int i; 2774632Seric WORK wlist[WLSIZE]; 2784632Seric int wn = 0; 2794632Seric extern workcmpf(); 2804632Seric 2814632Seric /* clear out old WorkQ */ 2824632Seric for (w = WorkQ; w != NULL; ) 2834632Seric { 2844632Seric register WORK *nw = w->w_next; 2854632Seric 2864632Seric WorkQ = nw; 2874632Seric free(w->w_name); 2884632Seric free((char *) w); 2894632Seric w = nw; 2904632Seric } 2914632Seric 2924632Seric /* open the queue directory */ 2938148Seric f = opendir("."); 2944632Seric if (f == NULL) 2954632Seric { 2968148Seric syserr("orderq: cannot open \"%s\" as \".\"", QueueDir); 2974632Seric return; 2984632Seric } 2994632Seric 3004632Seric /* 3014632Seric ** Read the work directory. 3024632Seric */ 3034632Seric 3046625Sglickman while (wn < WLSIZE && (d = readdir(f)) != NULL) 3054632Seric { 3069377Seric FILE *cf; 3074632Seric char lbuf[MAXNAME]; 3084632Seric 3094632Seric /* is this an interesting entry? */ 3107812Seric if (d->d_name[0] != 'q' || d->d_name[1] != 'f') 3114632Seric continue; 3124632Seric 3138148Seric /* yes -- open control file */ 3148148Seric cf = fopen(d->d_name, "r"); 3154632Seric if (cf == NULL) 3164632Seric { 3177055Seric /* this may be some random person sending hir msgs */ 3187055Seric /* syserr("orderq: cannot open %s", cbuf); */ 3197055Seric errno = 0; 3204632Seric continue; 3214632Seric } 3228148Seric wlist[wn].w_name = newstr(d->d_name); 3234632Seric 3244632Seric /* extract useful information */ 3254632Seric while (fgets(lbuf, sizeof lbuf, cf) != NULL) 3264632Seric { 3279377Seric if (lbuf[0] == 'P') 3284632Seric { 3295037Seric (void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri); 3304632Seric break; 3314632Seric } 3324632Seric } 3334632Seric wn++; 3344632Seric (void) fclose(cf); 3354632Seric } 3366625Sglickman (void) closedir(f); 3374632Seric 3384632Seric /* 3394632Seric ** Sort the work directory. 3404632Seric */ 3414632Seric 3424632Seric qsort(wlist, wn, sizeof *wlist, workcmpf); 3434632Seric 3444632Seric /* 3454632Seric ** Convert the work list into canonical form. 3469377Seric ** Should be turning it into a list of envelopes here perhaps. 3474632Seric */ 3484632Seric 3494632Seric wp = &WorkQ; 3504632Seric for (i = 0; i < wn; i++) 3514632Seric { 3524632Seric w = (WORK *) xalloc(sizeof *w); 3534632Seric w->w_name = wlist[i].w_name; 3544632Seric w->w_pri = wlist[i].w_pri; 3554632Seric w->w_next = NULL; 3564632Seric *wp = w; 3574632Seric wp = &w->w_next; 3584632Seric } 3594632Seric 3604632Seric # ifdef DEBUG 3617677Seric if (tTd(40, 1)) 3624632Seric { 3634632Seric for (w = WorkQ; w != NULL; w = w->w_next) 3645037Seric printf("%32s: pri=%ld\n", w->w_name, w->w_pri); 3654632Seric } 3664632Seric # endif DEBUG 3674632Seric } 3684632Seric /* 3697677Seric ** WORKCMPF -- compare function for ordering work. 3704632Seric ** 3714632Seric ** Parameters: 3724632Seric ** a -- the first argument. 3734632Seric ** b -- the second argument. 3744632Seric ** 3754632Seric ** Returns: 3764632Seric ** -1 if a < b 3774632Seric ** 0 if a == b 3784632Seric ** 1 if a > b 3794632Seric ** 3804632Seric ** Side Effects: 3814632Seric ** none. 3824632Seric */ 3834632Seric 3844632Seric # define PRIFACT 1800 /* bytes each priority point is worth */ 3854632Seric 3864632Seric workcmpf(a, b) 3875037Seric register WORK *a; 3885037Seric register WORK *b; 3894632Seric { 3905037Seric if (a->w_pri == b->w_pri) 3914632Seric return (0); 3925037Seric else if (a->w_pri > b->w_pri) 3934632Seric return (1); 3944632Seric else 3954632Seric return (-1); 3964632Seric } 3974632Seric /* 3984632Seric ** DOWORK -- do a work request. 3994632Seric ** 4004632Seric ** Parameters: 4014632Seric ** w -- the work request to be satisfied. 4024632Seric ** 4034632Seric ** Returns: 4044632Seric ** none. 4054632Seric ** 4064632Seric ** Side Effects: 4074632Seric ** The work request is satisfied if possible. 4084632Seric */ 4094632Seric 4104632Seric dowork(w) 4114632Seric register WORK *w; 4124632Seric { 4134632Seric register int i; 4144632Seric 4154632Seric # ifdef DEBUG 4167677Seric if (tTd(40, 1)) 4175037Seric printf("dowork: %s pri %ld\n", w->w_name, w->w_pri); 4184632Seric # endif DEBUG 4194632Seric 4204632Seric /* 4214632Seric ** Fork for work. 4224632Seric */ 4234632Seric 4244632Seric i = fork(); 4254632Seric if (i < 0) 4264632Seric { 4274632Seric syserr("dowork: cannot fork"); 4284632Seric return; 4294632Seric } 4304632Seric 4314632Seric if (i == 0) 4324632Seric { 4334632Seric /* 4344632Seric ** CHILD 4358148Seric ** Lock the control file to avoid duplicate deliveries. 4368148Seric ** Then run the file as though we had just read it. 4377350Seric ** We save an idea of the temporary name so we 4387350Seric ** can recover on interrupt. 4394632Seric */ 4404632Seric 4417763Seric /* set basic modes, etc. */ 4427356Seric (void) alarm(0); 4439338Seric CurEnv->e_flags &= ~EF_FATALERRS; 4444632Seric QueueRun = TRUE; 4459387Seric SendMode = SM_DELIVER; 4469377Seric ErrorMode = EM_MAIL; 4478148Seric CurEnv->e_id = &w->w_name[2]; 4487876Seric # ifdef LOG 4497876Seric if (LogLevel > 11) 4507881Seric syslog(LOG_DEBUG, "%s: dowork, pid=%d", CurEnv->e_id, 4517881Seric getpid()); 4527876Seric # endif LOG 4537763Seric 4547763Seric /* don't use the headers from sendmail.cf... */ 4557763Seric CurEnv->e_header = NULL; 4569348Seric (void) chompheader("from: $q", TRUE); 4577763Seric 4587763Seric /* create the link to the control file during processing */ 4597812Seric if (link(w->w_name, queuename(CurEnv, 'l')) < 0) 4606980Seric { 4617812Seric /* being processed by another queuer */ 4627881Seric # ifdef LOG 4637881Seric if (LogLevel > 4) 4647881Seric syslog(LOG_DEBUG, "%s: locked", CurEnv->e_id); 4657881Seric # endif LOG 4666980Seric exit(EX_OK); 4676980Seric } 4686980Seric 4696980Seric /* do basic system initialization */ 4704632Seric initsys(); 4716980Seric 4726980Seric /* read the queue control file */ 4739630Seric readqf(CurEnv, TRUE); 4749338Seric CurEnv->e_flags |= EF_INQUEUE; 4759377Seric eatheader(CurEnv); 4766980Seric 4776980Seric /* do the delivery */ 4789338Seric if (!bitset(EF_FATALERRS, CurEnv->e_flags)) 4799282Seric sendall(CurEnv, SM_DELIVER); 4806980Seric 4816980Seric /* if still not sent, perhaps we should time out.... */ 4824634Seric # ifdef DEBUG 4837677Seric if (tTd(40, 3)) 4847886Seric printf("curtime=%ld, TimeOut=%ld\n", curtime(), 4857860Seric CurEnv->e_ctime + TimeOut); 4864634Seric # endif DEBUG 4879338Seric if (curtime() > CurEnv->e_ctime + TimeOut) 4889338Seric CurEnv->e_flags |= EF_TIMEOUT; 4896980Seric 4906980Seric /* finish up and exit */ 4914632Seric finis(); 4924632Seric } 4934632Seric 4944632Seric /* 4954632Seric ** Parent -- pick up results. 4964632Seric */ 4974632Seric 4984632Seric errno = 0; 4999377Seric (void) waitfor(i); 5004632Seric } 5014632Seric /* 5024632Seric ** READQF -- read queue file and set up environment. 5034632Seric ** 5044632Seric ** Parameters: 5059377Seric ** e -- the envelope of the job to run. 5069630Seric ** full -- if set, read in all information. Otherwise just 5079630Seric ** read in info needed for a queue print. 5084632Seric ** 5094632Seric ** Returns: 5104632Seric ** none. 5114632Seric ** 5124632Seric ** Side Effects: 5134632Seric ** cf is read and created as the current job, as though 5144632Seric ** we had been invoked by argument. 5154632Seric */ 5164632Seric 5179630Seric readqf(e, full) 5189377Seric register ENVELOPE *e; 5199630Seric bool full; 5204632Seric { 5214632Seric register FILE *f; 5227785Seric char buf[MAXFIELD]; 5239348Seric extern char *fgetfolded(); 5249377Seric register char *p; 5254632Seric 5264632Seric /* 5274632Seric ** Open the file created by queueup. 5284632Seric */ 5294632Seric 5309377Seric p = queuename(e, 'q'); 5319377Seric f = fopen(p, "r"); 5324632Seric if (f == NULL) 5334632Seric { 5349377Seric syserr("readqf: no control file %s", p); 5354632Seric return; 5364632Seric } 5379377Seric FileName = p; 5389377Seric LineNumber = 0; 5394632Seric 5404632Seric /* 5414632Seric ** Read and process the file. 5424632Seric */ 5434632Seric 5449630Seric if (Verbose && full) 5459377Seric printf("\nRunning %s\n", e->e_id); 5467785Seric while (fgetfolded(buf, sizeof buf, f) != NULL) 5474632Seric { 5484632Seric switch (buf[0]) 5494632Seric { 5504632Seric case 'R': /* specify recipient */ 5519618Seric sendtolist(&buf[1], (ADDRESS *) NULL, &e->e_sendqueue); 5524632Seric break; 5534632Seric 5544632Seric case 'H': /* header */ 5559630Seric if (full) 5569630Seric (void) chompheader(&buf[1], FALSE); 5574632Seric break; 5584632Seric 5594632Seric case 'S': /* sender */ 5604634Seric setsender(newstr(&buf[1])); 5614632Seric break; 5624632Seric 5634632Seric case 'D': /* data file name */ 5649630Seric if (!full) 5659630Seric break; 5669377Seric e->e_df = newstr(&buf[1]); 5679544Seric e->e_dfp = fopen(e->e_df, "r"); 5689544Seric if (e->e_dfp == NULL) 5699377Seric syserr("readqf: cannot open %s", e->e_df); 5704632Seric break; 5714632Seric 5727860Seric case 'T': /* init time */ 5739377Seric (void) sscanf(&buf[1], "%ld", &e->e_ctime); 5744632Seric break; 5754632Seric 5764634Seric case 'P': /* message priority */ 5779377Seric (void) sscanf(&buf[1], "%ld", &e->e_msgpriority); 5785037Seric 5795037Seric /* make sure that big things get sent eventually */ 5809377Seric e->e_msgpriority -= WKTIMEFACT; 5814634Seric break; 5824634Seric 5835902Seric case 'M': /* define macro */ 5849630Seric if (full) 5859630Seric define(buf[1], newstr(&buf[2]), e); 5865902Seric break; 5875902Seric 5884632Seric default: 5899377Seric syserr("readqf(%s): bad line \"%s\"", e->e_id, buf); 5904632Seric break; 5914632Seric } 5924632Seric } 5939377Seric 5949377Seric FileName = NULL; 5954632Seric } 5964632Seric /* 5974632Seric ** TIMEOUT -- process timeout on queue file. 5984632Seric ** 5994632Seric ** Parameters: 6009338Seric ** e -- the envelope that timed out. 6014632Seric ** 6024632Seric ** Returns: 6034632Seric ** none. 6044632Seric ** 6054632Seric ** Side Effects: 6064632Seric ** Returns a message to the sender saying that this 6074632Seric ** message has timed out. 6084632Seric */ 6094632Seric 6109338Seric timeout(e) 6119338Seric register ENVELOPE *e; 6124632Seric { 6137369Seric char buf[MAXLINE]; 6147860Seric extern char *pintvl(); 6157369Seric 6164634Seric # ifdef DEBUG 6177677Seric if (tTd(40, 3)) 6189338Seric printf("timeout(%s)\n", e->e_id); 6194634Seric # endif DEBUG 6209338Seric e->e_to = NULL; 6216991Seric message(Arpa_Info, "Message has timed out"); 6224634Seric 6234634Seric /* return message to sender */ 6247860Seric (void) sprintf(buf, "Cannot send mail for %s", pintvl(TimeOut, FALSE)); 6259338Seric (void) returntosender(buf, &e->e_from, TRUE); 6264634Seric 6274634Seric /* arrange to remove files from queue */ 6289338Seric e->e_flags |= EF_CLRQUEUE; 6294632Seric } 6309630Seric /* 6319630Seric ** PRINTQUEUE -- print out a representation of the mail queue 6329630Seric ** 6339630Seric ** Parameters: 6349630Seric ** none. 6359630Seric ** 6369630Seric ** Returns: 6379630Seric ** none. 6389630Seric ** 6399630Seric ** Side Effects: 6409630Seric ** Prints a listing of the mail queue on the standard output. 6419630Seric */ 6425182Seric 6439630Seric printqueue() 6449630Seric { 6459630Seric register WORK *w; 6469630Seric FILE *f; 6479630Seric char buf[MAXLINE]; 6489630Seric 6499630Seric /* 6509630Seric ** Read and order the queue. 6519630Seric */ 6529630Seric 6539630Seric orderq(); 6549630Seric 6559630Seric /* 6569630Seric ** Print the work list that we have read. 6579630Seric */ 6589630Seric 6599630Seric /* first see if there is anything */ 6609630Seric if (WorkQ == NULL) 6619630Seric { 6629630Seric printf("\nMail queue is empty\n"); 6639630Seric return; 6649630Seric } 6659630Seric 6669630Seric printf("\n\t\tMail Queue\n"); 6679630Seric printf("--QID-- --Size-- -----Q Time----- --Sender/Recipient--\n"); 6689630Seric for (w = WorkQ; w != NULL; w = w->w_next) 6699630Seric { 6709630Seric struct stat st; 6719630Seric 6729630Seric printf("%7s", w->w_name + 2); 6739630Seric f = fopen(w->w_name, "r"); 6749630Seric if (f == NULL) 6759630Seric { 6769630Seric printf(" (finished)\n"); 6779630Seric continue; 6789630Seric } 6799630Seric (void) fstat(fileno(f), &st); 6809630Seric printf(" %8ld", st.st_size); 6819630Seric while (fgets(buf, sizeof buf, f) != NULL) 6829630Seric { 6839630Seric auto long ti; 6849630Seric 6859630Seric fixcrlf(buf, TRUE); 6869630Seric switch (buf[0]) 6879630Seric { 6889630Seric case 'S': /* sender name */ 6899630Seric printf(" %.20s", &buf[1]); 6909630Seric break; 6919630Seric 6929630Seric case 'R': /* recipient name */ 6939630Seric printf("\n\t\t\t\t %.20s", &buf[1]); 6949630Seric break; 6959630Seric 6969630Seric case 'T': /* creation time */ 6979630Seric sscanf(&buf[1], "%ld", &ti); 6989630Seric printf(" %.16s", ctime(&ti)); 6999630Seric break; 7009630Seric } 7019630Seric } 7029630Seric printf("\n"); 7039630Seric fclose(f); 7049630Seric } 7059630Seric } 7069630Seric 7075182Seric # endif QUEUE 708