Mail and text extraction

Gerhard Häring gh at ghaering.de
Mon Apr 21 01:45:55 CEST 2003


* Dino Levy <dino_levy at mindlessSPAM.com> [2003-04-21 01:19 +0200]:
> I have the following problem:
> I'm trying to make a script which will connect to POP3 server, print
> number of mails, print their size and subject, and then will ask the user
> which mail should be downloaded...
> So far so good, but I have problem: 
> [...]
> The
> mail looks like this:
> Agnell company
> 
> -Worker		Payment
> Joe Doe		500$
> Mary Smith	550$
> Karen Bay	495$
> 
> -New Employee: Peter Maley
> 
> some text...
> 
> -Raises:
> some text
> 
> And all you want to do is to connect to your POP3 server, and download
> the section called Raises ( for example, two or three lines after the
> title ), so all you want to do is to download those few lines containing your
> text... ( ONLY those lines, not the whole e-mail ) [...]

AFAIK, the POP3 protocol doesn't support downloading parts of emails. To
my knowledge, you can either download the headers (via TOP) or the body
(via RETR).

Of course I'd suppose you could download *up to* the part you're
interested in, then after reading as far as you're interested, close the
socket connection. That's not nice, but it should be possible :-) It'd
also involve doing it low-level style with sockets.

Perhaps you could use IMAP instead? I believe that with IMAP it is
possible to download parts of email messages (MIME parts), but even here
I doubt it's easily possible to cleanly download only a few lines of a
MIME part.

Gerhard
-- 
mail:   gh at ghaering.de
web:    http://ghaering.de/





More information about the Python-list mailing list