From 9bfc3e5df115d6d154568af327b898a4888d2839 Mon Sep 17 00:00:00 2001 From: Pietro Mingo Date: Fri, 29 Jul 2022 17:26:28 +0200 Subject: [PATCH] fix import --- build/lib/django_mailbox/models.py | 2 -- build/lib/django_mailbox/transports/base.py | 4 --- .../django_mailbox/transports/office365.py | 25 +++++----------- django_mailbox/models.py | 2 -- django_mailbox/transports/office365.py | 29 ++++++++----------- 5 files changed, 20 insertions(+), 42 deletions(-) diff --git a/build/lib/django_mailbox/models.py b/build/lib/django_mailbox/models.py index b9f84cc..c7c03f3 100644 --- a/build/lib/django_mailbox/models.py +++ b/build/lib/django_mailbox/models.py @@ -251,8 +251,6 @@ class Mailbox(models.Model): conn = Office365Transport( self.location, self.username, - port=self.port if self.port else None, - ssl=True, folder=self.folder ) conn.connect(self.client_id, self.client_secret, self.tenant_id) diff --git a/build/lib/django_mailbox/transports/base.py b/build/lib/django_mailbox/transports/base.py index 9d507a2..a3a2bc0 100644 --- a/build/lib/django_mailbox/transports/base.py +++ b/build/lib/django_mailbox/transports/base.py @@ -10,7 +10,3 @@ class EmailTransport: return message - def get_email_from_string(self, contents): - message = email.message_from_string(contents) - - return message diff --git a/build/lib/django_mailbox/transports/office365.py b/build/lib/django_mailbox/transports/office365.py index e60531b..47c86d6 100644 --- a/build/lib/django_mailbox/transports/office365.py +++ b/build/lib/django_mailbox/transports/office365.py @@ -1,4 +1,3 @@ -import O365 import logging from django.conf import settings @@ -10,13 +9,8 @@ logger = logging.getLogger(__name__) class Office365Transport(EmailTransport): def __init__( - self, hostname, username, port=None, ssl=False, tls=False, folder=None + self, hostname, username, folder=None ): - self.max_message_size = getattr( - settings, - 'DJANGO_MAILBOX_MAX_MESSAGE_SIZE', - False - ) self.integration_testing_subject = getattr( settings, 'DJANGO_MAILBOX_INTEGRATION_TESTING_SUBJECT', @@ -24,19 +18,16 @@ class Office365Transport(EmailTransport): ) self.hostname = hostname self.username = username - self.port = port self.folder = folder - self.tls = tls - if ssl: - #self.transport = imaplib.IMAP4_SSL - if not self.port: - self.port = 993 - else: - #self.transport = imaplib.IMAP4 - if not self.port: - self.port = 143 def connect(self, client_id, client_secret, tenant_id): + try: + import O365 + except ImportError: + raise ValueError( + "Install o365 to use oauth2 auth for office365" + ) + credentials = (client_id, client_secret) self.account = O365.Account(credentials, auth_flow_type='credentials', tenant_id=tenant_id) diff --git a/django_mailbox/models.py b/django_mailbox/models.py index b9f84cc..c7c03f3 100644 --- a/django_mailbox/models.py +++ b/django_mailbox/models.py @@ -251,8 +251,6 @@ class Mailbox(models.Model): conn = Office365Transport( self.location, self.username, - port=self.port if self.port else None, - ssl=True, folder=self.folder ) conn.connect(self.client_id, self.client_secret, self.tenant_id) diff --git a/django_mailbox/transports/office365.py b/django_mailbox/transports/office365.py index e60531b..2c137b3 100644 --- a/django_mailbox/transports/office365.py +++ b/django_mailbox/transports/office365.py @@ -1,4 +1,3 @@ -import O365 import logging from django.conf import settings @@ -10,13 +9,8 @@ logger = logging.getLogger(__name__) class Office365Transport(EmailTransport): def __init__( - self, hostname, username, port=None, ssl=False, tls=False, folder=None + self, hostname, username, folder=None ): - self.max_message_size = getattr( - settings, - 'DJANGO_MAILBOX_MAX_MESSAGE_SIZE', - False - ) self.integration_testing_subject = getattr( settings, 'DJANGO_MAILBOX_INTEGRATION_TESTING_SUBJECT', @@ -24,19 +18,16 @@ class Office365Transport(EmailTransport): ) self.hostname = hostname self.username = username - self.port = port self.folder = folder - self.tls = tls - if ssl: - #self.transport = imaplib.IMAP4_SSL - if not self.port: - self.port = 993 - else: - #self.transport = imaplib.IMAP4 - if not self.port: - self.port = 143 def connect(self, client_id, client_secret, tenant_id): + try: + import O365 + except ImportError: + raise ValueError( + "Install o365 to use oauth2 auth for office365" + ) + credentials = (client_id, client_secret) self.account = O365.Account(credentials, auth_flow_type='credentials', tenant_id=tenant_id) @@ -56,8 +47,12 @@ class Office365Transport(EmailTransport): if condition and not condition(message): continue + #TODO: implement archive function + yield message except MessageParseError: continue + + # TODO: delete all messages return