package JWebmail::View::RenderMail;
use Mojo::Base -base;
use Mojo::ByteStream;
use Mojo::Util 'xml_escape';
has 'c';
sub render_text_plain {
my ($_self, $_subtype, $content, $_path) = @_;
$content = xml_escape $content;
return qq'
';
my $i = 0;
my $end;
for (reverse @$parts) {
if (!$end) {
my $x = $self->mime_render(to_mime_types($_->{head}), $_->{body}, [@$path, $#$parts-$i]);
if ($x) {
$R .= $x;
$end = 1;
}
}
else {
$R .= '';
$R .= '';
$R .= to_mime_type($_->{head});
$R .= "
\n";
$R .= $self->mime_render(to_mime_types($_->{head}), $_->{body}, [@$path, $#$parts-$i]);
$R .= " \n";
}
++$i;
}
return $R . "
\n";
}
sub render_multipart {
my ($self, $_subtype, $content, $path) = @_;
my $parts = $content->{parts};
my $R = qq'';
my $i = 0;
for (@$parts) {
if ( !$_->{head}{content_disposition}
|| lc $_->{head}{content_disposition} eq 'none'
|| lc $_->{head}{content_disposition} eq 'inline') {
$R .= $self->mime_render(to_mime_types($_->{head}), $_->{body}, [@$path, $i]);
}
elsif (lc $_->{head}{content_disposition} eq 'attachment') {
$R .= '
';
$R .= $self->c->link_to($self->c->url_for(raw => id => $self->c->stash('id'))->query(path => join('.', @$path, $i)), (download => $_->{head}{filename}) => sub {
'Attachment ' . xml_escape($_->{head}{filename}) . ' of type ' . to_mime_type($_->{head});
});
$R .= "
\n";
}
else {
warn "unknown Content-Disposition '$_->{head}{content_disposition}'";
$R .= "
unknown Content-Disposition '$_->{head}{content_disposition}'
\n";
}
++$i;
}
return $R . "
\n";
}
sub _format_header {
my ($self, $category, $value) = @_;
my $R = '';
if (ref $value eq 'ARRAY' && $value->@*) {
$R .= '