#* MAIL SPECIFIC DECORATOR
Here the context is mail content. Current modes of display are - 'view', 'view-thread' and 'remove'
*#

#set ($helper = $params.get("helper"))
#set ($mode = $params.get("mode"))
#set ($mail = $helper.mail)
#set ($mailPanelWidth = $params.get("mailpanel-width"))

## mail specific macros
#macro (threadLine $node)
    #if (!$node.empty)
        <a href="$req.contextPath/display/$space.key/mail/$node.mailId" title="View this mail">$generalUtil.escapeXml($node.title)</a> $generalUtil.escapeXml($generalUtil.findAndMaskEmail($!node.from, $user))
        <p class="smalltext excerpt">$generalUtil.escapeXml($helper.action.getExcerpt($node.mailId))
    #else
        (message missing)
    #end
#end
#macro (threadChildren)
    #if (!$action.positionInThread.children.empty)
        <ul>
        #foreach ($child in $helper.action.positionInThread.children)
           <li>#threadLine($child)
           #if ($child.descendentsCount == 1)
                <span style="padding-left: 10px; color: #666666" class="smallfont">
                    ($child.descendentsCount more message in this thread)
                </span>
           #elseif ($child.descendentsCount > 1)
                <span style="padding-left: 10px; color: #666666" class="smallfont">
                    ($child.descendentsCount more messages in this thread)
                </span>
           #end
           </li>
        #end
        </ul>
    #end
#end

#infoPanelInitFromParams()
## GENERAL PAGE DECORATING BEGINS

<div id="navigation">
    <ul class="ajs-menu-bar">
        #menuMacros_renderAddMenu()
    </ul>
    #if ($mode != "remove" || $mode != "view-thread")
        <ul class="tabnav">
            <li class="tabs">
                #viewMailLink()
            </li>
        </ul>
    #end
