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.
Reply
 
Thread Tools Display Modes
  #1  
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:

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
  #2  
Old 23rd March 2007, 20:12
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

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

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

> 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.

You have to decide "how" you will determine if a part is given to
sendfax. That will depend on what types of emails you feed into it, and
what results you want.

It could be as simple as changing the one line.

If you want to only fax the PostScript documents:

push @parts, $_ if $_->mime_type eq 'applicatin/postscript';

or if you want to fax everything *except* text/plain or text/html:
next if $_->mime_type eq 'text/plain';
next if $_->mime_type eq 'text/html';
push @parts, $_;
__________________
Nenad Bulatovic
---------------
Debian Lenny & ISPConfig 3
Reply With Quote
Reply

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 19:29
Debian Sarge 3.1 & HylaFAX nenad Server Operation 0 12th March 2007 00:34
How to set a rule to forward email to perl script ametade General 2 4th September 2006 20:22
Perl and cgi script installation linuxuser1 General 30 27th April 2006 00:09
PERL script help... simple issue i think gjcomputer General 3 14th March 2006 10:49


All times are GMT +2. The time now is 06:59.


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