input('[Press Enter key]') # pause after each 5
def showmessage(i, msgList):
if 1 <= i <= len(msgList):
#print(msgList[i-1]) # old: prints entire mail--hdrs+text
print('-' 79)
msg = Parser().parsestr(msgList[i-1]) # expects str in 3.1
content = msg.get_payload() # prints payload: string, or [Messages]
if isinstance(content, str): # keep just one end-line at end
content = content.rstrip() + '\n'
print(content)
print('-' 79) # to get text only, see email.parsers
else:
print('Bad message number')
def savemessage(i, mailfile, msgList):
if 1 <= i <= len(msgList):
savefile = open(mailfile, 'a', encoding=mailconfig.fetchEncoding) # 4E
savefile.write('\n' + msgList[i-1] + '-'*80 + '\n')
else:
print('Bad message number')
def msgnum(command):
try:
return int(command.split()[1])
except:
return −1 # assume this is bad
helptext = """
Available commands:
i - index display
l n? - list all messages (or just message n)
d n? - mark all messages for deletion (or just message n)
s n? - save all messages to a file (or just message n)
m - compose and send a new mail message
q - quit pymail
? - display this help text
"""
def interact(msgList, mailfile):
showindex(msgList)
toDelete = []
while True:
try:
command = input('[Pymail] Action? (i, l, d, s, m, q, ?) ')
except EOFError:
command = 'q'
if not command: command = '*'
quit
if command == 'q':
break
index
elif command[0] == 'i':
950 | Chapter 13: Client-Side Scripting