HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

[hylafax-users] E-mail to Fax Gateway Problems and Solutions




I made the following post on the usenet.  I'm commenting on some very
useful material I found by doing a groups search on Google.  I almost got
this stuff to work.  Maybee, if I can get you guys to take a look at it
somebody could help me debug these scripts on my system.

Thanks in advance, Chris

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

comp.lang.perl:25104


I am trying to set up a perl script for use with Hylafax. (this is to
solve
a bug with the faxmail command)  These scripts are from a previous post
on this problem, but I'm getting the following error, and I am a total
newbie
when it comes to perl.  Any suggestions would totaly be appreciated.

I have included the error below and the post that described how to set up
the
script below that.

Thanks

 cat beer-3-red-amber-black.jpg | ./jpeg >/tmp/test.ps
/usr/local/lib/fax/filter.pl: line 4: syntax error near unexpected token
`;'
jpeg2ps V1.9: convert JPEG files to PostScript Level 2 or 3.
/usr/local/lib/fax/filter.pl: line 4: `@text=<STDIN>;'
(C) Thomas Merz 1994-2002

usage: jpeg2ps [options] jpegfile > epsfile
-a        auto rotate: produce landscape output if width > height
-b        binary mode: output 8 bit data (default: 7 bit with ASCII85)
-h        hex mode: output 7 bit data in ASCIIHex encoding
-o <name> output file name
-p <size> page size name. Known names are:
          a0, a1, a2, a3, a4, a5, a6, b5, letter, legal, ledger, p11x17
-q        quiet mode: suppress all informational messages
-r <dpi>  resolution value (dots per inch)
          0 means use value given in file, if any (disables autorotate)

The following is the previous post:

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

After suffering several days from web browsing, mail list seeking and
reference searching.

I am able to send fax with non-ASCII code (big5, GB, UTF8, shift-jis)
email
and attachments (jpg, gif, tif) together. However, it still fails in
sending
(postscript + body text) together.

In order to share my experience to all hylafax user. I write the
procedures
here for your comments.

============================================
Enable sending fax with Plain TEXT, JPEG, GIF and TIFF ...etc
============================================

1. Adding a line in /etc/hylafax/hyla.conf to let hylafax knows where the
MIME decoder located.
MIMEConverters: /usr/local/sbin/faxmail

2. Create the Type directories that your binary file belongs to.
(Type/Subtype)
For example, in email
a) jpg refers to "application/octet-stream" ,therefore, you should creat a
directory called "application" in the /usr/local/sbin/faxmail directory
b) gif refers to "application/octet-stream",  the same as jpg
c) tiff refers to "image/tiff", creat an "image" directory
d) txt refers to "text/plain", creat a "text" directory

3. Download and install the appropiate converter
For JPEG, We can download a jpeg to postscript converter, jpeg2ps (you can
search it from web).
For GIF, I use gif2ps.
For TIFF, tiff2ps
For TXT, uniprint (From the package of Yudit ) and a unicode font (
cyberbit.ttf )

4. Here is the most important and hardness part (you should be able to
write
some shell script or perl script)

----------------------------------------------------------------------------
For TIFF, create a file "tiff" in /usr/local/sbin/faxmail/image and chmod
755 it.
Here is the contain of the file "tiff"
################################
#!/bin/bash
/bin/echo " "
/bin/echo "showpage"
/usr/bin/tiff2ps -a $1 | /usr/local/sbin/faxmail/filter.pl
################################
----------------------------------------------------------------------------

----------------------------------------------------------------------------
For JPEG and GIF, it is more complicated. Since both of the format have
the
same subtype.
Therefore, the script should able to distingish them.
Creat a file "octet-stream" in /usr/local/sbin/faxmail/application and
also
chmod 755 it.
Here is a sample script of "octet-stream"
################################
#!/bin/bash
#    #This part is to convert GIF
        if [ "`cat $1 |grep GIF`" ]; then
                echo " "
                echo "showpage"
                /usr/bin/gif2ps $1 | /usr/local/sbin/faxmail/filter.pl
#    # Here is the jpg converting
        else
                echo " "
                echo "showpage"
                /usr/bin/jpeg2ps -q $1 | /usr/local/sbin/faxmail/filter.pl
        fi
##################################
----------------------------------------------------------------------------

----------------------------------------------------------------------------
For Plain text, creat the file "plain" in /usr/local/sbin/faxmail/text and
chmod 755 it.
Here is the sample script of "plain"
##################################
#!/bin/bash
/usr/bin/uniprint -font cyberbit.ttf -in $1 -out /tmp/tmptxt > /dev/null
2>&1
echo " "
echo "showpage"
cat /tmp/tmptxt | /usr/local/sbin/faxmail/filter.pl
rm /tmp/tmptxt

##################################
Remark:
This script also convert the body text of email.
You can customize the encoding of uniprint to BIG5, SHIFT-JIS, GB ..etc,
but
don't remember to use an appropiate font.
You can download fonts accroding to your encoding from web (the true type
font installation guide is in yudit package)
Use unicode in the body text when sending email.
----------------------------------------------------------------------------

----------------------------------------------------------------------------
To let the above script run properly, an extra perl script is need.
Without this script, you can already fax your stuff, but the problem is
that
blank sheet will automatically insert between each file.
A result of 3 page fax becomes 6 page or even more.
This is due to the insert mechanism of faxmail.
Normally, faxmail will generate the first page in postscript with TO and
FROM information.
Any attachments will insert in the middle of the postscript.
However, in postscript syntax the word "showpage" is an indicator of end
of
page.
Once the postscript that generated by the above process is inserted to the
middle of first page.
The whole file is corrupted, because the showpage is placed in the wrong
place.
This will result in print page without correct display of your file but a
blank page.
Therefore, I use some tricks here.
I print a "showpage" before each attachment to indicate the end of page.
and then I eliminate the last "showpage" at the bottom of each attchments.
After that I got everythings right.
OK. Come back to out procedure.
Creat a file "filter.pl" in /usr/local/sbin/faxmail directory and chmod
755
it.
Here is the code.
##################################
#!/usr/bin/perl
# Read from the standard input
@text=<STDIN>;
$size=@text;

# Count the number of "showpage"
$count=0;
for($i=0;$i<=$size;$i++){if($text[$i] =~ /showpage/){$count++;}}

# Discard the last line that contain "showpage"
$num=1;
for($i=0;$i<=$size;$i++){
        if($text[$i] =~ /showpage/){
                if($num!=$count){$num++;}
                else{$text[$i]=~s/showpage//g;}
        }

                print $text[$i];
}
##################################
----------------------------------------------------------------------------

Now you should be able to print GIF, JPEG and TIFF attachment with body
message.
You can also imprement the HTML2PS to allow html attachment.
However, html2ps as I know is not unicode compatable.

Thanks for any comment.
Hope it can help all of you.


Goldfish



____________________ HylaFAX(tm) Users Mailing List
_______________________
  To subscribe/unsubscribe, click
http://lists.hylafax.org/cgi-bin/lsg2.cgi
 On UNIX: mail -s unsubscribe hylafax-users-request@hylafax.org <
/dev/null

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

-------------------------------------------------------------------------------
Christopher G. Maness
http://www.chrismaness.com

          To reply by mail take the subdomain "p3" out of the addy.

-------------------------------------------------------------------------------


____________________ HylaFAX(tm) Users Mailing List _______________________
  To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi
 On UNIX: mail -s unsubscribe hylafax-users-request@hylafax.org < /dev/null




Project hosted by iFAX Solutions