<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div id="yiv1908986009"><div style="color:#000;background-color:#fff;font-family:times new roman, new york, times, serif;font-size:12pt;"><div id="yiv1908986009"><div id="yiv1908986009yui_3_2_0_6_130937867230255" class="yiv1908986009yui_3_2_0_6_130937867230248" style="color:#000;background-color:#fff;font-family:times new roman, new york, times, serif;font-size:12pt;"><div id="yiv1908986009yui_3_2_0_2_130932905173548"><span id="yiv1908986009yui_3_2_0_2_130932905173577"><br></span><span></span><span></span></div><br><div class="yiv1908986009yui_3_2_0_2_130932905173552 yiv1908986009yui_3_2_0_6_130937867230250" id="yiv1908986009yui_3_2_0_2_130932905173554" style="font-family:times new roman, new york, times, serif;font-size:12pt;"><div id="yiv1908986009yui_3_2_0_2_130932905173584" class="yiv1908986009yui_3_2_0_2_130932905173557
yiv1908986009yui_3_2_0_6_130937867230252" style="font-family:times new roman, new york, times, serif;font-size:12pt;">>On Tue, Jun 28, 2011 at 1:20 AM, Sebastian Spaeth wrote:<br>>> On Mon, 27 Jun
2011 20:05:54 -0700 (PDT), chris coleman wrote:<br>>>> @Sebastian : Wouldn't a better way to solve this bug (caused by failing to process legitimate, untagged messages from the IMAP server), and solve it (any any other unforeseen bugs) for any future scenario: for offlineimap to delay querying imaplib2 for UIDPLUS capability until
JUST BEFORE the various places in the offlineimap code where a UID might be received as part of a response. Then, depending on the response, the code would branch between different code paths: the UID case and the no-UID case.<br>>>><br>>><br>>>> It sounds like this solution is possible without any upgrade to<br>>>> imaplib2, which updates its cached CAPABILITIES array every time it<br>>>> receives new capabilities from the imap server, from what you've said.<br>>><br>>> Nah, it isn't possible, and it doesn't cache updated CAPABILITIES every<br>>> time it receveives them (well, it stores it just as it stores any<br>>> untagged response, so we could query for that response after each<br>>> operation, to be precise). It currently excplicitly asks once right<br>>> after connecting. We need to explicitly query capabilities every time we<br>>> want to get
them.<br>>><br>>>> The bigger point is: it seems this bug was caused by offlineimap not fully complying to the IMAP4 client spec according to the requirement to accept and process any response from the server at any time.<br>>><br>>> AFAIK, we need to be prepared to receive a server response at every<br>>> point in time. I am not sure we need to be prepared to dynamically adapt<br>>> to changing CAPABILITIES over time. What if the server says it accepts<br>>> UTF8 and then claims to not support it anymore while we are in a data<br>>> transmission? IMAP is ripe with enough edge cases already. I think it<br>>> makes sense to accept a different CAPABILITY set post-login so that it<br>>> can be per-user. But parsing every server response to see if it might<br>>> contain a CAPABILITY string sounds like it could kill off performance<br>>> quite severely.<br>><br>>I wouldn't think
it would be that bad, but its probably a different<br>>model than either imaplib or imaplib2 implement. You'd want to<br>>implement a callback based model where every untagged response would<br>>be looked up in a table and the callback invoked if one is present, or<br>>something like that.<br>><br>>For instance, are you watching for EXISTS & EXPUNGE responses on any<br>>command? You could probably ignore them and just wait for the next<br>>cycle to handle any changes, probably easier that way.<br><br><br>Callback based model is one way to call it.<br><br>I was going to say, Event-driven model, or Message-loop. <br><br>From windows/mac desktop apps.<br><br>According to protocol, you've got to respond to IMAP server responses, more or less as they come in (sometimes defer, like when in the middle of a big message or whatever).<br><br>This is why the Gmail issue happened, with us missing the UIDPLUS
capabilities response completely - it actually violates the protocol to look ONLY at the responses that arrive when you assume that they should come in, and ignore the untagged responses.<br><br><br><br><br>>> Having to query the server capabilities 20k times (forcing a<br>>> server/response roundtrip), just because we want to synchronize 20k<br>>> emails doesn't sound very appealing to me (and we'd probably even find<br>>> ourselves locked out of eg Gmail quite quickly) in terms of<br>>> performance, when it is pretty reasonable to assume that
capabilities<br>>> won't change over the life-time of an IMAP session. Also again, do NOTE<br>>> that we correctly detect an APPENDUID server reply already now, even if<br>>> we are not aware of server capabilities, so we *are already dynamically*<br>>> taking advantage of the feature on the offlineimap side.<br>><br>>Yeah, that's definitely overkill.<br><br>Right, that would be ridiculous. <br><br>And I didn't' mean that either. <br><br>What I meant was, we (offlineimap and imaplib2) shouldn't be working off cached copies of these capabilities values - because IMAP protocol implies that they can and DO go stale. See example where we crashed on Gmail changed capabilities. <br><br>The worst part is, we don't even know how many other untagged responses are getting missed.<br><br>The offlineimap code should be working off the TRUE values, which are subject to change, and should be stored/cached ONLY in
imaplib2. <br><br>For example , we should get UIDPLUS via a GetUIDPLUS() getter method only, every time the offlineimap code logic needs to check it, and never cache that value in the offlineimap data space,
except maybe at a "current single message loop" level of granularity.<br><br><br><br>>> One reason is because the IMAP specs are ambiguous at best, so it is<br>>> hard to follow them precisely and often the best way to follow them is<br>>> to see how servers interpret/implement them. Second reason is that<br>>> various servers complying to the specs with varying success, so even if<br>>> we clung 100% correctly to the specs, things wouldn't work out<br>>> correctly.<br>>><br>>> The specs eg don't even specify the character encoding that one should<br>>> be using for folder names etc, they just
recommend a weird one (which<br>>> hopefully dies very soon, being replaced with UTF8).<br>><br>>Weird, I'd never noticed that it was specified as "by convention"<br>>instead of an actual requirement.<br><br><br>Character sets that causes crashes/lost data/logic failures... this has bitten us in the a** before, and will probably do it again many more times in the future, unless we get a firm grip on it once and for all...<br><br><br>>> Again, assume the CAPABILITIES suddenly start saying they don't support<br>>> STARTTLS when we logged in via STARTTLS. Should we immediately drop the<br>>> connection? (or more realistically, my UTF8 example from before) I don't<br>>> think this is something I want to get into :).<br>><br>>Actually, from the spec you're supposed to query for CAPABILITIES<br>>again after STARTTLS, and STARTTLS is supposed to go away because you<br>>shouldn't call it
again.<br>><br>>In general, though, yes, they shouldn't go away.<br>><br>>Brandon<br><br><br>Chris<br><br></div></div></div></div></div></div></div></body></html>