self trace('connecting 'self getpassword(server poplib pop (self popserverserver user(self popuserserver pass_(self poppasswordself trace(server getwelcome()return server fileguior console connect,login pop server pass is reserved word print returned greeting use setting in client' mailconfig on import search pathto tailorthis can be changed in class or per instancefetchencoding mailconfig fetchencoding def decodefulltext(selfmessagebytes)"" epy decode full fetched mail text bytes to str unicode stringdone at fetchfor later display or parsing (full mail text is always unicode thereafter)decode with per-class or per-instance settingor common typescould also try headers inspectionor intelligent guess from structurein python this step may not be requiredif sochange to return message line list intactfor more details see an -bit encoding such as latin- will likely suffice for most emailsas ascii is the original standardthis method applies to entire/full message textwhich is really just one part of the email encoding storymessage payloads and message headers may also be encoded per emailmimeand unicode standardssee and mailparser and mailsender for more""text none kinds [self fetchencodingtry user setting first kinds +['ascii''latin ''utf 'then try common types kinds +[sys getdefaultencoding()and platform dflt (may differfor kind in kindsmay cause mail saves to fail trytext [line decode(kindfor line in messagebytesbreak except (unicodeerrorlookuperror)lookuperrorbad name pass if text =nonetry returning headers error msgelse except may kill clientstill try to decode headers per asciiotherplatform defaultblankline messagebytes index( ''hdrsonly messagebytes[:blanklinecommons ['ascii''latin ''utf 'for common in commonstrytext [line decode(commonfor line in hdrsonlybreak except unicodeerrorpass elsenone worked trytext [line decode(for line in hdrsonlyplatform dflt client-side scripting