import unittest import mail import os mail_data = b'Delivered-To: ycolakoglu.bilisim@gmail.com\r\nReceived: by 2002:a4a:3b52:0:0:0:0:0 with SMTP id s79csp5499397oos;\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)\r\nX-Received: by 2002:a62:5284:: with SMTP id g126mr36248899pfb.95.1571116620441;\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)\r\nARC-Seal: i=1; a=rsa-sha256; t=1571116620; cv=none;\r\n d=google.com; s=arc-20160816;\r\n b=cpnYE9u9z+MntvqooyBpwsjspuZ1eIXZ0CbeDqM41EV6hYZhvVh94tWy55IyY/NxO/\r\n FaR81R1OC5eVt50vyEx1HHVSfF592GrexKhS5I54EDXF/4d8bbsruipRnw3HzSefmu5F\r\n 662POtR4sxcxAWfP0RSjecj8F6HzL/fPsf/zltB1E2mATNmvi55MJbyiXrkgSki7AsH2\r\n V0OTSSRbkei2a0jW0mFAf1aikYODSqxInejlIKB+L1fAWXVHrd/gw8Bb4HEFyzCBzx5O\r\n pX1qj4hCg2zZ9mq2gOyNjYpQiQPcRl4PeP6WS2FlDQHF1pvo/YIWIY/X9meRZU7OVhak\r\n pRKg==\r\nARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;\r\n h=to:from:subject:message-id:feedback-id:date:mime-version\r\n :dkim-signature;\r\n bh=T4/J1/5TDNqRq8UWUiIGuzPe7Zv+PrrvC6tmCrrt0i4=;\r\n b=F6ssVJAjMg4eWB+FOYSxC6Z3QJ5AksZBZiNyyQJaLwbQawF+ENaOIYzOD4zzUWcK9U\r\n NEhcv9onqo9FLH1jl4bQcNV7f2oSfrf3eQvzR56E8JSemz/eH32uN4rnM/H7Q+Q9A4WB\r\n QSQaEnS7OOuUbx7Vb53yxJ+0+tKogaK+Io5APQ0psLW2i5/ZraPYS4uLfAgsqwPGLSxa\r\n lK2aYOcpqNSPnye3Ie2jib+jL44sW1vMhlfr46MoF28guVPpj0ByWy/m62HDwjKdVUap\r\n HBcvw2oEFLV3aiqxsifMlbin3W0IR+ZppnZkxMWs+bmNn8YcOvpSqZ5bZR2hnyOW8+Iy\r\n Trqg==\r\nARC-Authentication-Results: i=1; mx.google.com;\r\n dkim=pass header.i=@accounts.google.com header.s=20161025 header.b=yqMoB78r;\r\n spf=pass (google.com: domain of 3s1alxqgtaiars-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3S1alXQgTAIArs-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com;\r\n dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=accounts.google.com\r\nReturn-Path: <3S1alXQgTAIArs-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com>\r\nReceived: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73])\r\n by mx.google.com with SMTPS id m6sor19968531pgp.62.2019.10.14.22.17.00\r\n for \r\n (Google Transport Security);\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)\r\nReceived-SPF: pass (google.com: domain of 3s1alxqgtaiars-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73;\r\nAuthentication-Results: mx.google.com;\r\n dkim=pass header.i=@accounts.google.com header.s=20161025 header.b=yqMoB78r;\r\n spf=pass (google.com: domain of 3s1alxqgtaiars-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3S1alXQgTAIArs-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com;\r\n dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=accounts.google.com\r\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=accounts.google.com; s=20161025;\r\n h=mime-version:date:feedback-id:message-id:subject:from:to;\r\n bh=T4/J1/5TDNqRq8UWUiIGuzPe7Zv+PrrvC6tmCrrt0i4=;\r\n b=yqMoB78ruEfTrMV0UsPvCuTrOs+o++szTk6Tnw//IhMJ/jj2TJvAWQvuUXaHVQKb7p\r\n 1FYqRrqOWj+zSTv/xeHz2W6SnVvA7ThoE1QVbZKBX2zSDe/yG6NImw7luFE/D3zbQ4Xk\r\n mMg2AM3Vvttkz8krt6omolVeJab7luTChU6mfojgF3lcrkHL3l5w9Q6eUY7q8vOP4SmN\r\n RevtIe3vZw6T/ozfjbyD8ptEZHqrJ93KHrot3Oe4wg0sDkhdLY6eYfQnQAKuDQKnpLA3\r\n gMdeu+jDikTfhIKu99WQqoY5Rer9XGVedtaaAZFJ+BB11iEkc939LmH5W6bHXeGF/itd\r\n ldog==\r\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=1e100.net; s=20161025;\r\n h=x-gm-message-state:mime-version:date:feedback-id:message-id:subject\r\n :from:to;\r\n bh=T4/J1/5TDNqRq8UWUiIGuzPe7Zv+PrrvC6tmCrrt0i4=;\r\n b=Ljo8+tiQogDE4ff31Fo4bq6GHH1n64neGOaFLYFqd/1dBBZhxLI+FJH9s+mYesbWoY\r\n 4/X77kHpwd5MDkmbkP/wsOdZe7MG9YpyucuWMJXRDWONkjl2PjTVLlNUJxLVFfj4P8WD\r\n fxF8iPKdjRiSxCuZXhU/FmpYtWacYjExUml3pjORuQe7wULCZgwV/u5oVqdqasfEW9aL\r\n J/X+uLDSpEPxUv9PnxtPWtiijna9RDv9qQXrQgyHFzDTQZcbs54thNDNdo/7CAVAAYdg\r\n b2eBlrLRZJ94EAVi1NmaPcoYzZnUwTyUqwJLk+RZ/Vb1vqm5HxCtjydH/Mg3iL5G3mPd\r\n w6Qw==\r\nX-Gm-Message-State: APjAAAXaHG4hlX5O1w5p2nhqKp2xe86KL7aWAPSRwV5ro4Gff5pjFZKO\r\n\tHarqGjLc4s3u2l5B7JdgXtrpTsEau1FO\r\nX-Google-Smtp-Source: APXvYqz9YuaVV0VswWE1Tw9wz0kTyq1vBWKS9mjYoZMSZ+ldB0Z3zcy3qvUeDD5k4rGpwGVdYXSUjFdKQTANgYi2rqOszg==\r\nMIME-Version: 1.0\r\nX-Received: by 2002:a63:8dc2:: with SMTP id z185mr36524384pgd.228.1571116619995;\r\n Mon, 14 Oct 2019 22:16:59 -0700 (PDT)\r\nDate: Tue, 15 Oct 2019 05:16:58 +0000 (GMT)\r\nX-Account-Notification-Type: 31-anexp#givab-fa--mdv2-fa--hsc-control_b--ivab-fa\r\nFeedback-ID: 31-anexp#givab-fa--mdv2-fa--hsc-control_b--ivab-fa:account-notifier\r\nX-Notifications: 4e28bdab0a800000\r\nMessage-ID: \r\nSubject: Security alert\r\nFrom: Google \r\nTo: ycolakoglu.bilisim@gmail.com\r\nContent-Type: multipart/alternative; boundary="000000000000091c420594ec189c"\r\n\r\n--000000000000091c420594ec189c\r\nContent-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes\r\nContent-Transfer-Encoding: base64\r\n\r\nTmV3IGRldmljZSBzaWduZWQgaW4gdG8NCg0KDQp5Y29sYWtvZ2x1LmJpbGlzaW1AZ21haWwuY29t\r\nDQpZb3VyIEdvb2dsZSBBY2NvdW50IHdhcyBqdXN0IHNpZ25lZCBpbiB0byBmcm9tIGEgbmV3IExp\r\nbnV4IGRldmljZS4gWW91J3JlDQpnZXR0aW5nIHRoaXMgZW1haWwgdG8gbWFrZSBzdXJlIGl0IHdh\r\ncyB5b3UuDQpDaGVjayBhY3Rpdml0eQ0KPGh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9BY2Nv\r\ndW50Q2hvb3Nlcj9FbWFpbD15Y29sYWtvZ2x1LmJpbGlzaW1AZ21haWwuY29tJmNvbnRpbnVlPWh0\r\ndHBzOi8vbXlhY2NvdW50Lmdvb2dsZS5jb20vYWxlcnQvbnQvMTU3MTExNjYxODAwMD9yZm4lM0Qz\r\nMSUyNnJmbmMlM0QxJTI2ZWlkJTNELTg4NDgwODUyNzA4MzA0MDE5MDIlMjZldCUzRDAlMjZhbmV4\r\ncCUzRGdpdmFiLWZhLS1tZHYyLWZhLS1oc2MtY29udHJvbF9iLS1pdmFiLWZhPg0KWW91IHJlY2Vp\r\ndmVkIHRoaXMgZW1haWwgdG8gbGV0IHlvdSBrbm93IGFib3V0IGltcG9ydGFudCBjaGFuZ2VzIHRv\r\nIHlvdXINCkdvb2dsZSBBY2NvdW50IGFuZCBzZXJ2aWNlcy4NCsKpIDIwMTkgR29vZ2xlIExMQywg\r\nMTYwMCBBbXBoaXRoZWF0cmUgUGFya3dheSwgTW91bnRhaW4gVmlldywgQ0EgOTQwNDMsIFVTQQ0K\r\n--000000000000091c420594ec189c\r\nContent-Type: text/html; charset="UTF-8"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<=\r\ntd>
New device signed in to
Your Google Account was just signed in to fr=\r\nom a new Linux device. You\'re getting this email to make sure it was you.Check activity
You received this email to let you k=\r\nnow about important changes to your Google Account and services.
ycolakoglu.bilisim@gmail.com
\r\n--000000000000091c420594ec189c--\r\n' class MailTest(unittest.TestCase): def test_from(self): mail_obj = mail.Mail(mail_data) self.assertEqual(mail_obj.header_data["From"], "Google ") def test_received(self): mail_obj = mail.Mail(mail_data) self.assertEqual(mail_obj.header_data["Received"], 'by 2002:a4a:3b52:0:0:0:0:0 with SMTP id s79csp5499397oos;\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)') def test_date(self): mail_obj = mail.Mail(mail_data) self.assertEqual(mail_obj.header_data["Date"], "Tue, 15 Oct 2019 05:16:58 +0000 (GMT)") def test_mail_blacklist(self): mail_obj = mail.Mail(mail_data.replace(b"2002:a4a:3b52:0:0:0:0:0", b"unittest.malicious.com")) mail_obj.DOMAIN_COEFFICIENT = 2 mail_obj.DOMAIN_THRESHOLD = 5 mail_obj.check_blacklisted() self.assertTrue(mail_obj._spam) mail_obj = mail.Mail(mail_data.replace(b"no-reply@accounts.google.com", b"utest@malicious.com")) mail_obj.MAIL_COEFFICIENT = 2 mail_obj.MAIL_THRESHOLD = 5 mail_obj.check_blacklisted() self.assertTrue(mail_obj._spam) def test_domain_blacklist(self): mail_obj = mail.Mail(mail_data) mail_obj.DOMAIN_COEFFICIENT = 2 mail_obj.DOMAIN_THRESHOLD = 5 mail_obj.check_spam() self.assertTrue(mail_obj._spam) class MailBoxTest(unittest.TestCase): def test_mail_walk(self): mail_dir = os.path.join(os.getcwd(), "mails//") mailbox_obj = mail.MailBox("ycolakoglu.bilisim@gmail.com", "totallysecurepass", "imap.google.com", 993) self.assertEqual(list(mailbox_obj.mails.keys()), ["mail_example"]) def test_mail_parse(self): mail_dir = os.path.join(os.getcwd(), "mails//") mailbox_obj = mail.MailBox("ycolakoglu.bilisim@gmail.com", "totallysecurepass", "imap.google.com", 993) self.assertEqual(mailbox_obj.mails["mail_example"][0].message, "Hello boi this is a test\n") def test_xss_check(self): mail_dir = os.path.join(os.getcwd(), "mails//") mailbox_obj = mail.MailBox("ycolakoglu.bilisim@gmail.com", "totallysecurepass", "imap.google.com", 993) mailbox_obj.check_spam() self.assertEqual() if __name__ == '__main__': MailTest.run() MailBoxTest.run()