commit
9d1c49184f
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
else:
|
else:
|
||||||
|
@ -10,24 +11,32 @@ import imaplib
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import calendar
|
import calendar
|
||||||
|
|
||||||
# Change these to match your email setup
|
IMAP_SERVER_GMAIL = 'imap.gmail.com' # gmail server address
|
||||||
|
IMAP_SERVER_HOTMAIL = 'imap-mail.outlook.com' # hotmail server address
|
||||||
|
|
||||||
|
################# Change these to match your email setup ################
|
||||||
LOGIN_EMAIL = 'you@mail.com'
|
LOGIN_EMAIL = 'you@mail.com'
|
||||||
LOGIN_PASSWORD = 'your email password'
|
LOGIN_PASSWORD = 'your email password'
|
||||||
IMAP_SERVER = 'imap-mail.outlook.com' # change to match your email service
|
IMAP_SERVER = IMAP_SERVER_GMAIL # change to match your email service
|
||||||
|
|
||||||
MAX_EMAILS = 10
|
MAX_EMAILS = 10
|
||||||
|
|
||||||
|
|
||||||
def gui():
|
def gui():
|
||||||
sg.ChangeLookAndFeel('Topanga')
|
sg.ChangeLookAndFeel('Topanga')
|
||||||
|
|
||||||
sg.SetOptions(border_width=0, margins=(0,0), element_padding=(4,0))
|
sg.SetOptions(border_width=0, margins=(0, 0), element_padding=(4, 0))
|
||||||
|
|
||||||
layout = [[sg.T('Email New Mail Notification'+54*' '), sg.RButton('', image_data=red_x, button_color=('#282923', '#282923'), key='_quit_')],
|
layout = [[sg.T('Email New Mail Notification' + 48 * ' '),
|
||||||
[sg.T('', key='_status_', size=(25,1))],]
|
sg.RButton('', image_data=refresh, button_color=('#282923', '#282923'), key='_refresh_',
|
||||||
|
tooltip='Refreshes Email'),
|
||||||
|
sg.RButton('', image_data=red_x, button_color=('#282923', '#282923'), key='_quit_',
|
||||||
|
tooltip='Closes window')],
|
||||||
|
[sg.T('', key='_status_', size=(25, 1))], ]
|
||||||
|
|
||||||
for i in range(MAX_EMAILS):
|
for i in range(MAX_EMAILS):
|
||||||
layout.append ([sg.T('', size=(20,1), key='{}date'.format(i), font='Sans 8'),
|
layout.append([sg.T('', size=(20, 1), key='{}date'.format(i), font='Sans 8'),
|
||||||
sg.T('', size=(45,1), font='Sans 8', key='{}from'.format(i))])
|
sg.T('', size=(45, 1), font='Sans 8', key='{}from'.format(i))])
|
||||||
|
|
||||||
window = sg.Window('',
|
window = sg.Window('',
|
||||||
no_titlebar=True,
|
no_titlebar=True,
|
||||||
|
@ -38,7 +47,7 @@ def gui():
|
||||||
|
|
||||||
# move the window to the upper right corner of the screen
|
# move the window to the upper right corner of the screen
|
||||||
w, h = window.GetScreenDimensions()
|
w, h = window.GetScreenDimensions()
|
||||||
window.Move(w-410,0)
|
window.Move(w - 410, 0)
|
||||||
window.SetAlpha(.9)
|
window.SetAlpha(.9)
|
||||||
window.Refresh()
|
window.Refresh()
|
||||||
status_elem = window.FindElement('_status_')
|
status_elem = window.FindElement('_status_')
|
||||||
|
@ -48,7 +57,7 @@ def gui():
|
||||||
window.Refresh()
|
window.Refresh()
|
||||||
read_mail(window)
|
read_mail(window)
|
||||||
status_elem.Update('')
|
status_elem.Update('')
|
||||||
event, values = window.Read(timeout=30*1000)
|
event, values = window.Read(timeout=30 * 1000) # return every 30 seconds
|
||||||
if event == '_quit_':
|
if event == '_quit_':
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -77,17 +86,14 @@ def read_mail(window):
|
||||||
break
|
break
|
||||||
from_elem = window.FindElement('{}from'.format(n))
|
from_elem = window.FindElement('{}from'.format(n))
|
||||||
date_elem = window.FindElement('{}date'.format(n))
|
date_elem = window.FindElement('{}date'.format(n))
|
||||||
|
from_elem.Update('') # erase them so you know they're changing
|
||||||
|
date_elem.Update('')
|
||||||
|
window.Refresh()
|
||||||
typ, data = mail.fetch(message, '(RFC822)')
|
typ, data = mail.fetch(message, '(RFC822)')
|
||||||
for response_part in data:
|
for response_part in data:
|
||||||
if isinstance(response_part, tuple):
|
if isinstance(response_part, tuple):
|
||||||
original = email.message_from_bytes(response_part[1])
|
original = email.message_from_bytes(response_part[1])
|
||||||
date_str = original['Date']
|
date_str = original['Date'][:22]
|
||||||
cut_point = date_str.find('-') # a hack to shorten the datetime string
|
|
||||||
if cut_point == -1:
|
|
||||||
cut_point = date_str.find('+')
|
|
||||||
if cut_point == -1:
|
|
||||||
cut_point = len(date_str)
|
|
||||||
date_str = date_str[:cut_point]
|
|
||||||
from_elem.Update(original['From'])
|
from_elem.Update(original['From'])
|
||||||
date_elem.Update(date_str)
|
date_elem.Update(date_str)
|
||||||
window.Refresh() # make the window changes show up right away
|
window.Refresh() # make the window changes show up right away
|
||||||
|
@ -95,4 +101,6 @@ def read_mail(window):
|
||||||
|
|
||||||
red_x = "R0lGODlhEAAQAPeQAIsAAI0AAI4AAI8AAJIAAJUAAJQCApkAAJoAAJ4AAJkJCaAAAKYAAKcAAKcCAKcDA6cGAKgAAKsAAKsCAKwAAK0AAK8AAK4CAK8DAqUJAKULAKwLALAAALEAALIAALMAALMDALQAALUAALYAALcEALoAALsAALsCALwAAL8AALkJAL4NAL8NAKoTAKwbAbEQALMVAL0QAL0RAKsREaodHbkQELMsALg2ALk3ALs+ALE2FbgpKbA1Nbc1Nb44N8AAAMIWAMsvAMUgDMcxAKVABb9NBbVJErFYEq1iMrtoMr5kP8BKAMFLAMxKANBBANFCANJFANFEB9JKAMFcANFZANZcANpfAMJUEMZVEc5hAM5pAMluBdRsANR8AM9YOrdERMpIQs1UVMR5WNt8X8VgYMdlZcxtYtx4YNF/btp9eraNf9qXXNCCZsyLeNSLd8SSecySf82kd9qqc9uBgdyBgd+EhN6JgtSIiNuJieGHhOGLg+GKhOKamty1ste4sNO+ueenp+inp+HHrebGrefKuOPTzejWzera1O7b1vLb2/bl4vTu7fbw7ffx7vnz8f///wAAAAAAAAA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