From: Ross B. <ro...@bi...> - 2012-01-31 00:37:30
|
I think that it is not possible to reconstruct exactly which messages were added and removed in some circumstances. Is my understanding correct? If this sequence came back from the server * 4 EXPUNGE * 5 EXISTS then the new message is sequence 5. If this sequence came back * 5 EXISTS * 4 EXPUNGE then the new message is sequence 4. Since imaplib2 only gives the relative time sequence within a single class of untagged response (i.e., EXPUNGE or EXISTS) there is no way to tell which of these scenarios happened assuming one recovers the 2 separate responses. For my purposes that level of detail is probably not necessary; I can just err on the side of caution. Perhaps imaplib2 should have a callback that would enable tracking the exact sequence of messages. Context: iterating slowly through the messages in a large folder, so that messages might appear or vanish during the iteration. It looks to me as if doing this by message sequence number rather than UID is most natural.(*) The commands are like SEARCH 1:50 <some additional filters> it would be natural to do SEARCH 51:100 <some additional filters> for the next round, but this could miss messages if some were deleted in the interim. Hmm, there is still a problem with a race even if I check the message sequences immediately before the SEARCH, since a message could be deleted in between checking the status and issuing the SEARCH anyway..... (*) Most natural because EXISTS and EXPUNGE use sequence numbers, and because UIDs may in principle have large gaps. The latter implies there could be many searches by UID range that get nothing. Perhaps a more robust approach would be to collect the UIDs of messages at sequence 1, 50, 100, 150, .... at the start, and then fetch by the implied UID range. Ross Boylan |