antispam.pl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (C) 2004, 2005 Fletcher T. Penney <fletcher@freeshell.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('antispam.pl', 'Antispam Module');
  18. our (@MyRules);
  19. our ($DoMaskEmail, $CreateMailtoLinks, $EmailRegExp);
  20. $DoMaskEmail = 1; # Mask all email, not just those in []'s
  21. $CreateMailtoLinks = 1; # Create mailto's for all addresses
  22. $EmailRegExp = '[\w\.\-]+@([\w\-]+\.)+[\w]+';
  23. push(@MyRules, \&MaskEmailRule);
  24. sub MaskEmailRule {
  25. # Allow [email@foo.bar Email Me] links
  26. if (m/\G\[($EmailRegExp(\s\w+)*\s*)\]/cgi) {
  27. my $chunk = $1;
  28. $chunk =~ s/($EmailRegExp)//i;
  29. my $email = $1;
  30. $chunk =~ s/^\s*//;
  31. $chunk =~ s/\s*$//;
  32. my $masked = '';
  33. my @decimal = unpack('C*', $email);
  34. for (@decimal) {
  35. $masked .= '&#' . $_ . ';';
  36. }
  37. $email = $masked;
  38. $chunk = $email if $chunk eq "";
  39. return "<a href=\"mailto:$email\">$chunk</a>";
  40. }
  41. if (m/\G($EmailRegExp)/cgi) {
  42. my $email = $1;
  43. if ($DoMaskEmail) {
  44. my $masked="";
  45. my @decimal = unpack('C*', $email);
  46. for (@decimal) {
  47. $masked .= '&#' . $_ . ';';
  48. }
  49. $email = $masked;
  50. }
  51. if ($CreateMailtoLinks) {
  52. $email = "<a href=\"mailto:" . $email . "\">$email</a>";
  53. }
  54. return $email;
  55. }
  56. return;
  57. }