aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2003-01-17 15:08:03 +0000
committerEric S. Raymond <esr@thyrsus.com>2003-01-17 15:08:03 +0000
commita84e8bcb141f2b683e1bf20063cbf50245dfe583 (patch)
tree776eefcede7125e866a9650f65c3c415ac9f3b01
parent43a723bc4d043a147585e55824cfcc364bf2fdf6 (diff)
downloadfetchmail-a84e8bcb141f2b683e1bf20063cbf50245dfe583.tar.gz
fetchmail-a84e8bcb141f2b683e1bf20063cbf50245dfe583.tar.bz2
fetchmail-a84e8bcb141f2b683e1bf20063cbf50245dfe583.zip
Range support.
svn path=/trunk/; revision=3791
-rw-r--r--contrib/PopDel.py89
1 files changed, 44 insertions, 45 deletions
diff --git a/contrib/PopDel.py b/contrib/PopDel.py
index b879f6fd..90bcb6c0 100644
--- a/contrib/PopDel.py
+++ b/contrib/PopDel.py
@@ -8,6 +8,7 @@
#
# created: 01 May 02
# change log:
+# Hacked to support message ranges by ESR, January 2003.
#
import os, poplib, string, sys
@@ -28,19 +29,18 @@ class PopDel:
# get user to choose an element from thing
def query(self, thing, prompt):
length = len(thing)
- choice = length
+ choice = [length]
for i in range(0, length):
print '(' + `i + 1` + ') ' + thing[i]
- while (choice >= length):
+ while filter(lambda x: x > length, choice):
choice = raw_input(prompt)
if (choice == 'q'):
self.done = 1
- choice = -1
+ choice = [-1]
else:
- try:
- choice = int(choice) - 1
- except:
- choice = 666
+ choice = map(int, string.split(choice, "-"))
+ if len(choice) > 1:
+ choice = range(choice[0], choice[1]+1)
return choice
def run(self):
@@ -48,51 +48,50 @@ class PopDel:
os.system('clear')
print self.HDR
- try:
- subjects = []
+ subjects = []
- M = poplib.POP3(sys.argv[1])
- M.user(sys.argv[2])
- M.pass_(sys.argv[3])
+ M = poplib.POP3(sys.argv[1])
+ M.user(sys.argv[2])
+ M.pass_(sys.argv[3])
+ M.set_debuglevel(1)
- messages = M.list()
+ messages = M.list()
- list = messages[1]
- if (len(list) == 0):
- M.quit()
- print '\nNo messages on server.'
- else:
- for entry in list:
- tokens = string.split(entry)
- head = M.top(int(tokens[0]), 32)
- for line in head[1]:
- if (string.find(line, 'Subject:') == 0):
- subject = string.replace(line, 'Subject:','')
- subject = subject + ' - ' + tokens[1] + ' octets'
- subjects.append(subject)
- break
+ list = messages[1]
+ if (len(list) == 0):
+ M.quit()
+ print '\nNo messages on server.'
+ else:
+ for entry in list:
+ tokens = string.split(entry)
+ head = M.top(int(tokens[0]), 32)
+ for line in head[1]:
+ if (string.find(line, 'Subject:') == 0):
+ subject = string.replace(line, 'Subject:','')
+ subject = subject + ' - ' + tokens[1] + ' octets'
+ subjects.append(subject)
+ break
- while not self.done:
- os.system('clear')
- print self.HDR
- print '\nMessages on server:'
- msg = self.query(subjects, self.PROMPT1)
+ while not self.done:
+ os.system('clear')
+ print self.HDR
+ print '\nMessages on server:'
+ msglist = self.query(subjects, self.PROMPT1)
+ print "Choice:", msglist
+ for msg in msglist:
if (msg > -1):
- M.dele( msg + 1)
+ M.dele(msg+1)
subjects[msg] = subjects[msg] + ' -X-'
- print '\nExit Options:'
- choice = self.query(self.CHOICES, self.PROMPT2)
- if (choice == 0): # commit changes and quit
- M.quit()
- else: # reset and quit
- M.rset()
- M.quit()
-
- except: # if blows-up then quit gracefully
- print "Error: terminating on exception."
- M.rset()
- M.quit()
+ print '\nExit Options:'
+ choice = self.query(self.CHOICES, self.PROMPT2)
+ print "Choice:", choice
+ if (choice == [1]): # commit changes and quit
+ M.quit()
+ else: # reset and quit
+ M.rset()
+ M.quit()
+
print self.BYE
return