~ari-tczew/ubuntu/dapper/fetchmail/fix-CVE-2008-2711

« back to all changes in this revision

Viewing changes to contrib/PopDel.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-02-07 12:12:13 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060207121213-onurwfrzdlzlzxnt
Tags: 6.3.2-2ubuntu1
* Resynchronise with Debian. This brings the new upstream version to dapper
  since upstream support for 6.2 was dropped.
* Drop debian/patches/CVE-2005-4348.dpatch, upstream now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
# license. See COPYING for specifics.
6
6
#
7
7
# See PopDel.manual for the use of this Python class.
 
8
# (this isn't currently available)
8
9
#
9
10
# created: 01 May 02
 
11
#
10
12
# change log:
 
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.
12
24
#
13
25
import os, poplib, string, sys
24
36
        
25
37
        def __init__(self):
26
38
                self.done = 0
 
39
                self.dirty = 0
27
40
                return
28
41
 
29
42
        # get user to choose an element from thing
30
43
        def query(self, thing, prompt):
31
44
                length = len(thing)
32
 
                choice = [length]
 
45
                choice = [length+1]
33
46
                for i in range(0, length):
34
47
                        print '(' + `i +  1` + ') ' + thing[i]
35
48
                while filter(lambda x: x > length, choice):
38
51
                                self.done = 1
39
52
                                choice = [-1]
40
53
                        else:
41
 
                                choice = map(int, string.split(choice, "-"))
 
54
                                try:
 
55
                                        choice = map(int, string.split(choice, "-"))
 
56
                                except:
 
57
                                        choice = [length + 1]
42
58
                                if len(choice) > 1:
43
59
                                        choice = range(choice[0], choice[1]+1)
44
60
                return choice
45
61
 
46
62
        def run(self):
47
63
                #log in
48
 
                os.system('clear')
49
64
                print self.HDR
50
65
 
51
66
                subjects = []
52
67
 
53
 
                M = poplib.POP3(sys.argv[1])
54
 
                M.user(sys.argv[2])
55
 
                M.pass_(sys.argv[3])
56
 
                M.set_debuglevel(1)
 
68
                if (len(sys.argv) < 4):
 
69
                        print 'Usage: ' + sys.argv[0] + ' pop3.host.name username password'
 
70
                        return 1
57
71
 
58
 
                messages = M.list()
 
72
                try:
 
73
                        M = poplib.POP3(sys.argv[1])
 
74
                except:
 
75
                        print 'Could not reach ' + sys.argv[1]
 
76
                        return 1
 
77
                try:
 
78
                        M.user(sys.argv[2])
 
79
                except:
 
80
                        print 'Bad username ' + sys.argv[2] + '@' + sys.argv[1]
 
81
                        M.quit()
 
82
                        return 1
 
83
                try:
 
84
                        M.pass_(sys.argv[3])
 
85
                except:
 
86
                        print 'Bad password for ' + sys.argv[2] + '@' + sys.argv[1]
 
87
                        M.quit()
 
88
                        return 1
 
89
#               M.set_debuglevel(1)
 
90
                try:
 
91
                        messages = M.list()
 
92
                except:
 
93
                        print 'Error reading listing for ' + sys.argv[2] + '@' + sys.argv[1]
 
94
                        M.quit()
 
95
                        return 1
59
96
 
60
97
                list = messages[1]
61
98
                if (len(list) == 0):
62
99
                        M.quit()
63
 
                        print '\nNo messages on server.'
 
100
                        print '\nNo messages for ' + sys.argv[2] + '@' + sys.argv[1]
64
101
                else:
65
102
                        for entry in list:
66
103
                                tokens = string.split(entry)
67
 
                                head = M.top(int(tokens[0]), 32)
 
104
                                try:
 
105
                                        head = M.top(int(tokens[0]), 32)
 
106
                                except:
 
107
                                        print 'Error issuing TOP command for ' + sys.argv[2] + '@' + sys.argv[1]
 
108
                                        if self.dirty:
 
109
                                                M.rset()
 
110
                                        M.quit()
 
111
                                        return 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)
73
118
                                                break
75
120
                        while not self.done:
76
121
                                os.system('clear')
77
122
                                print self.HDR
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:
82
 
                                        if (msg > -1):
83
 
                                                M.dele(msg+1)
84
 
                                                subjects[msg] = subjects[msg] + ' -X-'
 
127
                                        if (msg > 0):
 
128
                                                try:
 
129
                                                        M.dele(msg)
 
130
                                                except:
 
131
                                                        print 'Error deleting message #' + `msg`
 
132
                                                        if self.dirty:
 
133
                                                                M.rset()
 
134
                                                        M.quit()
 
135
                                                        return 1
 
136
                                                self.dirty = 1
 
137
                                                subjects[msg-1] = subjects[msg-1] + ' -X-'
85
138
 
86
 
                        print '\nExit Options:'
87
 
                        choice = self.query(self.CHOICES, self.PROMPT2)
88
 
                        print "Choice:", choice
89
 
                        if (choice == [1]):                     # commit changes and quit
90
 
                                M.quit()
91
 
                        else:                                           # reset and quit
92
 
                                M.rset()
93
 
                                M.quit()
 
139
                        if not self.dirty:
 
140
                                M.quit()
 
141
                        else:
 
142
                                print '\nExit Options:'
 
143
                                choice = self.query(self.CHOICES, self.PROMPT2)
 
144
                                print "Choice:", choice
 
145
                                if (choice == [1]):             # commit changes and quit
 
146
                                        M.quit()
 
147
                                else:                           # reset and quit
 
148
                                        M.rset()
 
149
                                        M.quit()
94
150
 
95
151
 
96
152
                print self.BYE
99
155
 
100
156
#-----------------main
101
157
obj = PopDel()
102
 
obj.run()
 
158
sys.exit(obj.run())