[PATCH] wmbiff: EXAMINE before STATUS

Doug Torrance <[email protected]>
Newsgroups gmane.compw.window-managers.windowmaker.devel
Message-ID <[email protected]>
Patch by Nye Liu <[email protected]> to fix Debian bug #830889 [1].

Dear Maintainer,

Outlook Office365 IMAP servers now expect a client to issue at least one
EXAMINE before STATUS, or UNSEEN is always zero:

"unsub" folder has two messages, one unseen.

Broken:

56:04.84 > CJFK1 LOGIN "nyet@xxx" "xxx"
56:21.99 < CJFK1 OK LOGIN completed.
56:21.99 > CJFK2 STATUS unsub (MESSAGES UNSEEN)
56:22.20 < * STATUS unsub (MESSAGES 2 UNSEEN 0)
56:22.20 < CJFK2 OK STATUS completed.

Works:

56:46.04 > BPEB1 LOGIN "nyet@xxx" "xxx"
56:51.43 < BPEB1 OK LOGIN completed.
56:51.43 > BPEB2 EXAMINE unsub
56:51.67 < * 2 EXISTS
56:51.67 < * 0 RECENT
56:51.67 < * FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
56:51.67 < * OK [PERMANENTFLAGS ()] Permanent flags
56:51.67 < * OK [UNSEEN 2] Is the first unseen message
56:51.67 < * OK [UIDVALIDITY 164] UIDVALIDITY value
56:51.67 < * OK [UIDNEXT 16] The next unique identifier value
56:51.67 < BPEB2 OK [READ-ONLY] EXAMINE completed.
56:51.67 > BPEB3 STATUS unsub (MESSAGES UNSEEN)
56:51.89 < * STATUS unsub (MESSAGES 2 UNSEEN 1)
56:51.89 < BPEB3 OK STATUS completed.

Attached is a patch to always issue EXAMINE before a STATUS.

It doesn't seem like it has to be done before every STATUS, just at least once.
Is only a proof of concept. I don't presume to know the best way to handle
optimizing it.

[1] https://bugs.debian.org/830889
---
 wmbiff/wmbiff/Imap4Client.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/wmbiff/wmbiff/Imap4Client.c b/wmbiff/wmbiff/Imap4Client.c
index 8599f5a..882446d 100644
--- a/wmbiff/wmbiff/Imap4Client.c
+++ b/wmbiff/wmbiff/Imap4Client.c
@@ -294,6 +294,7 @@ int imap_checkmail( /*@notnull@ */ Pop3 pc)
 	/* recover connection state from the cache */
 	struct connection_state *scs = state_for_pcu(pc);
 	char buf[BUF_SIZE];
+	char examine_expect[BUF_SIZE];
 	static int command_id;
 
 	/* if it's not in the cache, try to open */
@@ -312,6 +313,14 @@ int imap_checkmail( /*@notnull@ */ Pop3 pc)
 		return -1;
 	}
 
+	command_id++;
+	tlscomm_printf(scs, "a%03d EXAMINE %s\r\n", command_id, pc->path);
+	snprintf(examine_expect, BUF_SIZE, "a%03d OK", command_id);
+	if (tlscomm_expect(scs, examine_expect, buf, 127) == 0) {
+		tlscomm_close(unbind(scs));
+		return -1;
+	}
+
 	/* if we've got it by now, try the status query */
 	command_id++;
 	tlscomm_printf(scs, "a%03d STATUS %s (MESSAGES UNSEEN)\r\n",
-- 
2.7.4


-- 
To unsubscribe, send mail to [email protected].
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.