]> 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)
Debbugs/CGI/Bugreport.pm
Debbugs/Config.pm
html/bugs.css

index 707c3a0d68a315d6e7791b265a04312be1b16522..29602c58c39f1088bc17208e49ab28c1561ac152 100644 (file)
@@ -32,6 +32,8 @@ use base qw(Exporter);
 
 use IO::Scalar;
 use Params::Validate qw(validate_with :types);
+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);
@@ -133,19 +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)?(?:;|$)})
@@ -426,6 +434,15 @@ sub handle_record{
 }
 
 
+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;
 
index 87e61a2f54de7efabac7526b12fda83529065a79..3a6e7cf366290b4e2f9e83ce8294488f2f38ce73 100644 (file)
@@ -364,6 +364,38 @@ Default: list_domain
 set_default(\%config,'bug_subscription_domain',$config{list_domain});
 
 
+=head2 CGI Options
+
+=over
+
+=item libravatar_uri
+
+URI to a libravatar configuration. If empty or undefined, libravatar
+support will be disabled. Defaults to
+http://cdn.libravatar.org/avatar/ which uses a federated Avatar system
+and falls back to gravatar if necessary.
+
+=cut
+
+set_default(\%config,'libravatar_uri',"http://cdn.libravatar.org/avatar/");
+
+=item libravatar_uri_options
+
+Options to append to the md5_hex of the e-mail. This sets the default
+avatar used when an avatar isn't available. Currently defaults to
+'?d=retro', which causes a bitmap-looking avatar to be displayed for
+unknown e-mails.
+
+Other options which make sense include ?d=404, ?d=wavatar, etc. See
+the API of libravatar for details.
+
+=cut
+
+set_default(\%config,'libravatar_uri_options','?d=retro');
+
+
+=back
+
 =head2 Misc Options
 
 =over
index db1d34b1d8c2265accc5320fe5a18d2d0a6254aa..8e324454f30371c2b97b14d0fd6e432c8c076311 100644 (file)
@@ -126,6 +126,29 @@ pre.headers {
     line-height: 120%
 }
 
+div.headers { 
+    border: #a7a7a7 1px solid;
+    background-color: #f0f0f0;
+    padding: 2px;
+ }
+
+div.headers p {
+    font-family: sans-serif;
+    font-size: 95%;
+    color: #3c3c3c;
+    padding: 0px;
+    line-height: 120%;
+    margin: 0px;
+}
+
+div.headers img {  
+    float: right;
+}
+
+span.header { 
+  font-weight: bold
+ };
+
 pre.mime {
     font-family: monospace;
     font-size: 95%;