print('error send failed'elseif failedprint('failed:'faileddef connect(servernameuserpasswd)print('connecting 'server poplib pop (servernameserver user(userserver pass_(passwdprint(server getwelcome()return server connectlog in to mail server pass is reserved word print returned greeting message def loadmessages(servernameuserpasswdloadfrom= )server connect(servernameuserpasswdtryprint(server list()(msgcountmsgbytesserver stat(print('there are'msgcount'mail messages in'msgbytes'bytes'print('retrieving 'msglist [fetch mail now for in range(loadfrommsgcount+ )empty if low >high (hdrmessageoctetsserver retr(isave text on list message decodetounicode(message epy bytes to str msglist append('\njoin(message)leave mail on server finallyserver quit(unlock the mail box assert len(msglist=(msgcount loadfrom msg nums start at return msglist def deletemessages(servernameuserpasswdtodeleteverify=true)print('to be deleted:'todeleteif verify and input('delete?')[: not in [' '' ']print('delete cancelled 'elseserver connect(servernameuserpasswdtryprint('deleting messages from server 'for msgnum in todeletereconnect to delete mail server dele(msgnummbox locked until quit(finallyserver quit(def showindex(msglist)count show some mail headers for msgtext in msglistmsghdrs parser(parsestr(msgtextheadersonly=trueexpects str in count + print('% :\ % bytes(countlen(msgtext))for hdr in ('from''to''date''subject')tryprint('\ %- =>% (hdrmsghdrs[hdr])except keyerrorprint('\ %- =>(unknown)hdrif count = console-based email client