[prev] [thread] [next] [lurker] [Date index for 2005/02/20]
Author: simon
Date: 2005-02-20 20:33:47 +0000 (Sun, 20 Feb 2005)
New Revision: 1925
Modified:
trunk/buscador/lib/Buscador/Attachment.pm
Log:
Make it so that html attachments have their inline images correctly rereferenced to
an internal buscador url
Modified: trunk/buscador/lib/Buscador/Attachment.pm
===================================================================
--- trunk/buscador/lib/Buscador/Attachment.pm 2005-02-19 13:20:04 UTC (rev 1924)
+++ trunk/buscador/lib/Buscador/Attachment.pm 2005-02-20 20:33:47 UTC (rev 1925)
@@ -33,8 +33,8 @@
package Email::Store::Attachment;
use strict;
use MIME::Base64 qw(decode_base64);
+use HTML::TokeParser::Simple;
-
sub view :Exported {
my ($self, $r, $att) = @_;
@@ -43,6 +43,33 @@
$r->{content_type} = $att->content_type;
$r->{output} = ($att->content_type =~ m!^text/!) ? $att->payload: decode_base64($att->payload);
+
+ return unless $att->content_type eq 'text/html';
+
+ my $mail = $att->mail;
+ my $id = $mail->message_id;
+ my @attachments = $mail->attachments;
+ my $base = Buscador->config->{uri_base}; $base =~ s!/+$!!;
+
+ my $html = "";
+ my $parser = HTML::TokeParser::Simple->new( string => $r->{output} );
+ while (my $token = $parser->get_token) {
+
+ goto END unless $token->is_start_tag( qr/img/ );
+ my $src = $token->get_attr('src');
+ goto END unless defined $src;
+
+ if ($src =~ m!^cid:part(\d+)!) {
+ $token->set_attr('src', "${base}/attachment/view/".$attachments[$1]->id);
+ }
+
+ END: $html .= $token->as_is;
+ }
+ $r->{output} = $html;
+
+
+
+
}
1;
Generated at 21:00 on 20 Feb 2005 by mariachi 0.52