mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
add imaps STARTTLS support (#94)
* add imaps STARTTLS support using +tls * documentation on STARTTLS
This commit is contained in:
parent
0f990a44d5
commit
8a73076427
3 changed files with 18 additions and 7 deletions
|
|
@ -144,6 +144,11 @@ class Mailbox(models.Model):
|
||||||
"""Returns whether or not this mailbox's connection uses SSL."""
|
"""Returns whether or not this mailbox's connection uses SSL."""
|
||||||
return '+ssl' in self._protocol_info.scheme.lower()
|
return '+ssl' in self._protocol_info.scheme.lower()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def use_tls(self):
|
||||||
|
"""Returns whether or not this mailbox's connection uses STARTTLS."""
|
||||||
|
return '+tls' in self._protocol_info.scheme.lower()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def archive(self):
|
def archive(self):
|
||||||
"""Returns (if specified) the folder to archive messages to."""
|
"""Returns (if specified) the folder to archive messages to."""
|
||||||
|
|
@ -174,6 +179,7 @@ class Mailbox(models.Model):
|
||||||
self.location,
|
self.location,
|
||||||
port=self.port if self.port else None,
|
port=self.port if self.port else None,
|
||||||
ssl=self.use_ssl,
|
ssl=self.use_ssl,
|
||||||
|
tls=self.use_tls,
|
||||||
archive=self.archive,
|
archive=self.archive,
|
||||||
folder=self.folder
|
folder=self.folder
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class ImapTransport(EmailTransport):
|
class ImapTransport(EmailTransport):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hostname, port=None, ssl=False, archive='', folder=None
|
self, hostname, port=None, ssl=False, tls=False,
|
||||||
|
archive='', folder=None,
|
||||||
):
|
):
|
||||||
self.max_message_size = getattr(
|
self.max_message_size = getattr(
|
||||||
settings,
|
settings,
|
||||||
|
|
@ -34,6 +35,7 @@ class ImapTransport(EmailTransport):
|
||||||
self.port = port
|
self.port = port
|
||||||
self.archive = archive
|
self.archive = archive
|
||||||
self.folder = folder
|
self.folder = folder
|
||||||
|
self.tls = tls
|
||||||
if ssl:
|
if ssl:
|
||||||
self.transport = imaplib.IMAP4_SSL
|
self.transport = imaplib.IMAP4_SSL
|
||||||
if not self.port:
|
if not self.port:
|
||||||
|
|
@ -45,6 +47,8 @@ class ImapTransport(EmailTransport):
|
||||||
|
|
||||||
def connect(self, username, password):
|
def connect(self, username, password):
|
||||||
self.server = self.transport(self.hostname, self.port)
|
self.server = self.transport(self.hostname, self.port)
|
||||||
|
if self.tls:
|
||||||
|
self.server.starttls()
|
||||||
typ, msg = self.server.login(username, password)
|
typ, msg = self.server.login(username, password)
|
||||||
|
|
||||||
if self.folder:
|
if self.folder:
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ POP3 and IMAP as well as local file-based mailboxes.
|
||||||
|
|
||||||
.. table:: 'Protocol' Options
|
.. table:: 'Protocol' Options
|
||||||
|
|
||||||
============ ================ =================================================================================================================================================================
|
============ ================ ====================================================================================================================================================================
|
||||||
Mailbox Type 'Protocol':// Notes
|
Mailbox Type 'Protocol':// Notes
|
||||||
============ ================ =================================================================================================================================================================
|
============ ================ ====================================================================================================================================================================
|
||||||
POP3 ``pop3://`` Can also specify SSL with ``pop3+ssl://``
|
POP3 ``pop3://`` Can also specify SSL with ``pop3+ssl://``
|
||||||
IMAP ``imap://`` Can also specify SSL with ``imap+ssl://``; additional configuration is also possible: see :ref:`pop3-and-imap-mailboxes` for details.
|
IMAP ``imap://`` Can also specify SSL with ``imap+ssl://`` or STARTTLS with ``imap+tls``; additional configuration is also possible: see :ref:`pop3-and-imap-mailboxes` for details.
|
||||||
Gmail IMAP ``gmail+ssl://`` Uses OAuth authentication for Gmail's IMAP transport. See :ref:`gmail-oauth` for details.
|
Gmail IMAP ``gmail+ssl://`` Uses OAuth authentication for Gmail's IMAP transport. See :ref:`gmail-oauth` for details.
|
||||||
Maildir ``maildir://``
|
Maildir ``maildir://``
|
||||||
Mbox ``mbox://``
|
Mbox ``mbox://``
|
||||||
|
|
@ -19,7 +19,7 @@ POP3 and IMAP as well as local file-based mailboxes.
|
||||||
MH ``mh://``
|
MH ``mh://``
|
||||||
MMDF ``mmdf://``
|
MMDF ``mmdf://``
|
||||||
Piped Mail *empty* See :ref:`receiving-mail-from-exim4-or-postfix`
|
Piped Mail *empty* See :ref:`receiving-mail-from-exim4-or-postfix`
|
||||||
============ ================ =================================================================================================================================================================
|
============ ================ ====================================================================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
@ -42,8 +42,9 @@ Basic IMAP Example: ``imap://username:password@server``
|
||||||
|
|
||||||
Basic POP3 Example: ``pop3://username:password@server``
|
Basic POP3 Example: ``pop3://username:password@server``
|
||||||
|
|
||||||
Most mailboxes these days are SSL-enabled;
|
Most mailboxes these days are SSL-enabled;
|
||||||
if yours is, add ``+ssl`` to the protocol section of your URI.
|
if yours use plain SSL add ``+ssl`` to the protocol section of your URI,
|
||||||
|
but for STARTTLS add ``+tls``.
|
||||||
Also, if your username or password include any non-ascii characters,
|
Also, if your username or password include any non-ascii characters,
|
||||||
they should be URL-encoded (for example, if your username includes an
|
they should be URL-encoded (for example, if your username includes an
|
||||||
``@``, it should be changed to ``%40`` in your URI).
|
``@``, it should be changed to ``%40`` in your URI).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue