If I isolate the sub  find_exp_to into a separate script, it breaks on Postfix's Delivered-To: and X-Original-To: headers when an email is piped through by hand. Also your regexes search through the entire email, so if the body contains "To: blah@blah" that probably gets returned..

To parse email, it will be useful to get explicit about the header and the body - probably best to use a module that does that for you like Mail::Internet, or look in the Perl Cookbook where you'll find the use of the  .. range operator to determine whether you're in headers or body (P179 of the first edition)

I would work on parsing the email first, without the mysql stuff. Have your filter write output of the parsed email to a disk file you can verify as a debugging step, so that you can make sure the piping through Postfix is working. You should see the filter return properly through Postfix's very imformative logs, but before installing the filter your test case should work from the command line, as you are already doing..

Most importantly,
use strict; use warnings;


In reply to Re: postfix filter... by hsinclai
in thread postfix filter... by Ang-st

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.