%# vim:ft=mason:sts=4:sw=4:et:
<%ARGS>
$Transaction
$EmailRecordPath
$Actions
</%ARGS>
<%INIT>

if ($Transaction->ObjectType eq 'RT::Ticket'
        and $Transaction->Type !~ /EmailRecord$/
        and $Transaction->HasContent
        and $EmailRecordPath) {

    # find the top-level attachment
    my $Attachment = $Transaction->Attachments->First;
    while ($Attachment->ParentObj) {
        $Attachment = $Attachment->ParentObj;
    }

    my $title;
    if ($RT::MAJOR_VERSION >= 5) {
        my $alt = loc('Show email contents');
        $title = qq[<span class="fas fa-envelope-open-text" alt="$alt" data-toggle="tooltip" data-placement="top" data-original-title="$alt"></span>];
    } else {
        $title = loc('Show');
    }

    push( @$Actions, {
        title  => $title,
        target => '_blank',
        path => $EmailRecordPath
            . '?id=' . $Transaction->ObjectId
            . '&Transaction=' . $Transaction->Id
            . '&Attachment=' . $Attachment->Id
    } );
}

</%INIT>
