antispam.pl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 2 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, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA
  18. use strict;
  19. use v5.10;
  20. AddModuleDescription('antispam.pl', 'Antispam Module');
  21. our (@MyRules);
  22. our ($DoMaskEmail, $CreateMailtoLinks, $EmailRegExp);
  23. $DoMaskEmail = 1; # Mask all email, not just those in []'s
  24. $CreateMailtoLinks = 1; # Create mailto's for all addresses
  25. $EmailRegExp = '[\w\.\-]+@([\w\-]+\.)+[\w]+';
  26. push(@MyRules, \&MaskEmailRule);
  27. sub MaskEmailRule {
  28. # Allow [email@foo.bar Email Me] links
  29. if (m/\G\[($EmailRegExp(\s\w+)*\s*)\]/cgi) {
  30. my $chunk = $1;
  31. $chunk =~ s/($EmailRegExp)//i;
  32. my $email = $1;
  33. $chunk =~ s/^\s*//;
  34. $chunk =~ s/\s*$//;
  35. my $masked = '';
  36. my @decimal = unpack('C*', $email);
  37. for (@decimal) {
  38. $masked .= '&#' . $_ . ';';
  39. }
  40. $email = $masked;
  41. $chunk = $email if $chunk eq "";
  42. return "<a href=\"mailto:$email\">$chunk</a>";
  43. }
  44. if (m/\G($EmailRegExp)/cgi) {
  45. my $email = $1;
  46. if ($DoMaskEmail) {
  47. my $masked="";
  48. my @decimal = unpack('C*', $email);
  49. for (@decimal) {
  50. $masked .= '&#' . $_ . ';';
  51. }
  52. $email = $masked;
  53. }
  54. if ($CreateMailtoLinks) {
  55. $email = "<a href=\"mailto:" . $email . "\">$email</a>";
  56. }
  57. return $email;
  58. }
  59. return;
  60. }