Found the explanation for/solution to probably the nastiest Pocket Inbox bug!
By Werner Ruotsalainen, Submitted Sunday, January 15, 2006
Topics:
http://www.smartphonemag.com/forum/topic.asp?TOPIC_ID=20296
As I know quite a bit about TCP/IP protocols, including POP3 (I've, for example, (with some beans, "only" co-)authored several IBM AlphaWorks TCP/IP-related JavaBeans back in 2000-2001, including the POP3 bean), in my previous article on this problem (alternatives: iPAQ HQ, AximSite, PPCT, FirstLoox, BrightHand) and in other, related discussion threas (for example this one; I particularly recommend the Pocket PC Thoughts one), I've been promising to dive into probably the nastiest Pocket Inbox / Messaging bugs. Now that I had some free time to write a minimalistic POP3 server emulator to generate debugging-friendly mails for this purpose and could allocate some time for debugging, I'm proud to present the protocol-level description of and several solutions to the problem. What happens? What happens, in the first place? Pocket Inbox (a.k.a., starting with WM2003SE, Messaging; from now on, I only use the word "Messaging" to refer to it) is very dumb in that it assumes no messages have been deleted from the mail (the POP3) server when it auto-connects to auto-fetch a mail body when you choose Mark for Download for a given mail message. If there were messages deleted in the meantime, depending on whether the server-side serial number was higher or lower than that of the message-to-be-retrieved, Messaging may return the body of a completely unrelated mail. Note that I've emphasized the word 'auto'. It's only at during auto-fetching that Messaging is buggy. When you manually connect to fetch mail bodies, you won't run in any problems. But, then, you must guarantee no automatic connection can take place and/or no messages have been deleted from there since the last synchronization. What does exactly happen? (Please note that I'll also provide POP3-level debug scrutinization later. In here, I only give a less technical explanation of what is happening.) When you choose to download the body of a mail by choosing Edit/Mark for Download while you read the body of a mail (or, you choose Mark for Download from the context menu from the mail header list), Messaging will auto-connect to the POP3 server to fetch the mail as soon as possible. This is certainly a very nice feature while you're reading a mail – after all, this way you get the mail body as soon as possible, without having to exit from the mail reader screen. During this auto-fetch, however, Messaging doesn't request the so-called UID list from the server again to recompute the then-current mail serial number (it's only by UID's that a mail message in a POP3 server can be safely identified; all on-server post numbers must be computed based on them). Instead, it just passes the old post number to the POP3 server, which may point to an entirely different mail because of the following: on the POP3 server, when you delete a mail, the serial number of all mails that have followed it will "shift down" by one. That is, if you delete mail number 9, then, the previous mail number 10 will be referred to by the serial number 9. This is what causes all these problems because Messaging doesn't take the possible serial numer shifting into account when it auto-fetches mail bodies. It just blindly assumes all server-side mail bodies have exactly the same serial number than the last time it saw them. Solutions The best solution to this problem is the following:- if you
- can afford it (because you aren't accessing your POP3 mailbox through time- or communication-wise expensive services) and
- don't want to access other POP3 mailboxes (you can only be connected to only one POP3 server at a time; that is, if you remain connected to a mailbox, you won't be able to fetch mail from the others. Then, the connection icons in other mailboxes will be rendered non-clickable, as in this screenshot)
- alternatively, if server-side mass-deletion of your mail is OK with you when you're absolutely sure you won't fetch any (more) mail bodies, make double sure you leave the "Empty deleted items" drop-down list at "Manually" in Accounts/Accounts.../Storage. Then, Messaging will only delete the mail when you go to the Deleted Items folder on your PDA and (mass-)delete the given message(s) from there: click for screenshot Please note that, in this case, when you delete something from the Inbox folder (by using, for example, the traditional message deletion icon or Delete from the context menu), these mails will never be deleted from the POP3 server unless you explicitly go to the Deleted items folder and manually initiate the deletion. Again: this means mail that you only delete from the Inbox folder will never be removed from the POP3 server. That will only happen when you set the "Empty deleted items" drop-down list to "Immediately" or "On connect/disconnect". click for screenshot
- if neither of the above solutions are OK with you because
- for some (pretty strange, I'd say; except for really-really strict security reasons) reason, you want to delete everything from the POP3 server as soon as possible without explicitly going to the Deleted Items folder (Manual deletion mode) or
- don't want to remain connected to the server because of, say, the high communication costs and want to choose the mail bodies to be downloaded while offline,
- If the state is connected (which is shown, as we've already seen, the network icon being highlighted), then, the current algorithm can be used.
- If the state isn't connected and a auto-reconnection must take place, however, the current algorithm must be abandoned and the 'manual' one should be used instead, which does download the UIDL and, based on the contents of UIDL, computes the parameter of the RETR command.
15/1/2006 15:42:13.218 - 00000032>+OK VPOP3 Server Ready <32.654.e676ff2> 15/1/2006 15:42:13.218 - 00000032<CAPA 15/1/2006 15:42:13.218 - 00000032>+OK Capability list follows TOP USER UIDL SASL CRAM-MD5 . 15/1/2006 15:42:13.234 - 00000032<AUTH 15/1/2006 15:42:13.234 - 00000032>-ERR Unrecognised AUTH typeIncidentally, here, as can be seen (and can also be read in the related RFC), this Messaging-issued AUTH command is faulty as AUTH must have the auth_type parameter. This bug doesn't result in any problem with a decent POP3 server, though.
15/1/2006 15:42:13.234 - 00000032<USER uus 15/1/2006 15:42:13.234 - 00000032>+OK User Accepted, PASSword required 15/1/2006 15:42:13.234 - 00000032<PASS uuspassu 15/1/2006 15:42:13.375 - 00000032>+OK uus has 10 message(s) (3110 octets) 15/1/2006 15:42:13.546 - 00000032<STAT 15/1/2006 15:42:14.046 - 00000032>+OK 10 3110 15/1/2006 15:42:14.062 - 00000032<UIDL 15/1/2006 15:42:14.062 - 00000032>+OK 15/1/2006 15:42:14.062 - 00000032>1 155 15/1/2006 15:42:14.062 - 00000032>2 157 15/1/2006 15:42:14.062 - 00000032>3 159 15/1/2006 15:42:14.062 - 00000032>4 161 15/1/2006 15:42:14.062 - 00000032>5 163 15/1/2006 15:42:14.062 - 00000032>6 165 15/1/2006 15:42:14.062 - 00000032>7 167 15/1/2006 15:42:14.062 - 00000032>8 169 15/1/2006 15:42:14.062 - 00000032>9 171 15/1/2006 15:42:14.062 - 00000032>10 173 15/1/2006 15:42:14.062 - 00000032>.Now, the following body will be repeated ten times, with the 9 in the subject/body (and 10 in the TOP 10 25 command) gradually decreasing to zero (and, with TOP, to one):
15/1/2006 15:42:14.109 - 00000032<TOP 10 25 15/1/2006 15:42:14.109 - 00000032>+OK 311 octets 15/1/2006 15:42:14.109 - 00000032>Received: from 127.0.0.1 (UIDL=0:93944148259805504) by winmobiletech.com (VPOP3) with POP3; Sun, 15 Jan 2006 15:28:31 +0100 15/1/2006 15:42:14.109 - 00000032>From: 9 15/1/2006 15:42:14.109 - 00000032>To: Menneisyys <a@b> 15/1/2006 15:42:14.109 - 00000032> Date: Fri, 13 Jan 2006 00:13:07 (GMT) 15/1/2006 15:42:14.109 - 00000032>X-VPOP3-Spam: 12.5 - SuspiciousHeader(12) 15/1/2006 15:42:14.109 - 00000032>X-VPOP3-Spam2: added bayes ham 15/1/2006 15:42:14.109 - 00000032>X-VPOP3-SpamBayes: 0 15/1/2006 15:42:14.109 - 00000032>Subject: 9 15/1/2006 15:42:14.109 - 00000032> 15/1/2006 15:42:14.109 - 00000032> 15/1/2006 15:42:14.109 - 00000032>9 15/1/2006 15:42:14.109 - 00000032>. 15/1/2006 15:42:16.421 - 00000032<QUIT 15/1/2006 15:42:16.421 - 00000032>+OK VPOP3 Server Closing Connection2. The user deletes three mails: as can clearly be seen (the UIDL is fetched by the client), there can be no problems in here because the deletion is UID-based, unlike auto-fetching:
15/1/2006 16:09:32.375 - 0000003b>+OK VPOP3 Server Ready <3b.1620.e8072e6> 15/1/2006 16:09:32.375 - 0000003b<CAPA 15/1/2006 16:09:32.375 - 0000003b>+OK Capability list follows TOP USER UIDL SASL CRAM-MD5 . 15/1/2006 16:09:32.390 - 0000003b<AUTH 15/1/2006 16:09:32.390 - 0000003b>-ERR Unrecognised AUTH type 15/1/2006 16:09:32.390 - 0000003b<USER uus 15/1/2006 16:09:32.390 - 0000003b>+OK User Accepted, PASSword required 15/1/2006 16:09:32.406 - 0000003b<PASS uuspassu 15/1/2006 16:09:32.406 - 0000003b>+OK uus has 10 message(s) (3100 octets) 15/1/2006 16:09:32.593 - 0000003b<STAT 15/1/2006 16:09:33.093 - 0000003b>+OK 10 3100 15/1/2006 16:09:33.203 - 0000003b<UIDL 15/1/2006 16:09:33.203 - 0000003b>+OK 15/1/2006 16:09:33.203 - 0000003b>1 175 15/1/2006 16:09:33.203 - 0000003b>2 177 15/1/2006 16:09:33.203 - 0000003b>3 179 15/1/2006 16:09:33.203 - 0000003b>4 181 15/1/2006 16:09:33.203 - 0000003b>5 183 15/1/2006 16:09:33.203 - 0000003b>6 185 15/1/2006 16:09:33.203 - 0000003b>7 187 15/1/2006 16:09:33.203 - 0000003b>8 189 15/1/2006 16:09:33.203 - 0000003b>9 191 15/1/2006 16:09:33.203 - 0000003b>10 193 15/1/2006 16:09:33.203 - 0000003b>. 15/1/2006 16:09:33.296 - 0000003b< DELE 8 15/1/2006 16:09:33.296 - 0000003b>+OK message 8 deleted 15/1/2006 16:09:33.312 - 0000003b< DELE 7 15/1/2006 16:09:33.312 - 0000003b>+OK message 7 deleted 15/1/2006 16:09:33.390 - 0000003b< DELE 4 15/1/2006 16:09:33.390 - 0000003b>+OK message 4 deleted 15/1/2006 16:09:59.109 - 0000003b<QUIT 15/1/2006 16:09:59.203 - 0000003b>+OK VPOP3 Server Closing Connection3. The user chooses to download the last mail (serial number 10, with 9 in the subject/body); the auto-connect communication is as follows:
15/1/2006 16:10:09.562 - 0000003c>+OK VPOP3 Server Ready <3c.1080.e81042a> 15/1/2006 16:10:09.562 - 0000003c<CAPA 15/1/2006 16:10:09.562 - 0000003c>+OK Capability list follows TOP USER UIDL SASL CRAM-MD5 . 15/1/2006 16:10:09.578 - 0000003c<AUTH 15/1/2006 16:10:09.578 - 0000003c>-ERR Unrecognised AUTH type 15/1/2006 16:10:09.578 - 0000003c<USER uus 15/1/2006 16:10:09.578 - 0000003c>+OK User Accepted, PASSword required 15/1/2006 16:10:09.578 - 0000003c<PASS uuspassu 15/1/2006 16:10:09.593 - 0000003c>+OK uus has 7 message(s) (2170 octets) 15/1/2006 16:10:09.640 - 0000003c<RETR 10 15/1/2006 16:10:09.640 - 0000003c>-ERR Invalid Message Number 15/1/2006 16:10:09.640 - 0000003c<QUIT 15/1/2006 16:10:09.656 - 0000003c>+OK VPOP3 Server Closing ConnectionInbox shows the error that has been encountered by still keeping the mail in 'to-be-downloaded' state. This mail will be later downloaded upon manual connection, when the new UIDL is read and its new position is, accordingly, recomputed by Messaging. 4. the user downloads the body of a mail that has already been "shifted" down but of which the original serial number is still valid. That is, as message 4, 7 and 8 have been deleted, we choose the fifth mail (the one with '4' in the subject) to be downloaded. This mail has shifted by one position downwards because of the mail that has been deleted under it and, therefore, the server will return the body for the mail that has '5' in it, instead of the requested mail with '4':
15/1/2006 16:18:29.406 - 0000003d>+OK VPOP3 Server Ready <3d.13d4.e88a4ae> 15/1/2006 16:18:29.437 - 0000003d<CAPA 15/1/2006 16:18:29.437 - 0000003d>+OK Capability list follows TOP USER UIDL SASL CRAM-MD5 . 15/1/2006 16:18:29.437 - 0000003d<AUTH 15/1/2006 16:18:29.437 - 0000003d>-ERR Unrecognised AUTH type 15/1/2006 16:18:29.437 - 0000003d<USER uus 15/1/2006 16:18:29.453 - 0000003d>+OK User Accepted, PASSword required 15/1/2006 16:18:29.453 - 0000003d<PASS uuspassu 15/1/2006 16:18:29.468 - 0000003d>+OK uus has 7 message(s) (2170 octets) 15/1/2006 16:18:29.500 - 0000003d<RETR 5As can be seen, the original serial number (the number originally used when the starting rows of the mail were first downloaded) was used to refer to the mail. This also means the server will return a mail that was later; in this case, the one that has '5' in the subject/body, instead of the one with '4':
15/1/2006 16:18:29.500 - 0000003d>+OK 310 octets 15/1/2006 16:18:29.500 - 0000003d>Received: from 127.0.0.1 (UIDL=0:1838254324449018) by winmobiletech.com (VPOP3) with POP3; Sun, 15 Jan 2006 16:07:44 +0100 15/1/2006 16:18:29.500 - 0000003d>From: 5 15/1/2006 16:18:29.500 - 0000003d>To: Menneisyys <a@b> 15/1/2006 16:18:29.500 - 0000003d> Date: Fri, 13 Jan 2006 00:13:07 (GMT) 15/1/2006 16:18:29.500 - 0000003d>X-VPOP3-Spam: 12.5 - SuspiciousHeader(12) 15/1/2006 16:18:29.500 - 0000003d>X-VPOP3-Spam2: added bayes ham 15/1/2006 16:18:29.500 - 0000003d>X-VPOP3-SpamBayes: 0 15/1/2006 16:18:29.500 - 0000003d>Subject: 5 15/1/2006 16:18:29.500 - 0000003d> 15/1/2006 16:18:29.500 - 0000003d> 15/1/2006 16:18:29.500 - 0000003d>5 15/1/2006 16:18:29.500 - 0000003d>. 15/1/2006 16:18:29.531 - 0000003d<QUIT 15/1/2006 16:18:29.546 - 0000003d>+OK VPOP3 Server Closing Connection
- Login or Register to post comments
Printer-friendly version




Are you accessing Gmail POP3 mail? This is a well-known problem with the flaky Gmail server-side implementation and can't be fighted other than switching to a mailer client that doesn't hide already-read Gmail messages; for example, FlexMail 2007 or Qmail. Please see the Maier Roundup here for more information.
Are the disappearing mails more than 3 days old? If not, are they deleted by, say, a desktop Outlook client in the meantime? That is, are you sure they are still there on the server?
If the answer to the two questions is a 'no', then, the POP3 mailbox must behave the same way as Gmail: it no longer lists already-read mails to POP3 clients as available mail. This is why Messaging doesn't list them any more. Qmail or FlexMail 2007 (both vastly superior mailer clients for the PPC) would - give them a try. (Do a generic blog search for them for more info; I've published several articles on both.)