#!/usr/bin/perl -w # # mail_get.pl 1.1.0, last changed 15/05/2003 # ###################################################################### # # Copyright (C) 2003 Semenenko Pavel # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ###################################################################### # # Great thanx to: # Sean Dowd # for Mail::POP3Client (tested with 2.14) # Eryq, # for MIME::Tools (tested with 5.411a) # ###################################################################### # # NOTE: I'm neither a perl nor *nix expert (as well # English isn't my natural language too) # ###################################################################### # # This script is intended to be used in conjunction with # HylaFAX which is a trademark of Silicon Graphics Corporation. # http://www.hylafax.org # tested with version 4.1.5 # ###################################################################### # # You can download the current version mail_get.pl from # http:// # # mail_get.pl called from crontab (mail_get.pl > /dev/null) & # ###################################################################### require 5.0; use Mail::POP3Client; use MIME::Parser; use MIME::WordDecoder; use MIME::Entity; ##mail box parameters my $USER = "fax"; my $HOST = "ip.ip.ip.ip"; my $PASSWORD = "pass"; ##fax mailbox string my @FAX_MAIL = ("fax\@tra-ta-ta.net", "fax\@tra-ta-ta.com"); ##temp diectory for getted mail my $TEMP_DIR = "/var/spool/hylafax/email_to_fax/tmp/"; ##dir for strange mail, okay mail, ps files for antiword my $SAVE_DIR = "/var/spool/hylafax/email_to_fax/mail/"; ##strange mail saving (subj ok, no att; att ok, subj invalid; antiword error) my $STRANGE_DIR = $SAVE_DIR . "strange/"; ##correct mail saving my $CORRECT_DIR = $SAVE_DIR . "correct/"; ##fax ready ps files saving my $FAXREADY_DIR = $SAVE_DIR . "faxready/"; ##process dir for users emailing my $PROCESS_DIR = $SAVE_DIR . "process/"; ##log dir for my $LOG_DIR = $SAVE_DIR . "/log/"; ##full log my $LOG_MAIL = $LOG_DIR . "mail_get_log"; ##strange log my $LOG_STRANGE = $LOG_DIR . "strange_log"; ##correct log my $LOG_CORRECT = $LOG_DIR . "correct_log"; ##faxready log my $LOG_FAXREADY = $LOG_DIR . "faxready_log"; ##sended to fax log my $LOG_SENDFAX = $LOG_DIR . "sendfax_log"; ##antiword script my $PATH_TO_ANTIWORD = "/usr/share/antiword/antiword"; ##path to map my $PATH_TO_MAP = "/usr/share/antiword/"; ##name of mapping file (such us Unix codepage!!!) my $NAME_MAP = "koi8-r.txt"; ##fax $PATH_TO_SENDFAX = "/usr/bin/sendfax"; #path to dir sendq $PATH_TO_SENDQ = "/var/spool/hylafax/sendq/"; #path to dir doneq $PATH_TO_DONEQ = "/var/spool/hylafax/doneq/"; ##sendmail $PATH_TO_SENDMAIL = "/usr/lib/sendmail"; ##minimal numbers in telephone number my $MIN_TEL = 7; ##for debug (don't delete templates) my $DEBUG = 0; ###################################################################### ##main part ##do not change here anything ##check if all needed dirs exists &check_create_dirs(); &check_processing_jobs(""); ##create connection to email $pop = new Mail::POP3Client(USER => $USER, PASSWORD => $PASSWORD, HOST => $HOST); &print_to_log($LOG_MAIL, "*****************************************************************" . "\n"); &print_to_log($LOG_MAIL, "************************* Session begin *************************" . "\n"); &print_to_log($LOG_MAIL, "Trying open mailbox at: " . localtime() . "\n"); ##check mail my $count = $pop->Count; if ($count <= 0) { &print_to_log($LOG_MAIL, "*****error*****Error\'s on mail or empty mailbox, count = " . $pop->Count . "\n"); exit(1); }#if else { &print_to_log($LOG_MAIL, "There are " . $count . " unreaded emails...\n"); }#else ##Create parser, and set some parsing options: $parser = new MIME::Parser; $parser->output_under($TEMP_DIR); $parser->decode_headers(1); ##array for messages dirs my @msg_dir; my %fields_source; ##if messages exist check all of them for($i = 1; $i <= $count; $i++) { my %fields_source; &print_to_log($LOG_MAIL, "\n...processing " . $i . "th mail...\n"); ##create temp file local $file_name = $TEMP_DIR . "mail" . $i; open(FILEIN, "+>" . $file_name); local $fh = new IO::Handle(); $fh->fdopen(fileno(FILEIN), "w"); ##drop to temp file e-mail $pop->HeadAndBodyToFile($fh, $i); $fh->close(); close(FILEIN); ##add " for Content-Type: filename and name open(FILEOUT, "" . $file_name); @file = ; close(FILEOUT); open(FILEIN, ">" . $file_name); foreach $line (@file) { if ($line =~ m/^(.*)(=\?.*\?=)([.\s]*)$/gi) { $line = $1 . "\"" . $2 . "\"" . $3; }#if print FILEIN $line; }#foreach close(FILEIN); ##parse mail from temp file local $entity; if (!($entity = $parser->parse_open($file_name))) { &print_to_log($LOG_MAIL, "*****error*****Parse failed\n"); exit(1); }#if ##get directory where parse message place local $results = $parser->results; local @msg = $results->msgs; local $msg_dir = $msg[0]; $msg_dir =~ s/(.)+ //gi; $msg_dir =~ s/$(\s+)//gi; ##search to, from, subject, and stripping from to&from all except e-mail local %fields = ("res", 0, "to", "", "from", "", "subject", "", "send", "", "code", ""); ##get decoded to, from, subject if (unmime($entity->head->get("to"))) { $fields{"to"} = unmime($entity->head->get("to")); }#if if (unmime($entity->head->get("from"))) { $fields{"from"} = unmime($entity->head->get("from")); }#if if (unmime($entity->head->get("subject"))) { $fields{"subject"} = unmime($entity->head->get("subject")); }#if if (unmime($entity->head->get("date"))) { $fields{"send"} = unmime($entity->head->get("date")); }#if ##for delete messages $fields{"code"} = $entity->stringify_body; $fields{"code"} =~ s/(\s*)$//; if (length($fields{"code"}) != 11) { $fields{"code"} = ""; }#if %fields_source = %fields; %fields = &checking_message_header(%fields); $fields{"num"} = $i; $fields{"temp_mail"} = $file_name; $fields{"attachments"} = $TEMP_DIR . $msg_dir; local $asd = &decode_result(%fields); if ($asd eq "1") { next; }#if elsif ($asd eq "0") { }#if else { $fields_source{"error"} = $asd; &send_mail(%fields_source); next; }#else ##if all correct place directory to array of directories $fields{"dir_num"} = &move_to_correct(%fields); $fields_source{"error"} = &send_to_fax(%fields); &send_mail(%fields_source); }#for ## close mail session $pop->Close(); &print_to_log($LOG_MAIL, "Close mailbox at: " . localtime() . "\n"); &print_to_log($LOG_MAIL, "************************* Session end *************************" . "\n"); &print_to_log($LOG_MAIL, "***************************************************************" . "\n\n"); ##end of main part ###################################################################### ###################################################################### ##check jobs in process sub check_processing_jobs($) { my $delete = $_[0]; local @jobs = glob($PROCESS_DIR . "*"); foreach $job (@jobs) { open(INFO, $job); @info = ; close(INFO); my %fields; foreach $line (@info) { if ($line =~ m/^From: (.*)$/) { $fields{"from"} = $1; }#if if ($line =~ m/^To: (.*)$/) { $fields{"to"} = $1; }#if if ($line =~ m/^Subject: (.*)$/) { $fields{"subject"} = $1; }#if if ($line =~ m/^Date: (.*)$/) { $fields{"send"} = $1; }#if if ($line =~ m/^Name file: (.*)$/) { $name_file = $1; }#if if ($line =~ m/^Dir num: (.*)$/) { $dir_num = $1; }#if if ($line =~ m/^UID: (.*)$/) { $uid = $1; }#if }#foreach $job =~ m/.*\/(\d+)$/; local $num = $1; $flag = 0; if (-e $PATH_TO_SENDQ . "q" . $num) { $path = $PATH_TO_SENDQ; $flag = 1; } elsif (-e $PATH_TO_DONEQ . "q" . $num) { $path = $PATH_TO_DONEQ; }#elseif else { unlink($job); next; } open(STATUS, $path . "q" . $num); local @in = ; close(STATUS); foreach $line (@in) { #print $line . "\n\n"; if ($line =~ m/^ndials\:(.*)$/) { $ndials = $1; }#if if ($line =~ m/^status\:(.*)$/) { $status = $1; }#if if ($line =~ m/^totdials\:(.*)$/) { $totdials = $1; }#if }#foreach $to_del = 0; if ($flag == 1) { $fields{"error"} = "Your attachment with name " . $name_file . " is in process...\nAlready passed " . $ndials . " dials...\nLast state is: " . $status; if ($delete eq $uid) { $fields{"error"} = "Delete your attachment with name " . $name_file . " from queue..."; unlink($PATH_TO_SENDQ . "q" . $num); $to_del = 1; }#if }#if else { if ($status eq "") { $status = "successfuly sended"; }#if $fields{"error"} = "Your attachment with name " . $name_file . " get out from queue...\nPassed " . $totdials . " dials...\nLast state is: " . $status; if ($delete eq $uid) { $fields{"error"} = "Sorry, lose to delete message...\n" . $fields{"error"}; }#if $to_del = 1; }#else if ($to_del == 1) { unlink($job); $name_file =~ s/\\ / /gi; unlink($CORRECT_DIR . $dir_num . "/attachments/" . $name_file); $name_file =~ m/(.*)\.doc$/; unlink($FAXREADY_DIR . $dir_num . "/" . $1 . ".ps"); ##if all docs processed clear and remove dirs local @docs = glob($CORRECT_DIR . $dir_num . "/attachments/*.doc"); local $doc_exst = 0; if (scalar(@docs) > 0) { $doc_exst = 1; } if ($doc_exst == 0) { local @temp = glob($CORRECT_DIR . $dir_num . "/attachments/*"); foreach (@temp) { unlink; }#foreach rmdir($CORRECT_DIR . $dir_num . "/attachments"); local @temp1 = glob($CORRECT_DIR . $dir_num ."/*"); foreach (@temp1) { unlink; }#foreach rmdir($CORRECT_DIR . $dir_num); rmdir($FAXREADY_DIR . $dir_num); }#if all docs processed, clear and remove dirs from faxready & correct }#if to_del &send_mail(%fields); }#foreach }#check_processing_jobs ###################################################################### ##send correct mails to fax sub send_to_fax(@) { local %fields = @_; mkdir($FAXREADY_DIR . $fields{"dir_num"}); local @docs = glob($CORRECT_DIR . $fields{"dir_num"} . "/attachments/*.doc"); foreach $doc (@docs) { if ($doc =~ m/(.*)\/(.+?)\.doc$/gi) { $name = $2; }#if ##change spaces $name =~ s/\s/\\ /gi; $doc =~ s/\s/\\ /gi; ##convert by antivord system($PATH_TO_ANTIWORD . " -i 2 -m " . $NAME_MAP . " -p a4 " . $doc . " > " . $FAXREADY_DIR . $fields{"dir_num"} . "\/" . $name . ".ps"); &print_to_log($LOG_MAIL, "[CONVERT] "); &print_to_log($LOG_FAXREADY, "[" . localtime() . "] [DIR " . $fields{"dir_num"} . "] From: " . $fields{"from"} . " Number: " . $fields{"subject"} . " Document name: " . $name . ".ps [CONVERTED]\n"); ##send on fax through sendfax &print_to_log($LOG_MAIL, "[SENDED TO FAX]\n"); ##cut work number local $str = $PATH_TO_SENDFAX . " -n -d " . $fields{"subject"} . " " . $FAXREADY_DIR . $fields{"dir_num"} . "\/" . $name . ".ps"; local $exit = `$str`; $exit =~ m/.*id is (\d*).*/gi; $exit = $1; ##create processing file open(JID, ">>" . $PROCESS_DIR . $exit); print(JID "To: " . $fields{"to"} . "\n"); print(JID "From: " . $fields{"from"} . "\n"); print(JID "Subject: " . $fields{"subject"} . "\n"); print(JID "Date: " . $fields{"send"} . "\n"); print(JID "Operated: " . localtime() . "\n"); print(JID "Name file: " . $name . ".doc\n"); print(JID "Dir num: " . $fields{"dir_num"} . "\n"); ##generate random string local $asd = crypt(rand, 'ab'); $asd =~ m/..(.*)/; $asd = $1; print(JID "UID: " . $asd . "\n"); close(JID); &print_to_log($LOG_SENDFAX, "[" . localtime() . "] [DIR " . $fields{"dir_num"} . "] From: " . $fields{"from"} . " Number: " . $fields{"subject"} . " Document name: " . $name . ".ps [SEND TO FAX] with work number " . $exit . " [UID] " . $asd . "\n"); $fields{"error"} = $fields{"error"} . "\t" . $name . ".doc\n\t\tUnical ID:\t" . $asd . "\n"; }#foreach return ("With attachment(s):\n" . $fields{"error"} . "was correctly redirected to fax modem...\nfor deleting your fax from queue,\nsend mail to fax-server with subject \"delete\" and Unical ID in body (with no signature)..."); }#send_to_fax ###################################################################### ##some subs ##check message headers on correct info sub checking_message_header(@) { local %fields = @_; ##stripping from to&from all except e-mail foreach (%fields) { s/^(\s*)//gi }#foreach foreach (%fields) { s/(\s*)$//gi }#foreach if ($fields{"to"} ne "") { $fields{"to"} =~ s/^(.*?)([\w\_\-\.]+\@[\w\_\-\.]+\.\w{2,6})(.*)$/$2/gi; }#if if ($fields{"from"} ne "") { $fields{"from"} =~ s/^(.*?)([\w\_\-\.]+\@[\w\_\-\.]+\.\w{2,6})(.*)$/$2/gi; }#if &print_to_log($LOG_MAIL, "To: " . $fields{"to"} . "\n"); &print_to_log($LOG_MAIL, "From: " . $fields{"from"} . "\n"); &print_to_log($LOG_MAIL, "Subject: " . $fields{"subject"} . "\n"); &print_to_log($LOG_MAIL, "Send: " . $fields{"send"} . "\n"); ##checking 'to', 'from', 'subject' (for correct number), rejecting if don't correct, erase mail ##if 'subject' incorrect and 'from' exist, send mail for sender with all attachments if (!($fields{"to"} =~ m/^([\w\_\-\.]+\@[\w\_\-\.]+\.\w{2,6})$/gi)) { $fields{"to"} = ""; &print_to_log($LOG_MAIL, "[ERROR To:] "); $fields{"res"} = 1; return %fields; }#if if (!($fields{"from"} =~ m/^([\w\_\-\.]+\@[\w\_\-\.]+\.\w{2,6})$/gi)) { $fields{"from"} = ""; &print_to_log($LOG_MAIL, "[ERROR From:] "); $fields{"res"} = 1; return %fields; }#if ##check more correctly local $exist = 0; foreach $faxmail (@FAX_MAIL) { if (lc($fields{"to"}) eq lc($faxmail)) { $exist = 1; } }#if,foreach if ($exist == 0) { &print_to_log($LOG_MAIL, "[ERROR To:] "); $fields{"res"} = 1; return %fields; }#if $fields{"subject"} =~ s/^(\s*)//; $fields{"subject"} =~ s/(\s*)$//; if (lc($fields{"subject"}) eq "delete") { &print_to_log($LOG_MAIL, "[MAIL FOR DELETING JOB]\n"); $fields{"res"} = 4; return %fields; }#if if (!($fields{"subject"} =~ m/^([\d\-\+\(\)]+)$/gi)) { $fields{"subject"} = ""; &print_to_log($LOG_MAIL, "[ERROR Subject:] "); $fields{"res"} = 2; return %fields; }#if $tmp = $fields{"subject"}; $tmp =~ s/[\+\-\(\)]+//gi; if (length($tmp) < $MIN_TEL) { &print_to_log($LOG_MAIL, "[ERROR Subject:] "); $fields{"res"} = 3; return %fields; }#if else { $fields{"subject"} =~ s/[\(\)]+//gi; $fields{"subject"} =~ s/[\+\-]+/\,/gi; $fields{"subject"} =~ s/^\,//gi; $fields{"subject"} =~ s/\,$//gi; }#else return %fields; }#sub check_message_header ###################################################################### ##decoding results of parsing headers sub decode_result(@) { local %fields = @_; ##decoding $fields{"res"} ##0 - all correct - nothing to do (if *.doc exists) ##1 - 'from' or 'to' empty or incorrect - delete directory and mail from mailbox ##2 - 'subject' empty or incorrect - send replay, delete directory and mail ##3 - 'subject' is too short - send replay, delete directory and mail ##4 - 'subject' is delete - delete job if possible local @docs = glob($fields{"attachments"} . "/*.doc"); ##if there are docs att?.. (for strange mail) local $doc_exst = 0; if (scalar(@docs) > 0) { $doc_exst = 1; } ##subject wrong but doc files exists if (($fields{"res"} == 0)&&($doc_exst == 0)) { &print_to_log($LOG_MAIL, "[REPLAY, MOVE -> STRANGE] "); $fields{"error"} = "Error: cann't find *.doc file(s) in attachment..."; #&send_mail(%fields); &move_to_strange(%fields); return $fields{"error"}; }#if elsif ($fields{"res"} == 1) { &print_to_log($LOG_MAIL, "[DELETE]\n"); &delete_temp(%fields); return 1; }#elsif elsif ($fields{"res"} == 2) { if ($doc_exst == 1) { &print_to_log($LOG_MAIL, "[REPLAY, MOVE -> STRANGE] "); $fields{"error"} = "Error: field subject is empty or incorrect..."; #&send_mail(%fields); &move_to_strange(%fields); return $fields{"error"}; }#if else { &print_to_log($LOG_MAIL, "[DELETE]\n"); }#else &delete_temp(%fields); return 1; }#elsif elsif ($fields{"res"} == 3) { if ($doc_exst == 1) { &print_to_log($LOG_MAIL, "[REPLAY, MOVE -> STRANGE] "); $fields{"error"} = "Error: fax number too short..."; #&send_mail(%fields); &move_to_strange(%fields); return $fields{"error"}; }#if else { &print_to_log($LOG_MAIL, "[DELETE]\n"); }#else &delete_temp(%fields); return 1; }#elsif elsif ($fields{"res"} == 4) { &delete_temp(%fields); check_processing_jobs($fields{"code"}); return 1; }#elseif return 0; }#sub decode_result ###################################################################### ##send message sub send_mail(@) { local %fields = @_; # $fields{"to"} =~s/\@/\\\@/gi; # $fields{"from"} =~s/\@/\\\@/gi; ### Create the top-level, and set up the mail headers: $top = MIME::Entity->build(Type => "multipart/mixed", From => $fields{"to"}, To => $fields{"from"}, Subject => "FAX daemon..."); ### Part #3: some literal text: local $data = "Your mail:\n\tTo: " . $fields{"to"} . "\n\tFrom: " . $fields{"from"} . "\n\tSubject: " . $fields{"subject"} . "\n\tSend date: " . $fields{"send"} . "\n\n" . $fields{"error"}; $data =~ s/\n+/\n/gi; $top->attach(Data => $data); ### Send it open MAIL, "| " . $PATH_TO_SENDMAIL . " -t -oi -oem" or die "open: $!"; $top->print(\*MAIL); close MAIL; }#sub send_message ###################################################################### ##move message, attachments and create info to correct dir sub move_to_correct(@) { local %fields = @_; #this is correct mail, move it to correct dir local $cur_num; if (-e $CORRECT_DIR . "nm") { open(NUM, $CORRECT_DIR . "nm"); local @num = ; $cur_num = $num[0]; close(NUM); unlink($CORRECT_DIR . "nm"); }#if else { $cur_num = 0; }#else open(NUM, ">" . $CORRECT_DIR . "nm"); print(NUM "" . ($cur_num + 1)); close(NUM); mkdir($CORRECT_DIR . $cur_num); ##copy email system("cp -f " . $fields{"temp_mail"} . " " . $CORRECT_DIR . $cur_num . "/" . $cur_num . ".eml"); ##move attachments mkdir($CORRECT_DIR . $cur_num . "/attachments"); system("cp -f " . $fields{"attachments"} . "/*.* " . $CORRECT_DIR . $cur_num . "/attachments/"); ##make info file open(INFO, ">>" . $CORRECT_DIR . $cur_num . "/INFO"); print(INFO "To: " . $fields{"to"} . "\n"); print(INFO "From: " . $fields{"from"} . "\n"); print(INFO "Subject: " . $fields{"subject"} . "\n"); print(INFO "Date: " . $fields{"send"} . "\n"); print(INFO "Operated: " . localtime() . "\n"); close(INFO); &print_to_log($LOG_MAIL, "[CORRECT] [DIR " . $cur_num . "]\n"); &print_to_log($LOG_CORRECT, "[" . localtime() . "] [DIR " . $cur_num . "] From: " . $fields{"from"} . " Send: " . $fields{"send"} . " Subject: " . $fields{"subject"} . "\n"); &delete_temp(%fields); return $cur_num; }#move_to_correct ###################################################################### ##move message, attachments and create info to strange dir sub move_to_strange(@) { local %fields = @_; #this is strange mail, move it to strange dir local $cur_num; if (-e $STRANGE_DIR . "nm") { open(NUM, $STRANGE_DIR . "nm"); local @num = ; $cur_num = $num[0]; close(NUM); unlink($STRANGE_DIR . "nm"); }#if else { $cur_num = 0; }#else open(NUM, ">" . $STRANGE_DIR . "nm"); print(NUM "" . ($cur_num + 1)); close(NUM); mkdir($STRANGE_DIR . $cur_num); ##copy email system("cp -f " . $fields{"temp_mail"} . " " . $STRANGE_DIR . $cur_num . "/" . $cur_num . ".eml"); ##move attachments mkdir($STRANGE_DIR . $cur_num . "/attachments"); system("cp -f " . $fields{"attachments"} . "/*.* " . $STRANGE_DIR . $cur_num . "/attachments/"); ##make info file open(INFO, ">>" . $STRANGE_DIR . $cur_num . "/INFO"); print(INFO "To: " . $fields{"to"} . "\n"); print(INFO "From: " . $fields{"from"} . "\n"); print(INFO "Subject: " . $fields{"subject"} . "\n"); print(INFO "Date: " . $fields{"send"} . "\n"); print(INFO "Operated: " . localtime() . "\n"); print(INFO "" . $fields{"error"}); close(INFO); &print_to_log($LOG_MAIL, "[DIR " . $cur_num . "]\n"); &print_to_log($LOG_STRANGE, "[" . localtime() . "] [DIR " . $cur_num . "] From: " . $fields{"from"} . " Send: " . $fields{"send"} . " " . "[ERROR " . $fields{"error"} . "]\n"); &delete_temp(%fields); }#move_to_strange ###################################################################### ##deleting temporary created dirs, and mail from mailbox sub delete_temp(@) { local %fields = @_; if (!$DEBUG) { unlink($fields{"temp_mail"}); @unlink_files = glob($fields{"attachments"} . "/*.*"); foreach (@unlink_files) { unlink; }#foreach rmdir($fields{"attachments"}); $pop->Delete($fields{"num"}); }#if $DEBUG }#delete_temp ###################################################################### ##create dir, and previous path if needed sub create_dir($) { local $dir = ""; local @splitted = split(/\//, $_[0]); foreach (@splitted) { $dir = $dir . $_ . "/"; if (!(-e $dir)) { mkdir($dir); }#if }#foreach }#create_dir ###################################################################### ##checking existing and creating if needed working dirs and files sub check_create_dirs() { if (!(-e $TEMP_DIR)) { &create_dir($TEMP_DIR); }#if if (!(-e $SAVE_DIR)) { &create_dir($SAVE_DIR); }#if if (!(-e $STRANGE_DIR)) { &create_dir($STRANGE_DIR); }#if if (!(-e $CORRECT_DIR)) { &create_dir($CORRECT_DIR); }#if if (!(-e $FAXREADY_DIR)) { &create_dir($FAXREADY_DIR); }#if if (!(-e $LOG_DIR)) { &create_dir($LOG_DIR); }#if if (!(-e $PROCESS_DIR)) { &create_dir($PROCESS_DIR); }#if ##clear temp dir local @temp_files = glob($TEMP_DIR . "*"); foreach $file (@temp_files) { if (-d $file) { local @temp = glob($file . "/*"); foreach (@temp) { unlink; }#foreach rmdir($file); }#if else { unlink($file); }#else }#foreach if (!(-e $PATH_TO_SENDQ)) { &print_to_log($LOG_MAIL, "*****error*****Cann't find sendq dir, check path please...\n"); exit(1); }#if if (!(-e $PATH_TO_DONEQ)) { &print_to_log($LOG_MAIL, "*****error*****Cann't find doneq dir, check path please...\n"); exit(1); }#if if (!(-e $PATH_TO_ANTIWORD)) { &print_to_log($LOG_MAIL, "*****error*****Cann't find antiword, check path please...\n"); exit(1); }#if if (!(-e $PATH_TO_MAP . $NAME_MAP)) { &print_to_log($LOG_MAIL, "*****error*****Cann't find map file, check path please...\n"); exit(1); }#if if (!(-e $PATH_TO_SENDFAX)) { &print_to_log($LOG_MAIL, "*****error*****Cann't find sendfax, check path please...\n"); exit(1); }#if if (!(-e $PATH_TO_SENDMAIL)) { &print_to_log($LOG_MAIL, "*****error*****Cann't find sendmail, check path please...\n"); exit(1); }#if }#check_create_dirs ###################################################################### ##printing out of working script to logfile sub print_to_log($$) { open(LOG, ">>" . $_[0]); print(LOG $_[1]); close(LOG); }#print_to_log