def read_mail(window):
    """
    Reads late emails from IMAP server and displays them in the Window
    :param window: window to display emails in
    :return:
    """
    mail = imaplib.IMAP4_SSL(IMAP_SERVER)

    (retcode, capabilities) = mail.login(LOGIN_EMAIL, LOGIN_PASSWORD)
    mail.list()
    typ, data = mail.select('Inbox')
    n = 0
    now = datetime.now()
    # get messages from today
    search_string = '(SENTON {}-{}-{})'.format(now.day, calendar.month_abbr[now.month], now.year)
    (retcode, messages) = mail.search(None, search_string)
    if retcode == 'OK':
        msg_list = messages[0].split()  # message numbers are separated by spaces, turn into list
        msg_list.sort(reverse=True)  # sort messages descending
        for n, message in enumerate(msg_list):
            if n >= MAX_EMAILS:
                break
            from_elem = window.FindElement('{}from'.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)')
            for response_part in data:
                if isinstance(response_part, tuple):
                    original = email.message_from_bytes(response_part[1])
                    date_str = original['Date'][:22]
                    from_elem.Update(original['From'])
                    date_elem.Update(date_str)
                    window.Refresh()
def read_mail ( window ) : mail = imaplib . IMAP4_SSL ( IMAP_SERVER ) ( retcode , capabilities ) = mail . login ( LOGIN_EMAIL , LOGIN_PASSWORD ) mail . list ( ) typ , data = mail . select ( 'Inbox' ) n = 0 now = datetime . now ( ) search_string = '(SENTON {}-{}-{})' . format ( now . day , calendar . month_abbr [ now . month ] , now . year ) ( retcode , messages ) = mail . search ( None , search_string ) if retcode == 'OK' : msg_list = messages [ 0 ] . split ( ) msg_list . sort ( reverse = True ) for n , message in enumerate ( msg_list ) : if n >= MAX_EMAILS : break from_elem = window . FindElement ( '{}from' . format ( n ) ) date_elem = window . FindElement ( '{}date' . format ( n ) ) from_elem . Update ( '' ) date_elem . Update ( '' ) window . Refresh ( ) typ , data = mail . fetch ( message , '(RFC822)' ) for response_part in data : if isinstance ( response_part , tuple ) : original = email . message_from_bytes ( response_part [ 1 ] ) date_str = original [ 'Date' ] [ : 22 ] from_elem . Update ( original [ 'From' ] ) date_elem . Update ( date_str ) window . Refresh ( )
Reads late emails from IMAP server and displays them in the Window
    :param window: window to display emails in
    :return: