1
0
Fork 0

Office365 API mailbox support (#251)

* Update models.py, __init__.py, and office365.py

* Update setup.py

* Office365Transport properties

* Update .gitignore

* wrong folder stage

* Update models.py

* Update office365.py and models.py

* office365 implementation

* Update office365.py

* clear code

* fix import

* Update readme.rst

* archive and delete

* fix and documentation

* removed build folder

* missing archive

Co-authored-by: Pietro Mingo <p.mingo@intac.it>
Co-authored-by: Serafim Bordei <s.bordei@intac.it>
This commit is contained in:
Pietro Mingo 2023-01-16 22:23:38 +01:00 committed by GitHub
parent 40263b6670
commit cefbcdebd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 129 additions and 3 deletions

View file

@ -31,7 +31,7 @@ from django_mailbox import utils
from django_mailbox.signals import message_received
from django_mailbox.transports import Pop3Transport, ImapTransport, \
MaildirTransport, MboxTransport, BabylTransport, MHTransport, \
MMDFTransport, GmailImapTransport
MMDFTransport, GmailImapTransport, Office365Transport
logger = logging.getLogger(__name__)
@ -189,6 +189,30 @@ class Mailbox(models.Model):
return None
return folder[0]
@property
def client_id(self):
"""Returns (if specified) the client id for Office365."""
client_id = self._query_string.get('client_id', None)
if not client_id:
return None
return client_id[0]
@property
def client_secret(self):
"""Returns (if specified) the client secret for Office365."""
client_secret = self._query_string.get('client_secret', None)
if not client_secret:
return None
return client_secret[0]
@property
def tenant_id(self):
"""Returns (if specified) the tenant id for Office365."""
tenant_id = self._query_string.get('tenant_id', None)
if not tenant_id:
return None
return tenant_id[0]
def get_connection(self):
"""Returns the transport instance for this mailbox.
@ -223,6 +247,14 @@ class Mailbox(models.Model):
ssl=self.use_ssl
)
conn.connect(self.username, self.password)
elif self.type == 'office365':
conn = Office365Transport(
self.location,
self.username,
folder=self.folder,
archive=self.archive
)
conn.connect(self.client_id, self.client_secret, self.tenant_id)
elif self.type == 'maildir':
conn = MaildirTransport(self.location)
elif self.type == 'mbox':