X-Git-Url: https://git.danix.xyz/?a=blobdiff_plain;f=bin%2Fexecutors%2Fmail-check;fp=bin%2Fexecutors%2Fmail-check;h=0000000000000000000000000000000000000000;hb=7abef725078fc52196b630c95f354fb58864c743;hp=95797c62d55836110e417c493df8c7e4a538cae9;hpb=6be4fcd546b01b14b5f06306ab5b7c0391913bfa;p=my-dotfiles.git diff --git a/bin/executors/mail-check b/bin/executors/mail-check deleted file mode 100755 index 95797c6..0000000 --- a/bin/executors/mail-check +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python3 - -""" -A very simple imap e-mail notifier. -Tested (and working) with Debian 8 (Jessie) + Xfce. -""" - -import imaplib -import re -import time -import sys -import os -import argparse - - -def MainProgram(): - server_error = 0 - status = "" - unread = 0 - - parser = argparse.ArgumentParser(description='Check your email.') - parser.add_argument("-g", "--gmail", help="connect to gmail imap server", action="store_true") - parser.add_argument("-c", "--custom", help="connect to custom imap server", type=str, default=argparse.SUPPRESS) - parser.add_argument("-u", "--user", help="Username", type=str, required=True) - parser.add_argument("-p", "--pword", help="Password", type=str, required=True) - parser.add_argument("-r", "--port", help="Port to connect to", default="993", type=int) - parser.add_argument("-d", "--display", help="Display Name", type=str) - - args = parser.parse_args() - - if args.gmail: - imapServer = "imap.gmail.com" - else: - if args.custom: - imapServer = args.custom - - if args.display: - displayName = args.display - else: - displayName = imapUserName - - try: - imapUserName = args.user - except Exception as e: - raise - - try: - imapPass = args.pword - except Exception as e: - raise - - try: - imapPort = args.port - except Exception as e: - raise - - - # # Enter your imap settings below - # imapServer = "imap.gmail.com" - # # imapUserName = "danixland@gmail.com" - # imapUserName = "it.danilo.macri@gmail.com" - # # imapPass = "jxibrnebktqbkhmx" - # imapPass = "udykutvueszpxfkd" - # imapPort = 993 - # # displayName = "gmail - danixland" - # displayName = "gmail - Danilo Macri" - - # Try to connect to imap server - try: - server = imaplib.IMAP4_SSL(imapServer, imapPort) - server.login(imapUserName, imapPass) - status, unread = server.status('INBOX', "(UNSEEN)") - except Exception: - pass - - if status != "OK": - server_error = 1 - - # Retry a couple of times even though we got wrong response from server - while server_error >= 1 and server_error < 4: - time.sleep(2) - if status == "OK": - server_error = 0 - else: - server_error += 1 - MainProgram() # Try to connect again - - CHECK_UNREAD = str(unread) - NO_OF_UNREAD = re.sub(r'\D', "", CHECK_UNREAD) - - if server_error > 3: - # os.system('notify-send "Problem connecting to imap server"') - print("Problem connecting to imap server") - elif int(NO_OF_UNREAD) > 0: - # os.system('notify-send "You have new mail"') - print("/usr/share/icons/MB-Mango-Suru-GLOW/panel/16/new-messages-red.svg") - print("{}: {} new mail".format(displayName, NO_OF_UNREAD)) - elif int(NO_OF_UNREAD) == 0: - print("/usr/share/icons/MB-Mango-Suru-GLOW/panel/16/applications-email-panel.svg") - print("{}: No new mail".format(displayName)) - - -MainProgram()