perl script hylafax email to fax gateway

Discussion in 'Programming/Scripts' started by nenad, Mar 23, 2007.

  1. nenad

    nenad Member

    Hello to everyone,

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

    I have some problems with following script:

    Code:
    #!/usr/bin/perl
    use MIME::Parser;
    use POSIX;
    
    my $tmp = "/tmp/mail-$$";
    mkdir $tmp, 0700;
    my $log_file = "/var/log/faxgw";
    
    my $parser = new MIME::Parser;
    $parser->output_under($tmp);
    
    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",
            "-R",
            "-m",
            "-n",
            "-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 TestPage.ps

    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 !!!
     
  2. nenad

    nenad Member

    One of the Developers of Hylafax sent to my email solution to this:

     

Share This Page