2 ** slocal.c -- asynchronously filter and deliver new mail
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
10 ** Under sendmail, users should add the line
12 ** "| /usr/local/mmh/bin/slocal"
14 ** to their $HOME/.forward file.
18 /* Changed to use getutent() and friends. Assumes that when getutent() exists,
19 ** a number of other things also exist. Please check.
20 ** Ruud de Rooij <ruud@ruud.org> Sun, 28 May 2000 17:28:55 +0200
24 #include <h/dropsbr.h>
25 #include <h/rcvmail.h>
26 #include <h/signals.h>
32 #include <sys/ioctl.h>
35 #ifdef INITGROUPS_HEADER
36 #include INITGROUPS_HEADER
39 ** On AIX 4.1, initgroups() is defined and even documented (giving the
40 ** parameter types as char* and int), but doesn't have a prototype in any
41 ** of the system header files. AIX 4.3, SunOS 4.1.3, and ULTRIX 4.2A have
44 extern int initgroups(char*, int);
52 # define UTMP_FILE _PATH_UTMP
54 # define UTMP_FILE "/etc/utmp"
59 static struct swit switches[] = {
61 { "addr address", 0 },
67 { "sender address", 0 },
69 { "mailbox file", 0 },
71 { "home directory", -4 },
75 { "maildelivery file", 0 },
90 /* global maildelivery file */
91 char *maildelivery = NMHETCDIR"/maildelivery";
94 static int globbed = 0; /* have we built "vars" table yet? */
95 static int parsed = 0; /* have we built header field table yet */
96 static int utmped = 0; /* have we scanned umtp(x) file yet */
98 static int verbose = 0;
101 static char *addr = NULL;
102 static char *user = NULL;
103 static char *info = NULL;
104 static char *file = NULL;
105 static char *sender = NULL;
106 static char *envelope = NULL; /* envelope information ("From " line) */
107 static char *mbox = NULL;
108 static char *home = NULL;
110 static struct passwd *pw; /* passwd file entry */
112 static char ddate[BUFSIZ]; /* record the delivery date */
115 static jmp_buf myctx;
117 /* flags for pair->p_flags */
119 #define P_ADR 0x01 /* field is address */
120 #define P_HID 0x02 /* special (fake) field */
132 ** Lookup table for matching fields and patterns
133 ** in messages. The rest of the table is added
134 ** when the message is parsed.
136 static struct pair hdrs[NVEC + 1] = {
137 { "source", NULL, P_HID },
138 { "addr", NULL, P_HID },
139 { "Return-Path", NULL, P_ADR },
140 { "Reply-To", NULL, P_ADR },
141 { "From", NULL, P_ADR },
142 { "Sender", NULL, P_ADR },
143 { "To", NULL, P_ADR },
144 { "cc", NULL, P_ADR },
145 { "Resent-Reply-To", NULL, P_ADR },
146 { "Resent-From", NULL, P_ADR },
147 { "Resent-Sender", NULL, P_ADR },
148 { "Resent-To", NULL, P_ADR },
149 { "Resent-Cc", NULL, P_ADR },
154 ** The list of builtin variables to expand in a string
155 ** before it is executed by the "pipe" or "qpipe" action.
157 static struct pair vars[] = {
158 { "sender", NULL, P_NIL },
159 { "address", NULL, P_NIL },
160 { "size", NULL, P_NIL },
161 { "reply-to", NULL, P_CHK },
162 { "info", NULL, P_NIL },
166 extern char **environ;
171 static int localmail(int, char *);
172 static int usr_delivery(int, char *, int);
173 static int split(char *, char **);
174 static int parse(int);
175 static void expand(char *, char *, int);
176 static void glob(int);
177 static struct pair *lookup(struct pair *, char *);
178 static int logged_in(void);
179 static int timely(char *, char *);
180 static int usr_file(int, char *);
181 static int usr_pipe(int, char *, char *, char **, int);
182 static int usr_folder(int, char *);
183 static RETSIGTYPE alrmser(int);
184 static void get_sender(char *, char **);
185 static int copy_message(int, char *, int);
186 static void verbose_printf(char *fmt, ...);
187 static void adorn(char *, char *, ...);
188 static void debug_printf(char *fmt, ...);
189 static char *trim(char *);
193 main(int argc, char **argv)
197 char *cp, *mdlvr = NULL, buf[BUFSIZ];
198 char mailbox[BUFSIZ], tmpfil[BUFSIZ];
199 char **argp, **arguments;
202 setlocale(LC_ALL, "");
204 invo_name = mhbasename(*argv);
206 /* foil search of user profile/context */
207 if (context_foil(NULL) == -1)
210 arguments = getarguments(invo_name, argc, argv, 0);
213 /* Parse arguments */
214 while ((cp = *argp++)) {
216 switch (smatch(++cp, switches)) {
218 ambigsw(cp, switches);
221 adios(NULL, "-%s unknown", cp);
224 snprintf(buf, sizeof(buf), "%s [switches] [address info sender]", invo_name);
225 print_help(buf, switches, 0);
228 print_version(invo_name);
232 if (!(addr = *argp++))
233 /* allow -xyz arguments */
234 adios(NULL, "missing argument to %s",
238 if (!(info = *argp++))
239 /* allow -xyz arguments */
240 adios(NULL, "missing argument to %s",
244 if (!(user = *argp++))
245 /* allow -xyz arguments */
246 adios(NULL, "missing argument to %s",
250 if (!(file = *argp++) || *file == '-')
251 adios(NULL, "missing argument to %s",
255 if (!(sender = *argp++))
256 /* allow -xyz arguments */
257 adios(NULL, "missing argument to %s",
261 if (!(mbox = *argp++) || *mbox == '-')
262 adios(NULL, "missing argument to %s",
266 if (!(home = *argp++) || *home == '-')
267 adios(NULL, "missing argument to %s",
272 if (!(cp = *argp++) || *cp == '-')
273 adios(NULL, "missing argument to %s",
276 adios(NULL, "only one maildelivery file at a time!");
293 switch (argp - (argv + 1)) {
307 addr = getusername();
309 user = (cp = strchr(addr, '.')) ? ++cp : addr;
310 if ((pw = getpwnam(user)) == NULL)
311 adios(NULL, "no such local user as %s", user);
313 if (chdir(pw->pw_dir) == -1)
317 if (geteuid() == 0) {
319 initgroups(pw->pw_name, pw->pw_gid);
328 /* Record the delivery time */
329 if ((now = dlocaltimenow()) == NULL)
330 adios(NULL, "unable to ascertain local time");
331 snprintf(ddate, sizeof(ddate), "Delivery-Date: %s\n", dtimenow(0));
334 ** Copy the message to a temporary file
339 /* getting message from file */
340 if ((tempfd = open(file, O_RDONLY)) == -1)
341 adios(file, "unable to open");
343 debug_printf("retrieving message from file \"%s\"\n",
345 if ((fd = copy_message(tempfd, tmpfil, 1)) == -1)
346 adios(NULL, "unable to create temporary file");
349 /* getting message from stdin */
351 debug_printf("retrieving message from stdin\n");
352 if ((fd = copy_message(fileno(stdin), tmpfil, 1)) == -1)
353 adios(NULL, "unable to create temporary file");
357 debug_printf("temporary file=\"%s\"\n", tmpfil);
360 ** Delete the temp file now or a copy of every single message
361 ** passed through slocal will be left in the /tmp directory until
362 ** deleted manually! This unlink() used to be under an 'else'
363 ** of the 'if (debug)' above, but since some people like to
364 ** always run slocal with -debug and log the results, the /tmp
365 ** directory would get choked over time. Of course, now that
366 ** we always delete the temp file, the "temporary file=" message
367 ** above is somewhat pointless -- someone watching debug output
368 ** wouldn't have a chance to 'tail -f' or 'ln' the temp file
369 ** before it's unlinked. The best thing would be to delay this
370 ** unlink() until later if debug == 1, but I'll leave that for
371 ** someone who cares about the temp-file-accessing functionality
372 ** (they'll have to watch out for cases where we adios()).
376 if (!(fp = fdopen(fd, "r+")))
377 adios(NULL, "unable to access temporary file");
380 ** If no sender given, extract it
381 ** from envelope information.
384 get_sender(envelope, &sender);
387 snprintf(mailbox, sizeof(mailbox), "%s/%s",
388 mailspool, pw->pw_name);
395 debug_printf("addr=\"%s\"\n", trim(addr));
396 debug_printf("user=\"%s\"\n", trim(user));
397 debug_printf("info=\"%s\"\n", trim(info));
398 debug_printf("sender=\"%s\"\n", trim(sender));
399 debug_printf("envelope=\"%s\"\n",
400 envelope ? trim(envelope) : "");
401 debug_printf("mbox=\"%s\"\n", trim(mbox));
402 debug_printf("home=\"%s\"\n", trim(home));
403 debug_printf("ddate=\"%s\"\n", trim(ddate));
404 debug_printf("now=%02d:%02d\n\n", now->tw_hour, now->tw_min);
407 /* deliver the message */
408 status = localmail(fd, mdlvr);
410 done(status != -1 ? RCV_MOK : RCV_MBX);
416 ** Main routine for delivering message.
420 localmail(int fd, char *mdlvr)
422 /* delivery according to personal Maildelivery file */
423 if (usr_delivery(fd, mdlvr ? mdlvr : ".maildelivery", 0) != -1)
426 /* delivery according to global Maildelivery file */
427 if (usr_delivery(fd, maildelivery, 1) != -1)
431 verbose_printf("(delivering to standard mail spool)\n");
433 /* last resort - deliver to standard mail spool */
434 return usr_file(fd, mbox);
438 #define matches(a,b) (stringdex(b, a) >= 0)
441 ** Parse the delivery file, and process incoming message.
445 usr_delivery(int fd, char *delivery, int su)
447 int i, accept, status=1, won, vecp, next;
448 char *field, *pattern, *action, *result, *string;
449 char buffer[BUFSIZ], tmpbuf[BUFSIZ];
450 char *cp, *vec[NVEC];
455 /* open the delivery file */
456 if ((fp = fopen(delivery, "r")) == NULL)
459 /* check if delivery file has bad ownership or permissions */
460 if (fstat(fileno(fp), &st) == -1 ||
461 (st.st_uid != 0 && (su || st.st_uid != pw->pw_uid)) ||
462 st.st_mode & (S_IWGRP|S_IWOTH)) {
464 verbose_printf("WARNING: %s has bad ownership/modes (su=%d,uid=%d,owner=%d,mode=0%o)\n", delivery, su, (int) pw->pw_uid, (int) st.st_uid, (int) st.st_mode);
472 /* read and process delivery file */
473 while (fgets(buffer, sizeof(buffer), fp)) {
474 /* skip comments and empty lines */
475 if (*buffer == '#' || *buffer == '\n')
478 /* zap trailing newline */
479 if ((cp = strchr(buffer, '\n')))
482 /* split buffer into fields */
483 vecp = split(buffer, vec);
485 /* check for too few fields */
488 debug_printf("WARNING: entry with only %d fields, skipping.\n", vecp);
493 for (i = 0; vec[i]; i++)
494 debug_printf("vec[%d]: \"%s\"\n",
504 /* find out how to perform the action */
509 ** If previous condition failed, don't
510 ** do this - else fall through
513 continue; /* else fall */
517 ** If already delivered, skip this action.
518 ** Else consider delivered if action is
522 continue; /* else fall */
527 ** Take action, and consider delivered if
528 ** action is successful.
537 ** Take action, but don't consider delivered,
538 ** even if action is successful
545 if (!mh_strcasecmp(vec[5], "select")) {
546 if (logged_in() != -1)
548 if (vecp > 7 && timely(vec[6], vec[7]) == -1)
553 /* check if the field matches */
561 ** "default" matches only if the message hasn't
562 ** been delivered yet.
564 if (!mh_strcasecmp(field, "default")) {
571 /* parse message and build lookup table */
572 if (!parsed && parse(fd) == -1) {
577 ** find header field in lookup table, and
578 ** see if the pattern matches.
580 if ((p = lookup(hdrs, field)) && (p->p_value != NULL)
581 && matches(p->p_value, pattern)) {
590 /* find out the action to perform */
593 /* deliver to quoted pipe */
594 if (mh_strcasecmp(action, "qpipe"))
595 continue; /* else fall */
597 expand(tmpbuf, string, fd);
598 if (split(tmpbuf, vec) < 1)
600 status = usr_pipe(fd, tmpbuf, vec[0], vec, 0);
604 /* deliver to pipe */
605 if (mh_strcasecmp(action, "pipe"))
606 continue; /* else fall */
610 expand(tmpbuf, string, fd);
613 status = usr_pipe(fd, tmpbuf, "/bin/sh",
619 if (!mh_strcasecmp(action, "file")) {
620 status = usr_file(fd, string);
623 /* deliver to nmh folder */
624 else if (mh_strcasecmp(action, "folder"))
625 continue; /* else fall */
627 status = usr_folder(fd, string);
632 if (mh_strcasecmp(action, "mbox"))
633 continue; /* else fall */
637 status = usr_file(fd, string);
642 if (mh_strcasecmp(action, "destroy"))
649 next = 0; /* action failed, mark for 'N' result */
651 if (accept && status == 0)
656 return (won ? 0 : -1);
663 ** Split buffer into fields (delimited by whitespace or
664 ** comma's). Return the number of fields found.
668 split(char *cp, char **vec)
675 /* split into a maximum of NVEC fields */
676 for (i = 0; i <= NVEC;) {
679 /* zap any whitespace and comma's */
680 while (isspace(*s) || *s == ',')
683 /* end of buffer, time to leave */
687 /* get double quote text as a single field */
689 for (vec[i++] = ++s; *s && *s != '"'; s++) {
691 ** Check for escaped double quote. We need
692 ** to shift the string to remove slash.
700 if (*s == '"') /* zap trailing double quote */
705 if (*s == QUOTE && *++s != '"')
709 /* move forward to next field delimiter */
710 while (*s && !isspace(*s) && *s != ',')
720 ** Parse the headers of a message, and build the
721 ** lookup table for matching fields and patterns.
730 char name[NAMESZ], field[BUFSIZ];
737 /* get a new FILE pointer to message */
738 if ((fd1 = dup(fd)) == -1)
740 if ((in = fdopen(fd1, "r")) == NULL) {
746 /* add special entries to lookup table */
747 if ((p = lookup(hdrs, "source")))
748 p->p_value = getcpy(sender);
749 if ((p = lookup(hdrs, "addr")))
750 p->p_value = getcpy(addr);
753 * Scan the headers of the message and build
756 for (i = 0, state = FLD;;) {
757 switch (state = m_getfld(state, name, field, sizeof(field),
763 while (state == FLDPLUS) {
764 state = m_getfld(state, name, field,
768 for (p = hdrs; p->p_name; p++) {
769 if (!mh_strcasecmp(p->p_name, name)) {
770 if (!(p->p_flags & P_HID)) {
771 if ((cp = p->p_value)) {
772 if (p->p_flags & P_ADR) {
773 dp = cp + strlen(cp) - 1;
776 cp = add(",\n\t", cp);
781 p->p_value = add(lp, cp);
787 if (p->p_name == NULL && i < NVEC) {
788 p->p_name = getcpy(name);
805 advise(NULL, "format error in message");
809 advise(NULL, "internal error in m_getfld");
817 if ((p = lookup(vars, "reply-to"))) {
818 if ((q = lookup(hdrs, "reply-to")) == NULL ||
820 q = lookup(hdrs, "from");
821 p->p_value = getcpy(q ? q->p_value : "");
822 p->p_flags &= ~P_CHK;
824 debug_printf("vars[%d]: name=\"%s\" value=\"%s\"\n",
825 p - vars, p->p_name, trim(p->p_value));
828 for (p = hdrs; p->p_name; p++)
829 debug_printf("hdrs[%d]: name=\"%s\" value=\"%s\"\n",
831 p->p_value ? trim(p->p_value) : "");
842 ** Expand any builtin variables such as $(sender),
843 ** $(address), etc., in a string.
847 expand(char *s1, char *s2, int fd)
855 while ((c = *s2++)) {
856 if (c != '$' || *s2 != LPAREN) {
859 for (cp = ++s2; *s2 && *s2 != RPAREN; s2++)
866 if ((p = lookup(vars, cp))) {
867 if (!parsed && (p->p_flags & P_CHK))
870 strcpy(s1, p->p_value);
880 ** Fill in the information missing from the "vars"
881 ** table, which is necessary to expand any builtin
882 ** variables in the string for a "pipe" or "qpipe"
896 if ((p = lookup(vars, "sender")))
897 p->p_value = getcpy(sender);
898 if ((p = lookup(vars, "address")))
899 p->p_value = getcpy(addr);
900 if ((p = lookup(vars, "size"))) {
901 snprintf(buffer, sizeof(buffer), "%d",
902 fstat(fd, &st) != -1 ? (int) st.st_size : 0);
903 p->p_value = getcpy(buffer);
905 if ((p = lookup(vars, "info")))
906 p->p_value = getcpy(info);
909 for (p = vars; p->p_name; p++)
910 debug_printf("vars[%d]: name=\"%s\" value=\"%s\"\n",
911 p - vars, p->p_name, trim(p->p_value));
917 ** Find a matching name in a lookup table. If found,
918 ** return the "pairs" entry, else return NULL.
922 lookup(struct pair *pairs, char *key)
924 for (; pairs->p_name; pairs++)
925 if (!mh_strcasecmp(pairs->p_name, key))
933 ** Check utmp(x) file to see if user is currently
948 while ((utp = getutent()) != NULL) {
950 #ifdef HAVE_STRUCT_UTMP_UT_TYPE
951 utp->ut_type == USER_PROCESS &&
953 utp->ut_name[0] != 0 &&
954 strncmp(user, utp->ut_name,
955 sizeof(utp->ut_name)) == 0) {
959 return (utmped = DONE);
964 return (utmped = NOTOK);
976 if ((uf = fopen(UTMP_FILE, "r")) == NULL)
979 while (fread((char *) &ut, sizeof(ut), 1, uf) == 1) {
980 if (ut.ut_name[0] != 0 &&
981 strncmp(user, ut.ut_name, sizeof(ut.ut_name))
986 return (utmped = DONE);
991 return (utmped = NOTOK);
995 #define check(t,a,b) if (t < a || t > b) return -1
996 #define cmpar(h1,m1,h2,m2) if (h1 < h2 || (h1 == h2 && m1 < m2)) return 0
999 timely(char *t1, char *t2)
1001 int t1hours, t1mins, t2hours, t2mins;
1003 if (sscanf(t1, "%d:%d", &t1hours, &t1mins) != 2)
1005 check(t1hours, 0, 23);
1006 check(t1mins, 0, 59);
1008 if (sscanf(t2, "%d:%d", &t2hours, &t2mins) != 2)
1010 check(t2hours, 0, 23);
1011 check(t2mins, 0, 59);
1013 cmpar(now->tw_hour, now->tw_min, t1hours, t1mins);
1014 cmpar(t2hours, t2mins, now->tw_hour, now->tw_min);
1021 ** Deliver message by appending to a file.
1025 usr_file(int fd, char *mailbox)
1030 verbose_printf("delivering to file \"%s\"", mailbox);
1033 verbose_printf(" (mbox style)");
1035 /* open and lock the file */
1036 if ((md = mbx_open(mailbox, pw->pw_uid, pw->pw_gid,
1037 m_gmprot())) == -1) {
1039 adorn("", "unable to open:");
1043 lseek(fd, (off_t) 0, SEEK_SET);
1045 /* append message to file */
1046 if (mbx_copy(mailbox, md, fd, verbose) == -1) {
1048 adorn("", "error writing to:");
1052 /* close and unlock file */
1053 if (mbx_close(mailbox, md) == NOTOK) {
1055 adorn("", "error closing:");
1060 verbose_printf(", success.\n");
1066 ** Deliver message to a nmh folder.
1070 usr_folder(int fd, char *string)
1073 char folder[BUFSIZ], *vec[3];
1075 /* get folder name ready */
1077 strncpy(folder, string, sizeof(folder));
1079 snprintf(folder, sizeof(folder), "+%s", string);
1082 verbose_printf("delivering to folder \"%s\"", folder + 1);
1084 vec[0] = "rcvstore";
1088 /* use rcvstore to put message in folder */
1089 status = usr_pipe(fd, "rcvstore", rcvstoreproc, vec, 1);
1093 ** Currently, verbose status messages are handled by usr_pipe().
1097 verbose_printf(", success.\n");
1099 verbose_printf(", failed.\n");
1107 ** Deliver message to a process.
1111 usr_pipe(int fd, char *cmd, char *pgm, char **vec, int suppress)
1114 int i, bytes, seconds, status;
1117 if (verbose && !suppress)
1118 verbose_printf("delivering to pipe \"%s\"", cmd);
1120 lseek(fd, (off_t) 0, SEEK_SET);
1122 for (i = 0; (child_id = fork()) == -1 && i < 5; i++)
1129 adorn("fork", "unable to");
1136 freopen("/dev/null", "w", stdout);
1137 freopen("/dev/null", "w", stderr);
1143 if ((fd = open("/dev/tty", O_RDWR)) != -1) {
1144 ioctl(fd, TIOCNOTTY, NULL);
1147 #endif /* TIOCNOTTY */
1149 /* put in own process group */
1150 setpgid((pid_t) 0, getpid());
1153 m_putenv("USER", pw->pw_name);
1154 m_putenv("HOME", pw->pw_dir);
1155 m_putenv("SHELL", pw->pw_shell);
1161 /* parent process */
1162 if (!setjmp(myctx)) {
1163 SIGNAL(SIGALRM, alrmser);
1164 bytes = fstat(fd, &st) != -1 ?
1165 (int) st.st_size : 100;
1168 ** amount of time to wait depends on
1172 /* give at least 5 minutes */
1174 } else if (bytes >= 90000) {
1175 /* a half hour is long enough */
1178 seconds = (bytes / 60) + 300;
1180 alarm((unsigned int) seconds);
1181 status = pidwait(child_id, 0);
1186 verbose_printf(", success.\n");
1188 if ((status & 0xff00) == 0xff00)
1189 verbose_printf(", system error\n");
1191 pidstatus(status, stdout, ", failed");
1193 return (status == 0 ? 0 : -1);
1196 ** Ruthlessly kill the child and anything
1197 ** else in its process group.
1199 KILLPG(child_id, SIGKILL);
1201 verbose_printf(", timed-out; terminated\n");
1211 #ifndef RELIABLE_SIGNALS
1212 SIGNAL(SIGALRM, alrmser);
1215 longjmp(myctx, DONE);
1220 ** Get the `sender' from the envelope
1221 ** information ("From " line).
1225 get_sender(char *envelope, char **sender)
1229 unsigned char buffer[BUFSIZ];
1231 if (envelope == NULL) {
1232 *sender = getcpy("");
1236 i = strlen("From ");
1237 strncpy(buffer, envelope + i, sizeof(buffer));
1238 if ((cp = strchr(buffer, '\n'))) {
1248 for (cp = buffer + strlen(buffer) - 1; cp >= buffer; cp--)
1253 *sender = getcpy(buffer);
1258 ** Copy message into a temporary file.
1259 ** While copying, it will do some header processing
1260 ** including the extraction of the envelope information.
1264 copy_message(int qd, char *tmpfil, int fold)
1266 int i, first = 1, fd1, fd2;
1267 char buffer[BUFSIZ];
1271 tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
1272 if (tfile == NULL) return -1;
1274 strncpy(tmpfil, tfile, BUFSIZ);
1277 while ((i = read(qd, buffer, sizeof(buffer))) > 0)
1278 if (write(fd1, buffer, i) != i) {
1286 lseek(fd1, (off_t) 0, SEEK_SET);
1290 /* dup the fd for incoming message */
1291 if ((fd2 = dup(qd)) == -1) {
1296 /* now create a FILE pointer for it */
1297 if ((qfp = fdopen(fd2, "r")) == NULL) {
1303 /* dup the fd for temporary file */
1304 if ((fd2 = dup(fd1)) == -1) {
1310 /* now create a FILE pointer for it */
1311 if ((ffp = fdopen(fd2, "r+")) == NULL) {
1319 ** copy message into temporary file
1320 ** and massage the headers. Save
1321 ** a copy of the "From " line for later.
1323 i = strlen("From ");
1324 while (fgets(buffer, sizeof(buffer), qfp)) {
1327 if (strncmp(buffer, "From ", i)==0) {
1329 char *fp, *cp, *hp, *ep;
1332 ** get copy of envelope information
1335 envelope = getcpy(buffer);
1339 ** First go ahead and put "From " line
1349 ** Now create a "Return-Path:" line
1350 ** from the "From " line.
1352 hp = cp = strchr(fp = envelope + i, ' ');
1353 while ((hp = strchr(++hp, 'r')))
1354 if (uprf(hp, "remote from")) {
1355 hp = strrchr(hp, ' ');
1360 ** return path for UUCP style
1363 ep = strchr(++hp, '\n');
1364 snprintf(buffer, sizeof(buffer), "Return-Path: %.*s!%.*s\n", (int)(ep - hp), hp, (int)(cp - fp), fp);
1367 ** return path for standard domain
1370 snprintf(buffer, sizeof(buffer), "Return-Path: %.*s\n", (int)(cp - fp), fp);
1373 /* Add Return-Path header to message */
1378 /* Put the delivery date in message */
1399 lseek(fd1, (off_t) 0, SEEK_SET);
1411 ** Trim strings for pretty printing of debugging output
1417 char buffer[BUFSIZ*4];
1418 unsigned char *bp, *sp;
1423 /* copy string into temp buffer */
1424 strncpy(buffer, cp, sizeof(buffer));
1427 /* skip over leading whitespace */
1428 while (isspace(*bp))
1431 /* start at the end and zap trailing whitespace */
1432 for (sp = bp + strlen(bp) - 1; sp >= bp; sp--) {
1439 /* replace remaining whitespace with spaces */
1440 for (sp = bp; *sp; sp++)
1444 /* now return a copy */
1449 ** Function for printing `verbose' messages.
1453 verbose_printf(char *fmt, ...)
1458 vfprintf(stdout, fmt, ap);
1461 fflush(stdout); /* now flush output */
1466 ** Function for printing `verbose' delivery
1471 adorn(char *what, char *fmt, ...)
1477 eindex = errno; /* save the errno */
1478 fprintf(stdout, ", ");
1481 vfprintf(stdout, fmt, ap);
1486 fprintf(stdout, " %s: ", what);
1487 if ((s = strerror(eindex)))
1488 fprintf(stdout, "%s", s);
1490 fprintf(stdout, "Error %d", eindex);
1493 fputc('\n', stdout);
1499 ** Function for printing `debug' messages.
1503 debug_printf(char *fmt, ...)
1508 vfprintf(stderr, fmt, ap);