Dealing with Unicode encoding can be a challenging task. However, it’s crucial for ensuring the accurate transmission of messages. In this blog post, we’ll explore some scripts and techniques that can help you work with Unicode in Hylafax/FaxMail, specifically for incoming HTML and text faxes.
HTML Fax Handling:
When it comes to processing HTML faxes with Unicode encoding, you can use the following script:
#!/bin/bash
cp -pf $1 /tmp/email.html
/usr/bin/lynx -dump -display_charset=utf-8 /tmp/email.html > /tmp/html_txt
/usr/bin/uniprint -font /etc/hylafax/faxmail/Cyberbit.ttf -in /tmp/html_txt -out /tmp/html_txt.uni
cat /tmp/html_txt.uni | /etc/hylafax/faxmail/filter.pl
rm /tmp/email.html
rm /tmp/html_txt
rm /tmp/html_txt.uni
Here’s a breakdown of what this script does:
- It copies the incoming fax to a temporary file,
/tmp/email.html
. - Using
lynx
, redirect the HTML content to plain text while specifying the UTF-8 character set for proper encoding. - The
uniprint
utility is then used to apply theCyberbit.ttf
font to the converted text, saving it as/tmp/html_txt.uni
. - Finally, it pipes the content through
filter.pl
, a Perl script that processes the text.
Plain Text Fax Handling:
For plain text faxes with Unicode encoding, you can utilize this script:
/usr/bin/uniprint -font /etc/hylafax/faxmail/Cyberbit.ttf -in $1 -out /tmp/plain_txt
cat /tmp/plain_txt | /etc/hylafax/faxmail/filter.pl
rm /tmp/plain_txt
This script is more straightforward. It uses uniprint
to apply the Cyberbit.ttf
font to the plain text content, and then pipes it through filter.pl
.
filter.pl:
The filter.pl
Perl script is responsible for processing the text content, including stripping out any “showpage” directives.
#!/usr/bin/perl
# Read from the standard input
@text=;
$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 contains "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];
}
This Perl script processes the text, counts the “showpage” occurrences, and removes the last “showpage” directive.
Leave a Reply