Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 23rd March 2007, 08:26
nenad nenad is offline
Senior Member
 
Join Date: Nov 2005
Location: Novi Sad, Serbia
Posts: 415
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:

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 !!!
__________________
Nenad Bulatovic
---------------
Debian Lenny & ISPConfig 3
Reply With Quote
Sponsored Links
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hylafax Email to fax gateway jfer HOWTO-Related Questions 2 10th February 2009 18:29
Debian Sarge 3.1 & HylaFAX nenad Server Operation 0 11th March 2007 23:34
How to set a rule to forward email to perl script ametade General 2 4th September 2006 19:22
Perl and cgi script installation linuxuser1 General 30 26th April 2006 23:09
PERL script help... simple issue i think gjcomputer General 3 14th March 2006 09:49


All times are GMT +2. The time now is 22:46.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.