#!/usr/local/bin/python ""#########################################################################pymail simple console email interface client in pythonuses python poplib module to view pop email messagessmtplib to send new mailsand the email package to extract mail headers and payload and compose mails#########################################################################""import poplibsmtplibemail utilsmailconfig from email parser import parser from email message import message fetchencoding mailconfig fetchencoding def decodetounicode(messagebytesfetchencoding=fetchencoding)"" epy decode fetched bytes to str unicode string for display or parsinguse global setting (or by platform defaulthdrs inspectionintelligent guess)in python this step may not be requiredif soreturn message intact""return [line decode(fetchencodingfor line in messagebytesdef splitaddrs(field)"" esplit address list on commasallowing for commas in name parts ""pairs email utils getaddresses([field][(name,addr)return [email utils formataddr(pairfor pair in pairs[name def inputmessage()import sys from input('from'strip(to input('to'strip(datetime hdr may be set auto to splitaddrs(topossible manynameokay subj input('subj'strip(don' split blindly on ',or ';print('type message textend with line="'text 'while trueline sys stdin readline(if line =\ 'break text +line return fromtosubjtext def sendmessage()fromtosubjtext inputmessage(msg message(msg['from'from msg['to''join(tomsg['subject'subj msg['date'email utils formatdate(msg set_payload(textserver smtplib smtp(mailconfig smtpservernametryfailed server sendmail(fromtostr(msg) client-side scripting join for hdrnot send curr datetimerfc may also raise exc