[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nmh-workers] logging outgoing messages
From: |
Steven Winikoff |
Subject: |
[nmh-workers] logging outgoing messages |
Date: |
Tue, 09 Jul 2019 17:43:06 -0400 |
I recently modified my configuration for nmh-1.7.1 to connect directly to
my ISP's sendmail, rather than going through sendmail on my desktop Linux
system.
This works perfectly, but as a side effect I lost all logging of outgoing
messages. This isn't the end of the world, but it's a pain because there
are times when outgoing messages may need to be traced, and in cases like
that it's important to be able to quote the ISP's assigned QID.
...so I hacked the appended patch together, and it seems to work, but I'm
sure there must be a better way to do this. Problems with my code include
(but are almost certainly not limited to) the following:
- It doesn't check to see whether it's connecting to a local sendmail
(if so, each message will be logged twice).
- It logs successful delivery, but not delivery failures (no matter
the reason).
- It seems to break two of the tests in make check:
# make check
[...]
PASS: test/post/test-messageid
send: message not delivered to anyone
FAIL: test/post/test-mts
send: message not delivered to anyone
FAIL: test/post/test-post-aliases
PASS: test/post/test-post-basic
[...]
=======================================
2 of 112 tests failed
Please report to address@hidden
=======================================
Makefile:4763: recipe for target 'check-TESTS' failed
make[1]: *** [check-TESTS] Error 1
make[1]: Leaving directory '/big/local/pkg/nmh/nmh-1.7.1'
Makefile:5019: recipe for target 'check-am' failed
Is there any interest in adding an improved version of this to the code
base?
- Steven
8<----------------------------- cut here ---------------------------->8
--- h/mts.h.original 2017-11-22 09:37:56.000000000 -0500
+++ h/mts.h 2019-07-09 16:51:34.260314328 -0400
@@ -57,3 +57,15 @@
* Global MailDelivery File
*/
extern char *maildelivery;
+
+#ifndef NOSYSLOG
+# define SYSLOG_FIELD_SIZE 1024
+# define SYSLOG_FIELD_LAST 1023
+
+ char syslog_from [SYSLOG_FIELD_SIZE];
+ char syslog_to [SYSLOG_FIELD_SIZE];
+ char syslog_msgid [SYSLOG_FIELD_SIZE];
+ char syslog_server[SYSLOG_FIELD_SIZE];
+ char syslog_port [SYSLOG_FIELD_SIZE];
+ char syslog_qid [SYSLOG_FIELD_SIZE];
+#endif
--- mts/smtp/smtp.c.original 2018-03-06 14:05:55.000000000 -0500
+++ mts/smtp/smtp.c 2019-07-09 17:17:34.382593987 -0400
@@ -13,6 +13,9 @@
#include <h/netsec.h>
#include <sys/socket.h>
+#ifndef NOSYSLOG
+ #include <syslog.h>
+#endif
/*
* This module implements an interface to SendMail very similar
@@ -74,6 +77,24 @@
int debug, int sasl, const char *saslmech, const char *user,
const char *oauth_svc, int tls)
{
+#ifndef NOSYSLOG
+ /** ensure fields are properly initialized to empty strings: **/
+
+ syslog_from [0] = '\0';
+ syslog_to [0] = '\0';
+ syslog_msgid[0] = '\0';
+ syslog_qid [0] = '\0';
+
+
+ /** ...except server and port, which can take their real values: **/
+
+ (void)strncpy(syslog_server, server, SYSLOG_FIELD_SIZE);
+ syslog_server[SYSLOG_FIELD_LAST] = '\0';
+
+ (void)strncpy(syslog_port, port, SYSLOG_FIELD_SIZE);
+ syslog_port[SYSLOG_FIELD_LAST] = '\0';
+#endif
+
if (sm_mts == MTS_SMTP)
return smtp_init (client, server, port, watch, verbose,
debug, sasl, saslmech, user, oauth_svc, tls);
@@ -454,6 +475,13 @@
}
}
+#ifndef NOSYSLOG
+ /** record from field for syslog: **/
+
+ (void)strncpy(syslog_from, from, SYSLOG_FIELD_SIZE);
+ syslog_from[SYSLOG_FIELD_LAST] = '\0';
+#endif
+
switch (smtalk (SM_MAIL, "MAIL FROM:<%s>%s", from, mail_parameters)) {
case 250:
sm_addrs = 0;
@@ -473,6 +501,37 @@
int
sm_wadr (char *mbox, char *host, char *path)
{
+#ifndef NOSYSLOG
+ {
+ /** record recipient address for syslog: **/
+
+ char address[SYSLOG_FIELD_SIZE];
+ int length, used, remaining;
+
+ if (host && *host)
+ (void)snprintf(address, SYSLOG_FIELD_SIZE, "<%s%s@%s>",
+ FENDNULL(path), mbox, host);
+ else
+ (void)snprintf(address, SYSLOG_FIELD_SIZE, "<%s%s>",
+ FENDNULL(path), mbox);
+
+ length = strlen(address);
+ used = strlen(syslog_to);
+ remaining = (SYSLOG_FIELD_SIZE - used) - 1;
+
+ if ((used == 0) && (length < remaining))
+ {
+ (void)strcat(syslog_to, address);
+ }
+ else if ((length + 1) < remaining)
+ {
+ (void)strcat(syslog_to, " ");
+ (void)strcat(syslog_to, address);
+ }
+
+ syslog_to[SYSLOG_FIELD_LAST] = '\0';
+ }
+#endif
switch (smtalk (SM_RCPT, host && *host ? "RCPT TO:<%s%s@%s>"
: "RCPT TO:<%s%s>",
FENDNULL(path), mbox, host)) {
@@ -717,6 +776,19 @@
}
for (bp = buffer; bp && len > 0; bp++, len--) {
+#ifndef NOSYSLOG
+ if (strncmp(bp, "Message-ID: ", 12) == 0)
+ {
+ int i;
+
+ (void)strncpy(syslog_msgid, bp + 12, SYSLOG_FIELD_SIZE);
+ for (i=0; i<SYSLOG_FIELD_LAST; i++)
+ if (syslog_msgid[i] == '\012')
+ syslog_msgid[i] = '\0';
+
+ syslog_msgid[SYSLOG_FIELD_LAST] = '\0';
+ }
+#endif
switch (*bp) {
case '\n':
sm_nl = TRUE;
@@ -858,6 +930,15 @@
sm_reply.length = rp - sm_reply.text;
sm_reply.text[sm_reply.length] = 0;
+#ifndef NOSYSLOG
+ if (strncmp(sm_reply.text, "OK id=", 6) == 0)
+ {
+ (void)snprintf(syslog_qid, SYSLOG_FIELD_SIZE,
+ "Sent (%s Message accepted for delivery)",
+ sm_reply.text+6);
+ syslog_qid[SYSLOG_FIELD_LAST] = '\0';
+ }
+#endif
return sm_reply.code;
}
--- uip/post.c.original 2018-03-06 14:05:56.000000000 -0500
+++ uip/post.c 2019-07-09 17:18:58.345425453 -0400
@@ -23,6 +23,10 @@
#endif
#include <time.h>
+#ifndef NOSYSLOG
+ #include <syslog.h>
+#endif
+
#include <mts/smtp/smtp.h>
#ifndef CYRUS_SASL
@@ -1760,6 +1764,15 @@
}
fflush (stdout);
+
+#ifndef NOSYSLOG
+ openlog("nmh_smtp", LOG_PID, LOG_MAIL);
+ syslog(LOG_NOTICE,
+ "from=%s, to=%s, msgid=%s, relay=%s, port=%s, stat=%s",
+ syslog_from, syslog_to, syslog_msgid, syslog_server,
+ syslog_port, syslog_qid);
+ closelog();
+#endif
}
}
8<----------------------------- cut here ---------------------------->8
--
___________________________________________________________________________
Steven Winikoff |
Montreal, QC, Canada | "I'd love to go out with you, but I want
address@hidden | to spend more time with my blender."
http://smwonline.ca |
| - fortune(6)
- [nmh-workers] Multiple identities and envelope-from, Conrad Hughes, 2019/07/06
- Re: [nmh-workers] Multiple identities and envelope-from, Conrad Hughes, 2019/07/06
- Re: [nmh-workers] Multiple identities and envelope-from, Ken Hornstein, 2019/07/06
- Re: [nmh-workers] Multiple identities and envelope-from, Ken Hornstein, 2019/07/06
- [nmh-workers] logging outgoing messages,
Steven Winikoff <=
- Re: [nmh-workers] logging outgoing messages, Ken Hornstein, 2019/07/09
- Re: [nmh-workers] logging outgoing messages, Michael Richardson, 2019/07/09
- Re: [nmh-workers] logging outgoing messages, Ken Hornstein, 2019/07/09
- Re: [nmh-workers] logging outgoing messages, Ronald F. Guilmette, 2019/07/09
- Re: [nmh-workers] logging outgoing messages, Michael Richardson, 2019/07/09
- Re: [nmh-workers] logging outgoing messages, Bakul Shah, 2019/07/09
- Re: [nmh-workers] logging outgoing messages, Ken Hornstein, 2019/07/10
- Re: [nmh-workers] logging outgoing messages, Ralph Corderoy, 2019/07/10
- Re: [nmh-workers] logging outgoing messages, Bakul Shah, 2019/07/10
- Re: [nmh-workers] logging outgoing messages, Ken Hornstein, 2019/07/10