Email processing in Python (was: e-mail processing in C)
Giorgos Keramidas
keramida at ceid.upatras.gr
Mon Mar 24 11:56:55 PDT 2008
On Mon, 24 Mar 2008 14:32:02 -0400, Robert Huff <roberthuff at rcn.com> wrote:
> I need to write a quick and not-too-dirty C program to process some
> e-mail. (Including dealing with mbox files.)
>
> Is there a standard library to do this? Respectfully,
No, there's no library for `email processing' in the C standard. You
can probably find a lot of non-standard ones, by Googling however :)
It's worth writing that plain C is the wrong language for this sort of
thing, if you ask me. There are excellent high-level libraries in Perl,
and Python to do this sort of thing. Email processing is going to
require a log of string processing, and C is notoriously 'tricky' for
this sort of thing.
As an example of the expressiveness of using a higher level language,
you can display the authors of all the messages in a UNIX mailbox with
the following short Python script:
import mailbox
m = mailbox.mbox('/home/keramida/mbox')
for message in m:
author = m['from]
print author
This is not just a `readable pseudo-code-like example'. It's *real*
Python code, that you can run _now_ in your Python shell.
To perform a similar task in plain C you will need several dozens of
lines of code, and it won't necessarily be as readable. It _may_ be
faster, in some cases, but it will probably won't be as 'safe'.
More information about the freebsd-questions
mailing list