forked from mirror/django-mailbox
Improve documentation and flake8
This commit is contained in:
parent
88e17ea684
commit
6dcded0e75
4 changed files with 13 additions and 13 deletions
|
|
@ -300,7 +300,7 @@ class Mailbox(models.Model):
|
||||||
new = EmailMessage()
|
new = EmailMessage()
|
||||||
if (
|
if (
|
||||||
msg.is_multipart()
|
msg.is_multipart()
|
||||||
and not 'attachment' in msg.get('Content-Disposition', '')
|
and 'attachment' not in msg.get('Content-Disposition', '')
|
||||||
):
|
):
|
||||||
for header, value in msg.items():
|
for header, value in msg.items():
|
||||||
new[header] = value
|
new[header] = value
|
||||||
|
|
@ -647,20 +647,18 @@ class Message(models.Model):
|
||||||
return addresses
|
return addresses
|
||||||
|
|
||||||
def reply(self, message):
|
def reply(self, message):
|
||||||
"""Sends a message as a reply to this message instance.
|
"""Sends an EmailMessage as a reply to this message instance::
|
||||||
|
|
||||||
Although Django's e-mail processing will set both Message-ID
|
|
||||||
and Date upon generating the e-mail message, we will not be able
|
|
||||||
to retrieve that information through normal channels, so we must
|
|
||||||
pre-set it.
|
|
||||||
|
|
||||||
For conveninence, you can use django.core.mail.EmailMessage to build a Message instance::
|
|
||||||
|
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
|
|
||||||
message.reply(
|
message.reply(
|
||||||
EmailMessage(subject="pong", body="pongpong")
|
EmailMessage(subject="pong", body="pongpong")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Although Django's e-mail processing will set both Message-ID
|
||||||
|
and Date upon generating the e-mail message, we will not be able
|
||||||
|
to retrieve that information through normal channels, so we must
|
||||||
|
pre-set it.
|
||||||
"""
|
"""
|
||||||
from django.core.mail import EmailMessage as DjangoEmailMessage
|
from django.core.mail import EmailMessage as DjangoEmailMessage
|
||||||
|
|
||||||
|
|
@ -900,7 +898,6 @@ class MessageAttachment(models.Model):
|
||||||
return f'{self.get_filename()}: {self.document.url}'
|
return f'{self.get_filename()}: {self.document.url}'
|
||||||
return self.get_filename()
|
return self.get_filename()
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Message attachment')
|
verbose_name = _('Message attachment')
|
||||||
verbose_name_plural = _('Message attachments')
|
verbose_name_plural = _('Message attachments')
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,9 @@ class TestProcessEmail(EmailMessageTestCase):
|
||||||
)
|
)
|
||||||
msg = self.mailbox.record_outgoing_message(email_object.message())
|
msg = self.mailbox.record_outgoing_message(email_object.message())
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
msg.reply(Message(subject="ping", body="pong"))
|
||||||
|
|
||||||
self.assertTrue(msg.outgoing)
|
self.assertTrue(msg.outgoing)
|
||||||
|
|
||||||
actual_from = 'username@example.com'
|
actual_from = 'username@example.com'
|
||||||
|
|
@ -439,7 +442,7 @@ class TestProcessEmail(EmailMessageTestCase):
|
||||||
|
|
||||||
msg = self.mailbox.process_incoming_message(message)
|
msg = self.mailbox.process_incoming_message(message)
|
||||||
|
|
||||||
actual_email_object = msg.get_email_object()
|
_actual_email_object = msg.get_email_object()
|
||||||
|
|
||||||
self.assertTrue(msg.eml.name.endswith('.eml.gz'))
|
self.assertTrue(msg.eml.name.endswith('.eml.gz'))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,4 @@ class EmailTransport:
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ class ImapTransport(EmailTransport):
|
||||||
try:
|
try:
|
||||||
self.server.close()
|
self.server.close()
|
||||||
self.server.logout()
|
self.server.logout()
|
||||||
except (imaplib.IMAP4.error, OSError) as e:
|
except (imaplib.IMAP4.error, OSError) as e:
|
||||||
logger.warning(f'Failed to close IMAP connection, ignoring: {e}')
|
logger.warning(f'Failed to close IMAP connection, ignoring: {e}')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue