[Tutor] Working with Email question

Joel Ricker joejava@dragoncat.net
Sat, 23 Feb 2002 17:34:47 -0500

----- Original Message -----
From: Sheila King <sheila@thinkspot.net>

> Well, I don't know if you have to save them to a local file or not.
> rfc822 will read from stdin (and actually, anything that will read from
> a file can be made to read from stdin).

Right, as Danny was so good as to point out

> The mail filters I've read
> reside on my web host, who hosts my email addresses, and whenever an
> incoming email message arrives, I have my filters invoked by .qmail
> (they use Qmail as a Mail Transfer Agent). It sounds like you are trying
> to retrieve the mail via pop and then filter it.

Correct.  I've got two systems that I plan to run a filter through, once
that may be possible to get to the physical mailbox files, the other not so
the best approach I see is to log in using poplib -- with plans to use IMAP
as an option since one mail server supports it.  poplib is pretty
straightforward, allowing you to easily connect and extract a particular
message in a flat file.

> I've not worked with
> the poplib, but I would assume you could read the messages straight from
> stdin as the poplib is retrieving them, into an instance of rfc822.

Thats right, poplib reads it in through stdin.  Just learned actually that I
can fetch just the headers using poplib.top(messagenumber, 0) so then I'll
just need to need to fetch the message as a whole and subtract the header --
so I can get just the header and just the body.

> If you use rfc822, you have to read in the body separately (rfc822 only
> reads in the headers).

Ok. Thanks.

> Then you will have to look for the content boundaries or just load the
> whole body. Yes. When filtering for banned words, you will encounter
> other problems, such as HTML mark-up and other types of encoding (such
> as quoted-printable and so on...)

Right, didn't expect this to be real simple :) But it'll be a learning
experience for sure.