diff --git a/check_imap_login.py b/check_imap_login.py old mode 100644 new mode 100755 index 621f06d..b8f0a42 --- a/check_imap_login.py +++ b/check_imap_login.py @@ -15,20 +15,20 @@ import sys, os, imaplib, getopt def usage(): - print "-u " - print "-p " - print "-s use SSL" - print "-H " + print("-u ") + print("-p ") + print("-s use SSL") + print("-H ") def main(): - try: - opts, args = getopt.getopt(sys.argv[1:], "u:p:sH:") + try: + opts, args = getopt.getopt(sys.argv[1:], "u:p:sH:") except getopt.GetoptError: usage() return 3 user = host = password = use_ssl = None - + for o, a in opts: if o == "-u": user = a @@ -41,24 +41,21 @@ def main(): if user == None or password == None or host == None: usage() return 1 - + if use_ssl: M = imaplib.IMAP4_SSL(host=host) else: - M = imaplib.IMAP4(host) - + M = imaplib.IMAP4(host) + try: M.login(user, password) - except Exception, e: - print "CRITICAL: IMAP Login not Successful: %s" % e + except Exception as e: + print(f"CRITICAL: IMAP Login not Successful: {e}") sys.exit(2) - + M.logout() - print "OK IMAP Login Successful" + print("OK IMAP Login Successful") return 0 if __name__ == "__main__": - sys.exit(main()) - - - + sys.exit(main())