Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter via Perl 1

Status
Not open for further replies.

unixkid

IS-IT--Management
Joined
May 22, 2001
Messages
105
Location
US
Newbie in need of help....Would like to run a Perl script form .forward file and redirect mail to dir called /opt/newmail
 
in your .forward file.

[tt]| cat >> /opt/newmail/$USER.mail[/tt]

Why do you want to do this by the way? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Yes this makes sense but I need to strip attachments and dump those into a dir. Possible?
 
Possible yes -- a Perl script in that command line instead of [tt]cat[/tt] would work and, in the script, you could filter the mail message in any way you want.

What are you trying to achive here? Do you want to stop your users receiving email with attachments or .....? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
What we are trying to accomplish strip data coming from an email attachment outside the US into a dir local to the unix server. My issue is not knowing how to write the piece to stip off the attachment
 
Ok, here's an example to start you thinking.
[tt]
#!/usr/bin/perl -w
use strict;
my $attachment_file = shift
or die "I need the attachment filename on the command line please\n";
while(<>){
next unless /Start of attachment/;
open(F,$attachment_file) || die &quot;can't write file $!\n&quot;;
while(<>){
last if /End of attachment/;
print F $_;
}
close(F);
}
[/tt]

The logic of the script runs like this:

Read through the mail until I find the string that marks the begininning of an attachment.
Open a file to store the attachment.
Print each line from the mail into the attachment file, until I find the string that marks the end of an attachment.
Close the attachment file.

You with me? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Yes I'm with you on your script. After closing the attachment can it be moved saved as a file into a dir called /opt/newmail
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top