This patch logs raw socket data, to assist debugging when discriminating
between server and fetchmail bugs.
-Apply it to fetchmail 6.3.20 and set the environment variable
-FETCHMAIL_RAW_LOGFILE to a log file writable by fetchmail. If it's not
-there, it gets created with mode 0600 (which requires directory write
-permission).
+Apply it to socket.c (works as of 6.3.20) and set the environment
+variable FETCHMAIL_RAW_LOGFILE to a log file writable by fetchmail. If
+it's not there, it gets created with mode 0600 (which requires directory
+write permission).
The file gets appended to, so you can log into named pipes, character
(stream) devices and to the console if you're so inclined.
Note 1: any logging failures cause fetchmail to abort() forcefully.
-Note 2: non-printable characters are hex-escaped, so it is safe to use
-FETCHMAIL_RAW_LOGFILE=/dev/stderr or similar.
+Note 2: raw control characters persist in the log and are not filtered
+out. In doubt use a pager that filters control characters, or use tools
+such as a binary-capable text edtior, vim's xxd, or hexdump, or od, to
+view the raw log message.
--- Matthias Andree, August 2011
+-- Matthias Andree, June 2011
-diff --git a/sink.c b/sink.c
-index 5d92556..ff6208d 100644
---- a/sink.c
-+++ b/sink.c
-@@ -649,6 +649,10 @@ int stuffline(struct query *ctl, char *buf)
- while ((last += strlen(last)) && (last[-1] != '\n'))
- last++;
-
-+ if (outlevel >= O_DEBUG && (size_t)(last - buf) != strlen(buf))
-+ report(stdout, GT_("DEBUG: stuffline shipping line with NULs, length=%lu, strlen=%lu\n"), last - buf, strlen(buf));
-+
-+
- /* fix message lines that have only \n termination (for qmail) */
- if (ctl->forcecr)
- {
diff --git a/socket.c b/socket.c
-index e338207..dcaf19d 100644
+index daa291d..dab91ba 100644
--- a/socket.c
+++ b/socket.c
-@@ -381,6 +381,49 @@ static SSL *_ssl_context[FD_SETSIZE];
+@@ -333,6 +333,49 @@ static SSL *_ssl_context[FD_SETSIZE];
static SSL *SSLGetContext( int );
#endif /* SSL_ENABLE */
int SockWrite(int sock, const char *buf, int len)
{
int n, wrlen = 0;
-@@ -388,6 +431,12 @@ int SockWrite(int sock, const char *buf, int len)
+@@ -340,6 +383,8 @@ int SockWrite(int sock, const char *buf, int len)
SSL *ssl;
#endif
-+ if (SockLog()) {
-+ char *tmps = sdump(buf, len);
-+ LogPrintf("[>%d-%s count=%04d] %s\n", sock, SSLGetContext(sock) ? "crypt" : "plain", len, tmps);
-+ free(tmps);
-+ }
++ LogPrintf("[>%d-%s count=%04d] %.*s%s", sock, SSLGetContext(sock) ? "crypt" : "plain", len, len, buf, (len < 1 || buf[len - 1] != '\n') ? "\n" : "");
+
while (len)
{
#ifdef SSL_ENABLE
-@@ -504,6 +553,13 @@ int SockRead(int sock, char *buf, int len)
+@@ -442,6 +487,8 @@ int SockRead(int sock, char *buf, int len)
(!newline && len);
*bp = '\0';
-+ if (SockLog())
-+ {
-+ char *tmps = sdump(buf, bp - buf);
-+ LogPrintf("[<%d-%s count=%04d] %s\n", sock, SSLGetContext(sock) ? "crypt" : "plain", bp - buf, tmps);
-+ free(tmps);
-+ }
++ LogPrintf("[<%d-%s count=%04d] %.*s%s", sock, SSLGetContext(sock) ? "crypt" : "plain", bp - buf, bp - buf, buf, newline ? "" : "\n");
+
return bp - buf;
}