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

SOLUCIONADO: faxrcvd de Hylafax para enviar faxes como PDF, PNG, JPG...



Hola,

Pues nada que me estoy peleando con el hylafax y he tenido que modificar
el script que se ejecuta al recibir los faxes para poder imprimir directamente
los faxes que llegan (esta comentado) y para enviar por mail el fax como
adjunto PDF, TIFF, PNG, y JPEG ademas del PS que ya enviaba...
Os lo pongo adjunto.

Un ejemplo de tamaño según formato:

        # TIFF -> 26 KBytes                                                      
        # PNG  -> 21 KBytes                                                      
        # PDF  -> 55 KBytes                                                      

	JPEG
        # jpeg pierde información al comprimir, con -quality 75 queda bien      
        # y no se ahorra mucho espacio reduciendo la calidad, ejemplos:         

        # 75	172 KBytes se ve bien                                               
        # 50	142 KBytes puntitos alrededor del texto                             
        # 25	115 KBytes nuve alrededor del texto                                 
        #  0	 63 KBytes inhumano :-)                                             

El PNG se ve perfecto, y es el formato que mas comprime, pero hay problemas
 al imprimir con algunos navegadores

¿Que opinais?	


Por cierto ¿usais hylafax? ¿con que modem (marca/modelo)? ¿te va bien?
Lo cierto es que configurarlo es "un infierno" llevo una semana y aun no he
 acabado, menos mal que los retos "me ponen" :-)


Que aproveche ;-)

Saludos,
-- 
-------------------------------------------------
Manel Marin   e-mail: manel3@apdo.com
Linux Powered (Debian 2.1 slink)  kernel 2.2.14

