This repository has been archived by the owner on Jul 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mailbox_extended.py
85 lines (69 loc) · 2.19 KB
/
test_mailbox_extended.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
"""
@brief test log(time=1s)
"""
import sys
import os
import unittest
import warnings
import datetime
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import is_travis_or_appveyor
try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src
from src.pymmails import MailBoxImap
class TestMailBox(unittest.TestCase):
def test_mailbox_extended(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
if is_travis_or_appveyor():
warnings.warn("requires a password")
return
now = datetime.datetime.now()
now -= datetime.timedelta(1)
date = now.strftime("%d-%b-%Y")
if "DOUZE2016" in os.environ.get("COMPUTERNAME", ""):
# does not work on the remote build server
return
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
import keyring
user = keyring.get_password(
"gmail", os.environ["COMPUTERNAME"] + "user")
code = keyring.get_password(
"gmail", os.environ["COMPUTERNAME"] + "pwd")
box = MailBoxImap(user, code,
"imap.gmail.com", ssl=True, fLOG=fLOG)
box.login()
mails = box.enumerate_mails_in_folder("inbox", date=date)
li = list(mails)
self.assertTrue(len(li) > 0)
box.logout()
issues = []
for mail in li:
name = mail.get_name()
if "=?" in mail:
issues.append(name)
fr = mail.get_from()
frm = [_ for _ in fr if _]
if "=?" in frm[0]:
issues.append(name)
if "@" not in fr[1]:
issues.append(name)
if len(issues) > 0:
raise Exception("Issues with\n{0}".format(
"\n".join(str(_) for _ in issues)))
if __name__ == "__main__":
unittest.main()