]> Pileus Git - ~andy/fetchmail/blobdiff - imap.c
Deal with Post Office/NT.
[~andy/fetchmail] / imap.c
diff --git a/imap.c b/imap.c
index 3b25c6ec82a2fe6e9b0ec2db118c8849c14fe7d9..ef4df99cfc016556fc9e6ddbca018b958268e111 100644 (file)
--- a/imap.c
+++ b/imap.c
@@ -35,7 +35,7 @@ extern char *strstr();        /* needed on sysV68 R3V7.1. */
 
 static int count, seen, recent, unseen, deletecount, imap_version;
 
-int imap_ok (int sock,  char *argbuf)
+int imap_ok(int sock, char *argbuf)
 /* parse command response */
 {
     char buf [POPBUFSIZE+1];
@@ -63,10 +63,8 @@ int imap_ok (int sock,  char *argbuf)
             */
            unseen = 0;
            for (cp = buf; *cp && !isdigit(*cp); cp++)
-           {
-               unseen = atoi(cp);
-               break;
-           }
+               continue;
+           unseen = atoi(cp);
        }
        if (strstr(buf, "FLAGS"))
            seen = (strstr(buf, "Seen") != (char *)NULL);
@@ -75,7 +73,8 @@ int imap_ok (int sock,  char *argbuf)
 
     if (tag[0] == '\0')
     {
-       strcpy(argbuf, buf);
+       if (argbuf)
+           strcpy(argbuf, buf);
        return(PS_SUCCESS); 
     }
     else
@@ -90,7 +89,8 @@ int imap_ok (int sock,  char *argbuf)
 
        if (strncmp(cp, "OK", 2) == 0)
        {
-           strcpy(argbuf, cp);
+           if (argbuf)
+               strcpy(argbuf, cp);
            return(PS_SUCCESS);
        }
        else if (strncmp(cp, "BAD", 2) == 0)
@@ -367,7 +367,10 @@ int imap_getauth(int sock, struct query *ctl, char *buf)
             error(0, 0, "Protocol identified as IMAP4 rev 0");
      }
 
-     peek_capable = (imap_version >= IMAP4);
+     /* eat the tail of the CAPABILITY response (if any) */
+     if ((peek_capable = (imap_version >= IMAP4)))
+        if ((ok = imap_ok(sock, (char *)NULL)))
+            return(ok);
 
 #ifdef KERBEROS_V4
      if (strstr(rbuf, "AUTH=KERBEROS_V4"))
@@ -449,7 +452,7 @@ static int imap_getsizes(int sock, int count, int *sizes)
     char buf [POPBUFSIZE+1];
 
     gen_send(sock, "FETCH 1:%d RFC822.SIZE", count);
-    while (SockRead(sock, buf, sizeof(buf)))
+    for (;;)
     {
        int num, size, ok;
 
@@ -625,36 +628,21 @@ static int imap_delete(int sock, struct query *ctl, int number)
     return(PS_SUCCESS);
 }
 
-static flag imap_retain_check(int num, char *buf)
-/* is this a special message that should be retained? */
-{
-    /*
-     * The University of Washington IMAP server (the reference
-     * implementation of IMAP4 written by Mark Crispin) relies
-     * on being able to keep base-UID information in a special
-     * message at the head of the mailbox.  This message should
-     * neither be deleted nor forwarded.
-     */
-    return (num == 1 && !strncasecmp(buf, "X-IMAP:", 7));
-}
-
 const static struct method imap =
 {
     "IMAP",            /* Internet Message Access Protocol */
     143,               /* standard IMAP2bis/IMAP4 port */
     TRUE,              /* this is a tagged protocol */
     FALSE,             /* no message delimiter */
-    FALSE,             /* fetch response size is reliable */ 
     imap_ok,           /* parse command response */
     imap_getauth,      /* get authorization */
     imap_getrange,     /* query range of messages */
-    imap_getsizes,     /* grab message sizes */
+    imap_getsizes,     /* get sizes of messages (used for --limit option */
     imap_is_old,       /* no UID check */
     imap_fetch_headers,        /* request given message headers */
     imap_fetch_body,   /* request given message body */
     imap_trail,                /* eat message trailer */
     imap_delete,       /* delete the message */
-    imap_retain_check, /* leave this message alone? */
     "LOGOUT",          /* the IMAP exit command */
 };