On Fri, 6 Oct 2000, Brett Randall wrote:

> Hi one and all
> 
> I have been asked to supply an additional function to qmail...to receive an
> e-mail to [EMAIL PROTECTED] (eg [EMAIL PROTECTED]),
> and put it into the queue for a fax program (which dials using an attached
> fax modem). Now, my guess would be to have a local concurrency of 1, and
> pipe each message (via .qmail-default) through a fax spooler...but has
> anyone actually done this, and what do you guys reckon is the best package
> to send faxes with? Alternately, is there a utility I can stick on qmail to
> do this? I know there is for sendmail somewhere...and if need be I will
> *try* and adapt it if all else fails, but any ideas? Thanks!

setup a virtual domain for fax.hillsong.com

    /var/qmail/control/virtualdomains:
        fax.hillsong.com:faxuser
    
    ~faxuser/.qmail-default
        | decoder $DEFAULT

the decoder program should be able to extract relevant parts of the
message and send them to the fax spooler. $DEFAULT will contain the
user component of the email address which should be the phone number.
You can also overload the address to include fax header details, eg

    [EMAIL PROTECTED]

decoder should have support for checking the sender's credentials so
that only authorised users can send faxes (otherwise I'll be abusing
the system to fax my Mum and Dad in Australia, and I'm sure you don't
want to pay for that :).

decoder should also remove any unwanted headers (do you really want
all those Received: headers in the fax?) and it should also know how
to handle mime decoding and ignore attachments that your fax system
doesn't understand, eg mpeg movies, MS Word documents etc).

I'm not aware of any system that does this yet. I have played around
with such a system (doesn't do the mime extraction or user credential
checking) that interfaces to mgetty+sendfax.

I've attached my code (which is sort of ugly) and will require changes
because it was coded for a specific installation where the fax modem
was on a different machine to the mailhost.

-- 
Regards
Peter
----------
Peter Samuel                            [EMAIL PROTECTED]
http://www.e-smith.org (development)    http://www.e-smith.com (corporate)
Phone: +1 613 368 4398                  Fax: +1 613 564 7739
e-smith, inc. 1500-150 Metcalfe St, Ottawa, ON K2P 1P1 Canada

"If you kill all your unhappy customers, you'll only have happy ones left"
#!/pkgs/bin/perl -w

###########################################################################
#
# Simple SMTP to FAX gateway
#
# Uses mgetty+sendfax and qmail.
#
# This program takes advantage of qmail's address overloading features.
# Mail will be addressed to one of the following:
#
#   user-fax-number@domain
#   user-fax-number-attention@domain
#
# In the user's home directory will be two dot-qmail files
#
#   ~/.qmail-fax
#   ~/.qmail-fax-default
#
# The first file will catch any incoming mail without a fax number. It
# should be a link to ~/.qmail-fax-default.
#
# The second file should contain the following details
#
#   # Any sender restrictions can be placed here
#   | /path/to/smtp2fax
#
###########################################################################

require 5;
use strict;
use Mail::Header;

my $faxspool =
    "rsh grizzly.ind.tansu.com.au PATH=$ENV{'PATH'} /pkgs/mgetty-1.1.17/bin/faxspool 
-q -h -";

# You might need to prefix numbers with a PABX dialout code. This only
# applies to fax numbers that contain digits. If the fax number
# contains non-digit characters, the number will be assumed to be an
# entry in ~/.faxnrs.

my $phone_prefix = "0";

# Today's date
my $today = &today();

###########################################################################

&initialise();
my ($fax_number, $attention) = &extract_fax_number();
my $header = &extract_headers();

###########################################################################

open(FAX, "| $faxspool -f $ENV{'SENDER'} $fax_number -");
select FAX; $| = 1;

print FAX << "EOF";
From: $ENV{'SENDER'} via smtp2fax
Attention: $attention
Date: $today

###########################################################################

EOF

print FAX "From: ", $header->get("From:")
    if (defined $header->get("From:"));

print FAX "Date: ", $header->get("Date:")
    if (defined $header->get("Date:"));

print FAX "Subject: ", $header->get("Subject:")
    if (defined $header->get("Subject:"));

print FAX "ReSent-From: ", $header->get("ReSent-From:")
    if (defined $header->get("ReSent-From:"));

print FAX "ReSent-Date: ", $header->get("ReSent-Date:")
    if (defined $header->get("ReSent-Date:"));

print FAX "ReSent-Subject: ", $header->get("ReSent-Subject:")
    if (defined $header->get("ReSent-Subject:"));


while(<STDIN>)
{
    print FAX;
}

close FAX;

exit(0);

###########################################################################

sub initialise
{
    &is_input_from_qmail();
    &do_we_have_a_valid_sender();
    &do_we_have_a_valid_fax_number();
}

sub is_input_from_qmail
{
    # If qmail processed this message, it should have set the $DTLINE
    # environment variable.

    die "Input has not been processed by qmail.\n"
        unless defined $ENV{'DTLINE'};
}

sub do_we_have_a_valid_sender
{
    # Ignore bounce and double bounce messages

    if ($ENV{'SENDER'} =~ /^$|^#\@\[\]$/)
    {
        print STDERR "smtp2fax: ignoring input from invalid sender\n";
        exit(0);
    }
}

sub do_we_have_a_valid_fax_number
{
    # $DEFAULT should contain the number and the optional attention
    # string. If it is empty, then the sender has not supplied a fax
    # number.

    if ($ENV{'DEFAULT'} eq "")
    {
        # Blank lines in bounce messages should have some whitespace in
        # them. Otherwise qmail will display them as a slash instead of a
        # blank line.

        my $blank = " ";

        print << "EOF";
No fax number supplied in address.
$blank
Messages for the smtp2fax gateway should be addressed to:
$blank
    $ENV{'LOCAL'}-faxnumber-attention\@$ENV{'HOST'}
$blank
Where "faxnumber" is the telephone number of the remote fax machine and
"attention" is an optional Attention field with spaces replaced by
underbar characters. For example
$blank
    $ENV{'LOCAL'}-12345-To_whom_it_may_concern\@$ENV{'HOST'}
EOF

        exit(100);
    }
}

sub today
{
    require 'ctime.pl';

    return scalar localtime();
}

sub extract_fax_number
{
    my ($faxno, $attn) = split(/-/, $ENV{'DEFAULT'}, 2);

    # If the fax number contains digits only, insert the PABX dialout
    # prefix number. If the fax number contains other characters, it
    # should match an entry in ~/.faxnrs.

    if ($faxno =~ /^\d+$/)
    {
        $faxno = $phone_prefix . $faxno;
    }

    $attn = "To whom it may concern" unless $attn;

    $attn =~ s/_/ /g;

    return ($faxno, $attn);
}

sub extract_headers
{
    return new Mail::Header \*STDIN, Modify => 0, MailFrom => 'IGNORE';
}

Reply via email to