fetchmail-friends
[Top] [All Lists]

[fetchmail] unreadable mail in maildir

2002-07-08 06:00:47
If a mail in a maildir folder is not readable, fetchmail parses the
responses slightly incorrectly.

Here is a sample transaction:

=====================================================================
2 messages for shetye at server.bombay.retortsoft.com.
fetchmail: IMAP> A0005 FETCH 1:2 RFC822.SIZE
fetchmail: IMAP< * NO Cannot open message 1
fetchmail: IMAP> A0006 FETCH 1 RFC822.HEADER

[here, fetchmail sends A0006 even though the response to A0005 is not
complete]

fetchmail: IMAP< * 2 FETCH (RFC822.SIZE 2157)

[this size is not read by fetchmail]

fetchmail: IMAP< A0005 OK FETCH completed.
fetchmail: IMAP< * NO Cannot open message 1
couldn't fetch headers, message 
shetye(_at_)server(_dot_)bombay(_dot_)retortsoft(_dot_)com:1 (1076017536 octets)

[note the size!]

fetchmail: IMAP> A0007 FETCH 2 RFC822.HEADER

[here, fetchmail sends A0007 even though the response to A0006 is not
complete]

fetchmail: IMAP< A0006 OK FETCH completed.
fetchmail: IMAP< * 2 FETCH (RFC822.HEADER {551}
reading message shetye(_at_)server(_dot_)bombay(_dot_)retortsoft(_dot_)com:2 of 
2 (551 header octets)
fetchmail: SMTP< 220 client.bombay.retortsoft.com ESMTP
fetchmail: SMTP> EHLO localhost
fetchmail: SMTP< 250-client.bombay.retortsoft.com
fetchmail: SMTP< 250-PIPELINING
fetchmail: SMTP< 250 8BITMIME
fetchmail: SMTP> MAIL FROM:<shetye(_at_)bombay(_dot_)retortsoft(_dot_)com>

[here, fetchmail uses an incorrect size if size is supported. There is
a possibility that a mail can be rejected because of that size.]

fetchmail: SMTP< 250 ok
fetchmail: SMTP> RCPT 
TO:<shetye(_at_)client(_dot_)bombay(_dot_)retortsoft(_dot_)com>
fetchmail: SMTP< 250 ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 go ahead
#
fetchmail: IMAP< )
fetchmail: IMAP< A0007 OK FETCH completed.
fetchmail: IMAP> A0008 FETCH 2 BODY.PEEK[TEXT]
fetchmail: IMAP< * 2 FETCH (BODY[TEXT] {1606}
 (1606 body octets) ***************************.************
fetchmail: IMAP< )
fetchmail: IMAP< A0008 OK FETCH completed.
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 ok 1026130343 qp 23292
 flushed
fetchmail: IMAP> A0009 STORE 2 +FLAGS (\Seen \Deleted)
fetchmail: IMAP< * 2 FETCH (FLAGS (\Seen \Deleted \Recent))
fetchmail: IMAP< A0009 OK STORE completed.
fetchmail: IMAP> A0010 EXPUNGE
fetchmail: IMAP< * 2 EXPUNGE
fetchmail: IMAP< * 1 EXISTS
fetchmail: IMAP< * 0 RECENT
fetchmail: IMAP< A0010 OK EXPUNGE completed
fetchmail: SMTP> QUIT
fetchmail: SMTP< 221 client.bombay.retortsoft.com
=====================================================================

Here is a patch which fixes all these:

=====================================================================
diff -Naur fetchmail-5.9.13.orig/driver.c fetchmail-5.9.13/driver.c
--- fetchmail-5.9.13.orig/driver.c      Sat Jul  6 13:12:37 2002
+++ fetchmail-5.9.13/driver.c   Mon Jul  8 17:21:25 2002
@@ -442,9 +442,7 @@
                    report_build(stdout, GT_(" (length -1)"));
                    break;
                case MSGLEN_TOOLARGE:
-                   report_build(stdout, 
-                                GT_(" (oversized, %d octets)"),
-                                msgsizes[num-1]);
+                   report_build(stdout, GT_(" (oversized)"));
                    break;
                }
            }
@@ -457,8 +455,8 @@
            err = 
(ctl->server.base_protocol->fetch_headers)(mailserver_socket,ctl,num, &len);
            if (err == PS_TRANSIENT)    /* server is probably Exchange */
            {
-               report_build(stdout,
-                            GT_("couldn't fetch headers, message %s(_at_)%s:%d 
(%d octets)"),
+               report(stdout,
+                            GT_("couldn't fetch headers, message %s(_at_)%s:%d 
(%d octets)\n"),
                             ctl->remotename, ctl->server.truename, num,
                             msgsizes[num-1]);
                continue;
@@ -1344,8 +1342,10 @@
                    /* OK, we're going to gather size info next */
                    xalloca(msgsizes, int *, sizeof(int) * count);
                    xalloca(msgcodes, int *, sizeof(int) * count);
-                   for (i = 0; i < count; i++)
+                   for (i = 0; i < count; i++) {
+                       msgsizes[i] = 0;
                        msgcodes[i] = MSGLEN_UNKNOWN;
+                   }
 
                    /* 
                     * We need the size of each message before it's
diff -Naur fetchmail-5.9.13.orig/imap.c fetchmail-5.9.13/imap.c
--- fetchmail-5.9.13.orig/imap.c        Tue Jun  4 19:25:05 2002
+++ fetchmail-5.9.13/imap.c     Mon Jul  8 17:27:08 2002
@@ -691,6 +691,9 @@
 
        if ((ok = gen_recv(sock, buf, sizeof(buf))))
            return(ok);
+       /* an untagged NO means that a message was not readable */
+       else if (strstr(buf, "* NO"))
+           ;
        else if (strstr(buf, "OK") || strstr(buf, "NO"))
            break;
        else if (sscanf(buf, "* %u FETCH (RFC822.SIZE %u)", &num, &size) == 2) {
@@ -763,9 +766,19 @@
            break;
        /* try to recover from chronically fucked-up M$ Exchange servers */
        else if (!strncmp(ptr, "NO", 2))
+       {
+           /* wait for a tagged response */
+           if (strstr (buf, "* NO"))
+               imap_ok (sock, 0);
            return(PS_TRANSIENT);
+       }
        else if (!strncmp(ptr, "BAD", 3))
+       {
+           /* wait for a tagged response */
+           if (strstr (buf, "* BAD"))
+               imap_ok (sock, 0);
            return(PS_TRANSIENT);
+       }
     }
 
     if (num != number)
=====================================================================

Sunil Shetye.

<Prev in Thread] Current Thread [Next in Thread>