[plug] print contents list of mbox folder
Bernd Felsche
bernie at innovative.iinet.net.au
Mon Sep 18 15:00:10 WST 2006
Russell <russellsteicke at gmail.com> writes:
>On 9/17/06, Gavin Chester <sales at ecosolutions.com.au> wrote:
>> Can't find _anywhere_ instruction on how I can print (hardcopy or
>> to a formatted file) the list of emails in a folder such as
>> /inbox/plug/ that is in (evolution) mbox format. That is, I want
>> to print out the email list with just the 'from', 'to', 'subject'
>> being almost all that shows such that the output resembles what
>> you see when looking at the list of email in your email client.
>Trivial mbox parsing is easy. Handling all the corner cases is hard.
>Continuation lines (header lines starting with white space continue
>the previous line) and slightly different From_ line formats are the
>most obvious. And I think that header field names are case-folded,
>although almost everything uses "From" and "To" instead of "from" and
>"to".
>Here's a trivial awk script that ignores most of those cases:
>#!/usr/bin/awk -f
>BEGIN { Inheaders=0; }
>/^From / { Inheaders=1; }
>/^(To|From|Subject):/ { if (Inheaders) { print $0; } }
>/^$/ { if (Inheaders) { Inheaders=0; print ""; } }
Python has some handy modules for that sort of thing.
This should get you started; there are examples in the Python
documentation that you may not have installed in
/usr/share/doc/packages/python/Demo/
e.g. scripts/mboxconvert.py
Modules email and mailbox are quite useful.
(module rfc822 has been superseded by email)
http://docs.python.org/lib/module-mailbox.html
http://docs.python.org/lib/module-email.html
--
/"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
\ / ASCII ribbon campaign | "Laws do not persuade just because
X against HTML mail | they threaten."
/ \ and postings | Lucius Annaeus Seneca, c. 4BC - 65AD.
More information about the plug
mailing list