text ['from(sender of unknown unicode format headers)'text +['''--sorrymailtools cannot decode this mail content!--'return text def downloadmessage(selfmsgnum)""load full raw text of one mail msggiven its pop relative msgnumcaller must parse content ""self trace('load str(msgnum)server self connect(tryrespmsglinesrespsz server retr(msgnumfinallyserver quit(msglines self decodefulltext(msglinesraw bytes to unicode str return '\njoin(msglinesconcat lines for parsing def downloadallheaders(selfprogress=noneloadfrom= )""get sizesraw header text onlyfor all or new msgs begins loading headers from message number loadfrom use loadfrom to load newly arrived mails only use downloadmessage to get full msg text later progress is function called with (counttotal)returns[headers text][mail sizes]loadedfull eadd mailconfig fetchlimit to support large email inboxesif not noneonly fetches that many headersand returns others as dummy/empty mailelse inboxes like one of mine ( emailsare not practical to use epass loadfrom along to downloadallmsgs ( buglet)""if not self srvrhastopnot all servers support top naively load full msg text return self downloadallmsgs(progressloadfromelseself trace('loading headers'fetchlimit mailconfig fetchlimit server self connect(mbox now locked until quit tryrespmsginfosrespsz server list('num sizelines list msgcount len(msginfosalt to srvr stat[ msginfos msginfos[loadfrom- :drop already loadeds allsizes [int( split()[ ]for in msginfosallhdrs [for msgnum in range(loadfrommsgcount+ )poss empty if progressprogress(msgnummsgcountrun callback if fetchlimit and (msgnum <msgcount fetchlimit)skipadd dummy hdrs hdrtext 'subject--mail skipped--\ \nallhdrs append(hdrtextelsefetchretr hdrs only the mailtools utility package