From bcd160efb2b279e21d0e1046c380e49a9b4cd677 Mon Sep 17 00:00:00 2001 From: Michael Elkins Date: Thu, 21 Dec 2000 19:11:02 +0000 Subject: [PATCH] can't assume flag order when fetching a message. just search for the first `{' to find the message size. --- imap.c | 17 ++++++++++------- sync.c | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/imap.c b/imap.c index 18ee0c6..79e21ae 100644 --- a/imap.c +++ b/imap.c @@ -575,7 +575,7 @@ imap_fetch_message (imap_t * imap, unsigned int uid, int fd) size_t n; char buf[1024]; - send_server (imap->sock, "UID FETCH %d RFC822.PEEK", uid); + send_server (imap->sock, "UID FETCH %d (RFC822.PEEK)", uid); for (;;) { @@ -594,9 +594,10 @@ imap_fetch_message (imap_t * imap, unsigned int uid, int fd) next_arg (&cmd); /* * */ next_arg (&cmd); /* */ next_arg (&cmd); /* FETCH */ - next_arg (&cmd); /* (RFC822 */ - arg = next_arg (&cmd); - if (*arg != '{') + + while ((arg = next_arg (&cmd)) && *arg != '{') + ; + if (!arg) { puts ("parse error getting size"); return -1; @@ -662,11 +663,13 @@ imap_fetch_message (imap_t * imap, unsigned int uid, int fd) puts ("wrong tag"); return -1; } - break; + arg = next_arg (&cmd); + if (!strcmp ("OK", arg)) + return 0; + return -1; } } - - return 0; + /* not reached */ } /* add flags to existing flags */ diff --git a/sync.c b/sync.c index 4eae1ed..1166460 100644 --- a/sync.c +++ b/sync.c @@ -150,9 +150,9 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags) ret = imap_fetch_message (imap, cur->uid, fd); - close (fd); - - if (!ret) + if (close (fd)) + perror ("close"); + else if (!ret) { p = strrchr (path, '/');