pop to fetch headers textuse if inbox can change due to deletes in other clientor automatic action by email serverraises except if out of synchor error while talking to serverfor speedonly checks last in lastthis catches inbox deletesbut assumes server won' insert before last (true for incoming mails)check inbox size firstsmaller if just deleteselse top will differ if deletes and newly arrived messages added at endresult valid only when runinbox may change after return""self trace('synch check'errormsg 'message index out of synch with mail server \nerrormsg +'mail client may require restart or reload server self connect(trylastmsgnum len(synchheaders (msgcountmsgbytesserver stat(inbox size if lastmsgnum msgcountfewer nowraise messagesyncherror(errormsgnone to cmp if self srvrhastopresphdrlinesrespsz server top(lastmsgnum hdrs only hdrlines self decodefulltext(hdrlineslastmsghdrs '\njoin(hdrlinesif not self headersmatch(lastmsghdrssynchheaders[- ])raise messagesyncherror(errormsgfinallyserver quit(def headersmatch(selfhdrtext hdrtext )"""may not be as simple as string comparesome servers add "status:header that changes over timeon one ispit begins as "statusu(unread)and changes to "statusro(readoldafter fetched once throws off synch tests if new when index fetchedbut have been fetched once before delete or last-message check"message-id:line is unique per message in theorybut optionaland can be anything if forgedmatch more commontry firstparsing costlytry last ""try match by simple string compare if hdrtext =hdrtext self trace('same headers text'return true try match without status lines split hdrtext splitlines( split('\ ')but no final 'split hdrtext splitlines(strip [line for line in split if not line startswith('status:')strip [line for line in split if not line startswith('status:')if strip =strip self trace('same without status'return true try mismatch by message-id headers if either has one client-side scripting