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: 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, June 2011
+
+diff --git a/socket.c b/socket.c
+index c8117a5..89847fe 100644
+--- a/socket.c
++++ b/socket.c
+@@ -362,6 +362,49 @@ static SSL *_ssl_context[FD_SETSIZE];
+=======
Note 2: non-printable characters are hex-escaped, so it is safe to use
FETCHMAIL_RAW_LOGFILE=/dev/stderr or similar.
--- a/socket.c
+++ b/socket.c
@@ -381,6 +381,49 @@ static SSL *_ssl_context[FD_SETSIZE];
+>>>>>>> legacy_63
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)
+@@ -369,6 +412,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)
+@@ -471,6 +516,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;
}