#!/usr/bin/perl -w # Antispam.pl # Copyright (C) 2003 Oliver Bossert # 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use strict; use Image::Magick; my $DB = "dbase.txt"; my $IMGPATH = "./"; my @names = (); open DB, $DB or warn "Could not open file $DB"; while () { chomp; push @names, [split]; } close DB; # Read the file my $string; open IN, $ARGV[0] or die "Could not open file : " . $ARGV[0] . "!"; while () { $string .= $_; } close IN; $string =~ s/\"mailto:.+?\"/mailto:please\@type.it.manually.in/g; while ($string =~ /(\w+@\w+(\.\w+)+)/g ) { my $mail = $1; if ($mail ne "please\@type.it.manually.in") { my $nb = subst( $mail ); if (!defined($nb)) { $nb = 0; $nb = $names[$#names][1] if ($#names>=0); $nb++; $nb = sprintf("%04d", $nb); create_pic( $mail, filename($nb) ); push @names, [$mail, $nb]; } $nb = ''; $mail = quotemeta($mail); $string =~ s/$mail/$nb/; } } print $string; open DB, ">" . $DB or die "Could not open file : " . $DB . " for writing!"; for (my $i=0; $i<=$#names; $i++) { print DB $names[$i][0] . "\t" . $names[$i][1] . "\n"; } close DB; sub filename { my $nb = shift; return $IMGPATH . $nb . ".png"; } sub subst { my $mail = shift; my @erg = grep {$_->[0] eq $mail} @names; my $ret = undef; $ret = $erg[0][1] if ( $#erg >= 0); return $ret; } sub create_pic { my ($mail, $file) = @_; my $i = new Image::Magick; $i->ReadImage('xc:white'); my ($xp, $yp, $ascend, $descend, $width, $height, $max_advance) = $i->QueryFontMetrics( font=>'/usr/X11R6/lib/X11/fonts/truetype/arial.ttf', pointsize=>11, text=>$mail, antialias=>'true'); my $realheight = $ascend - $descend; my $image = new Image::Magick ( size=>$width . 'x' . $realheight ); $image->ReadImage('xc:white'); $image->Annotate( font => '/usr/X11R6/lib/X11/fonts/truetype/arial.ttf', encoding => 'UTF-8', text => $mail, pointsize => 11, fill => 'black', x=>0, y=> $ascend ); $image->Write($file); }