Mira mis chuletas de Linux en  http://perso.wanadoo.es/manel3
-------------------------------------------------
Mi petición de drivers para Linux es la nº 33126
 (Pasate por http://www.libranet.com/petition.html ;-)
#! /bin/sh
#	faxrcvd de Hylafax modificado para imprimir faxes que llegan (comentado)
#	y enviar por mail como adjuntos PDF, TIFF, PNG, y JPEG (ademas del PS)
#	elige el que quieras y comenta los demas...
#
#	modificaciones: (c) 2000 Manel Marin, bajo la licencia GNU GPL
#	
#
#
#	$Id: faxrcvd,v 1.2 1998/03/05 23:27:32 behanw Exp $
#
# HylaFAX Facsimile Software
#
# Copyright (c) 1990-1996 Sam Leffler
# Copyright (c) 1991-1996 Silicon Graphics, Inc.
# HylaFAX is a trademark of Silicon Graphics
# 
# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
# 
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
# 
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

#
# Modifications by: Behan Webster <behanw@pobox.com>
#

#
# faxrcvd file devID commID error-msg
#
if [ $# != 4 ]; then
	echo "Usage: $0 file devID commID error-msg"
	exit 1
fi

test -f etc/setup.cache || {
	SPOOL=`pwd`
	cat<<EOF

FATAL ERROR: $SPOOL/etc/setup.cache is missing!

The file $SPOOL/etc/setup.cache is not present.  This
probably means the machine has not been setup using the faxsetup(1M)
command.  Read the documentation on setting up HylaFAX before you
startup a server system.

EOF
	exit 1
}
. etc/setup.cache

INFO=$SBIN/faxinfo
FAX2PS=$TIFFBIN/fax2ps

SENDFROM=hylafax
TOADDR=FaxMaster

#
# There is no good portable way to find out the fully qualified
# domain name (FQDN) of the host or the TCP port for the hylafax
# service so we fudge here.  Folks may want to tailor this to
# their needs; e.g. add a domain or use localhost so the loopback
# interface is used.
#
HOSTNAME=`hostname`			# XXX no good way to find FQDN
PORT=4559				# XXX no good way to lookup service

###########################################################################
# Send email about fax
#
function emailfax () {
	TO=$1
	FROM=$2
	NUM=$3
	FAX=$4
	DEV=$5
	LOG=$6
	ERR=$7
	SENT=$8

	(MIMEBOUNDARY="NextPart$$"
	echo "Mime-Version: 1.0"
	echo "Content-Type: Multipart/Mixed; Boundary=\"$MIMEBOUNDARY\""
	echo "Content-Transfer-Encoding: 7bit"
	echo "To: $TO"
	echo "From: The HylaFAX Receive Agent <$FROM>"
	echo "Subject: facsimile received from $NUM";
	echo ""
	echo "--$MIMEBOUNDARY"
	echo "Content-Type: text/plain"
	echo "Content-Description: FAX info"
	echo "Content-Transfer-Encoding: 7bit"
	echo ""
	echo "$FILE (ftp://$HOSTNAME:$PORT/$FAX):"; $INFO -n $FAX
	echo "ReceivedOn: $DEV"
	if [ "$ERR" ]; then
		echo ""
		echo "The full document was not received because:"
		echo ""
		echo "    $ERR"
		echo ""
		echo "    ---- Transcript of session follows ----"
		echo ""
		if [ -f log/c$COMMID ]; then
		$SED -e '/-- data/d' \
			-e '/start.*timer/d' -e '/stop.*timer/d' \
			log/c$LOG
		elif [ -n "$LOG" ]; then
		echo "    No transcript available (CommID c$LOG)."
		else
		echo "    No transcript available."
		fi
	else
		echo "CommID:     c$LOG (ftp://$HOSTNAME:$PORT/log/c$LOG)"
	fi
	if [ -n "$SENT" ]; then
		echo ""
		echo "The facsimile was automatically dispatched to: $SENT." 
	fi
	echo ""
	echo ""

	# A partir de aqui son los adjuntos, comenta o borra los que no quieras

	# PS: Este adjunto era el original... Los demas son mios :-)
	echo "--$MIMEBOUNDARY"
	echo "Content-Type: application/postscript"
	echo "Content-Description: FAX document in PS"
	echo "Content-Transfer-Encoding: 7bit"
	echo ""
	$FAX2PS $FAX 2>/dev/null
	echo ""

	# PDF: Para convertir ps a pdf parto de como lo hace el script ps2pdf
	# y sustituyo entrada y salida por stdin y stdout (con el simbolo "-")
	# para poder enviar el correo por internet hace falta codificarlo
	# a base64 con mimencode, ya que el pdf contiene codigos de 8 bits
	echo "--$MIMEBOUNDARY"
	echo "Content-Type: application/pdf"
	echo "Content-Description: FAX document in PDF"
	echo "Content-Transfer-Encoding: base64"
	echo ""
	$FAX2PS $FAX 2>/dev/null | gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=- $OPTIONS -c save pop - | mimencode
	echo ""

	# TIFF: Ya es tiff, no hay que convertir ;-)
	echo "--$MIMEBOUNDARY"
	echo "Content-Type: image/tiff"
	echo "Content-Description: FAX document in TIFF"
	echo "Content-Transfer-Encoding: base64"
	echo ""
	cat $FAX | mimencode
	echo ""

	# PNG: Requiere paquetes: netpbm, pnmtopng
	# se ve perfecto, pero hay problemas al imprimir con algunos navegadores
	# es el formato que comprime MAS y *SIN* perdida de calidad
	echo "--$MIMEBOUNDARY"
	echo "Content-Type: image/png"
	echo "Content-Description: FAX document in PNG"
	echo "Content-Transfer-Encoding: base64"
	echo ""
	tifftopnm $FAX 2>/dev/null | pnmtopng | mimencode
	echo ""

	# JPEG: Requiere paquete: netpbm, libjpeg-progs
	# El pbmtopgm convierte a escala de grises aplicando antialiasing
	# jpeg pierde información al comprimir, con -quality 75 queda bien
	# y no se ahorra mucho espacio reduciendo la calidad, ejemplos:
	#
	# 75 172KBytes se ve bien
	# 50 142KBytes puntitos alrededor del texto
	# 25 115KBytes nuve alrededor del texto
	#  0  63KBytes inhumano :-)
	#
	# El mismo fax en los otros formatos:
	# TIFF -> 26KBytes
	# PNG  -> 21KBytes
	# PDF  -> 55KBytes
	#
	echo "--$MIMEBOUNDARY"
	echo "Content-Type: image/jpeg"
	echo "Content-Description: FAX document in JPEG"
	echo "Content-Transfer-Encoding: base64"
	echo ""
	tifftopnm $FAX 2>/dev/null | pbmtopgm 1 1 | cjpeg -grayscale -quality 75 | mimencode
	echo ""

	# Finalizamos el mail
	echo "--$MIMEBOUNDARY--"
	) | 2>&1 $SENDMAIL -f$FROM -oi $TO
}
###########################################################################


FILE="$1"
DEVICE="$2"
COMMID="$3"
MSG="$4"

if [ -f $FILE ]; then
	#
	# Check the sender's TSI and setup to dispatch
	# facsimile received from well-known senders.
	#
	SENDER="`$INFO $FILE | $AWK -F: '/Sender/ { print $2 }' 2>/dev/null`"

	SENDTO=
	if [ -f etc/FaxDispatch ]; then
		. etc/FaxDispatch	# NB: FaxDispatch sets SENDTO based on $SENDER
	fi

	if [ -n "$TOADDR" ]; then

#Comentar esta linea de "emailfax" para no enviar por mail los faxes que llegan,
# esto es util solo si descomentamos la impresión directa...
		emailfax "$TOADDR" "$SENDFROM" "$SENDER" "$FILE" "$DEVICE" "$COMMID" "$MSG" "$SENDTO"

#Descomentar las lineas siguiente para imprimir directamente cada fax que llega
#	    PRINT="lpr"	#Comando para poner trabajo en cola de impresión
#	    $FAX2PS $FILE 2>/dev/null | $PRINT

	fi

	if [ -n "$SENDTO" ]; then
		emailfax "$SENDTO" "$SENDFROM" "$SENDER" "$FILE" "$DEVICE" "$COMMID" "$MSG"
	fi

else
	#
	# Generate notification mail for a failed attempt.
	#
	(echo "To: $TOADDR"
	 echo "From: The HylaFAX Receive Agent <$FROM>"
	 echo "Subject: facsimile not received"
	 echo ""
	 echo "An attempt to receive facsimile on $DEVICE failed because:"
	 echo ""
	 echo "    $MSG"
	 echo ""
	 echo "    ---- Transcript of session follows ----"
	 echo ""
	 if [ -f log/c$COMMID ]; then
	$SED -e '/-- data/d' \
		 -e '/start.*timer/d' -e '/stop.*timer/d' \
		log/c$COMMID
	 elif [ -n "$COMMID" ]; then
	echo "    No transcript available (CommID c$COMMID)."
	 else
	echo "    No transcript available."
	 fi
	) | 2>&1 $SENDMAIL -f$FROM -oi $TOADDR
fi

Reply to: