6 use Debbugs::Config qw(:config);
7 use Debbugs::CGI qw(cgi_parameters);
9 use Digest::MD5 qw(md5_hex);
11 use File::Temp qw(tempfile);
12 use Debbugs::Libravatar qw(:libravatar);
22 my $q = CGI::Simple->new();
25 cgi_parameters(query => $q,
26 single => [qw(email avatar default)],
27 default => {avatar => 'yes',
28 default => $config{libravatar_uri_options},
31 # if avatar is no, serve the empty png
32 if ($param{avatar} ne 'yes' or not defined $param{email} or not length $param{email}) {
37 # figure out what the md5sum of the e-mail is.
38 my $email_md5sum = md5_hex(lc($param{email}));
39 my $cache_location = cache_location(email => lc($param{email}));
40 # if we've got it, and it's less than one hour old, return it.
41 if (cache_valid($cache_location)) {
42 serve_cache($cache_location,$q);
45 # if we don't have it, get it, and store it in the cache
46 $cache_location = retrieve_libravatar(location => $cache_location,
47 email => lc($param{email}),
49 if (not defined $cache_location) {
50 # failure, serve the default image
54 serve_cache($cache_location,$q);
60 my ($cache_location,$q) = @_;
61 if (not defined $cache_location or not length $cache_location) {
62 # serve the default image
63 $cache_location = $config{libravatar_default_image};
65 my $fh = IO::File->new($cache_location,'r') or
66 error($q,404, "Failed to open cached image $cache_location");
67 my $m = File::LibMagic->new() or
68 error($q,500,'Unable to create File::LibMagic object');
69 my $mime_string = $m->checktype_filename(abs_path($cache_location)) or
70 error($q,500,'Bad file; no mime known');
71 print $q->header(-type => $mime_string,
80 my ($q,$error,$text) = @_;
82 print $q->header(-status => $error);
83 print "<h2>$error: $text</h2>";