View Single Post
Old 23rd March 2007, 09:26
nenad nenad is offline
Senior Member
Join Date: Nov 2005
Location: Novi Sad, Serbia
Posts: 416
Thanks: 13
Thanked 5 Times in 5 Posts
Default perl script hylafax email to fax gateway

Hello to everyone,

I am setting up hylafax server, and everything is working except one detail:

I have some problems with following script:

use MIME::Parser;
use POSIX;

my $tmp = "/tmp/mail-$$";
mkdir $tmp, 0700;
my $log_file = "/var/log/faxgw";

my $parser = new MIME::Parser;

my $entity = $parser->parse(\*STDIN);

my @parts;
my @entities = ($entity);

while ($_ = shift(@entities))
    my @p;
    if (@p = $_->parts)
        unshift @entities, @p;
    } else
        push @parts, $_;

my $from = $entity->head->get('From');$from =~ s/\n//go;
my $oldsubject = $entity->head->get('Subject');$oldsubject =~ s/\[(\d+)\]\s*(.*)//go;$number = $1;
my $subject = $2; 

system( "sendfax",
        "-f", $from,
        "-r", $subject,
        "-d", $number,
        map ({$_->bodyhandle->path() } @parts)

#system("/bin/rm", "-rf", $tmp);

my $logmessage = strftime("%d.%m.%Y %H:%M:%S", localtime) . " Sent fax, from: $from, to: $number, regarding: $subject.\n";
open (my $log, ">>", $log_file) || die "Could not open $file for append: $!";
print $log $logmessage;
close $log;
This script is doing following:

strips out from email:
- text component
- html component
- attachements

it creates in /tmp/ directory

mail-16738 sub-directory and within it it creates

msg-1174598017-16738-0 subdirectory and within it creates files

msg-16738-1.txt msg-16738-2.html

I think it's done somewhere within loop:

while ($_ = shift(@entities)) ...etc )

and the script is invoking system command sendfax to send a fax.

What I need is limiting to extracting only attachement component out of email, or parsing just a attachement to sendfax, withouth text and html components.

Considering that I don't have any knowledge about perl , please HELP !!!
Nenad Bulatovic
Debian Lenny & ISPConfig 3
Reply With Quote
Sponsored Links