Listing contents of a POP3 mailbox from the command line
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?
Marlier, Ian wrote:
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?
I wonder if perhaps fetchmail would let you do something like that? /Per Jessen, Zürich
On Mon, 6 Mar 2006 13:27:53 -0500, you wrote:
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?
cat /var/spool/mail/<boxaddr>/* ? Mike- -- If you're not confused, you're not trying hard enough. -- Please note - Due to the intense volume of spam, we have installed site-wide spam filters at catherders.com. If email from you bounces, try non-HTML, non-encoded, non-attachments,
Michael W Cocke wrote:
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?
cat /var/spool/mail/<boxaddr>/* ?
Um, not exactly using POP3 is it? :-) /Per Jessen, Zürich
Maybe Pine is still available. Or maybe fetchmail plus cat /var/spool/mail.... Or, the most basic 'telnet server 110'. L.
Michael W Cocke wrote:
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?
cat /var/spool/mail/<boxaddr>/* ?
Um, not exactly using POP3 is it? :-)
/Per Jessen, Zürich
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
Tue, 07 Mar 2006, by twe-suse.e@ferrets4me.xs4all.nl: [..]
Here's my concoction: +++++++++++++++++++++ #!/usr/bin/env python
$ diff -u popheads.py.old popheads.py --- popheads.py.old 2006-03-07 00:41:50.983956636 +0100 +++ popheads.py 2006-03-07 00:38:38.427101171 +0100 @@ -17,8 +17,8 @@ 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("^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): Theo -- Theo v. Werkhoven Registered Linux user# 99872 http://counter.li.org ICBM 52 13 26N , 4 29 47E. + ICQ: 277217131 SUSE 9.2 + Jabber: muadib@jabber.xs4all.nl Kernel 2.6.8 + See headers for PGP/GPG info. Claimer: any email I receive will become my property. Disclaimers do not apply.
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
participants (6)
-
Ian Marlier
-
Lorenzo Cerini
-
Marlier, Ian
-
Michael W Cocke
-
Per Jessen
-
Theo v. Werkhoven