First things first: What I am trying to do is create a very simple postfix filter. it'll examine each message and upon finding a word, it will replace that word with another word, and inject the modified email back into the postfix queue. Here's what I have done so far:
#!/usr/bin/perl use Mail::Internet; $msg = Mail::Internet->new([ <> ]); $to = $msg->get('To'); #$content = join( '',@{$msg->body} ); @content = @{$msg->body}; print "To: " . $to; foreach $line (@content) { @words = split(/ /, $line); foreach $word (@words) { if ($word =~ /blah/) { $word = "something"; } print "$word "; } }
So, upon finding "blah" it will replace it with "something". here's a test email that I fed into it:
From root@val.vmsinfo.com Fri Dec 14 14:54:57 2007 Return-Path: <root@val.vmsinfo.com> X-Original-To: vxp Delivered-To: vxp@val.vmsinfo.com Received: by val.vmsinfo.com (Postfix, from userid 0) id 86A085FD705; Fri, 14 Dec 2007 14:54:57 -0500 (EST) To: vxp@val.vmsinfo.com Subject: hi Message-Id: <20071214195457.86A085FD705@val.vmsinfo.com> Date: Fri, 14 Dec 2007 14:54:57 -0500 (EST) From: root@val.vmsinfo.com (root) Status: O X-Status: X-Keywords: X-UID: 7 hi Val blah some more blah ..
and here's the resulting output:
[vxp@val ~]$ ./mail.pl test.txt To: vxp@val.vmsinfo.com hi Val something some more something .. [vxp@val ~]$
Now, as you see, the "\n" before the second line was lost in the output: the ".." is now on the first line.. Any suggestions ? :)

In reply to A regex question by vxp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.