portnum = cp;
}
if ((ctl->smtp_socket = SockOpen(parsed_host,portnum,
- ctl->server.plugout)) == -1)
+ ctl->server.plugout, &ai1)) == -1)
{
xfree(parsed_host);
continue;
else
{
if ((ctl->smtp_socket = SockOpen(parsed_host,portnum,
- ctl->server.plugout)) == -1)
+ ctl->server.plugout, &ai1)) == -1)
{
xfree(parsed_host);
continue;
/* we need only SMTP for this purpose */
/* XXX FIXME: hardcoding localhost is nonsense if smtphost can be
* configured */
- if ((sock = SockOpen("localhost", SMTP_PORT, NULL)) == -1)
+ if ((sock = SockOpen("localhost", SMTP_PORT, NULL, &ai1)) == -1)
return(FALSE);
if (SMTP_ok(sock, SMTP_MODE) != SM_OK)
if (ctl->server.base_protocol->delimited) /* server has already byte-stuffed */
{
if (ctl->mda) {
+ /* writing to MDA, undo byte-stuffing */
++buf;
} else {
/* writing to SMTP, leave the byte-stuffing in place */;
}
else /* if (!protocol->delimited) -- not byte-stuffed already */
{
- if (!ctl->mda) /* byte-stuff it */
- {
- if (!ctl->bsmtp)
- SockWrite(ctl->smtp_socket, buf, 1);
- else
- {
- fwrite(buf, 1, 1, sinkfp);
+ /* byte-stuff it */
+ if (!ctl->mda) {
+ if (!ctl->bsmtp) {
+ n = SockWrite(ctl->smtp_socket, buf, 1);
+ } else {
+ n = fwrite(buf, 1, 1, sinkfp);
+ if (ferror(sinkfp)) n = -1;
}
+ if (n < 0)
+ return n;
}
}
}
}
n = 0;
- if (ctl->mda || ctl->bsmtp)
+ if (ctl->mda || ctl->bsmtp) {
n = fwrite(buf, last - buf, 1, sinkfp);
- else if (ctl->smtp_socket != -1)
+ if (ferror(sinkfp)) n = -1;
+ } else if (ctl->smtp_socket != -1)
n = SockWrite(ctl->smtp_socket, buf, last - buf);
phase = oldphase;
int smtp_err;
if (ctl->mda)
{
- int rc;
+ int rc,e,e2,err = 0;
/* close the delivery pipe, we'll reopen before next message */
if (sinkfp)
{
+ if (ferror(sinkfp))
+ err = 1, e2 = errno;
+ if ((fflush(sinkfp)))
+ err = 1, e2 = errno;
+
+ errno = 0;
rc = pclose(sinkfp);
+ e = errno;
sinkfp = (FILE *)NULL;
}
else
- rc = 0;
+ rc = e = 0;
deal_with_sigchld(); /* Restore SIGCHLD handling to reap zombies */
- if (rc)
+ if (rc || err)
{
- if (WIFSIGNALED(rc)) {
+ if (err) {
+ report(stderr, GT_("Error writing to MDA: %s\n"), strerror(e2));
+ } else if (WIFSIGNALED(rc)) {
report(stderr,
GT_("MDA died of signal %d\n"), WTERMSIG(rc));
} else if (WIFEXITED(rc)) {
GT_("MDA returned nonzero status %d\n"), WEXITSTATUS(rc));
} else {
report(stderr,
- GT_("Strange: MDA pclose returned %d, cannot handle at %s:%d\n"), rc, __FILE__, __LINE__);
+ GT_("Strange: MDA pclose returned %d and errno %d/%s, cannot handle at %s:%d\n"),
+ rc, e, strerror(e), __FILE__, __LINE__);
}
return(FALSE);