home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume15 / uumailclean < prev    next >
Text File  |  1988-07-06  |  20KB  |  861 lines

  1. Subject:  v15i089:  Clean-up backlogged UUCP mail
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Rick Adams <rick@uunet.uu.net>
  7. Posting-number: Volume 15, Issue 89
  8. Archive-name: uumailclean
  9.  
  10. [  This program has been running on UUNET (and SEISMO) for quite some time.
  11.    It rummages through the UUCP spool directory looking for old mail,
  12.    returning it to the sender or just warning them.  This plus uuclean
  13.    results in the HDB uucleanup program, more or less.  There are
  14.    several config parameters early in the source.  --r$  ]
  15.  
  16. # To extract, sh this file
  17. echo x - uumailclean.c 1>&2
  18. sed 's/.//' >uumailclean.c <<'*-*-END-of-uumailclean.c-*-*'
  19. -/*
  20. - * uumailclean  -  this program searches through the uucp spool directory
  21. - * looking for mail files.  Files which have been around for longer than
  22. - * "failtime" hours will be returned to the sender.  If a file has been
  23. - * around longer than "warntime" hours, then a warning message is sent (once)
  24. - * to the sender. 
  25. - *
  26. - * Originally Written by Jim Crammond    <jim@cs.hw.ac.uk> 3/86
  27. - * Hacked to death by Rick Adams <rick@seismo.css.gov> 5/87 
  28. - * Released to comp.sources.unix 6/88
  29. - *
  30. - * This program contains no ATT code and may be freely used on sites without a
  31. - * source license. 
  32. - */
  33. -
  34. -#include <stdio.h>
  35. -#include <sys/types.h>
  36. -#include <sys/stat.h>
  37. -#include <ctype.h>
  38. -
  39. -#define BSD4_2            /**/
  40. -/* #define USG    /* */
  41. -/* #define NDIR    /* */
  42. -#define HASSUBDIRS        /**/
  43. -
  44. -#ifdef    BSD4_2
  45. -#include <sys/dir.h>
  46. -#ifndef HASSUBDIRS
  47. -#define HASSUBDIRS
  48. -#endif /* !HASSUBDIRS */
  49. -#endif    BSD4_2
  50. -
  51. -#ifdef    NDIR
  52. -#include <ndir.h>
  53. -#endif    NDIR
  54. -
  55. -#define STRCMP(a,b)  ((*(a) != *(b)) ? (*(a)-*(b)) : strcmp((a)+1, (b)+1))
  56. -#define STRNCMP(a,b,n)  ((*(a) != *(b)) ? (*(a)-*(b)) : strncmp(a, b, n))
  57. -
  58. -long Now;
  59. -
  60. -/* Various UUCP specific defines */
  61. -#define CMDPRE    'C'
  62. -#define MAXBASENAME    14
  63. -#define SYSNSIZE    (MAXBASENAME-1-1-1-4)    /* system name length */
  64. -#define FILENAMELEN    (MAXBASENAME + 1)    /* uucp filename length */
  65. -#define DEBUG(level, format, param) if (Debug >= level) fprintf(stderr, format, param); else
  66. -
  67. -#ifndef SENDMAIL
  68. -#define SENDMAIL   "/usr/lib/sendmail"
  69. -#endif    /* !SENDMAIL */
  70. -#define BLKSIZE    ((BUFSIZ/FILENAMELEN) - 1)
  71. -
  72. -
  73. -#ifdef HASSUBDIRS
  74. -/* Hacks to deal with 4.2 BSD style subfiles */
  75. -char CSubfilebuf[FILENAMELEN + 5] = "C./";
  76. -char XSubfilebuf[FILENAMELEN + 5] = "X./";
  77. -# define Csubfile(x)    (strcpy(&CSubfilebuf[3], x)-3)
  78. -# define Xsubfile(x)    (strcpy(&XSubfilebuf[3], x)-3)
  79. -char *Dsubfile();
  80. -#else    /* !HASSUBDIRS */
  81. -# define Csubfile(x)    x
  82. -# define Dsubfile(x)    x
  83. -# define Xsubfile(x)    x
  84. -#endif    /* !HASSUBDIRS */
  85. -
  86. -#ifdef USG
  87. -#include <string.h>
  88. -#define index strchr
  89. -#define rindex strrchr
  90. -#include <sys/utsname.h>
  91. -#endif /* !USG */
  92. -char *index(), *rindex();
  93. -char *strcpy();
  94. -
  95. -struct flist {
  96. -    char fname[BLKSIZE][FILENAMELEN];
  97. -    int nused;
  98. -    struct flist *next;
  99. -};
  100. -
  101. -struct flist warnlist;
  102. -FILE *warnfp;
  103. -
  104. -char *Spool = "/usr/spool/uucp";
  105. -char myuucpname[FILENAMELEN];
  106. -
  107. -
  108. -#define WARNFILE "warnlist.mail"
  109. -
  110. -int warntime = 24 * 3;        /* default hours before sending a warning */
  111. -int failtime = 24 * 14;        /* default hours before returning the mail */
  112. -
  113. -int Debug = 0;
  114. -int nflag = 0;
  115. -
  116. -main(argc, argv)
  117. -char **argv;
  118. -{
  119. -    int c;
  120. -    extern int optind;
  121. -    extern char *optarg;
  122. -
  123. -    while ((c = getopt(argc, argv, "S:f:w:x:h:n")) != EOF)
  124. -        switch (c) {
  125. -        case 'S':
  126. -            Spool = optarg;
  127. -            break;
  128. -        case 'f':
  129. -            failtime = atoi(optarg);
  130. -            break;
  131. -        case 'w':
  132. -            warntime = atoi(optarg);
  133. -            break;
  134. -        case 'x':
  135. -            Debug = atoi(optarg);
  136. -            break;
  137. -        case 'h':
  138. -            strncpy(myuucpname, optarg, FILENAMELEN);
  139. -            break;
  140. -        case 'n':
  141. -            nflag++;
  142. -            break;
  143. -        }
  144. -
  145. -    if (myuucpname[0] == '\0') {
  146. -        register char *p;
  147. -#ifdef USG
  148. -        struct utsname utb;
  149. -
  150. -        (void) uname(&utb);
  151. -        (void) strcpy(myuucpname, utb.nodename);
  152. -#else    /* !USG */
  153. -        gethostname(myuucpname, FILENAMELEN);
  154. -        p = index(myuucpname, '.');
  155. -        if (p)
  156. -            *p = '\0';
  157. -#endif    /* !USG */
  158. -    }
  159. -    if (chdir(Spool) < 0) {
  160. -        perror(Spool);
  161. -        exit(1);
  162. -    }
  163. -    init_warnedlist(WARNFILE);
  164. -
  165. -#ifdef HASSUBDIRS
  166. -    checkfiles("C.");
  167. -#else    /* !HASSUBDIRS */
  168. -    checkfiles(".");
  169. -#endif    /* !HASSUBDIRS */
  170. -
  171. -    exit(0);
  172. -}
  173. -
  174. -
  175. -/*
  176. - * checkfiles  -  scan a directory looking for "old" control files. For each
  177. - * one found, call fail or warn as appropriate. 
  178. - */
  179. -checkfiles(dir)
  180. -char *dir;
  181. -{
  182. -    register DIR *dirp;
  183. -    register struct direct *dentp;
  184. -    struct stat stbuf;
  185. -    int hours;
  186. -    int clen;
  187. -
  188. -    (void) time(&Now);
  189. -
  190. -    DEBUG(5, "checkfiles(%s)\n", dir);
  191. -    if ((dirp = opendir(dir)) == NULL) {
  192. -        perror("directory unreadable\n");
  193. -        return;
  194. -    }
  195. -    while ((dentp = readdir(dirp)) != NULL) {
  196. -        if (dentp->d_name[0] != CMDPRE)
  197. -            continue;
  198. -
  199. -        clen = strlen(dentp->d_name) - 4;
  200. -        if ((clen > 0) && (STRCMP("POLL", &dentp->d_name[clen]) == 0))
  201. -            continue;
  202. -
  203. -        DEBUG(9, "stat %s\n", dentp->d_name);
  204. -        if (stat(Csubfile(dentp->d_name), &stbuf) == -1) {
  205. -            if (Debug >= 4) {
  206. -                fprintf(stderr, "stat failed: ");
  207. -                perror(Csubfile(dentp->d_name));
  208. -            }
  209. -            continue;
  210. -        }
  211. -        if ((stbuf.st_mode & S_IFMT) == S_IFDIR)
  212. -            continue;
  213. -
  214. -        hours = (int) (Now - stbuf.st_mtime) / 3600;
  215. -        DEBUG(9, "%d hours old\n", hours);
  216. -        if (hours >= failtime)
  217. -            fail(dentp->d_name, hours);
  218. -        else if (hours >= warntime)
  219. -            warn(dentp->d_name, hours);
  220. -    }
  221. -}
  222. -
  223. -
  224. -/*
  225. - * fail  -  send a failure message to the sender and delete the mail. 
  226. - */
  227. -fail(cmdfile, hours)
  228. -char *cmdfile;
  229. -int hours;
  230. -{
  231. -    char dfile[FILENAMELEN], xfile[FILENAMELEN];
  232. -    char host[FILENAMELEN];
  233. -    register char *from, **to;
  234. -    char *sender(), **recipients();
  235. -    FILE *out, *popen();
  236. -    char cmd[BUFSIZ];
  237. -
  238. -
  239. -    DEBUG(4, "fail called on %s\n", cmdfile);
  240. -    if (getfnames(cmdfile, dfile, xfile) < 0)
  241. -        return;
  242. -
  243. -    if (xfile[0] == '\0' || (to = recipients(xfile)) == NULL)
  244. -        return;
  245. -    if (dfile[0] == '\0' || (from = sender(dfile)) == NULL)
  246. -        return;
  247. -    strcpy(host, &cmdfile[2]);
  248. -    host[strlen(cmdfile) - SYSNSIZE] = '\0';
  249. -
  250. -    sprintf(cmd, "%s -t", SENDMAIL);
  251. -    DEBUG(1, "Failed: From: %s\n\tTo:", from);
  252. -    if (nflag) {
  253. -        out = stdout;
  254. -        fflush(stderr);
  255. -        printf("\nFile: %s\n", cmdfile);
  256. -    } else
  257. -        out = popen(cmd, "w");
  258. -    fprintf(out,
  259. -        "From: MAILER-DAEMON\nSubject: Failed Mail\nTo: %s\n\n",
  260. -        from);
  261. -    fprintf(out,
  262. -        "After %d days (%d hours), your message to the following people:\n\n",
  263. -        hours / 24, hours);
  264. -
  265. -    /* put out recipents */
  266. -    while (*to) {
  267. -        DEBUG(1, " %s!", host);
  268. -        DEBUG(1, "%s", *to);
  269. -        fprintf(out, "\t%s  (host=%s)\n", *to, host);
  270. -        to++;
  271. -    }
  272. -    DEBUG(1, "\n", 0);
  273. -
  274. -    fprintf(out, "\ncould not be delivered.\n\n");
  275. -    fprintf(out, "   ----- Unsent message follows -----   \n");
  276. -
  277. -    /* print all of the message */
  278. -    print_message(dfile, out, 0);
  279. -
  280. -    if (nflag)
  281. -        return;
  282. -    pclose(out);
  283. -
  284. -    (void) unlink(Csubfile(cmdfile));
  285. -    (void) unlink(Dsubfile(dfile));
  286. -    (void) unlink(Dsubfile(xfile));
  287. -}
  288. -
  289. -/*
  290. - * warn  -  send a warning message to the sender and add the control file to
  291. - * the list of files for which warnings have been sent. 
  292. - */
  293. -warn(cmdfile, hours)
  294. -char *cmdfile;
  295. -int hours;
  296. -{
  297. -    char dfile[FILENAMELEN], xfile[FILENAMELEN];
  298. -    char host[FILENAMELEN];
  299. -    char *from, **to;
  300. -    char *sender(), **recipients();
  301. -    FILE *out, *popen();
  302. -    char cmd[50];
  303. -
  304. -    if (in_warnedlist(cmdfile))
  305. -        return;
  306. -
  307. -    DEBUG(4, "warn called on %s\n", cmdfile);
  308. -    if (getfnames(cmdfile, dfile, xfile) < 0) {
  309. -        DEBUG(5, "getfnames(%s) failed\n", cmdfile);
  310. -        return;
  311. -    }
  312. -
  313. -    if ((to = recipients(xfile)) == NULL || (from = sender(dfile)) == NULL)
  314. -        return;
  315. -
  316. -    strcpy(host, &cmdfile[2]);
  317. -    host[strlen(cmdfile) - SYSNSIZE] = '\0';
  318. -
  319. -    sprintf(cmd, "%s -t", SENDMAIL);
  320. -    DEBUG(1, "Warning: From: %s\n\tTo:", from);
  321. -    if (nflag) {
  322. -        out = stdout;
  323. -        fflush(stderr);
  324. -        printf("\nFile: %s\n", cmdfile);
  325. -    } else
  326. -        out = popen(cmd, "w");
  327. -
  328. -    fprintf(out, "From: MAILER-DAEMON\nSubject: Waiting Mail\nTo: %s\n\n",
  329. -        from);
  330. -    fprintf(out,
  331. -        "After %d days (%d hours), your message to the following people:\n\n",
  332. -        hours / 24, hours);
  333. -
  334. -    /* put out recipents */
  335. -    while (*to) {
  336. -        DEBUG(1, " %s!", host);
  337. -        DEBUG(1, "%s", *to);
  338. -        fprintf(out, "\t%s  (host=%s)\n", *to, host);
  339. -        to++;
  340. -    }
  341. -    DEBUG(1, "\n", 0);
  342. -
  343. -    fprintf(out, "\nhas not yet been delivered. Attempts to deliver the message will\n");
  344. -    fprintf(out, "continue for %d more days. No further action is required by you.\n\n", (failtime - hours) / 24);
  345. -    fprintf(out, "   ----- Queued message begins -----   \n");
  346. -
  347. -    /* print a summary of the message */
  348. -    print_message(dfile, out, 1);
  349. -    if (nflag)
  350. -        return;
  351. -
  352. -    pclose(out);
  353. -
  354. -    fprintf(warnfp, "%s\n", cmdfile);
  355. -}
  356. -
  357. -/*
  358. - * getfnames  -  read the control file to find the data and execute files
  359. - * which contain the message and list of recipients. dfile is set to the
  360. - * datafile, xfile to the execute file. 
  361. - */
  362. -getfnames(cmdfile, dfile, xfile)
  363. -char *cmdfile;
  364. -char *dfile;
  365. -char *xfile;
  366. -{
  367. -    register FILE *fp;
  368. -    register char *s, *d;
  369. -    register int n;
  370. -    char buf[BUFSIZ];
  371. -
  372. -    DEBUG(5, "getfnames(%s) called\n", cmdfile);
  373. -    if ((fp = fopen(Csubfile(cmdfile), "r")) == NULL) {
  374. -        perror(Csubfile(cmdfile));
  375. -        return -1;
  376. -    }
  377. -    if (fgets(buf, BUFSIZ, fp) == NULL) {
  378. -        DEBUG(7, "fgets dfile %s failed\n", cmdfile);
  379. -        fclose(fp);
  380. -        return -1;
  381. -    }
  382. -    s = buf;
  383. -    d = dfile;
  384. -    while (*s != '\0' && *s++ != ' ')
  385. -        /* skip first argument */;
  386. -    n = FILENAMELEN - 1;
  387. -    do {
  388. -        *d++ = *s;
  389. -    } while (*s != '\0' && *s != ' ' && *s++ != '\n' && --n);
  390. -    d[-1] = '\0';
  391. -    DEBUG(5, "dfile set to %s\n", dfile);
  392. -
  393. -    if (fgets(buf, BUFSIZ, fp) == NULL) {
  394. -        DEBUG(7, "fgets xfile %s failed\n", cmdfile);
  395. -        fclose(fp);
  396. -        return -1;
  397. -    }
  398. -
  399. -    s = buf;
  400. -    d = xfile;
  401. -    while (*s != '\0' && *s++ != ' ')
  402. -        /* skip first argument */;
  403. -    n = FILENAMELEN - 1;
  404. -    do {
  405. -        *d++ = *s;
  406. -    } while (*s != '\0' && *s != ' ' && *s++ != '\n' && --n);
  407. -    d[-1] = '\0';
  408. -    DEBUG(5, "xfile set to %s\n", xfile);
  409. -
  410. -    fclose(fp);
  411. -    return 0;
  412. -}
  413. -
  414. -/*
  415. - * recipients -  returns a list of recipients that the mail was intended for,
  416. - * or NULL if the execute file is not a mail file. 
  417. - */
  418. -char **
  419. -recipients(xfile)
  420. -char *xfile;
  421. -{
  422. -    static char rbuf[BUFSIZ];
  423. -    static char *tobuf[1000];    /* see uuxqt */
  424. -    register FILE *fp;
  425. -    register char *p, **t;
  426. -
  427. -    DEBUG(7, "recipients(%s)\n", xfile);
  428. -    if ((fp = fopen(Dsubfile(xfile), "r")) == NULL) {
  429. -        perror(Dsubfile(xfile));
  430. -        return NULL;
  431. -    }
  432. -    while (fgets(rbuf, BUFSIZ, fp) != NULL) {
  433. -        if (rbuf[0] == 'C' && STRNCMP(rbuf, "C rmail ", 8) == 0) {
  434. -
  435. -            /* turn into an array of addresses */
  436. -            for (p = &rbuf[8], t = tobuf; *p;) {
  437. -                while (*p == ' ' || *p == '\n')
  438. -                    *p++ = '\0';
  439. -                *t = p;
  440. -                while (*p && *p != ' ' && *p != '\n')
  441. -                    p++;
  442. -                if (*t != p)
  443. -                    t++;
  444. -            }
  445. -            *t = NULL;
  446. -            fclose(fp);
  447. -            return tobuf;
  448. -        }
  449. -    }
  450. -
  451. -    fclose(fp);
  452. -    return NULL;
  453. -}
  454. -
  455. -char *badnames[] = {
  456. -    "daemon",
  457. -    "/dev/null",
  458. -    "mailer",
  459. -    "postmaster",
  460. -    "netlib",
  461. -    "netlibd",
  462. -    "listserv",
  463. -    "uucp",
  464. -    "news",
  465. -    "usenet",
  466. -    0
  467. -};
  468. -
  469. -char *badsuffix[] = {
  470. -    "archive",
  471. -    "daemon",
  472. -    "sender",
  473. -    "mailer",
  474. -    "relay",
  475. -    "request",
  476. -    "reply",
  477. -    "server",
  478. -    0
  479. -};
  480. -
  481. -/*
  482. - * sender  -  returns the sender address from the uucp from line, or NULL if
  483. - * not found. 
  484. - */
  485. -char *
  486. -sender(dfile)
  487. -char *dfile;
  488. -{
  489. -    static char buf[BUFSIZ];
  490. -    char username[BUFSIZ];
  491. -    register char *senderof, *cp, **bname;
  492. -    register FILE *fp;
  493. -
  494. -    DEBUG(7, "sender(%s)\n", dfile);
  495. -    if ((fp = fopen(Dsubfile(dfile), "r")) == NULL) {
  496. -        perror(Dsubfile(dfile));
  497. -        return NULL;
  498. -    }
  499. -    if (fgets(buf, BUFSIZ, fp) == NULL)
  500. -        return NULL;
  501. -    fclose(fp);
  502. -
  503. -    senderof = index(buf, ' ');
  504. -    if (senderof++ == NULL)
  505. -        return NULL;
  506. -    cp = index(senderof, ' ');
  507. -    if(cp != NULL)
  508. -        *cp = '\0';
  509. -
  510. -    /* pick of the username */
  511. -    cp = rindex(senderof, '!');    /* try uucp style */
  512. -    if (cp != NULL) {
  513. -        strcpy(username, cp+1);
  514. -    } else {    /* try arpa style */
  515. -        cp = index(senderof, '@');
  516. -        if (cp == NULL)
  517. -            return senderof;
  518. -        strcpy(username, senderof);
  519. -        cp = index(username, '@');
  520. -        *cp = '\0';
  521. -    }
  522. -    /* lower case username so get case independent strcmp */
  523. -    cp = username;
  524. -    do {
  525. -        if (isupper(*cp))
  526. -            *cp = tolower(*cp);
  527. -    } while (*cp++ != '\0');
  528. -    DEBUG(7,"checking username \"%s\"\n", username);
  529. -
  530. -    /* some lists begin with info- */
  531. -    if (STRNCMP(username, "info-", 5) == 0) {
  532. -        DEBUG(7, "Not warning %s\n", senderof);
  533. -        return NULL;
  534. -    }
  535. -
  536. -    cp = rindex(username, '-');
  537. -    if (cp++ == NULL) {
  538. -        bname = badnames;
  539. -        cp = username;
  540. -    } else {
  541. -        bname = badsuffix;
  542. -    }
  543. -
  544. -    do {
  545. -        DEBUG(9, "\tcomparing against %s\n", *bname);
  546. -        if (STRCMP(*bname, cp) == 0) {
  547. -            DEBUG(7, "Not warning %s\n", senderof);
  548. -            return NULL;
  549. -        }
  550. -    } while (*bname++ != NULL);
  551. -
  552. -    return senderof;
  553. -}
  554. -
  555. -/*
  556. - * print_message  -  print the message in "dfile" on the stream "outp". If
  557. - * the edited flag is set, then only print some interesting headers and the
  558. - * first few lines of the body. 
  559. - */
  560. -print_message(dfile, outp, edited)
  561. -char *dfile;
  562. -register FILE *outp;
  563. -int edited;
  564. -{
  565. -    register FILE *dfp;
  566. -    char buf[BUFSIZ];
  567. -    int iflg, linecount;
  568. -
  569. -    if ((dfp = fopen(Dsubfile(dfile), "r")) == NULL)
  570. -        return;
  571. -
  572. -    /* skip unix from line */
  573. -    fgets(buf, BUFSIZ, dfp);
  574. -
  575. -    /* print header */
  576. -    iflg = 0;
  577. -    while (fgets(buf, BUFSIZ, dfp) != NULL && buf[0] != '\n') {
  578. -        if (edited) {
  579. -            if (buf[0] == '\t' || buf[0] == ' ') {
  580. -                if (iflg)
  581. -                    fputs(buf, outp);
  582. -                continue;
  583. -            }
  584. -            if (!interested(buf)) {
  585. -                iflg = 0;
  586. -                continue;
  587. -            }
  588. -            iflg = 1;
  589. -        }
  590. -        fputs(buf, outp);
  591. -    }
  592. -    putc('\n', outp);
  593. -
  594. -    /* print body */
  595. -    linecount = 0;
  596. -    while (fgets(buf, BUFSIZ, dfp) != NULL) {
  597. -        if (edited && ++linecount > 5) {
  598. -            fprintf(outp, ".....\n");
  599. -            break;
  600. -        }
  601. -        fputs(buf, outp);
  602. -    }
  603. -    fclose(dfp);
  604. -}
  605. -
  606. -static char *headers[] = {
  607. -    "From:",
  608. -    "Date:",
  609. -    "To:",
  610. -    "Cc:",
  611. -    "Subject:",
  612. -    0
  613. -};
  614. -
  615. -/*
  616. - * interested  -  determine whether "hdr" is considered interesting and thus
  617. - * should be printed in edited mode. 
  618. - */
  619. -interested(hdr)
  620. -char *hdr;
  621. -{
  622. -    register char **hp = headers;
  623. -
  624. -    while (*hp) {
  625. -        if (STRNCMP(hdr, *hp, strlen(*hp)) == 0)
  626. -            return 1;
  627. -        hp++;
  628. -    }
  629. -    return 0;
  630. -}
  631. -
  632. -/*
  633. - * Initialise list of files for which warning messages have already been
  634. - * sent. This involves reading the warnfile into a table, removing files
  635. - * which no longer exist (i.e. been sent or deleted), and writing this out
  636. - * again. 
  637. - */
  638. -init_warnedlist(warnfile)
  639. -char *warnfile;
  640. -{
  641. -    register struct flist *wp;
  642. -    register char *p;
  643. -    register int i;
  644. -    char warned[FILENAMELEN];
  645. -
  646. -    wp = &warnlist;
  647. -    wp->next = NULL;
  648. -    wp->nused = 0;
  649. -
  650. -    if ((warnfp = fopen(warnfile, "r")) != NULL) {
  651. -        while (fgets(warned, FILENAMELEN, warnfp) != NULL) {
  652. -            if(warned[0] == '\n')
  653. -                    continue;
  654. -            if ((p = index(warned, '\n')) != NULL)
  655. -                *p = '\0';
  656. -
  657. -            if (access(Csubfile(warned), 0) == 0) {
  658. -                if (wp->nused >= BLKSIZE) {
  659. -                    wp->next = (struct flist *) malloc(sizeof(warnlist));
  660. -                    wp = wp->next;
  661. -                    wp->next = (struct flist *) NULL;
  662. -                    wp->nused = 0;
  663. -                }
  664. -                strcpy(wp->fname[wp->nused], warned);
  665. -                wp->nused++;
  666. -            }
  667. -        }
  668. -        fclose(warnfp);
  669. -    }
  670. -    /*
  671. -     * Rewrite warnedlist removing files that no longer exist. Could be
  672. -     * really paranoid here and create a temporary file first, rather
  673. -     * than overwrite; in case of crashed 
  674. -     */
  675. -    if ((warnfp = fopen(warnfile, "w")) != NULL) {
  676. -        wp = &warnlist;
  677. -        while (wp) {
  678. -            for (i = 0; i < wp->nused; i++)
  679. -                fprintf(warnfp, "%s\n", wp->fname[i]);
  680. -            wp = wp->next;
  681. -        }
  682. -        fflush(warnfp);
  683. -    }
  684. -}
  685. -
  686. -/*
  687. - * Determine whether the given filename is in the warn list. Returns 1 if
  688. - * found, 0 otherwise. 
  689. - * 
  690. - * This should really use some clever hashing scheme, but the cpu
  691. - * time spent traversing this list is only 1% of total.
  692. - */
  693. -in_warnedlist(file)
  694. -register char *file;
  695. -{
  696. -    register struct flist *wp = &warnlist;
  697. -    register int i;
  698. -
  699. -    while (wp) {
  700. -        for (i = 0; i < wp->nused; i++) {
  701. -            if (STRCMP(file, wp->fname[i]) == 0)
  702. -                return 1;
  703. -        }
  704. -        wp = wp->next;
  705. -    }
  706. -    return 0;
  707. -}
  708. -
  709. -char DLocalX[FILENAMELEN], DLocal[FILENAMELEN];
  710. -
  711. -static char *dprefix[] = {
  712. -    DLocalX,    /* Outbound 'xqt' request files */
  713. -    DLocal,        /* Outbound data files */
  714. -    "D.",        /* Other "D." files (remember the "."!) */
  715. -    "C.",        /* "C." subdirectory */
  716. -    "X.",        /* "X." subdirectory */
  717. -    "TM.",        /* Temporaries for inbound files */
  718. -    0
  719. -};
  720. -
  721. -/*
  722. - * return (possibly) remapped string s 
  723. - */
  724. -char *
  725. -Dsubfile(as)
  726. -char *as;
  727. -{
  728. -    static char fn1[FILENAMELEN * 2], fn2[FILENAMELEN * 2];
  729. -    register char *s, **p;
  730. -    register int n;
  731. -    static char *tptr = NULL;
  732. -
  733. -    if (DLocalX[0] == '\0') {
  734. -        sprintf(DLocalX, "D.%sX", myuucpname);
  735. -        sprintf(DLocal, "D.%s", myuucpname);
  736. -    }
  737. -    /* Alternate buffers so "link(subfile(a), subfile(b))" works */
  738. -    if (tptr != fn1)
  739. -        tptr = fn1;
  740. -    else
  741. -        tptr = fn2;
  742. -
  743. -    s = as;
  744. -    tptr[0] = '\0';
  745. -
  746. -    /* look for first prefix which matches, and make subdirectory */
  747. -    for (p = &dprefix[0]; *p; p++) {
  748. -        if (STRNCMP(s, *p, n = strlen(*p)) == 0
  749. -            && s[n] && s[n] != '/') {
  750. -            sprintf(tptr, "%s/%s", *p, s);
  751. -            return tptr;
  752. -        }
  753. -    }
  754. -    return as;
  755. -}
  756. *-*-END-of-uumailclean.c-*-*
  757. echo x - Makefile 1>&2
  758. sed 's/.//' >Makefile <<'*-*-END-of-Makefile-*-*'
  759. -
  760. -CFLAGS=-O
  761. -
  762. -uumailclean: uumailclean.c
  763. -    cc $(CFLAGS) -o uumailclean uumailclean.c
  764. -
  765. -install: uumailclean uumailclean.8c
  766. -    install -s uumailclean /usr/lib/uucp
  767. -    install -c uumailclean.8c /usr/man/man8
  768. -clean:
  769. -    -rm -f core uumailclean *.o errs
  770. *-*-END-of-Makefile-*-*
  771. echo x - uumailclean.8c 1>&2
  772. sed 's/.//' >uumailclean.8c <<'*-*-END-of-uumailclean.8c-*-*'
  773. -.TH UUMAILCLEAN 8C "May 8, 1987"
  774. -.UC 4
  775. -.SH NAME
  776. -uumailclean \- uucp spool directory mail clean-up
  777. -.SH SYNOPSIS
  778. -.B /usr/lib/uucp/uumailclean
  779. -[
  780. -.BI \-f failtime
  781. -] [
  782. -.BI \-w warntime
  783. -] [
  784. -.BI \-S spooldir
  785. -] [
  786. -.BI \-h myhostname
  787. -] [
  788. -.BI \-x debug
  789. -] [
  790. -.BI \-n 
  791. -]
  792. -.SH DESCRIPTION
  793. -.I Uumailclean
  794. -scans the uucp spool directory for mail files and checks to see how long
  795. -they have been queued.
  796. -If a mail message is found to have been queued for longer than 
  797. -.I failtime
  798. -hours, then it is returned to the sender and deleted from the queue.
  799. -If a mail message is found to have been queued for longer than
  800. -.I warntime
  801. -hours (but less than 
  802. -.I failtime),
  803. -then a warning message is sent to the sender to inform them that the mail
  804. -has yet to be delivered.
  805. -.PP
  806. -The 
  807. -.I \-f
  808. -flag can be used to override the default 
  809. -.I failtime
  810. -of 336 hours (2 weeks).
  811. -.PP
  812. -The
  813. -.I \-w
  814. -flag can be used to override the default
  815. -.I warntime
  816. -of 72 hours (3 days).
  817. -.PP
  818. -The 
  819. -.I \-S
  820. -flag can be used to specify an alternate spool directory. (The default
  821. -is /usr/spool/uucp.)
  822. -.PP
  823. -The
  824. -.I \-h
  825. -flag can be used to specify you host's uucp name. The default is to use
  826. -.IR gethostname ().
  827. -.PP
  828. -The 
  829. -.I \-x
  830. -flag is used for debugging. A higher debugging level implies more output.
  831. -.PP
  832. -The
  833. -.I \-n
  834. -flag says to do the normal checking, but to not take any action. Instead, the
  835. -warnings and failure messages are sent to standard output.
  836. -.PP
  837. -.I Uumailclean
  838. -maintains a list of mail files for which warning messages
  839. -have already been sent out, so that the sender will only receive one
  840. -warning message.  This is normally the file
  841. -.I warnlist.mail
  842. -in the appropriate spool directory.
  843. -.PP
  844. -.I Uumailclean
  845. -will typically be started by
  846. -.IR cron (8).
  847. -.SH FILES
  848. -/usr/spool/uucp            uucp spool directory
  849. -.br
  850. -/usr/spool/uucp/warnlist.mail    list of warned mail files
  851. -.br
  852. -.SH "SEE ALSO"
  853. -sendmail(8), uuclean(8C)
  854. -.SH AUTHORS
  855. -Jim Crammond
  856. -.br
  857. -Rick Adams
  858. *-*-END-of-uumailclean.8c-*-*
  859. exit
  860.  
  861.