5
5
# license. See COPYING for specifics.
7
7
# See PopDel.manual for the use of this Python class.
8
# (this isn't currently available)
9
10
# created: 01 May 02
13
# Joshua Crawford, November 2004:
14
# Out of range error fixed
15
# Allow for all caps SUBJECT:
16
# Display email address
17
# Don't prompt for save if no changes
18
# Don't clear the screen until we're displaying a menu
19
# Check for invalid choice
20
# Check all arguments exist
21
# Check for errors in POP
22
# Return 1 on errors, 0 otherwise
11
23
# Hacked to support message ranges by ESR, January 2003.
13
25
import os, poplib, string, sys
25
37
def __init__(self):
29
42
# get user to choose an element from thing
30
43
def query(self, thing, prompt):
31
44
length = len(thing)
33
46
for i in range(0, length):
34
47
print '(' + `i + 1` + ') ' + thing[i]
35
48
while filter(lambda x: x > length, choice):
41
choice = map(int, string.split(choice, "-"))
55
choice = map(int, string.split(choice, "-"))
42
58
if len(choice) > 1:
43
59
choice = range(choice[0], choice[1]+1)
53
M = poplib.POP3(sys.argv[1])
68
if (len(sys.argv) < 4):
69
print 'Usage: ' + sys.argv[0] + ' pop3.host.name username password'
73
M = poplib.POP3(sys.argv[1])
75
print 'Could not reach ' + sys.argv[1]
80
print 'Bad username ' + sys.argv[2] + '@' + sys.argv[1]
86
print 'Bad password for ' + sys.argv[2] + '@' + sys.argv[1]
93
print 'Error reading listing for ' + sys.argv[2] + '@' + sys.argv[1]
61
98
if (len(list) == 0):
63
print '\nNo messages on server.'
100
print '\nNo messages for ' + sys.argv[2] + '@' + sys.argv[1]
65
102
for entry in list:
66
103
tokens = string.split(entry)
67
head = M.top(int(tokens[0]), 32)
105
head = M.top(int(tokens[0]), 32)
107
print 'Error issuing TOP command for ' + sys.argv[2] + '@' + sys.argv[1]
68
112
for line in head[1]:
69
if (string.find(line, 'Subject:') == 0):
113
if (string.find(string.upper(line), 'SUBJECT:') == 0):
70
114
subject = string.replace(line, 'Subject:','')
115
subject = string.replace(subject, 'SUBJECT:','')
71
116
subject = subject + ' - ' + tokens[1] + ' octets'
72
117
subjects.append(subject)
75
120
while not self.done:
76
121
os.system('clear')
78
print '\nMessages on server:'
123
print '\nMessages for ' + sys.argv[2] + '@' + sys.argv[1] + ':'
79
124
msglist = self.query(subjects, self.PROMPT1)
80
125
print "Choice:", msglist
81
126
for msg in msglist:
84
subjects[msg] = subjects[msg] + ' -X-'
131
print 'Error deleting message #' + `msg`
137
subjects[msg-1] = subjects[msg-1] + ' -X-'
86
print '\nExit Options:'
87
choice = self.query(self.CHOICES, self.PROMPT2)
88
print "Choice:", choice
89
if (choice == [1]): # commit changes and quit
91
else: # reset and quit
142
print '\nExit Options:'
143
choice = self.query(self.CHOICES, self.PROMPT2)
144
print "Choice:", choice
145
if (choice == [1]): # commit changes and quit
147
else: # reset and quit