Results 1 to 3 of 3
  1. #1

    Seeking Perl or PHP examples of email interception

    Greetings:

    RE: Seeking Perl or PHP examples of email interception on the mail server itself.

    I've complete access to our mail servers, and I'm looking to write a small Perl or PHP application which can intercept an email to a specific email box, and from there do the following:

    Determine if the email is plain text or HTML/MIME-based with or without an attachment.

    Insert one to several lines into the email in such a way it does not break any content encoding.

    We are using qmail/vpopmail, so I know how to use a .qmail forward file where I can get info from STDIN and pipe out to STDOUT to feed into the actual mail box.

    What I've been having trouble with is the inserting of the text so it comes in the body after any content endcoding start but before the content encoding end.

    Can anyone share any good Perl or PHP libraries, code, etc. for handling this endeavor?

    If it helps, this is some quick and dirty Perl code I drafted up which does work with plain text, but not with HTML/MIME et al:

    use strict;
    use Mail::Internet;
    my $message = new Mail::Internet \*STDIN;
    my $from = $message->head->get("From");
    my $domain = (split(/@/, $from))[1];
    $domain = (split(/>/,$domain))[0];
    my $customer_id = '##hs_customer_id:' . $domain . '##' . "\n\n";
    my $body = $message->body();

    my $first_line = shift(@{$body});
    my $second_line = shift(@{$body});
    unshift(@{$body}, $customer_id);
    unshift(@{$body}, $second_line);
    unshift(@{$body}, $first_line);

    $message->body($body);
    $message->print( \*STDOUT );
    close($message);
    exit (99);


    Thank you.

  2. #2
    Join Date
    May 2009
    Posts
    766
    You might have to deal with the message at a lower level. I'd probably look at the Mail::Internet::asString() method. Then, find the content encoding and slip your stuff in right after.

  3. #3
    I've done this same thing before using Qmail + PHP/CLI. Now days I know there are some built-in solutions (and PEAR based solutions) but I prefer to use a pre-built class because it provides a more complete end-to-end solution.

    When I did this I used a class from PHPClasses. I guess I'm too new here to post a URL so just google "PHP Classes" and they'll be the first match.

    Once you're on the site, search for the word "MIME" and you'll find several solutions for encoding and decoding mime based emails.

    I hope this helps.

Similar Threads

  1. Email interception
    By dnki in forum Hosting Security and Technology
    Replies: 14
    Last Post: 05-22-2009, 06:08 AM
  2. Seeking Talented Perl/PHP Programmer
    By tylercruz in forum Employment / Job Offers
    Replies: 2
    Last Post: 07-02-2008, 02:28 AM
  3. Seeking web programmer: web data extraction in Perl
    By david22 in forum Employment / Job Offers
    Replies: 5
    Last Post: 06-27-2006, 10:25 AM
  4. Seeking PERL programmer
    By EdgeWise in forum Employment / Job Offers
    Replies: 1
    Last Post: 02-24-2005, 12:36 AM
  5. CGI/Perl/ASP Coder Seeking Project/Web Designers
    By procgi in forum Employment / Job Offers
    Replies: 0
    Last Post: 03-28-2004, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •