]> git.donarmstrong.com Git - debbugs.git/commitdiff
merge libravatar support into master
authorDon Armstrong <don@donarmstrong.com>
Thu, 14 Mar 2013 20:13:56 +0000 (13:13 -0700)
committerDon Armstrong <don@donarmstrong.com>
Thu, 14 Mar 2013 20:13:56 +0000 (13:13 -0700)
1  2 
Debbugs/CGI/Bugreport.pm

diff --combined Debbugs/CGI/Bugreport.pm
index 707c3a0d68a315d6e7791b265a04312be1b16522,59d88b07f5dedbdcb112574881a2085f084405be..29602c58c39f1088bc17208e49ab28c1561ac152
@@@ -32,10 -32,11 +32,12 @@@ use base qw(Exporter)
  
  use IO::Scalar;
  use Params::Validate qw(validate_with :types);
 -use Debbugs::MIME qw(convert_to_utf8 decode_rfc1522 create_mime_message);
+ use Digest::MD5 qw(md5_hex);
+ use Debbugs::Mail qw(get_addresses);
 +use Debbugs::MIME qw(decode_rfc1522 create_mime_message);
  use Debbugs::CGI qw(:url :html :util);
  use Debbugs::Common qw(globify_scalar english_join);
 +use Debbugs::UTF8;
  use Debbugs::Config qw(:config);
  use POSIX qw(strftime);
  use Encode qw(decode_utf8);
@@@ -133,19 -134,25 +135,25 @@@ sub display_entity 
        not $param{terse} and
        not exists $param{att}) {
         my $header = $entity->head;
-        print {$param{output}} "<pre class=\"headers\">\n";
+        print {$param{output}} "<div class=\"headers\">\n";
         if ($param{trim_headers}) {
              my @headers;
              foreach (qw(From To Cc Subject Date)) {
                   my $head_field = $head->get($_);
                   next unless defined $head_field and $head_field ne '';
-                  push @headers, qq(<b>$_:</b> ) . html_escape(decode_rfc1522($head_field));
+                    if ($_ eq 'From') {
+                        my $libravatar_url = __libravatar_url(decode_rfc1522($head_field));
+                        if (defined $libravatar_url and length $libravatar_url) {
+                            push @headers,q(<img src=").$libravatar_url.q(">);
+                        }
+                    }
+                  push @headers, qq(<p><span class="header">$_:</span> ) . html_escape(decode_rfc1522($head_field))."</p>";
              }
              print {$param{output}} join(qq(), @headers);
         } else {
-             print {$param{output}} html_escape(decode_rfc1522($entity->head->stringify));
+             print {$param{output}} "<pre>".html_escape(decode_rfc1522($entity->head->stringify))."</pre>\n";
         }
-        print {$param{output}} "</pre>\n";
+        print {$param{output}} "</div>\n";
      }
  
      if (not (($param{outer} and $type =~ m{^text(?:/plain)?(?:;|$)})
@@@ -335,7 -342,7 +343,7 @@@ sub handle_record
       local $_ = $record->{type};
       if (/html/) {
         # $record->{text} is not in perl's internal encoding; convert it
 -       my $text = decode_utf8(decode_rfc1522($record->{text}));
 +       my $text = decode_rfc1522(decode_utf8($record->{text}));
          my ($time) = $text =~ /<!--\s+time:(\d+)\s+-->/;
          my $class = $text =~ /^<strong>(?:Acknowledgement|Reply|Information|Report|Notification)/m ? 'infmessage':'msgreceived';
          $output .= $text;
  }
  
  
+ sub __libravatar_url {
+     my ($email) = @_;
+     if (not defined $config{libravatar_uri} or not length $config{libravatar_uri}) {
+         return undef;
+     }
+     ($email) = get_addresses($email);
+     return $config{libravatar_uri}.md5_hex(lc($email)).($config{libravatar_uri_options}//'');
+ }
  
  1;