[prev] [thread] [next] [lurker] [Date index for 2005/02/21]
Author: simon Date: 2005-02-21 13:48:31 +0000 (Mon, 21 Feb 2005) New Revision: 1931 Added: trunk/buscador/lib/Buscador/HTML.pm Modified: trunk/buscador/MANIFEST trunk/buscador/lib/Buscador/Attachment.pm trunk/buscador/lib/Buscador/Decorate.pm Log: Move the HTML parsing stuff out into a seperate module Modified: trunk/buscador/MANIFEST =================================================================== --- trunk/buscador/MANIFEST 2005-02-21 11:01:58 UTC (rev 1930) +++ trunk/buscador/MANIFEST 2005-02-21 13:48:31 UTC (rev 1931) @@ -42,6 +42,7 @@ lib/Buscador/Config.pm lib/Buscador/Date.pm lib/Buscador/Decorate.pm +lib/Buscador/HTML.pm lib/Buscador/Raw.pm lib/Buscador/Recent.pm lib/Buscador/Root.pm Modified: trunk/buscador/lib/Buscador/Attachment.pm =================================================================== --- trunk/buscador/lib/Buscador/Attachment.pm 2005-02-21 11:01:58 UTC (rev 1930) +++ trunk/buscador/lib/Buscador/Attachment.pm 2005-02-21 13:48:31 UTC (rev 1931) @@ -32,8 +32,8 @@ package Email::Store::Attachment; use strict; +use Buscador::HTML; use MIME::Base64 qw(decode_base64); -use HTML::TokeParser::Simple; sub view :Exported { my ($self, $r, $att) = @_; @@ -46,26 +46,7 @@ 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; + $r->{output} = Buscador::HTML::fix_cid($att->mail, $r->{output}); Modified: trunk/buscador/lib/Buscador/Decorate.pm =================================================================== --- trunk/buscador/lib/Buscador/Decorate.pm 2005-02-21 11:01:58 UTC (rev 1930) +++ trunk/buscador/lib/Buscador/Decorate.pm 2005-02-21 13:48:31 UTC (rev 1931) @@ -35,6 +35,7 @@ use Text::Decorator; use Text::Autoformat; use HTML::Scrubber; +use Buscador::HTML; sub format_body { my $mail = shift; @@ -45,7 +46,7 @@ return $mail->body if ($ct =~ m!text/html!i); my $html = ($mail->html)[0]; - return $html->scrubbed if $html; + return Buscador::HTML::fix_cid($mail,$html->raw) if $html; my $body = $mail->body; Added: trunk/buscador/lib/Buscador/HTML.pm =================================================================== --- trunk/buscador/lib/Buscador/HTML.pm 2005-02-21 11:01:58 UTC (rev 1930) +++ trunk/buscador/lib/Buscador/HTML.pm 2005-02-21 13:48:31 UTC (rev 1931) @@ -0,0 +1,56 @@ +package Buscador::HTML; +use HTML::TokeParser::Simple; + + +sub fix_cid { + my ($mail, $body) = @_; + + my $id = $mail->id; + my @attachments = $mail->attachments; + my $base = Buscador->config->{uri_base}; $base =~ s!/+$!!; + + my $html = ""; + my $parser = HTML::TokeParser::Simple->new( string => $body ); + 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; + } + + return $html; +} + + +1; +__END__ + +=pod + +=head1 NAME + +Buscador::HTML - various html related utilities + +=head1 METHODS + +=head2 fix_cid <message> <html> + +Parse some html and replace all internal C<cid> links with internal Buscador links. + +=head1 AUTHOR + +Simon Wistow <simon@xxxxxxxxxx.xxx> + +=head1 COPYRIGHT + +Copyright, 2005 - Simon Wistow + +Distributed under the same terms as Perl itself. + +=cut
Generated at 14:00 on 21 Feb 2005 by mariachi 0.52