def GetMail self server self Config get POP3 server port int self Conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def GetMail(self):
server = self.Config.get('POP3', 'server')
port = int(self.Config.get('POP3', 'port'))
username = self.Config.get('POP3', 'username')
password = self.Config.get('POP3', 'password')
try:
print 'Connecting to ', server, '...',
pop3 = poplib.POP3(server)
print 'OK'
except:
print 'ERROR'
return None
try:
print 'Sending username...',
pop3.user(username)
print 'OK'
except:
print 'ERROR'
return None
try:
print 'Sending password...',
pop3.pass_(password)
print 'OK'
except:
print 'ERROR'
return None
Command = Message = None
if len(pop3.list()[1]):
str = pop3.retr(1)[1]
pop3.dele(1)
str = str[str.index('')+1:]
index = str[0].index(' ')
Command = str[0][:index]
str[0] = str[0][index+1:]
#str = str[index+2:]
Message = ''
for s in str:
Message += s+'\n'
Message = Message.strip()
#Message = Message.decode('cp1251')
#Message = Message.encode('utf-8')
print Message
Message = unicode(Message, 'cp1251')
print 'cmd=',Command
print 'text=',Message
try:
print 'Closing connection...',
pop3.quit()
print 'OK'
except:
print 'ERROR'
return None
return Command, Message
#...
def SendMessage(self, text):
for Subscriber in self.Subscribers:
print 'Sending to ', Subscriber, '...',
msg = jabber.Message(Subscriber, text)
msg.setType('chat')
self.JabberClient.send(msg)
print 'OK'