6 use Debbugs::Config qw(:config);
7 use Debbugs::CGI qw(cgi_parameters);
10 use Debbugs::Libravatar qw(:libravatar);
17 my $q = CGI::Simple->new();
20 cgi_parameters(query => $q,
21 single => [qw(email avatar default)],
22 default => {avatar => 'yes',
23 default => $config{libravatar_uri_options},
26 # if avatar is no, serve the empty png
27 if ($param{avatar} ne 'yes' or not defined $param{email} or not length $param{email}) {
32 my ($cache_location, $is_valid) = cache_location(email => lc($param{email}));
33 # if we've got it, and it's less than one hour old, return it.
35 serve_cache($cache_location,$q);
38 # if we don't have it, get it, and store it in the cache
39 $cache_location = retrieve_libravatar(location => $cache_location,
40 email => lc($param{email}),
42 if (not defined $cache_location) {
43 # failure, serve the default image
47 serve_cache($cache_location,$q);
53 my ($cache_location,$q) = @_;
54 if (not defined $cache_location or not length $cache_location) {
55 # serve the default image
56 $cache_location = $config{libravatar_default_image};
58 my $fh = IO::File->new($cache_location,'r') or
59 error($q,404, "Failed to open cached image $cache_location");
60 my $m = File::LibMagic->new() or
61 error($q,500,'Unable to create File::LibMagic object');
62 my $mime_string = $m->checktype_filename(abs_path($cache_location)) or
63 error($q,500,'Bad file; no mime known');
64 print $q->header(-type => $mime_string,
73 my ($q,$error,$text) = @_;
75 print $q->header(-status => $error);
76 print "<h2>$error: $text</h2>";