Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7287 > unrolled thread
| Started by | Adam Tauno Williams <awilliam@whitemice.org> |
|---|---|
| First post | 2011-06-09 07:24 -0400 |
| Last post | 2011-06-09 07:24 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: smtp - python Adam Tauno Williams <awilliam@whitemice.org> - 2011-06-09 07:24 -0400
| From | Adam Tauno Williams <awilliam@whitemice.org> |
|---|---|
| Date | 2011-06-09 07:24 -0400 |
| Subject | Re: smtp - python |
| Message-ID | <mailman.50.1307618780.11593.python-list@python.org> |
On Wed, 2011-06-08 at 17:18 -0300, Josias L.G wrote:
> Hi for all,
> I'm very newbie in python and is very good language.
> I'm trying to adopt a example:
> import smtpd
> import asyncore
> server = smtpd.PureProxy(('127.0.0.1', 1025), ('mail', 25))
> asyncore.loop()
> I'm trying to copy the email that is send to another email in maildir format.
> Here, i'm reading about the mailbox module, however, i don't know how
>start that (get the email that was transferred and, trought mailbox
>module, save all mails in one file).
> an someone indicate something to me read ?.. examples... texts and
I don't know much about the "mailbox" module; the documentation looks
straight-forward enough, what exactly is the question?
<http://docs.python.org/library/mailbox.html>?
If you want to put all the messages in a single file use mbox.
import mailbox
mybox = mailbox.mbox('my.mbox', create=True)
mybox.lock()
for message in messages:
mybox.add(message)
mybox.flush()
mybox.unlock()
mybox.close()
To read a message into a Message object from a stream/file -
from email import message_from_file
message = message_from_file(stream)
The best way to serialize a Message to a stream seems to be
from email.generator import Generator
tmp = BLOBManager.ScratchFile() # Create a stream
g = Generator(tmp, mangle_from_=False, maxheaderlen=60)
g.flatten(message)
tmp.seek(0)
--
Adam Tauno Williams <awilliam@whitemice.org> LPIC-1, Novell CLA
<http://www.whitemiceconsulting.com>
OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba
Back to top | Article view | comp.lang.python
csiph-web