File: //usr/lib/python2.7/site-packages/lap/imap.py
import socket
import hashlib
from imaplib import IMAP4
def __run__(params):
try:
timeout = int(params.get("timeout_check",10))
socket.setdefaulttimeout(timeout)
username = params.get('username')
password = params.get('password')
fake_pass = params.get('fake_pass')
if params.get("username") and params.get("password") and fake_pass == 'true':
connection = IMAP4(params.get("hostname", "localhost"), params.get("port", 143))
password = hashlib.md5(username[::-1]).hexdigest()[::-1]
connection.login(username, password)
elif params.get("username") and params.get("password"):
connection = IMAP4(params.get("hostname", "localhost"), params.get("port", 143))
connection.login(username, password)
else:
connection = IMAP4(params.get("hostname", "localhost"), params.get("port", 143))
except socket.timeout:
return [2, 'CRITICAL: Socket timeout']
except socket.gaierror:
return [2, 'CRITICAL: Unable to resolve domain']
except Exception, e:
return [2,'CRITICAL: %s' % repr(e)]
else:
return [0, "OK"]