mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-10 06:48:19 +02:00
Modifying management command to accept incoming mail from STDIN.
--HG-- branch : exim4_pipe
This commit is contained in:
parent
b7192e9149
commit
5cf07a1c7b
2 changed files with 32 additions and 14 deletions
|
|
@ -89,19 +89,23 @@ class Mailbox(models.Model):
|
|||
conn = MMDFTransport(self.location)
|
||||
return conn
|
||||
|
||||
def process_incoming_message(self, message):
|
||||
msg = Message()
|
||||
msg.mailbox = self
|
||||
msg.subject = message['subject'][0:255]
|
||||
msg.message_id = message['message-id'][0:255]
|
||||
msg.from_address = rfc822.parseaddr(message['from'])[1][0:255]
|
||||
msg.body = message.as_string()
|
||||
msg.save()
|
||||
message_received.send(sender=self, message=msg)
|
||||
return msg
|
||||
|
||||
def get_new_mail(self):
|
||||
connection = self.get_connection()
|
||||
new_mail = []
|
||||
for message in connection.get_message():
|
||||
msg = Message()
|
||||
msg.mailbox = self
|
||||
msg.subject = message['subject'][0:255]
|
||||
msg.message_id = message['message-id'][0:255]
|
||||
msg.from_address = rfc822.parseaddr(message['from'])[1][0:255]
|
||||
msg.body = message.as_string()
|
||||
msg.save()
|
||||
msg = self.process_incoming_message(message)
|
||||
new_mail.append(msg)
|
||||
message_received.send(sender=self, message=msg)
|
||||
return new_mail
|
||||
|
||||
def __unicode__(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue