forked from mirror/django-mailbox
Minor alterations to @yellowcap's pull request submission:
* Using a query parameter argument (rather than the entire query string) to specify the folder into which e-mail messages should be archived. * Duplicating the IMAP tests; this could probably be a bit more simply done, but we'll at least be verifying both archived and non-archived use cases. * Simplifying some aspects of the documentation to include references to this new feature.
This commit is contained in:
parent
0e0c6cf170
commit
02567acdc2
3 changed files with 70 additions and 18 deletions
|
|
@ -18,7 +18,7 @@ from django_mailbox.transports import Pop3Transport, ImapTransport,\
|
|||
MMDFTransport
|
||||
from django_mailbox.signals import message_received
|
||||
import six
|
||||
from six.moves.urllib.parse import unquote, urlparse
|
||||
from six.moves.urllib.parse import parse_qs, unquote, urlparse
|
||||
|
||||
from .utils import convert_header_to_unicode
|
||||
|
||||
|
|
@ -115,6 +115,10 @@ class Mailbox(models.Model):
|
|||
def _protocol_info(self):
|
||||
return urlparse(self.uri)
|
||||
|
||||
@property
|
||||
def _query_string(self):
|
||||
return parse_qs(self._protocol_info.query)
|
||||
|
||||
@property
|
||||
def _domain(self):
|
||||
return self._protocol_info.hostname
|
||||
|
|
@ -148,7 +152,10 @@ class Mailbox(models.Model):
|
|||
|
||||
@property
|
||||
def archive(self):
|
||||
return self._protocol_info.query
|
||||
archive_folder = self._query_string.get('archive', None)
|
||||
if not archive_folder:
|
||||
return None
|
||||
return archive_folder[0]
|
||||
|
||||
def get_connection(self):
|
||||
if not self.uri:
|
||||
|
|
|
|||
|
|
@ -6,6 +6,47 @@ from django_mailbox.transports import ImapTransport, Pop3Transport
|
|||
|
||||
|
||||
class TestImapTransport(EmailMessageTestCase):
|
||||
def setUp(self):
|
||||
self.arbitrary_hostname = 'one.two.three'
|
||||
self.arbitrary_port = 100
|
||||
self.ssl = False
|
||||
self.transport = ImapTransport(
|
||||
self.arbitrary_hostname,
|
||||
self.arbitrary_port,
|
||||
self.ssl
|
||||
)
|
||||
self.transport.server = None
|
||||
super(TestImapTransport, self).setUp()
|
||||
|
||||
def test_get_email_message(self):
|
||||
with mock.patch.object(self.transport, 'server') as server:
|
||||
server.search.return_value = (
|
||||
'OK',
|
||||
[
|
||||
'One', # This is totally arbitrary
|
||||
]
|
||||
)
|
||||
server.fetch.return_value = (
|
||||
'OK',
|
||||
[
|
||||
[
|
||||
'1 (RFC822 {8190}', # Wat?
|
||||
self._get_email_as_text('generic_message.eml')
|
||||
],
|
||||
')',
|
||||
]
|
||||
)
|
||||
actual_messages = list(self.transport.get_message())
|
||||
|
||||
self.assertEqual(len(actual_messages), 1)
|
||||
|
||||
actual_message = actual_messages[0]
|
||||
expected_message = self._get_email_object('generic_message.eml')
|
||||
|
||||
self.assertEqual(expected_message, actual_message)
|
||||
|
||||
|
||||
class TestImapArchivedTransport(EmailMessageTestCase):
|
||||
def setUp(self):
|
||||
self.arbitrary_hostname = 'one.two.three'
|
||||
self.arbitrary_port = 100
|
||||
|
|
@ -18,7 +59,7 @@ class TestImapTransport(EmailMessageTestCase):
|
|||
self.archive
|
||||
)
|
||||
self.transport.server = None
|
||||
super(TestImapTransport, self).setUp()
|
||||
super(TestImapArchivedTransport, self).setUp()
|
||||
|
||||
def test_get_email_message(self):
|
||||
with mock.patch.object(self.transport, 'server') as server:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue