Browse Source

improve email address munging, and apply to raw output

Byron Jones 6 years ago
parent
commit
a2955f5124
2 changed files with 17 additions and 4 deletions
  1. 2 2
      lib/LogBot/Web/Channel.pm
  2. 15 2
      lib/LogBot/Web/Util.pm

+ 2 - 2
lib/LogBot/Web/Channel.pm

@@ -8,7 +8,7 @@ use DateTime ();
 use Encode qw( decode );
 use LogBot::Database qw( dbh execute_with_timeout );
 use LogBot::Util qw( event_to_short_string );
-use LogBot::Web::Util qw( channel_from_param date_from_param preprocess_event );
+use LogBot::Web::Util qw( channel_from_param date_from_param munge_emails preprocess_event );
 
 sub _get_logs {
     my ($c, $dbh, $channel, $date) = @_;
@@ -125,7 +125,7 @@ sub render_raw {
 
     my @lines;
     foreach my $event (@{$logs}) {
-        $event->{text} = decode('UTF-8', $event->{text});
+        $event->{text} = munge_emails(decode('UTF-8', $event->{text}));
         push @lines, event_to_short_string($event);
     }
 

+ 15 - 2
lib/LogBot/Web/Util.pm

@@ -3,6 +3,7 @@ use local::lib;
 use v5.10;
 use strict;
 use warnings;
+use utf8;
 
 use Date::Parse qw( str2time );
 use DateTime ();
@@ -23,7 +24,7 @@ our @EXPORT_OK = qw(
     rewrite_old_urls
     url_for_channel irc_host
     channel_from_param date_from_param
-    linkify
+    linkify munge_emails
     preprocess_event
     channel_topics
 );
@@ -185,7 +186,7 @@ sub linkify {
     $finder->find(\$value, \&xml_escape);
 
     # munge email addresses
-    $value =~ s{([a-zA-Z0-9\.-]+)\@(([a-zA-Z0-9\.-]+\.)+[a-zA-Z0-9\.-]+)}{$1⊙$2}g;
+    $value = munge_emails($value);
 
     # linkify "bug NNN"
     $value =~ s{(\bbug\s+(\d+))}{<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=$2">$1</a>}gi;
@@ -196,6 +197,18 @@ sub linkify {
     return $value;
 }
 
+sub _munge_domain {
+    my ($domain) = @_;
+    $domain =~ s/(.)(?:[^.]+\.|.+$)/$1/g;
+    return $domain;
+}
+
+sub munge_emails {
+    my ($value) = @_;
+    $value =~ s{([a-zA-Z0-9\.-]+)\@(([a-zA-Z0-9\.-]+\.)+[a-zA-Z0-9\.-]+)}{$1 . '⊙' . _munge_domain($2)}ge;
+    return $value;
+}
+
 # trims the middle of a url, or generates nice short version
 sub shorten_url {
     my ($value) = @_;