On 3/6/06 6:33 PM, "Theo v. Werkhoven"
Mon, 06 Mar 2006, by ian.marlier@studentuniverse.com:
Hey, all --
I'm trying to find some kind of a simple utility/script that will allow me to list the messages in an arbitrary POP3 mailbox to STDOUT.
Anyone have thoughts on the easiest way to do this?
Well, "easy is relative", it's all in the eye of the beholder :) Here's my concuction: +++++++++++++++++++++ #!/usr/bin/env python
from poplib import * import re server = POP3('your.pop.server') server.user('youraccount') server.pass_('yourpw')
messages = server.stat()[0] if messages > 0: for mail in range(messages): headers = server.top(mail+1,0)[1] for header in headers: if re.match("^From:.*",header): print re.match("^From:.*",header).group() if re.match("^Return_Path:.*",header): print re.match("^return-Path:.*",header).group() if re.match("^Subject:.*",header): print re.match("^Subject:.*",header).group() if re.match("^Date:.*",header): print re.match("^Date:.*",header).group() print else: print "Sorry, no messages" +++++++++++++++++++++
$ python popheads.py Date: Mon, 6 Mar 2006 23:55:07 +0100 (CET) From: Theo van Werkhoven
Subject: pophead.py test From: Ken Schneider
Date: Mon, 06 Mar 2006 17:58:19 -0500 Subject: Re: [SLE] OOo Quickstart Icon From: "Cynthia Wilkerson"
Subject: Diamond Equities Date: Mon, 06 Mar 2006 10:58:08 +0000 From: "Kai Ponte"
Date: Mon, 06 Mar 2006 15:24:00 -0800 Subject: Re: [SLE] Xen as replacement for vmware Date: Mon, 6 Mar 2006 23:26: 0 +0180 From: "Cheryl Kenny"
Subject: re: Huge news shows promise
Theo, that's great -- exactly what I was looking for! ( As far as the other suggestions go: - I couldn't figure out a way to get fetchmail to give me a listing of the mailbox contents. Doesn't mean it can't be done, just means that I couldn't figure out how to do it. I do think that using the --mta flag to grab messages and then send them to a script of some kind would probably do it, though. - I _wish_ that `cat /var/mail/spool/mailbox` was an option, but I'm trying to test for successful delivery to an Exchange server. (shudder) - I did manage to put together an expect script that worked; to say that it wasn't robust, though, is significant understatement. Mostly because I don't know TCL syntax. Switching to the expect module in Perl or something would have been my next step, if Theo weren't so smart... Thanks, all! - Ian