shithub: riscv

Download patch

ref: cd694c60169796b96f689546ca5a0e019cb7048b
parent: 20ba8815bc00bcf3548547e78d5d2a2e08de8cfd
author: cinap_lenrek <[email protected]>
date: Tue May 2 00:07:21 EDT 2017

upas/fs: handle partial fetches (imap server returning less messages than available)

--- a/sys/src/cmd/upas/fs/imap.c
+++ b/sys/src/cmd/upas/fs/imap.c
@@ -918,9 +918,6 @@
 	imap->nuid = 0;
 	imap->muid = imap->nmsg;
 	imap->f = erealloc(imap->f, imap->nmsg*sizeof imap->f[0]);
-	f = imap->f;
-	n = imap->nmsg;
-
 	if(imap->nmsg > 0){
 		imap4cmd(imap, "uid fetch 1:* (uid rfc822.size internaldate)");
 		if(!isokay(s = imap4resp(imap)))
@@ -927,6 +924,9 @@
 			return s;
 	}
 
+	f = imap->f;
+	n = imap->nuid;
+	if(n < imap->nmsg) idprint(imap, "partial sync %d < %d\n", n, imap->nmsg);
 	qsort(f, n, sizeof f[0], (int(*)(void*, void*))fetchicmp);
 	nnew = ndel = 0;
 	ll = &mb->root->part;
@@ -943,7 +943,7 @@
 		if(c < 0){
 			/* new message */
 			idprint(imap, "new: %U (%U)\n", f[i].uid, m? m->imapuid: 0);
-			if(f[i].sizes > Maxmsg){
+			if(f[i].sizes == 0 || f[i].sizes > Maxmsg){
 				idprint(imap, "skipping bad size: %lud\n", f[i].sizes);
 				i++;
 				continue;