# /* send_distrib.c * * Send mail to all the people on a distribution list. A distribution * list is just a text file, containing usernames separated by newlines. * The mail is sent to each username in the file. */ #include "rqfile.h" #include "extern.h" #include "tcode.h" send_distrib (mlfile, rqp, dlname) /* Send the mail file mlfile to the users listed in the distribution * list dlname. This is done just by rewriting a request file * containing a request record for each user in the distribution * list. Returns TNOUSR if no such distribution list exists, * TACESS if a file I/O error occurs, and TDSTRB if it's successful. * * Arguments: */ char *mlfile; /* name of file containing mail */ struct req_rec *rqp; /* ptr. to request record */ char *dlname; /* distribution list file name */ { int dlfd; /* distribution list file descriptor */ register char *ptr; /* temp char pointer */ register char *dp; /* ptr. to contents of distrib. list */ register int i; /* distrib. list char. count */ char dlbuf[BIGBUF]; /* buffer for distrib. list */ int dlsz; /* char count in buffer */ if ((dlfd = open (dlname, 0)) < 0) return (TNOUSR); ptr = rqp->rq_name; /* build request rec. for each user name */ for (;;) { /* read distrib. list a block at a time */ dlsz = read (dlfd, dlbuf, BIGBUF); if (dlsz <= 0) /* end of file? */ break; for (i = dlsz, dp = dlbuf; i > 0; i--) if (*dp == '\n') { /* end of user name? */ *ptr = '\0'; /* yes; rewrite record */ rqp->rq_retries = RETRIES + 1; if (rewrite (mlfile, rqp) != SAVE) { close(dlfd); return (TACESS); } ptr = rqp->rq_name; dp++; } else /* no, copy user name to request rec. */ *ptr++ = *dp++; } close(dlfd); if (ptr != rqp->rq_name) { /* flush out last user name */ *ptr = '\0'; rqp->rq_retries = RETRIES + 1; if (rewrite (mlfile, rqp) != SAVE) return (TACESS); } return (TDSTRB); }