# Copyright (c) 2008 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: MailBodyPlain.pm,v 1.3 2008/10/27 21:58:03 nagler Exp $ package Bivio::UI::XHTML::Widget::MailBodyPlain; use strict; use Bivio::Base 'XHTMLWidget.Tag'; use Text::Tabs (); our($VERSION) = sprintf('%d.%02d', q$Revision: 1.3 $ =~ /\d+/g); sub NEW_ARGS { return [qw(value ?class)]; } sub initialize { my($self) = @_; $self->put_unless_exists( tag => 'div', class => 'text_plain', ); return shift->SUPER::initialize(@_); } sub render_tag_value { my($self, $source, $buffer) = @_; $$buffer .= join( "
\n", map({ $_ = Text::Tabs::expand($_); $_ =~ s{ ((?:ftp|http)s?:\/\/[^\s"]*)(?=[\s>\)\],\.\!"']|$) | ([\w\-\+\.]+@(?:[[\w\-]{2,}\.?){2,}) | (?:^|(?<=\W))(www(?:\.[\w\-]{2,}){2,})(?=\W|$) | ([\&<>]) }{ $1 ? _a($1, $1) : $2 ? _a("mailto:$2", $2) : $3 ? _a("http://$3", $3) : Bivio::HTML->escape($4) }exsg; $_ =~ s/^(\s+)/' ' x length($1)/es; $_; } split(/\n/, $self->render_simple_attr('value', $source))), ); return; } sub _a { my($href, $value) = @_; return qq{$value}; } 1;