1
2
3
4 import poplib
5 import warn
6
8 - def __init__(self, remotehost, port = None, usingssl=True):
9 """ Authentication based on POP3, if usingssl is True then SSL is used
10 to perform the communication"""
11 self.usingssl = usingssl
12 self.remotehost = remotehost
13 self.port = port
14 if usingssl:
15 if port is None: self.port = poplib.POP3_SSL_PORT
16 else:
17 if port is None: self.port = poplib.POP3_PORT
18
19 - def auth(self, user, password):
21
23 if self.usingssl:
24 pop = poplib.POP3_SSL(self.remotehost, self.port)
25 else:
26 pop = poplib.POP3(self.remotehost, self.port)
27 try:
28 pop.user(user)
29 pop.pass_(password)
30 pop.stat()
31 except:
32 pop.quit()
33 return False
34 pop.quit()
35 return True
36
37 if __name__ == '__main__':
38 auth = POP3Auth("localhost")
39 import getpass
40 print auth.auth(getpass.getuser(), getpass.getpass())
41