Converting to python3
Signed-off-by: Alarig Le Lay <alarig@swordarmor.fr>
This commit is contained in:
parent
ce7fa554bf
commit
8c01a68245
25
check_imap_login.py
Normal file → Executable file
25
check_imap_login.py
Normal file → Executable file
|
@ -15,14 +15,14 @@
|
||||||
import sys, os, imaplib, getopt
|
import sys, os, imaplib, getopt
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print "-u <user>"
|
print("-u <user>")
|
||||||
print "-p <password>"
|
print("-p <password>")
|
||||||
print "-s use SSL"
|
print("-s use SSL")
|
||||||
print "-H <host>"
|
print("-H <host>")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "u:p:sH:")
|
opts, args = getopt.getopt(sys.argv[1:], "u:p:sH:")
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
usage()
|
usage()
|
||||||
return 3
|
return 3
|
||||||
|
@ -45,20 +45,17 @@ def main():
|
||||||
if use_ssl:
|
if use_ssl:
|
||||||
M = imaplib.IMAP4_SSL(host=host)
|
M = imaplib.IMAP4_SSL(host=host)
|
||||||
else:
|
else:
|
||||||
M = imaplib.IMAP4(host)
|
M = imaplib.IMAP4(host)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
M.login(user, password)
|
M.login(user, password)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print "CRITICAL: IMAP Login not Successful: %s" % e
|
print(f"CRITICAL: IMAP Login not Successful: {e}")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
M.logout()
|
M.logout()
|
||||||
print "OK IMAP Login Successful"
|
print("OK IMAP Login Successful")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue