forked from mirror/django-mailbox
fix import
This commit is contained in:
parent
8f944190ad
commit
9bfc3e5df1
5 changed files with 20 additions and 42 deletions
|
|
@ -251,8 +251,6 @@ class Mailbox(models.Model):
|
||||||
conn = Office365Transport(
|
conn = Office365Transport(
|
||||||
self.location,
|
self.location,
|
||||||
self.username,
|
self.username,
|
||||||
port=self.port if self.port else None,
|
|
||||||
ssl=True,
|
|
||||||
folder=self.folder
|
folder=self.folder
|
||||||
)
|
)
|
||||||
conn.connect(self.client_id, self.client_secret, self.tenant_id)
|
conn.connect(self.client_id, self.client_secret, self.tenant_id)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,3 @@ class EmailTransport:
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def get_email_from_string(self, contents):
|
|
||||||
message = email.message_from_string(contents)
|
|
||||||
|
|
||||||
return message
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import O365
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
@ -10,13 +9,8 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Office365Transport(EmailTransport):
|
class Office365Transport(EmailTransport):
|
||||||
def __init__(
|
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(
|
self.integration_testing_subject = getattr(
|
||||||
settings,
|
settings,
|
||||||
'DJANGO_MAILBOX_INTEGRATION_TESTING_SUBJECT',
|
'DJANGO_MAILBOX_INTEGRATION_TESTING_SUBJECT',
|
||||||
|
|
@ -24,19 +18,16 @@ class Office365Transport(EmailTransport):
|
||||||
)
|
)
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
self.username = username
|
self.username = username
|
||||||
self.port = port
|
|
||||||
self.folder = folder
|
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):
|
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)
|
credentials = (client_id, client_secret)
|
||||||
|
|
||||||
self.account = O365.Account(credentials, auth_flow_type='credentials', tenant_id=tenant_id)
|
self.account = O365.Account(credentials, auth_flow_type='credentials', tenant_id=tenant_id)
|
||||||
|
|
|
||||||
|
|
@ -251,8 +251,6 @@ class Mailbox(models.Model):
|
||||||
conn = Office365Transport(
|
conn = Office365Transport(
|
||||||
self.location,
|
self.location,
|
||||||
self.username,
|
self.username,
|
||||||
port=self.port if self.port else None,
|
|
||||||
ssl=True,
|
|
||||||
folder=self.folder
|
folder=self.folder
|
||||||
)
|
)
|
||||||
conn.connect(self.client_id, self.client_secret, self.tenant_id)
|
conn.connect(self.client_id, self.client_secret, self.tenant_id)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import O365
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
@ -10,13 +9,8 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Office365Transport(EmailTransport):
|
class Office365Transport(EmailTransport):
|
||||||
def __init__(
|
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(
|
self.integration_testing_subject = getattr(
|
||||||
settings,
|
settings,
|
||||||
'DJANGO_MAILBOX_INTEGRATION_TESTING_SUBJECT',
|
'DJANGO_MAILBOX_INTEGRATION_TESTING_SUBJECT',
|
||||||
|
|
@ -24,19 +18,16 @@ class Office365Transport(EmailTransport):
|
||||||
)
|
)
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
self.username = username
|
self.username = username
|
||||||
self.port = port
|
|
||||||
self.folder = folder
|
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):
|
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)
|
credentials = (client_id, client_secret)
|
||||||
|
|
||||||
self.account = O365.Account(credentials, auth_flow_type='credentials', tenant_id=tenant_id)
|
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):
|
if condition and not condition(message):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
#TODO: implement archive function
|
||||||
|
|
||||||
yield message
|
yield message
|
||||||
except MessageParseError:
|
except MessageParseError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# TODO: delete all messages
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue