[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

print('\t%-8s=>%s' % (hdr, msg.get(hdr, '(unknown)')))
if count % chunk == 0:
input('[Press Enter key]') # pause after each chunk


def showmessage(i, msgList):
if 1 <= i <= len(msgList):
fulltext = fetchmessage(i)
message = parser.parseMessage(fulltext)
ctype, maintext = parser.findMainText(message)
print('-' 79)
print(maintext.rstrip() + '\n') # main text part, not entire mail
print('-'
79) # and not any attachments after
else:
print('Bad message number')


def savemessage(i, mailfile, msgList):
if 1 <= i <= len(msgList):
fulltext = fetchmessage(i)
savefile = open(mailfile, 'a', encoding=mailconfig.fetchEncoding) # 4E
savefile.write('\n' + fulltext + '-'*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, msgSizes, mailfile):
showindex(msgList, msgSizes)
toDelete = []
while True:
try:
command = input('[Pymail] Action? (i, l, d, s, m, q, ?) ')
except EOFError:
command = 'q'
if not command: command = '*'


if command == 'q': # quit
break


elif command[0] == 'i': # index
showindex(msgList, msgSizes)


The mailtools Utility Package | 987
Free download pdf