For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2005 > Help: automated email forwarding similar to .forward









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help: automated email forwarding similar to .forward
Rich Fernandez

2005-07-27, 5:02 pm

Hi folks,

I'm working on a project where I'm given a pool of users and I have to
determine if there are any messages in their spool files, and if so, forward
them on to a new user.

I'm looking for functionality similar to what you get with a .forward file,
only I don't want the messages forwarded as soon as they come in. Instead
the messages will be spooled normally and forwarded at some arbitrary time
in the future.

What I'm looking for is advice on what perl modules/documentation I should
be looking at and maybe ideas on an approach. So far I've looked at
Mail::Box::Manager, Mail::Sender, and Mail::MBoxParser, but they don't seem
to be able to do what I want.

Of course if I'm not seeing the forest for the trees and there's a simple
non-Perl solution anyone would care to share, that would be appreciated as
well.

Thanks All!

richf
MNibble

2005-07-27, 5:02 pm

..forward is fine for that kind of thing, if you modify it to a pipe
where a perl skript reads from. Then pass the message throw it, while
doing what ever you like with it - for example sleep(3600) in fork / or
threaded spawn of you programm.

MNibble


Rich Fernandez wrote:
> Hi folks,
>
> I'm working on a project where I'm given a pool of users and I have to
> determine if there are any messages in their spool files, and if so, forward
> them on to a new user.
>
> I'm looking for functionality similar to what you get with a .forward file,
> only I don't want the messages forwarded as soon as they come in. Instead
> the messages will be spooled normally and forwarded at some arbitrary time
> in the future.
>
> What I'm looking for is advice on what perl modules/documentation I should
> be looking at and maybe ideas on an approach. So far I've looked at
> Mail::Box::Manager, Mail::Sender, and Mail::MBoxParser, but they don't seem
> to be able to do what I want.
>
> Of course if I'm not seeing the forest for the trees and there's a simple
> non-Perl solution anyone would care to share, that would be appreciated as
> well.
>
> Thanks All!
>
> richf

Rich Fernandez

2005-07-27, 5:02 pm

Thanks for the reply, but what I need to do is hang onto the messages for an
indefinite period of time, maybe days, during which time the box might get
rebooted, crash, etc. I can't rely on a process sleeping.

richf

> -----Original Message-----
> From: MNibble [mailto:ms@definitiv-ba.de]
> Sent: Wednesday, July 27, 2005 9:56 AM
> To: beginners@perl.org
> Subject: Re: Help: automated email forwarding similar to .forward
>
>
> .forward is fine for that kind of thing, if you modify it to a pipe
> where a perl skript reads from. Then pass the message throw it, while
> doing what ever you like with it - for example sleep(3600) in
> fork / or
> threaded spawn of you programm.
>
> MNibble
>
>
> Rich Fernandez wrote:
> and I have to
> and if so, forward
> a .forward file,
> come in. Instead
> arbitrary time
> modules/documentation I should
> they don't seem
> there's a simple
> appreciated as
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>

Wiggins d'Anconia

2005-07-27, 5:02 pm

"Because it's up-side down.
Why is that?
It makes replies harder to read.
Why not?
Please don't top-post." - Sherm Pendley, Mac OS X list

Rich Fernandez wrote:
> Thanks for the reply, but what I need to do is hang onto the messages for an
> indefinite period of time, maybe days, during which time the box might get
> rebooted, crash, etc. I can't rely on a process sleeping.
>
> richf
>


I would take a two step approach to this. Using the pipe method
mentioned earlier I would have the message pass to a script through the
pipe and have that script be incredibly simple and fast, all it should
do is write the message to your storage area in whatever manner is best.
The keys to this are that the message is received on STDIN, and you need
to be able to generate a unique name to prevent collisions. This allows
the SMTP server to not get bogged down doing a bunch of processing if
you get hit by a large number of messages rapidly.

Then your second stage can be slow and handle everything else, as it
seems like this fits your requirements anyways. You could setup some
kind of long running daemon to watch a directory and handle the files as
they come in, or I assume you could launch the script via a scheduler if
it is more of a periodic thing. As far as reading the message in,
parsing it, and then forwarding it, I guarantee the Mail::Box suite can
handle what you want, but it does have a learning curve. And since it is
intended to read various mail box formats it is a little trickier to get
it to read a single raw message (though it is possible, and not that
difficult once you understand Mail::Box's foundation). I have done
similar. I can't speak from experience on the other modules you listed.

Sorry I can't provide source what I wrote was under license,

http://danconia.org
Rich Fernandez

2005-07-27, 5:02 pm

Thanks Wiggins,

> As far as reading the message in,
> parsing it, and then forwarding it, I guarantee the Mail::Box
> suite can
> handle what you want, but it does have a learning curve.


You are right, I did not read the doco carefully enough. Sorry.

> Sorry I can't provide source what I wrote was under license,
>


No prob, I can work that out for myself.

Thanks again to you and the others that responded.

richf
Jay Savage

2005-07-27, 10:00 pm

On 7/27/05, Rich Fernandez <rfernandez@arrow.com> wrote:
> Thanks Wiggins,
>=20
>=20
> You are right, I did not read the doco carefully enough. Sorry.
>=20
>=20
> No prob, I can work that out for myself.
>=20
> Thanks again to you and the others that responded.
>=20
> richf
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>=20
>=20
>=20


Rich,

To flesh out Wiggins' response a little, I would do something like this:

use forward to pipe the mail that will take the messages and write
them to a specific directory. You can use something in the Mail::* or
MIME::* suites to parse them and save them in a usable format, and add
a "this message has been forward from" announcement if you want. Use
File::Temp or similar to give each a unique filename, preferably based
on the original or new recipients' email.

Then write a script based on Mail::Mailer or MIME:Lite to go through
the directory and mail them back out at your convenience. You can
write it as a daemon, run it as a cron job, or just run it from the
command line, depending on your needs. If you put useful information
in the filenames, you can easily send just the mail to one remote
user, or just them mail to one of the local users being forwarded.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com