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/nmh/lib/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>
33 #include <sys/ioctl.h>
36 #ifdef INITGROUPS_HEADER
37 #include INITGROUPS_HEADER
40 ** On AIX 4.1, initgroups() is defined and even documented (giving the
41 ** parameter types as char* and int), but doesn't have a prototype in any
42 ** of the system header files. AIX 4.3, SunOS 4.1.3, and ULTRIX 4.2A have
45 extern int initgroups(char*, int);
53 # define UTMP_FILE _PATH_UTMP
55 # define UTMP_FILE "/etc/utmp"
60 static struct swit switches[] = {
62 { "addr address", 0 },
68 { "sender address", 0 },
70 { "mailbox file", 0 },
72 { "home directory", -4 },
76 { "maildelivery file", 0 },
91 /* global maildelivery file */
92 char *maildelivery = NMHETCDIR"/maildelivery";
95 static int globbed = 0; /* have we built "vars" table yet? */
96 static int parsed = 0; /* have we built header field table yet */
97 static int utmped = 0; /* have we scanned umtp(x) file yet */
99 static int verbose = 0;
100 static int debug = 0;
102 static char *addr = NULL;
103 static char *user = NULL;
104 static char *info = NULL;
105 static char *file = NULL;
106 static char *sender = NULL;
107 static char *envelope = NULL; /* envelope information ("From " line) */
108 static char *mbox = NULL;
109 static char *home = NULL;
111 static struct passwd *pw; /* passwd file entry */
113 static char ddate[BUFSIZ]; /* record the delivery date */
116 static jmp_buf myctx;
118 /* flags for pair->p_flags */
120 #define P_ADR 0x01 /* field is address */
121 #define P_HID 0x02 /* special (fake) field */
133 ** Lookup table for matching fields and patterns
134 ** in messages. The rest of the table is added
135 ** when the message is parsed.
137 static struct pair hdrs[NVEC + 1] = {
138 { "source", NULL, P_HID },
139 { "addr", NULL, P_HID },
140 { "Return-Path", NULL, P_ADR },
141 { "Reply-To", NULL, P_ADR },
142 { "From", NULL, P_ADR },
143 { "Sender", NULL, P_ADR },
144 { "To", NULL, P_ADR },
145 { "cc", NULL, P_ADR },
146 { "Resent-Reply-To", NULL, P_ADR },
147 { "Resent-From", NULL, P_ADR },
148 { "Resent-Sender", NULL, P_ADR },
149 { "Resent-To", NULL, P_ADR },
150 { "Resent-Cc", NULL, P_ADR },
155 ** The list of builtin variables to expand in a string
156 ** before it is executed by the "pipe" or "qpipe" action.
158 static struct pair vars[] = {
159 { "sender", NULL, P_NIL },
160 { "address", NULL, P_NIL },
161 { "size", NULL, P_NIL },
162 { "reply-to", NULL, P_CHK },
163 { "info", NULL, P_NIL },
167 extern char **environ;
172 static int localmail(int, char *);
173 static int usr_delivery(int, char *, int);
174 static int split(char *, char **);
175 static int parse(int);
176 static void expand(char *, char *, int);
177 static void glob(int);
178 static struct pair *lookup(struct pair *, char *);
179 static int logged_in(void);
180 static int timely(char *, char *);
181 static int usr_file(int, char *);
182 static int usr_pipe(int, char *, char *, char **, int);
183 static int usr_folder(int, char *);
184 static RETSIGTYPE alrmser(int);
185 static void get_sender(char *, char **);
186 static int copy_message(int, char *, int);
187 static void verbose_printf(char *fmt, ...);
188 static void adorn(char *, char *, ...);
189 static void debug_printf(char *fmt, ...);
190 static char *trim(char *);
194 main(int argc, char **argv)
198 char *cp, *mdlvr = NULL, buf[BUFSIZ];
199 char mailbox[BUFSIZ], tmpfil[BUFSIZ];
200 char **argp, **arguments;
203 setlocale(LC_ALL, "");
205 invo_name = mhbasename(*argv);
207 /* foil search of user profile/context */
208 if (context_foil(NULL) == -1)
211 arguments = getarguments(invo_name, argc, argv, 0);
214 /* Parse arguments */
215 while ((cp = *argp++)) {
217 switch (smatch(++cp, switches)) {
219 ambigsw(cp, switches);
222 adios(NULL, "-%s unknown", cp);
225 snprintf(buf, sizeof(buf), "%s [switches] [address info sender]", invo_name);
226 print_help(buf, switches, 0);
229 print_version(invo_name);
233 if (!(addr = *argp++))
234 /* allow -xyz arguments */
235 adios(NULL, "missing argument to %s",
239 if (!(info = *argp++))
240 /* allow -xyz arguments */
241 adios(NULL, "missing argument to %s",
245 if (!(user = *argp++))
246 /* allow -xyz arguments */
247 adios(NULL, "missing argument to %s",
251 if (!(file = *argp++) || *file == '-')
252 adios(NULL, "missing argument to %s",
256 if (!(sender = *argp++))
257 /* allow -xyz arguments */
258 adios(NULL, "missing argument to %s",
262 if (!(mbox = *argp++) || *mbox == '-')
263 adios(NULL, "missing argument to %s",
267 if (!(home = *argp++) || *home == '-')
268 adios(NULL, "missing argument to %s",
273 if (!(cp = *argp++) || *cp == '-')
274 adios(NULL, "missing argument to %s",
277 adios(NULL, "only one maildelivery file at a time!");
294 switch (argp - (argv + 1)) {
308 addr = getusername();
310 user = (cp = strchr(addr, '.')) ? ++cp : addr;
311 if ((pw = getpwnam(user)) == NULL)
312 adios(NULL, "no such local user as %s", user);
314 if (chdir(pw->pw_dir) == -1)
318 if (geteuid() == 0) {
320 initgroups(pw->pw_name, pw->pw_gid);
329 /* Record the delivery time */
330 if ((now = dlocaltimenow()) == NULL)
331 adios(NULL, "unable to ascertain local time");
332 snprintf(ddate, sizeof(ddate), "Delivery-Date: %s\n", dtimenow(0));
335 ** Copy the message to a temporary file
340 /* getting message from file */
341 if ((tempfd = open(file, O_RDONLY)) == -1)
342 adios(file, "unable to open");
344 debug_printf("retrieving message from file \"%s\"\n",
346 if ((fd = copy_message(tempfd, tmpfil, 1)) == -1)
347 adios(NULL, "unable to create temporary file");
350 /* getting message from stdin */
352 debug_printf("retrieving message from stdin\n");
353 if ((fd = copy_message(fileno(stdin), tmpfil, 1)) == -1)
354 adios(NULL, "unable to create temporary file");
358 debug_printf("temporary file=\"%s\"\n", tmpfil);
361 ** Delete the temp file now or a copy of every single message
362 ** passed through slocal will be left in the /tmp directory until
363 ** deleted manually! This unlink() used to be under an 'else'
364 ** of the 'if (debug)' above, but since some people like to
365 ** always run slocal with -debug and log the results, the /tmp
366 ** directory would get choked over time. Of course, now that
367 ** we always delete the temp file, the "temporary file=" message
368 ** above is somewhat pointless -- someone watching debug output
369 ** wouldn't have a chance to 'tail -f' or 'ln' the temp file
370 ** before it's unlinked. The best thing would be to delay this
371 ** unlink() until later if debug == 1, but I'll leave that for
372 ** someone who cares about the temp-file-accessing functionality
373 ** (they'll have to watch out for cases where we adios()).
377 if (!(fp = fdopen(fd, "r+")))
378 adios(NULL, "unable to access temporary file");
381 ** If no sender given, extract it
382 ** from envelope information.
385 get_sender(envelope, &sender);
388 snprintf(mailbox, sizeof(mailbox), "%s/%s",
389 mailspool, pw->pw_name);
396 debug_printf("addr=\"%s\"\n", trim(addr));
397 debug_printf("user=\"%s\"\n", trim(user));
398 debug_printf("info=\"%s\"\n", trim(info));
399 debug_printf("sender=\"%s\"\n", trim(sender));
400 debug_printf("envelope=\"%s\"\n",
401 envelope ? trim(envelope) : "");
402 debug_printf("mbox=\"%s\"\n", trim(mbox));
403 debug_printf("home=\"%s\"\n", trim(home));
404 debug_printf("ddate=\"%s\"\n", trim(ddate));
405 debug_printf("now=%02d:%02d\n\n", now->tw_hour, now->tw_min);
408 /* deliver the message */
409 status = localmail(fd, mdlvr);
411 done(status != -1 ? RCV_MOK : RCV_MBX);
417 ** Main routine for delivering message.
421 localmail(int fd, char *mdlvr)
423 /* delivery according to personal Maildelivery file */
424 if (usr_delivery(fd, mdlvr ? mdlvr : ".maildelivery", 0) != -1)
427 /* delivery according to global Maildelivery file */
428 if (usr_delivery(fd, maildelivery, 1) != -1)
432 verbose_printf("(delivering to standard mail spool)\n");
434 /* last resort - deliver to standard mail spool */
435 return usr_file(fd, mbox);
439 #define matches(a,b) (stringdex(b, a) >= 0)
442 ** Parse the delivery file, and process incoming message.
446 usr_delivery(int fd, char *delivery, int su)
448 int i, accept, status=1, won, vecp, next;
449 char *field, *pattern, *action, *result, *string;
450 char buffer[BUFSIZ], tmpbuf[BUFSIZ];
451 char *cp, *vec[NVEC];
456 /* open the delivery file */
457 if ((fp = fopen(delivery, "r")) == NULL)
460 /* check if delivery file has bad ownership or permissions */
461 if (fstat(fileno(fp), &st) == -1 ||
462 (st.st_uid != 0 && (su || st.st_uid != pw->pw_uid)) ||
463 st.st_mode & (S_IWGRP|S_IWOTH)) {
465 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);
473 /* read and process delivery file */
474 while (fgets(buffer, sizeof(buffer), fp)) {
475 /* skip comments and empty lines */
476 if (*buffer == '#' || *buffer == '\n')
479 /* zap trailing newline */
480 if ((cp = strchr(buffer, '\n')))
483 /* split buffer into fields */
484 vecp = split(buffer, vec);
486 /* check for too few fields */
489 debug_printf("WARNING: entry with only %d fields, skipping.\n", vecp);
494 for (i = 0; vec[i]; i++)
495 debug_printf("vec[%d]: \"%s\"\n",
505 /* find out how to perform the action */
510 ** If previous condition failed, don't
511 ** do this - else fall through
514 continue; /* else fall */
518 ** If already delivered, skip this action.
519 ** Else consider delivered if action is
523 continue; /* else fall */
528 ** Take action, and consider delivered if
529 ** action is successful.
538 ** Take action, but don't consider delivered,
539 ** even if action is successful
546 if (!mh_strcasecmp(vec[5], "select")) {
547 if (logged_in() != -1)
549 if (vecp > 7 && timely(vec[6], vec[7]) == -1)
554 /* check if the field matches */
562 ** "default" matches only if the message hasn't
563 ** been delivered yet.
565 if (!mh_strcasecmp(field, "default")) {
572 /* parse message and build lookup table */
573 if (!parsed && parse(fd) == -1) {
578 ** find header field in lookup table, and
579 ** see if the pattern matches.
581 if ((p = lookup(hdrs, field)) && (p->p_value != NULL)
582 && matches(p->p_value, pattern)) {
591 /* find out the action to perform */
594 /* deliver to quoted pipe */
595 if (mh_strcasecmp(action, "qpipe"))
596 continue; /* else fall */
598 expand(tmpbuf, string, fd);
599 if (split(tmpbuf, vec) < 1)
601 status = usr_pipe(fd, tmpbuf, vec[0], vec, 0);
605 /* deliver to pipe */
606 if (mh_strcasecmp(action, "pipe"))
607 continue; /* else fall */
611 expand(tmpbuf, string, fd);
614 status = usr_pipe(fd, tmpbuf, "/bin/sh",
620 if (!mh_strcasecmp(action, "file")) {
621 status = usr_file(fd, string);
624 /* deliver to nmh folder */
625 else if (mh_strcasecmp(action, "folder"))
626 continue; /* else fall */
628 status = usr_folder(fd, string);
633 if (mh_strcasecmp(action, "mbox"))
634 continue; /* else fall */
638 status = usr_file(fd, string);
643 if (mh_strcasecmp(action, "destroy"))
650 next = 0; /* action failed, mark for 'N' result */
652 if (accept && status == 0)
657 return (won ? 0 : -1);
664 ** Split buffer into fields (delimited by whitespace or
665 ** comma's). Return the number of fields found.
669 split(char *cp, char **vec)
676 /* split into a maximum of NVEC fields */
677 for (i = 0; i <= NVEC;) {
680 /* zap any whitespace and comma's */
681 while (isspace(*s) || *s == ',')
684 /* end of buffer, time to leave */
688 /* get double quote text as a single field */
690 for (vec[i++] = ++s; *s && *s != '"'; s++) {
692 ** Check for escaped double quote. We need
693 ** to shift the string to remove slash.
701 if (*s == '"') /* zap trailing double quote */
706 if (*s == QUOTE && *++s != '"')
710 /* move forward to next field delimiter */
711 while (*s && !isspace(*s) && *s != ',')
721 ** Parse the headers of a message, and build the
722 ** lookup table for matching fields and patterns.
731 char name[NAMESZ], field[BUFSIZ];
738 /* get a new FILE pointer to message */
739 if ((fd1 = dup(fd)) == -1)
741 if ((in = fdopen(fd1, "r")) == NULL) {
747 /* add special entries to lookup table */
748 if ((p = lookup(hdrs, "source")))
749 p->p_value = getcpy(sender);
750 if ((p = lookup(hdrs, "addr")))
751 p->p_value = getcpy(addr);
754 * Scan the headers of the message and build
757 for (i = 0, state = FLD;;) {
758 switch (state = m_getfld(state, name, field, sizeof(field),
764 while (state == FLDPLUS) {
765 state = m_getfld(state, name, field,
769 for (p = hdrs; p->p_name; p++) {
770 if (!mh_strcasecmp(p->p_name, name)) {
771 if (!(p->p_flags & P_HID)) {
772 if ((cp = p->p_value)) {
773 if (p->p_flags & P_ADR) {
774 dp = cp + strlen(cp) - 1;
777 cp = add(",\n\t", cp);
782 p->p_value = add(lp, cp);
788 if (p->p_name == NULL && i < NVEC) {
789 p->p_name = getcpy(name);
806 advise(NULL, "format error in message");
810 advise(NULL, "internal error in m_getfld");
818 if ((p = lookup(vars, "reply-to"))) {
819 if ((q = lookup(hdrs, "reply-to")) == NULL ||
821 q = lookup(hdrs, "from");
822 p->p_value = getcpy(q ? q->p_value : "");
823 p->p_flags &= ~P_CHK;
825 debug_printf("vars[%d]: name=\"%s\" value=\"%s\"\n",
826 p - vars, p->p_name, trim(p->p_value));
829 for (p = hdrs; p->p_name; p++)
830 debug_printf("hdrs[%d]: name=\"%s\" value=\"%s\"\n",
832 p->p_value ? trim(p->p_value) : "");
843 ** Expand any builtin variables such as $(sender),
844 ** $(address), etc., in a string.
848 expand(char *s1, char *s2, int fd)
856 while ((c = *s2++)) {
857 if (c != '$' || *s2 != LPAREN) {
860 for (cp = ++s2; *s2 && *s2 != RPAREN; s2++)
867 if ((p = lookup(vars, cp))) {
868 if (!parsed && (p->p_flags & P_CHK))
871 strcpy(s1, p->p_value);
881 ** Fill in the information missing from the "vars"
882 ** table, which is necessary to expand any builtin
883 ** variables in the string for a "pipe" or "qpipe"
897 if ((p = lookup(vars, "sender")))
898 p->p_value = getcpy(sender);
899 if ((p = lookup(vars, "address")))
900 p->p_value = getcpy(addr);
901 if ((p = lookup(vars, "size"))) {
902 snprintf(buffer, sizeof(buffer), "%d",
903 fstat(fd, &st) != -1 ? (int) st.st_size : 0);
904 p->p_value = getcpy(buffer);
906 if ((p = lookup(vars, "info")))
907 p->p_value = getcpy(info);
910 for (p = vars; p->p_name; p++)
911 debug_printf("vars[%d]: name=\"%s\" value=\"%s\"\n",
912 p - vars, p->p_name, trim(p->p_value));
918 ** Find a matching name in a lookup table. If found,
919 ** return the "pairs" entry, else return NULL.
923 lookup(struct pair *pairs, char *key)
925 for (; pairs->p_name; pairs++)
926 if (!mh_strcasecmp(pairs->p_name, key))
934 ** Check utmp(x) file to see if user is currently
949 while ((utp = getutent()) != NULL) {
951 #ifdef HAVE_STRUCT_UTMP_UT_TYPE
952 utp->ut_type == USER_PROCESS &&
954 utp->ut_name[0] != 0 &&
955 strncmp(user, utp->ut_name,
956 sizeof(utp->ut_name)) == 0) {
960 return (utmped = DONE);
965 return (utmped = NOTOK);
977 if ((uf = fopen(UTMP_FILE, "r")) == NULL)
980 while (fread((char *) &ut, sizeof(ut), 1, uf) == 1) {
981 if (ut.ut_name[0] != 0 &&
982 strncmp(user, ut.ut_name, sizeof(ut.ut_name))
987 return (utmped = DONE);
992 return (utmped = NOTOK);
996 #define check(t,a,b) if (t < a || t > b) return -1
997 #define cmpar(h1,m1,h2,m2) if (h1 < h2 || (h1 == h2 && m1 < m2)) return 0
1000 timely(char *t1, char *t2)
1002 int t1hours, t1mins, t2hours, t2mins;
1004 if (sscanf(t1, "%d:%d", &t1hours, &t1mins) != 2)
1006 check(t1hours, 0, 23);
1007 check(t1mins, 0, 59);
1009 if (sscanf(t2, "%d:%d", &t2hours, &t2mins) != 2)
1011 check(t2hours, 0, 23);
1012 check(t2mins, 0, 59);
1014 cmpar(now->tw_hour, now->tw_min, t1hours, t1mins);
1015 cmpar(t2hours, t2mins, now->tw_hour, now->tw_min);
1022 ** Deliver message by appending to a file.
1026 usr_file(int fd, char *mailbox)
1031 verbose_printf("delivering to file \"%s\"", mailbox);
1034 verbose_printf(" (mbox style)");
1036 /* open and lock the file */
1037 if ((md = mbx_open(mailbox, pw->pw_uid, pw->pw_gid,
1038 m_gmprot())) == -1) {
1040 adorn("", "unable to open:");
1044 lseek(fd, (off_t) 0, SEEK_SET);
1046 /* append message to file */
1047 if (mbx_copy(mailbox, md, fd, verbose) == -1) {
1049 adorn("", "error writing to:");
1053 /* close and unlock file */
1054 if (mbx_close(mailbox, md) == NOTOK) {
1056 adorn("", "error closing:");
1061 verbose_printf(", success.\n");
1067 ** Deliver message to a nmh folder.
1071 usr_folder(int fd, char *string)
1074 char folder[BUFSIZ], *vec[3];
1076 /* get folder name ready */
1078 strncpy(folder, string, sizeof(folder));
1080 snprintf(folder, sizeof(folder), "+%s", string);
1083 verbose_printf("delivering to folder \"%s\"", folder + 1);
1085 vec[0] = "rcvstore";
1089 /* use rcvstore to put message in folder */
1090 status = usr_pipe(fd, "rcvstore", rcvstoreproc, vec, 1);
1094 ** Currently, verbose status messages are handled by usr_pipe().
1098 verbose_printf(", success.\n");
1100 verbose_printf(", failed.\n");
1108 ** Deliver message to a process.
1112 usr_pipe(int fd, char *cmd, char *pgm, char **vec, int suppress)
1115 int i, bytes, seconds, status;
1118 if (verbose && !suppress)
1119 verbose_printf("delivering to pipe \"%s\"", cmd);
1121 lseek(fd, (off_t) 0, SEEK_SET);
1123 for (i = 0; (child_id = fork()) == -1 && i < 5; i++)
1130 adorn("fork", "unable to");
1137 freopen("/dev/null", "w", stdout);
1138 freopen("/dev/null", "w", stderr);
1144 if ((fd = open("/dev/tty", O_RDWR)) != -1) {
1145 ioctl(fd, TIOCNOTTY, NULL);
1148 #endif /* TIOCNOTTY */
1150 /* put in own process group */
1151 setpgid((pid_t) 0, getpid());
1154 m_putenv("USER", pw->pw_name);
1155 m_putenv("HOME", pw->pw_dir);
1156 m_putenv("SHELL", pw->pw_shell);
1162 /* parent process */
1163 if (!setjmp(myctx)) {
1164 SIGNAL(SIGALRM, alrmser);
1165 bytes = fstat(fd, &st) != -1 ?
1166 (int) st.st_size : 100;
1169 ** amount of time to wait depends on
1173 /* give at least 5 minutes */
1175 } else if (bytes >= 90000) {
1176 /* a half hour is long enough */
1179 seconds = (bytes / 60) + 300;
1181 alarm((unsigned int) seconds);
1182 status = pidwait(child_id, 0);
1187 verbose_printf(", success.\n");
1189 if ((status & 0xff00) == 0xff00)
1190 verbose_printf(", system error\n");
1192 pidstatus(status, stdout, ", failed");
1194 return (status == 0 ? 0 : -1);
1197 ** Ruthlessly kill the child and anything
1198 ** else in its process group.
1200 KILLPG(child_id, SIGKILL);
1202 verbose_printf(", timed-out; terminated\n");
1212 #ifndef RELIABLE_SIGNALS
1213 SIGNAL(SIGALRM, alrmser);
1216 longjmp(myctx, DONE);
1221 ** Get the `sender' from the envelope
1222 ** information ("From " line).
1226 get_sender(char *envelope, char **sender)
1230 unsigned char buffer[BUFSIZ];
1232 if (envelope == NULL) {
1233 *sender = getcpy("");
1237 i = strlen("From ");
1238 strncpy(buffer, envelope + i, sizeof(buffer));
1239 if ((cp = strchr(buffer, '\n'))) {
1249 for (cp = buffer + strlen(buffer) - 1; cp >= buffer; cp--)
1254 *sender = getcpy(buffer);
1259 ** Copy message into a temporary file.
1260 ** While copying, it will do some header processing
1261 ** including the extraction of the envelope information.
1265 copy_message(int qd, char *tmpfil, int fold)
1267 int i, first = 1, fd1, fd2;
1268 char buffer[BUFSIZ];
1272 tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
1273 if (tfile == NULL) return -1;
1275 strncpy(tmpfil, tfile, BUFSIZ);
1278 while ((i = read(qd, buffer, sizeof(buffer))) > 0)
1279 if (write(fd1, buffer, i) != i) {
1287 lseek(fd1, (off_t) 0, SEEK_SET);
1291 /* dup the fd for incoming message */
1292 if ((fd2 = dup(qd)) == -1) {
1297 /* now create a FILE pointer for it */
1298 if ((qfp = fdopen(fd2, "r")) == NULL) {
1304 /* dup the fd for temporary file */
1305 if ((fd2 = dup(fd1)) == -1) {
1311 /* now create a FILE pointer for it */
1312 if ((ffp = fdopen(fd2, "r+")) == NULL) {
1320 ** copy message into temporary file
1321 ** and massage the headers. Save
1322 ** a copy of the "From " line for later.
1324 i = strlen("From ");
1325 while (fgets(buffer, sizeof(buffer), qfp)) {
1328 if (strncmp(buffer, "From ", i)==0) {
1330 char *fp, *cp, *hp, *ep;
1333 ** get copy of envelope information
1336 envelope = getcpy(buffer);
1340 ** First go ahead and put "From " line
1350 ** Now create a "Return-Path:" line
1351 ** from the "From " line.
1353 hp = cp = strchr(fp = envelope + i, ' ');
1354 while ((hp = strchr(++hp, 'r')))
1355 if (uprf(hp, "remote from")) {
1356 hp = strrchr(hp, ' ');
1361 ** return path for UUCP style
1364 ep = strchr(++hp, '\n');
1365 snprintf(buffer, sizeof(buffer), "Return-Path: %.*s!%.*s\n", (int)(ep - hp), hp, (int)(cp - fp), fp);
1368 ** return path for standard domain
1371 snprintf(buffer, sizeof(buffer), "Return-Path: %.*s\n", (int)(cp - fp), fp);
1374 /* Add Return-Path header to message */
1379 /* Put the delivery date in message */
1400 lseek(fd1, (off_t) 0, SEEK_SET);
1412 ** Trim strings for pretty printing of debugging output
1418 char buffer[BUFSIZ*4];
1419 unsigned char *bp, *sp;
1424 /* copy string into temp buffer */
1425 strncpy(buffer, cp, sizeof(buffer));
1428 /* skip over leading whitespace */
1429 while (isspace(*bp))
1432 /* start at the end and zap trailing whitespace */
1433 for (sp = bp + strlen(bp) - 1; sp >= bp; sp--) {
1440 /* replace remaining whitespace with spaces */
1441 for (sp = bp; *sp; sp++)
1445 /* now return a copy */
1450 ** Function for printing `verbose' messages.
1454 verbose_printf(char *fmt, ...)
1459 vfprintf(stdout, fmt, ap);
1462 fflush(stdout); /* now flush output */
1467 ** Function for printing `verbose' delivery
1472 adorn(char *what, char *fmt, ...)
1478 eindex = errno; /* save the errno */
1479 fprintf(stdout, ", ");
1482 vfprintf(stdout, fmt, ap);
1487 fprintf(stdout, " %s: ", what);
1488 if ((s = strerror(eindex)))
1489 fprintf(stdout, "%s", s);
1491 fprintf(stdout, "Error %d", eindex);
1494 fputc('\n', stdout);
1500 ** Function for printing `debug' messages.
1504 debug_printf(char *fmt, ...)
1509 vfprintf(stderr, fmt, ap);