</div>

            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td valign="top" class="pagebody">
            ## output errors
            #parse ( "/template/includes/actionerrors.vm" )
            ## MODE SPECIFIC DECORATING BEGINS
            <table width="100%" cellpadding="0" cellspacing="0" border="0" style="clear: both">
                <tr>
                    <td class="pagecontent" valign="top">


                    ## VIEW
                    #if ($mode == "view")

                        #if (!$action.hasErrors())
                            #permitSearchEngines()

                            <div class="greybox" style="padding: 10px; ">
                               <table cellpadding="0" width="100%" border=0>
                                <tr>
                                    <td width="75" class="mailLabel" align="right">$helper.getText("view.mail.subject"):</td>
                                    <td width="5">&nbsp;</td>
                                    <td><strong>$mail.title</strong>&nbsp;<span class="smalltext">(<a title="$helper.getText("find.mail.bySubject")" href="$req.contextPath/dosearchsite.action?key=$action.space.key&type=mail&queryString=%22$generalUtil.urlEncode($mail.displayableCanonicalSubject)%22">$helper.getText("mail.related")</a>)</span></td>
                                </tr>
                                <tr>
                                    <td class="mailLabel" align="right">$helper.getText("view.mail.from"):</td>
                                    <td width="5">&nbsp;</td>
                                    <td>#foreach ($address in $mail.from) $!generalUtil.escapeXml($generalUtil.findAndMaskEmail($address.toUnicodeString(), $user))&nbsp;#if($address.personal)<span class="smalltext">(<a title="$helper.getText("find.mail.byAuthor")" href="$req.contextPath/dosearchsite.action?key=$action.space.key&type=mail&queryString=%22$generalUtil.urlEncode($address.personal)%22%20%22$generalUtil.urlEncode($address.address)%22">$helper.getText("mail.related")</a>)</span>#end#end</td>        </tr>
                                <tr>
                                    <td class="mailLabel" align="right">$helper.getText("view.mail.date"):</td>
                                    <td width="5">&nbsp;</td>
                                    <td>$action.dateFormatter.formatDateTime($mail.creationDate)</td>
                                </tr>
                                <tr><td colspan="3"><hr style="border: 0; height: 1px; background-color: #cccccc"></td></tr>
                                <tr>
                                    <td colspan="3">
                                        <div class="monospaceInput">$generalUtil.plain2html($generalUtil.findAndMaskEmail($mail.messageBody, $user))</div>
                                    </td>
                                </tr>
                                </table>
                            </div>

                            #if ($action.attachmentsShowing)
                                #if ($latestVersionsOfAttachments.size() > 0)
                                    <div class="tabletitle">
                                        <a name="attachments">Attachments</a>

                                        <span class="bodytext">
                                        &nbsp;
                                        <a href="$req.contextPath$generalUtil.appendAmpsandOrQuestionMark($mail.urlPath)showAttachments=false">Hide Attachments</a>
                                        #if ($action.attachmentsInWebDavFolder)
                                            <a href="$helper.attachmentsWebDavUrlForPage" style="{behavior: url(#default#AnchorClick);}"
                                               folder="$helper.attachmentsWebDavUrlForPage" target="_top">Open Web Folder</a>
                                        #end
                                        </span>
                                    </div>

                                    <div class="greybox" align="left">
                                        #foreach( $attachment in $latestVersionsOfAttachments )
                                            <div class="attachment" #if ($action.highlight.contains($attachment.fileName)) style="background:#ddffdd" #end>
                                                #if ($attachment.previousVersions && !$attachment.previousVersions.isEmpty())<img align="absmiddle" height="16" width="16" id="arrow$attachment.id" src="$staticResourceUrlPrefix/images/icons/arrow_closed_active_16.gif" onClick="javascript:toggle('$attachment.id')">#else<img align="absmiddle" height="16" width="16" id="arrow$attachment.id" src="$staticResourceUrlPrefix/images/border/spacer.gif">#end<a name="$generalUtil.urlEncode($mail.title)-attachment-$generalUtil.urlEncode($attachment.fileName)">#parse ("/pages/includes/attachment_icon.vm")</a>
                                                <a href="$req.contextPath$attachment.downloadPath">$attachment.fileName</a>

                                                <span class="smalltext">
                                                    ($attachment.niceFileSize -
                                                    #usernameLink($attachment.lastModifierName) -
                                                    $dateFormatter.format($attachment.lastModificationDate))
                                                </span>

                                            </div>

                                            #if ($attachment.previousVersions && !$attachment.previousVersions.isEmpty())
                                                <div id="attachment$attachment.id" style="display: none">
                                                    #foreach( $previousVersionOfAttachment in $attachment.previousVersionsSorted )
                                                        <img align="absmiddle" height="16" width="16" id="arrow$attachment.id" src="$staticResourceUrlPrefix/images/border/spacer.gif"><img align="absmiddle" height="16" width="16" id="arrow$attachment.id" src="$staticResourceUrlPrefix/images/icons/arrow_block_16.gif">
                                                        <span class="smalltext">
                                                        <a href="$req.contextPath$previousVersionOfAttachment.downloadPath">Version $previousVersionOfAttachment.getVersion()</a>
                                                        #if (!$helper.attachmentsInWebDavFolder)
                                                            ($previousVersionOfAttachment.niceFileSize -
                                                            #usernameLink($previousVersionOfAttachment.lastModifierName) -
                                                            ${dateFormatter.format($previousVersionOfAttachment.lastModificationDate)})
                                                            #if ($previousVersionOfAttachment.comment && $previousVersionOfAttachment.comment.length() > 0)
                                                                <div class="smalltext" style="margin: 0 0 0 36px">$previousVersionOfAttachment.comment</div>
                                                            #end
                                                        #end
                                                        </span><br>
                                                    #end
                                                </div>
                                            #end
                                        #end
                                    </div>
                                #end
                            #else
                                #if ($latestVersionsOfAttachments.size() > 0)
                                    <div class="greybox">
                                        <img src="$staticResourceUrlPrefix/images/icons/attach_file_16.gif" height="16" width="16" border="0" align="absmiddle">
                                        <a href="$req.contextPath$generalUtil.appendAmpsandOrQuestionMark($mail.urlPath)showAttachments=true#attachments">$latestVersionsOfAttachments.size() attachment#if($mail.attachments.size() > 1)s#end</a>
                                    </div>
                                #end
                            #end

                            ## Preliminary threading hack
                            #if ($helper.action.inThread)
                                <div class="greybox" style="padding: 10px">
                                <a href="$req.contextPath/spaces/viewthread.action?key=$helper.action.key&id=$helper.action.mail.id" title="$helper.getText("view.mail.thread.title")"><img src="$staticResourceUrlPrefix/images/icons/mail_thread_16.gif" height=16 width=16 align="absmiddle" border="0" alt=""></a> <a href="$req.contextPath/spaces/viewthread.action?key=$helper.action.key&id=$helper.action.mail.id" title="$helper.getText("view.mail.thread.title")">${helper.action.getText("view.mail.thread.desc.full", [$helper.action.visibleThreadCount, $helper.action.totalThreadCount])}</a>
                                <p>
                                    <ul class="mailthread #if ($helper.action.positionInThread.parent.parent.parent) parented #else unparented #end">

                                        #foreach ($parent in $helper.action.getParents(2))
                                            <li>#threadLine($parent)<ul>
                                        #end

                                        #if ($helper.action.positionInThread.parent)
                                            #foreach ($child in $helper.action.positionInThread.parent.children)
                                                #if ($child == $helper.action.positionInThread)
                                                    <li><div class="selectedMail"><strong>$generalUtil.escapeXml($child.title)</strong> $generalUtil.escapeXml($generalUtil.findAndMaskEmail($child.from, $user))
                                                    <p class="smalltext excerpt">$generalUtil.escapeXml($helper.getExcerpt($child.mailId))</p></div>
                                                    #threadChildren()
                                                    </li>
                                                #else
                                                    <li>#threadLine($child)</li>
                                                #end
                                            #end
                                        #else
                                            <li><span class="selectedMail"><strong>$generalUtil.escapeXml($helper.action.positionInThread.title)</strong> $generalUtil.escapeXml($generalUtil.findAndMaskEmail($helper.action.positionInThread.from, $user))</span>
                                            #threadChildren()
                                            </li>
                                        #end

                                    </ul>

                                    #foreach ($parent in $helper.action.getParents(2))
                                        </ul></li>
                                    #end
                                    #if ($helper.action.positionInThread.parent.parent.parent)
                                        </ul></li>
                                    #end

                                    </ul>
                                </div>
                            #end
                        #end

                    ## VIEW THREAD
                    #elseif ($mode == "view-thread")
                        #permitSearchEngines()

                        $body

                    ## VIEW THREAD
                    #elseif ($mode == "remove")

                        $body

                    #end

                    ## MAIL PANEL TO HOLD OPERATIONS
                    #if (!$action.hasErrors())
                        #if ($mailPanelWidth)
                            <td width="$mailPanelWidth" valign="top">
                                <div class="rightpanel">
                                    #mailOperations($helper)
                                </div>
                            </td>
                        #end
                    #end

                </td>
            </tr>
        </table>

        ## MODE SPECIFIC DECORATING ENDS
        </td>
    </tr>
</table>
## GENERAL PAGE DECORATING ENDS

#parse("/breadcrumbs.vm")

#if ($space)
    <content tag="spacename">$space.name</content>
    <content tag="spacekey">$helper.spaceKey</content>
    <content tag=mailId>$mail.id</content>
#end
