2 * sink.c -- forwarding/delivery support for fetchmail
4 * The interface of this module (open_sink(), stuff_line(), close_sink(),
5 * release_sink()) seals off the delivery logic from the protocol machine,
6 * so the latter won't have to care whether it's shipping to an [SL]MTP
7 * listener daemon or an MDA pipe.
9 * Copyright 1998 by Eric S. Raymond
10 * For license terms, see the file COPYING in this directory.
21 #endif /* HAVE_MEMORY_H */
22 #if defined(STDC_HEADERS)
25 #if defined(HAVE_UNISTD_H)
28 #if defined(HAVE_STDARG_H)
34 #include "fetchmail.h"
39 /* BSD portability hack...I know, this is an ugly place to put it */
40 #if !defined(SIGCHLD) && defined(SIGCLD)
41 #define SIGCHLD SIGCLD
44 /* makes the open_sink()/close_sink() pair non-reentrant */
45 static lmtp_responses;
47 static int smtp_open(struct query *ctl)
48 /* try to open a socket to the appropriate SMTP server for this query */
50 /* maybe it's time to close the socket in order to force delivery */
51 if (NUM_NONZERO(ctl->batchlimit) && (ctl->smtp_socket != -1) && batchcount++ == ctl->batchlimit)
53 close(ctl->smtp_socket);
54 ctl->smtp_socket = -1;
58 /* if no socket to any SMTP host is already set up, try to open one */
59 if (ctl->smtp_socket == -1)
62 * RFC 1123 requires that the domain name in HELO address is a
63 * "valid principal domain name" for the client host. If we're
64 * running in invisible mode, violate this with malice
65 * aforethought in order to make the Received headers and
68 * In fact this code relies on the RFC1123 requirement that the
69 * SMTP listener must accept messages even if verification of the
70 * HELO name fails (RFC1123 section 5.2.5, paragraph 2).
72 * How we compute the true mailhost name to pass to the
73 * listener doesn't affect behavior on RFC1123- violating
74 * listeners that check for name match; we're going to lose
75 * on those anyway because we can never give them a name
76 * that matches the local machine fetchmail is running on.
77 * What it will affect is the listener's logging.
80 const char *id_me = run.invisible ? ctl->server.truename : fetchmailhost;
86 * Run down the SMTP hunt list looking for a server that's up.
87 * Use both explicit hunt entries (value TRUE) and implicit
88 * (default) ones (value FALSE).
91 phase = LISTENER_WAIT;
93 set_timeout(ctl->server.timeout);
94 for (idp = ctl->smtphunt; idp; idp = idp->next)
96 char *cp, *parsed_host;
98 char *portnum = SMTP_PORT;
100 int portnum = SMTP_PORT;
103 xalloca(parsed_host, char *, strlen(idp->id) + 1);
105 ctl->smtphost = idp->id; /* remember last host tried. */
107 strcpy(parsed_host, idp->id);
108 if ((cp = strrchr(parsed_host, '/')))
118 if ((ctl->smtp_socket = SockOpen(parsed_host,portnum,NULL,
119 ctl->server.plugout)) == -1)
122 /* are we doing SMTP or LMTP? */
123 SMTP_setmode(ctl->listener);
125 /* first, probe for ESMTP */
126 if (SMTP_ok(ctl->smtp_socket) == SM_OK &&
127 SMTP_ehlo(ctl->smtp_socket, id_me,
128 &ctl->server.esmtp_options) == SM_OK)
132 * RFC 1869 warns that some listeners hang up on a failed EHLO,
133 * so it's safest not to assume the socket will still be good.
135 SockClose(ctl->smtp_socket);
136 ctl->smtp_socket = -1;
138 /* if opening for ESMTP failed, try SMTP */
139 if ((ctl->smtp_socket = SockOpen(parsed_host,portnum,NULL,
140 ctl->server.plugout)) == -1)
143 if (SMTP_ok(ctl->smtp_socket) == SM_OK &&
144 SMTP_helo(ctl->smtp_socket, id_me) == SM_OK)
147 SockClose(ctl->smtp_socket);
148 ctl->smtp_socket = -1;
155 * RFC 1123 requires that the domain name part of the
156 * RCPT TO address be "canonicalized", that is a FQDN
157 * or MX but not a CNAME. Some listeners (like exim)
158 * enforce this. Now that we have the actual hostname,
159 * compute what we should canonicalize with.
161 ctl->destaddr = ctl->smtpaddress ? ctl->smtpaddress : ( ctl->smtphost ? ctl->smtphost : "localhost");
163 if (outlevel >= O_DEBUG && ctl->smtp_socket != -1)
164 error(0, 0, _("forwarding to %s"), ctl->smtphost);
166 return(ctl->smtp_socket);
169 /* these are shared by open_sink and stuffline */
171 static RETSIGTYPE (*sigchld)(int);
173 int stuffline(struct query *ctl, char *buf)
174 /* ship a line to the given control block's output sink (SMTP server or MDA) */
179 /* The line may contain NUL characters. Find the last char to use
180 * -- the real line termination is the sequence "\n\0".
183 while ((last += strlen(last)) && (last[-1] != '\n'))
186 /* fix message lines that have only \n termination (for qmail) */
189 if (last - 1 == buf || last[-2] != '\r')
198 phase = FORWARDING_WAIT;
201 * SMTP byte-stuffing. We only do this if the protocol does *not*
202 * use .<CR><LF> as EOM. If it does, the server will already have
203 * decorated any . lines it sends back up.
206 if (ctl->server.base_protocol->delimited) /* server has already byte-stuffed */
211 /* writing to SMTP, leave the byte-stuffing in place */;
213 else /* if (!protocol->delimited) -- not byte-stuffed already */
216 SockWrite(ctl->smtp_socket, buf, 1); /* byte-stuff it */
218 /* leave it alone */;
221 /* we may need to strip carriage returns */
226 for (sp = tp = buf; sp < last; sp++)
234 if (ctl->mda || ctl->bsmtp)
235 n = fwrite(buf, 1, last - buf, sinkfp);
236 else if (ctl->smtp_socket != -1)
237 n = SockWrite(ctl->smtp_socket, buf, last - buf);
244 static void sanitize(char *s)
245 /* replace unsafe shellchars by an _ */
247 const static char *ok_chars = " 1234567890!@%-_=+:,./abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
250 for (cp = s; *(cp += strspn(cp, ok_chars)); /* NO INCREMENT */)
254 static int send_bouncemail(struct msgblk *msg,
255 char *message, int nerrors, char *errors[])
256 /* bounce back an error report a la RFC 1892 */
258 char daemon_name[18 + HOSTLEN] = "FETCHMAIL-DAEMON@";
259 char boundary[BUFSIZ];
262 /* don't bounce in reply to undeliverable bounces */
263 if (!msg->return_path[0] || strcmp(msg->return_path, "<>") == 0)
266 SMTP_setmode(SMTP_MODE);
268 strcat(daemon_name, fetchmailhost);
270 /* we need only SMTP for this purpose */
271 if ((sock = SockOpen("localhost", SMTP_PORT, NULL, NULL)) == -1
272 || SMTP_ok(sock) != SM_OK
273 || SMTP_helo(sock, "localhost") != SM_OK
274 || SMTP_from(sock, daemon_name, (char *)NULL) != SM_OK
275 || SMTP_rcpt(sock, msg->return_path) != SM_OK
276 || SMTP_data(sock) != SM_OK)
280 "om-mani-padme-hum-%d-%d-%ld",
281 getpid(), getppid(), time((time_t *)NULL));
283 if (outlevel >= O_VERBOSE)
284 error(0, 0, "SMTP: (bounce-message body)");
286 /* bouncemail headers */
287 SockPrintf(sock, "Return-Path: <>");
288 SockPrintf(sock, "From: FETCHMAIL-DAEMON@%s\r\n", fetchmailhost);
289 SockPrintf(sock, "To: %s\n", msg->return_path);
290 SockPrintf(sock, "MIME-Version: 1.0\r\n");
291 SockPrintf(sock, "Content-Type: multipart/report; report-type=delivery-status; boundary=\"%s\"\r\n", boundary);
292 SockPrintf(sock, "\r\n");
293 SockPrintf(sock, "Content-Transfer-Encoding: 7bit\r\n");
294 SockPrintf(sock, "\r\n");
296 /* RFC1892 part 1 -- human-readable message */
297 SockPrintf(sock, "--%s\r\n", boundary);
298 SockPrintf(sock,"Content-Type: text/plain\r\n");
299 SockPrintf(sock, "\r\n");
300 SockWrite(sock, message, strlen(message));
301 SockPrintf(sock, "\r\n");
302 SockPrintf(sock, "\r\n");
306 /* RFC1892 part 2 -- machine-readable responses */
307 SockPrintf(sock, "--%s\r\n", boundary);
308 SockPrintf(sock,"Content-Type: message/delivery-status\r\n");
309 SockPrintf(sock, "\r\n");
310 for (i = 0; i < nerrors; i++)
311 SockPrintf(sock, "%s\r\n", errors[i]);
312 SockPrintf(sock, "\r\n");
315 /* RFC1892 part 3 -- headers of undelivered message */
316 SockPrintf(sock, "--%s\r\n", boundary);
317 SockPrintf(sock, "Content-Type: text/rfc822-headers\r\n");
318 SockPrintf(sock, "\r\n");
319 SockWrite(sock, msg->headers, strlen(msg->headers));
320 SockPrintf(sock, "\r\n");
321 SockPrintf(sock, "--%s--\r\n", boundary);
323 if (SMTP_eom(sock) != SM_OK || SMTP_quit(sock))
331 static int handle_smtp_error(struct query *ctl, struct msgblk *msg)
332 /* handle SMTP errors based on the content of SMTP_response */
334 int smtperr = atoi(smtp_response);
337 responses[0] = smtp_response;
339 /* required by RFC1870; sets us up to be able to send bouncemail */
340 SMTP_rset(ctl->smtp_socket);
343 * Note: send_bouncemail message strings are not made subject
344 * to gettext translation because (a) they're going to be
345 * embedded in a text/plain 7bit part, and (b) they're
346 * going to be associated with listener error-response
347 * messages, which are probably in English (none of the
348 * MTAs I know about are internationalized).
350 if (str_find(&ctl->antispam, smtperr))
353 * SMTP listener explicitly refuses to deliver mail
354 * coming from this address, probably due to an
355 * anti-spam domain exclusion. Respect this. Don't
356 * try to ship the message, and don't prevent it from
357 * being deleted. Typical values:
359 * 501 = exim's old antispam response
360 * 550 = exim's new antispam response (temporary)
361 * 553 = sendmail 8.8.7's generic REJECT
362 * 571 = sendmail's "unsolicited email refused"
366 "We do not accept mail from you.\r\n",
372 * Suppress error message only if the response specifically
373 * meant `excluded for policy reasons'. We *should* see
374 * an error when the return code is less specific.
377 error(0, -1, _("%cMTP error: %s"),
383 case 452: /* insufficient system storage */
385 * Temporary out-of-queue-space condition on the
386 * ESMTP server. Don't try to ship the message,
387 * and suppress deletion so it can be retried on
388 * a future retrieval cycle.
390 * Bouncemail *might* be appropriate here as a delay
391 * notification. But it's not really necessary because
392 * this is not an actual failure, we're very likely to be
393 * able to recover on the next cycle.
395 return(PS_TRANSIENT);
397 case 552: /* message exceeds fixed maximum message size */
399 * Permanent no-go condition on the
400 * ESMTP server. Don't try to ship the message,
401 * and allow it to be deleted.
404 "This message was too large.\r\n",
408 case 553: /* invalid sending domain */
410 * These latter days 553 usually means a spammer is trying to
414 "Invalid address.\r\n",
418 default: /* bounce the error back to the sender */
420 "General SMTP/ESMTP error.\r\n",
426 int open_sink(struct query *ctl, struct msgblk *msg,
427 int *good_addresses, int *bad_addresses)
428 /* set up sinkfp to be an input sink we can ship a message to */
432 *bad_addresses = *good_addresses = 0;
434 if (ctl->bsmtp) /* dump to a BSMTP batch file */
436 if (strcmp(ctl->bsmtp, "-") == 0)
439 sinkfp = fopen(ctl->bsmtp, "a");
441 /* see the ap computation under the SMTP branch */
443 "MAIL FROM: %s", (msg->return_path[0]) ? msg->return_path : user);
445 if (ctl->pass8bits || (ctl->mimemsg & MSG_IS_8BIT))
446 fputs(" BODY=8BITMIME", sinkfp);
447 else if (ctl->mimemsg & MSG_IS_7BIT)
448 fputs(" BODY=7BIT", sinkfp);
450 fprintf(sinkfp, " SIZE=%d\r\n", msg->reallen);
453 * RFC 1123 requires that the domain name part of the
454 * RCPT TO address be "canonicalized", that is a FQDN
455 * or MX but not a CNAME. Some listeners (like exim)
456 * enforce this. Now that we have the actual hostname,
457 * compute what we should canonicalize with.
459 ctl->destaddr = ctl->smtpaddress ? ctl->smtpaddress : "localhost";
462 for (idp = msg->recipients; idp; idp = idp->next)
463 if (idp->val.status.mark == XMIT_ACCEPT)
465 if (strchr(idp->id, '@'))
467 "RCPT TO: %s\r\n", idp->id);
470 "RCPT TO: %s@%s\r\n", idp->id, ctl->destaddr);
474 fputs("DATA\r\n", sinkfp);
478 error(0, -1, _("BSMTP file open or preamble write failed"));
482 else if (ctl->mda) /* we have a declared MDA */
484 int length = 0, fromlen = 0, nameslen = 0;
485 char *names = NULL, *before, *after, *from = NULL;
487 ctl->destaddr = "localhost";
489 for (idp = msg->recipients; idp; idp = idp->next)
490 if (idp->val.status.mark == XMIT_ACCEPT)
493 length = strlen(ctl->mda);
494 before = xstrdup(ctl->mda);
496 /* get user addresses for %T (or %s for backward compatibility) */
497 if (strstr(before, "%s") || strstr(before, "%T"))
500 * We go through this in order to be able to handle very
501 * long lists of users and (re)implement %s.
504 for (idp = msg->recipients; idp; idp = idp->next)
505 if ((idp->val.status.mark == XMIT_ACCEPT))
506 nameslen += (strlen(idp->id) + 1); /* string + ' ' */
507 if ((*good_addresses == 0))
508 nameslen = strlen(run.postmaster);
510 names = (char *)xmalloc(nameslen + 1); /* account for '\0' */
511 if (*good_addresses == 0)
512 strcpy(names, run.postmaster);
516 for (idp = msg->recipients; idp; idp = idp->next)
517 if (idp->val.status.mark == XMIT_ACCEPT)
519 strcat(names, idp->id);
522 names[--nameslen] = '\0'; /* chop trailing space */
525 /* sanitize names in order to contain only harmless shell chars */
529 /* get From address for %F */
530 if (strstr(before, "%F"))
532 from = xstrdup(msg->return_path);
534 /* sanitize from in order to contain *only* harmless shell chars */
537 fromlen = strlen(from);
540 /* do we have to build an mda string? */
545 /* find length of resulting mda string */
547 while ((sp = strstr(sp, "%s"))) {
548 length += nameslen - 2; /* subtract %s */
552 while ((sp = strstr(sp, "%T"))) {
553 length += nameslen - 2; /* subtract %T */
557 while ((sp = strstr(sp, "%F"))) {
558 length += fromlen - 2; /* subtract %F */
562 after = xmalloc(length + 1);
564 /* copy mda source string to after, while expanding %[sTF] */
565 for (dp = after, sp = before; (*dp = *sp); dp++, sp++) {
566 if (sp[0] != '%') continue;
568 /* need to expand? BTW, no here overflow, because in
569 ** the worst case (end of string) sp[1] == '\0' */
570 if (sp[1] == 's' || sp[1] == 'T') {
573 sp++; /* position sp over [sT] */
574 dp--; /* adjust dp */
575 } else if (sp[1] == 'F') {
578 sp++; /* position sp over F */
579 dp--; /* adjust dp */
598 if (outlevel >= O_DEBUG)
599 error(0, 0, _("about to deliver with: %s"), before);
603 * Arrange to run with user's permissions if we're root.
604 * This will initialize the ownership of any files the
605 * MDA creates properly. (The seteuid call is available
606 * under all BSDs and Linux)
609 #endif /* HAVE_SETEUID */
611 sinkfp = popen(before, "w");
616 /* this will fail quietly if we didn't start as root */
618 #endif /* HAVE_SETEUID */
622 error(0, 0, _("MDA open failed"));
626 sigchld = signal(SIGCHLD, SIG_DFL);
628 else /* forward to an SMTP or LMTP listener */
631 char options[MSGBUFSIZE];
632 char addr[HOSTLEN+USERNAMELEN+1];
633 char **from_responses;
636 /* build a connection to the SMTP listener */
637 if ((smtp_open(ctl) == -1))
639 error(0, errno, _("%cMTP connect to %s failed"),
641 ctl->smtphost ? ctl->smtphost : "localhost");
646 * Compute ESMTP options.
649 if (ctl->server.esmtp_options & ESMTP_8BITMIME) {
650 if (ctl->pass8bits || (ctl->mimemsg & MSG_IS_8BIT))
651 strcpy(options, " BODY=8BITMIME");
652 else if (ctl->mimemsg & MSG_IS_7BIT)
653 strcpy(options, " BODY=7BIT");
656 if ((ctl->server.esmtp_options & ESMTP_SIZE) && msg->reallen > 0)
657 sprintf(options + strlen(options), " SIZE=%d", msg->reallen);
660 * Try to get the SMTP listener to take the Return-Path
661 * address as MAIL FROM . If it won't, fall back on the
662 * calling-user ID. This won't affect replies, which use the
663 * header From address anyway.
665 * RFC 1123 requires that the domain name part of the
666 * MAIL FROM address be "canonicalized", that is a
667 * FQDN or MX but not a CNAME. We'll assume the From
668 * header is already in this form here (it certainly
669 * is if rewrite is on). RFC 1123 is silent on whether
670 * a nonexistent hostname part is considered canonical.
672 * This is a potential problem if the MTAs further upstream
673 * didn't pass canonicalized From/Return-Path lines, *and* the
674 * local SMTP listener insists on them.
676 ap = (msg->return_path[0]) ? msg->return_path : user;
677 if (SMTP_from(ctl->smtp_socket, ap, options) != SM_OK)
678 return(handle_smtp_error(ctl, msg));
681 * Now list the recipient addressees
684 for (idp = msg->recipients; idp; idp = idp->next)
686 xalloca(from_responses, char **, sizeof(char *) * total_addresses);
687 for (idp = msg->recipients; idp; idp = idp->next)
688 if (idp->val.status.mark == XMIT_ACCEPT)
690 if (strchr(idp->id, '@'))
691 strcpy(addr, idp->id);
694 snprintf(addr, sizeof(addr)-1, "%s@%s", idp->id, ctl->destaddr);
696 sprintf(addr, "%s@%s", idp->id, ctl->destaddr);
697 #endif /* HAVE_SNPRINTF */
699 if (SMTP_rcpt(ctl->smtp_socket, addr) == SM_OK)
703 char errbuf[POPBUFSIZE];
705 strcpy(errbuf, idp->id);
706 strcat(errbuf, ": ");
707 strcat(errbuf, smtp_response);
709 xalloca(from_responses[*bad_addresses],
712 strcpy(from_responses[*bad_addresses], errbuf);
715 idp->val.status.mark = XMIT_RCPTBAD;
716 if (outlevel >= O_VERBOSE)
718 _("%cMTP listener doesn't like recipient address `%s'"),
719 ctl->listener, addr);
724 "Some addresses were rejected by the MDA fetchmail forwards to.\r\n",
725 *bad_addresses, from_responses);
727 * It's tempting to do local notification only if bouncemail was
728 * insufficient -- that is, to add && total_addresses > *bad_addresses
729 * to the test here. The problem with this theory is that it would
730 * make initial diagnosis of a broken multidrop configuration very
731 * hard -- most single-recipient messages would just invisibly bounce.
733 if (!(*good_addresses))
735 if (strchr(run.postmaster, '@'))
736 strcpy(addr, run.postmaster);
740 snprintf(addr, sizeof(addr)-1, "%s@%s", run.postmaster, ctl->destaddr);
742 sprintf(addr, "%s@%s", run.postmaster, ctl->destaddr);
743 #endif /* HAVE_SNPRINTF */
746 if (SMTP_rcpt(ctl->smtp_socket, addr) != SM_OK)
748 error(0, 0, _("can't even send to %s!"), run.postmaster);
749 SMTP_rset(ctl->smtp_socket); /* required by RFC1870 */
753 if (outlevel >= O_VERBOSE)
754 error(0, 0, _("no address matches; forwarding to %s."), run.postmaster);
758 * Tell the listener we're ready to send data.
759 * Some listeners (like zmailer) may return antispam errors here.
761 if (SMTP_data(ctl->smtp_socket) != SM_OK)
762 return(handle_smtp_error(ctl, msg));
766 * We need to stash this away in order to know how many
767 * response lines to expect after the LMTP end-of-message.
769 lmtp_responses = *good_addresses;
774 void release_sink(struct query *ctl)
775 /* release the per-message output sink, whether it's a pipe or SMTP socket */
784 sinkfp = (FILE *)NULL;
786 signal(SIGCHLD, sigchld);
790 int close_sink(struct query *ctl, struct msgblk *msg, flag forward)
791 /* perform end-of-message actions on the current output sink */
797 /* close the delivery pipe, we'll reopen before next message */
801 sinkfp = (FILE *)NULL;
805 signal(SIGCHLD, sigchld);
808 error(0, -1, _("MDA exited abnormally or returned nonzero status"));
814 /* implicit disk-full check here... */
815 fputs("..\r\n", sinkfp);
816 if (strcmp(ctl->bsmtp, "-"))
820 error(0, -1, _("Message termination or close of BSMTP file failed"));
826 /* write message terminator */
827 if (SMTP_eom(ctl->smtp_socket) != SM_OK)
829 error(0, -1, _("SMTP listener refused delivery"));
834 * If this is an SMTP connection, SMTP_eom() ate the response.
835 * But could be this is an LMTP connection, in which case we have to
836 * interpret either (a) a single 503 response meaning there
837 * were no successful RCPT TOs, or (b) a variable number of
838 * responses, one for each successful RCPT TO. We need to send
839 * bouncemail on each failed response and then return TRUE anyway,
840 * otherwise the message will get left in the queue and resent
841 * to people who got it the first time.
843 if (ctl->listener == LMTP_MODE)
844 if (lmtp_responses == 0)
846 SMTP_ok(ctl->smtp_socket);
849 * According to RFC2033, 503 is the only legal response
850 * if no RCPT TO commands succeeded. No error recovery
851 * is really possible here, as we have no idea what
852 * insane thing the listener might be doing if it doesn't
855 if (atoi(smtp_response) == 503)
856 error(0, -1, _("LMTP delivery error on EOM"));
859 _("Unexpected non-503 response to LMTP EOM: %s"),
863 * It's not completely clear what to do here. We choose to
864 * interpret delivery failure here as a transient error,
865 * the same way SMTP delivery failure is handled. If we're
866 * wrong, an undead message will get stuck in the queue.
875 /* eat the RFC2033-required responses, saving errors */
876 xalloca(responses, char **, sizeof(char *) * lmtp_responses);
877 for (errors = i = 0; i < lmtp_responses; i++)
879 if (SMTP_ok(ctl->smtp_socket) == SM_OK)
880 responses[i] = (char *)NULL;
883 xalloca(responses[errors],
885 strlen(smtp_response)+1);
886 strcpy(responses[errors], smtp_response);
892 return(TRUE); /* all deliveries succeeded */
895 * One or more deliveries failed.
896 * If we can bounce a failures list back to the sender,
897 * return TRUE, deleting the message from the server so
898 * it won't be re-forwarded on subsequent poll cycles.
900 return(send_bouncemail(msg,
901 "LSMTP partial delivery failure.\r\n",
909 int open_warning_by_mail(struct query *ctl, struct msgblk *msg)
910 /* set up output sink for a mailed warning to calling user */
915 * Dispatching warning email is a little complicated. The problem is
916 * that we have to deal with three distinct cases:
918 * 1. Single-drop running from user account. Warning mail should
919 * go to the local name for which we're collecting (coincides
920 * with calling user).
922 * 2. Single-drop running from root or other privileged ID, with rc
923 * file generated on the fly (Ken Estes's weird setup...) Mail
924 * should go to the local name for which we're collecting (does not
925 * coincide with calling user).
927 * 3. Multidrop. Mail must go to postmaster. We leave the recipients
928 * member null so this message will fall through to run.postmaster.
930 * The zero in the reallen element means we won't pass a SIZE
931 * option to ESMTP; the message length would be more trouble than
932 * it's worth to compute.
934 struct msgblk reply = {NULL, NULL, "FETCHMAIL-DAEMON", 0};
936 if (!MULTIDROP(ctl)) /* send to calling user */
940 save_str(&reply.recipients, ctl->localnames->id, XMIT_ACCEPT);
941 status = open_sink(ctl, &reply, &good, &bad);
942 free_str_list(&reply.recipients);
945 else /* send to postmaster */
946 return(open_sink(ctl, &reply, &good, &bad));
949 #if defined(HAVE_STDARG_H)
950 void stuff_warning(struct query *ctl, const char *fmt, ... )
952 void stuff_warning(struct query *ctl, fmt, va_alist)
954 const char *fmt; /* printf-style format */
957 /* format and ship a warning message line by mail */
959 char buf[POPBUFSIZE];
963 * stuffline() requires its input to be writeable (for CR stripping),
964 * so we needed to copy the message to a writeable buffer anyway in
965 * case it was a string constant. We make a virtue of that necessity
966 * here by supporting stdargs/varargs.
968 #if defined(HAVE_STDARG_H)
973 #ifdef HAVE_VSNPRINTF
974 vsnprintf(buf, sizeof(buf), fmt, ap);
976 vsprintf(buf, fmt, ap);
985 void close_warning_by_mail(struct query *ctl, struct msgblk *msg)
986 /* sign and send mailed warnings */
988 stuff_warning(ctl, "--\r\n\t\t\t\tThe Fetchmail Daemon\r\n");
989 close_sink(ctl, msg, TRUE);
992 /* sink.c ends here */