4 A very simple imap e-mail notifier.
5 Tested (and working) with Debian 8 (Jessie) + Xfce.
21 parser
= argparse
.ArgumentParser(description
='Check your email.')
22 parser
.add_argument("-g", "--gmail", help="connect to gmail imap server", action
="store_true")
23 parser
.add_argument("-c", "--custom", help="connect to custom imap server", type=str, default
=argparse
.SUPPRESS
)
24 parser
.add_argument("-u", "--user", help="Username", type=str, required
=True)
25 parser
.add_argument("-p", "--pword", help="Password", type=str, required
=True)
26 parser
.add_argument("-r", "--port", help="Port to connect to", default
="993", type=int)
27 parser
.add_argument("-d", "--display", help="Display Name", type=str)
29 args
= parser
.parse_args()
32 imapServer
= "imap.gmail.com"
35 imapServer
= args
.custom
38 displayName
= args
.display
40 displayName
= imapUserName
43 imapUserName
= args
.user
44 except Exception as e
:
49 except Exception as e
:
54 except Exception as e
:
58 # # Enter your imap settings below
59 # imapServer = "imap.gmail.com"
60 # # imapUserName = "danixland@gmail.com"
61 # imapUserName = "it.danilo.macri@gmail.com"
62 # # imapPass = "jxibrnebktqbkhmx"
63 # imapPass = "udykutvueszpxfkd"
65 # # displayName = "gmail - danixland"
66 # displayName = "gmail - Danilo Macri"
68 # Try to connect to imap server
70 server
= imaplib
.IMAP4_SSL(imapServer
, imapPort
)
71 server
.login(imapUserName
, imapPass
)
72 status
, unread
= server
.status('INBOX', "(UNSEEN)")
79 # Retry a couple of times even though we got wrong response from server
80 while server_error
>= 1 and server_error
< 4:
86 MainProgram() # Try to connect again
88 CHECK_UNREAD
= str(unread
)
89 NO_OF_UNREAD
= re
.sub(r
'\D', "", CHECK_UNREAD
)
92 # os.system('notify-send "Problem connecting to imap server"')
93 print("Problem connecting to imap server")
94 elif int(NO_OF_UNREAD
) > 0:
95 # os.system('notify-send "You have new mail"')
96 print("/usr/share/icons/MB-Mango-Suru-GLOW/panel/16/new-messages-red.svg")
97 print("{}: {} new mail".format(displayName
, NO_OF_UNREAD
))
98 elif int(NO_OF_UNREAD
) == 0:
99 print("/usr/share/icons/MB-Mango-Suru-GLOW/panel/16/applications-email-panel.svg")
100 print("{}: No new mail".format(displayName
))