diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index c90d0e5..8e15470 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -87,7 +87,9 @@ class IMAPFolder(BaseFolder):
             try:
                 # Some mail servers do not return an EXISTS response if
                 # the folder is empty.
-                maxmsgid = long(imapobj.untagged_responses['EXISTS'][0])
+                maxmsgid = 0
+                for msgid in imapobj.untagged_responses['EXISTS']:
+                    maxmsgid = max(long(msgid), maxmsgid)
             except KeyError:
                 return True
 
@@ -169,8 +171,9 @@ class IMAPFolder(BaseFolder):
                 try:
                     # Some mail servers do not return an EXISTS response if
                     # the folder is empty.
-
-                    maxmsgid = long(imapobj.untagged_responses['EXISTS'][0])
+                    maxmsgid = 0
+                    for msgid in imapobj.untagged_responses['EXISTS']:
+                        maxmsgid = max(long(msgid), maxmsgid)
                     messagesToFetch = '1:%d' % maxmsgid;
                 except KeyError:
                     return
