<?php
$currentFolderGlobal = $this->AtmailMailStorageMain->getCurrentFolder();


/**
 * this include is designed to be used recursively, lets hope this is supported in PHP5/6
 * it needs to have $currentThreadNode passed to it, and optional $args
 */
/*
$argsDefault = array('showReply' => true);


if(!isset($args) )
	$args = $argsDefault;
else
	$args = array_merge($argsDefault, $args);
*/

$folderUTF7UrlencodedDouble = urlencode( urlencode( $this->folderUTF7 ) );

//set uniqueid else false
if( isset($this->currentThreadNode['UID']) && $this->currentThreadNode['UID']!='' )
	$currentUID = $this->currentThreadNode['UID'];
else if( isset($header['uniqueid']) && $header['uniqueid'] != '' )
	$currentUID = $header['uniqueid'];
else
	$currentUID = null;

if( !array_key_exists('_preview', $this->currentThreadNode) )
{
	$cacheName = Atmail_Cache::generateCacheIdString(array($folderUTF7UrlencodedDouble, $currentUID));
	$this->currentThreadNode['_preview'] = Atmail_Cache::fetch(Atmail_Cache::TYPE_MAIL_PREVIEW, $cacheName );
}

if( array_key_exists('_preview', $this->currentThreadNode) )
	$preview = mb_substr(strip_tags($this->currentThreadNode['_preview']), 0, 300);//strpos($this->currentThreadNode['_preview'], '-----') );
else
	$preview = '';

if( isset($this->currentThreadNode['messageArray']) ) :

	$preparedMessageArray = $this->currentThreadNode['messageArray'];
	$header = $preparedMessageArray['headers'];
	
	if( empty($header['name']) && ($header['email'] == '@' ||  $header['email'] == '') ) 
	{
		
		if( !empty($header['from']) ) 
		{
		
			$gtPos = strrpos($header['from'], '<');
			if( $gtPos !== false && trim(substr($header['from'], 0, $gtPos)) != 'Unknown' )
				$addressString = '<strong>' . htmlentities(substr($header['from'], 0, $gtPos), null, 'UTF-8') . '</strong> ' . htmlentities(substr($header['from'], $gtPos), null, 'UTF-8');
			else
				$addressString = htmlentities($header['from'], null, 'UTF-8');

		}
		elseif( !empty($header['reply-to']) )
		    $addressString = htmlentities($header['reply-to'], null, 'UTF-8');
		elseif( !empty($header['return-path']) )
			$addressString = htmlentities($header['return-path'], null, 'UTF-8');

	}
	else
	{
		
		if( trim($header['name']) != 'Unknown' && trim($header['name']) != '' )
			$addressString = '<strong>' . htmlentities($header['name'], null, 'UTF-8') . '</strong> ' . htmlentities($header['email'], null, 'UTF-8');
		else
			$addressString = htmlentities($header['email'], null, 'UTF-8');

	}
	
	if( $this->showToInstead )
	{
		
		$addressString = '<strong>' . $this->translate('To:') . ' </strong> ' . htmlentities($header['to'], null, 'UTF-8');
		/*
		$addressObjectsArray = getProcessedRecipientObjects( $header['to'] );
        foreach ($addressObjectsArray as $addressObject)
		{

			$personal = '';
			if (is_string($addressObject))
			{

				preg_match('/(.*?)<(.*?)>/', $addressObject, $m);
				$personal = trim($m[1]);
				$mail = $m[2];

			}
			else
			{

				$personal = $addressObject->personal;
				$mail = $addressObject->mailbox . '@' . $addressObject->host;

			}
			$personal = trim($personal, '"');
			$newMessage->addTo($mail, (strlen($personal)>0?$personal:null) );

		}
		*/
		
	}
	
	//remove double quotes cos autocomplete code doesnt like it
	$addressString = str_replace('"','', $addressString);

	if( isset($header['cc']) )
		$ccEmailString = htmlentities($header['cc'], null, 'UTF-8');
			
?>

	<div class="message" msghref="<?php echo $this->moduleBaseUrl ?>viewmessage/index/folder/<?php echo $folderUTF7UrlencodedDouble ?>/uniqueId/<?php echo $currentUID ?>/inline/true/messagePanelContextName/<?php echo $this->messagePanelContextName; ?>">
		<div class="message_outer">
			<div class="message_inner">
				
				<div id='<?php echo $currentUID ?>' class="details details-showphoto">
					<div class="photo">

						<?php if( !empty($preparedMessageArray['headers']['UserPhoto']) ) : ?>
						<img id="fromPhoto" alt="Photo of sender" src="<?php echo $this->moduleBaseUrl . $preparedMessageArray['headers']['UserPhoto'] . "/1/1" ?>" style="max-height: 80px; max-width: 60px;" />
						<?php else : ?>
						<img id="fromPhoto" alt="" src="<?php echo $this->moduleBaseUrl . 'contacts/viewphoto/id/0' ?>" style="max-height: 80px; max-width: 60px;" />
						<?php endif ?> 
					</div>
				
					<h3 class="inner-address"><?php echo $addressString ?>
						<span class="unread-icon"></span>
						<div class="threadNodePreview"><?php echo $preview ?></div>
					</h3>
					<h1>
						<span id='viewmessageSubject' style="display: none;"><?php echo htmlentities($header['subject'], null, 'UTF-8') ?></span>
					</h1>

					<div class="meta">
						<div style="position: relative; float: left; padding: 6px 14px 0pt 0pt;">
					    <?php if( isset( $preparedMessageArray['attachmentsList']) && count($preparedMessageArray['attachmentsList']) > 0 ) : ?>
						<a href="#" id="attachments_id"><h4 class="attachments">
							<?php $translatedAttachmentString = (count($preparedMessageArray['attachmentsList'])>1?$this->translate('Attachments'):$this->translate('Attachment')) ?>
							<?php echo count($preparedMessageArray['attachmentsList']) ?> <?php print $translatedAttachmentString ?>
						</h4></a>
						<?php endif; ?>
						
									<?php
					$timestr = timeago(strtotime($header['date'])); 
					if ($timestr != '')
					{
											$timeAgo = $timestr . ' ' . $this->translate('ago');
									
									$timestrapart = explode(' ',$timestr);
						$timestr = $timestrapart[0];
						$timestr = '-'.$timestr.' hours'; 
						$headerTime = htmlentities($header['date'], null, 'UTF-8');
					$timeDate = date("m/d/Y H:i:s",strtotime($headerTime));
						//$timeDate = date('Y-m-d  H:i', strtotime($timestr));
						//echo $timeDate;
					}
					?>
			
						<h4 class="<?php echo $timeDate ?>" title="<?php echo $timeDate?>">
							<?php $timestr=timeago(strtotime($header['date'])); if($timestr != '') 
							echo htmlspecialchars($timestr, ENT_QUOTES, 'UTF-8') . ' ' . $this->translate('ago'); ?>
						</h4>
						</div>
						

						
		               	<?php
		               	
		               	 $ccSender = $header['cc'];;


$userAccount = $this->UserSettings['Account'];


$ccSender = trim($ccSender);



  $toHtmlspecialcharsCC = str_replace($userAccount, "", $ccSender);

   $toHtmlspecialcharsCC = str_replace('&lt;&gt;', "", $toHtmlspecialcharsCC);
   $toHtmlspecialcharsCC = str_replace('&quot;&quot;', "", $toHtmlspecialcharsCC);
   $toHtmlspecialcharsCC = str_replace('"" <>,', '', $toHtmlspecialcharsCC);
		               	
$toHtmlspecialchars = $header['to'];

$origSender = $this->UserSettings['Account'];

$origSender = trim($origSender);
$firstReplace = '&lt;'.$origSender.'&gt;';

  $toHtmlspecialchars = str_replace($firstReplace, "", $toHtmlspecialchars);
  //print $toHtmlspecialchars;
   $toHtmlspecialchars = str_replace($origSender, "", $toHtmlspecialchars);
   // print $toHtmlspecialchars;
   $toHtmlspecialchars = str_replace('&quot;&quot;', "", $toHtmlspecialchars);

//print $this->UserSettings['Account'].'<br />';
//print $header['to'];
 
		               	
							$to = addslashes( htmlentities(messageHandling::getUniqueAddresses($header['to']), ENT_QUOTES, 'UTF-8') );
					//	$to = $toHtmlspecialchars;
							if( array_key_exists('reply-to', $header) )
								$replyTo = htmlspecialchars($header['reply-to'], ENT_QUOTES, 'UTF-8');
							else
								$replyTo = htmlspecialchars($header['from'], ENT_QUOTES, 'UTF-8');

							//strip out commas for now
							$replyTo = str_replace(',', '', $replyTo);
							
							if(!isset($header['cc']))
							{
								$header['cc'] = '';
							}
							
							//$replyAllTo = addslashes( htmlentities(messageHandling::getUniqueAddresses($header['from'] . ', ' . $header['to']), ENT_QUOTES, 'UTF-8') );
							if( array_key_exists('reply-to', $header) )
								$replyAllTo = addslashes( htmlentities(messageHandling::getUniqueAddresses($header['reply-to'] . ', ' . $toHtmlspecialchars), ENT_QUOTES, 'UTF-8') );
							else
								$replyAllTo = addslashes( htmlentities(messageHandling::getUniqueAddresses($header['from'] . ', ' . $header['to']), ENT_QUOTES, 'UTF-8') );
							
							//$replyAllCc = addslashes( htmlentities(messageHandling::getUniqueAddresses($header['cc']), ENT_QUOTES, 'UTF-8') );
							$replyAllCc = $toHtmlspecialcharsCC;
							
							$sent = htmlentities($header['date'], ENT_QUOTES, 'UTF-8');
							$subjectOriginal = htmlentities($header['subject'], ENT_QUOTES, 'UTF-8');
							$subjectReply = htmlentities($this->AtmailMailStorageMain->reReply($header['subject']), ENT_QUOTES, 'UTF-8');
							$relatedMessageMessageId = (isset($header['message-id']) ? htmlentities($header['message-id'], ENT_QUOTES, 'UTF-8') : '');
		               	?>
				
						
						
						<div 
							class="button nodeActionsButtons" 
							to='<?php echo $to ?>' 
							replyto='<?php echo $replyTo ?>' 
							replyallto='<?php echo $replyAllTo ?>' 
							replyallcc='<?php echo $replyAllCc ?>' 
							uniqueid='<?php echo $header['uniqueid'] ?>' 
							sent='<?php echo $sent ?>' 
							subjectOriginal='<?php echo $subjectOriginal ?>' 
							subjectReply='<?php echo $subjectReply ?>' 
							relatedMessageMessageId='<?php echo $relatedMessageMessageId ?>'
							folder='<?php echo addslashes($currentFolderGlobal) ?>' 
						>
							<?php 
							$uset = Zend_Registry::get('UserSettings');
							if($uset["DisplayEmailImages"] != 1) : ?>
							<div style="display:none; float:left; margin-right:5px;">
								<a id='nodeImagesAnchor' href="#" title="<?php echo $this->translate("Display blocked images"); ?>"><strong><img src="<?php echo $this->siteBaseUrl; ?>images/icons/display-images.png" alt="Info" style="padding-top: 4px; padding-right: 2px;"/></strong></a>
							</div>
							<?php endif; ?>
								<div class="node-actions">
								<div class="msgIconDiv"  style="float:left; margin-right:5px;">
									<a id='nodeReplyBtnAnchor' class="reply" href="#" title="<?php echo $this->translate("Reply Message"); ?>"></a>
								</div>

								<div class="msgIconDiv"  style="float:left; margin-right:5px;">
									<a id='nodeReplyAllBtnAnchor' class="reply-all" href="#" title="<?php echo $this->translate("Reply All"); ?>"></a>
								</div>

								<div class="msgIconDiv"  style="float:left; margin-right:5px;">
									<a id='nodeForwardBtnAnchor' class="forward" href="#" title="<?php echo $this->translate("Forward Message"); ?>"></a>
								</div>
								</div>
							
							<div class="separate-node"></div>
						
							<div class="info-anchor" style="float:left; margin-right:5px;">
								<a id='nodeInfoAnchor' href="#" title="<?php echo $this->translate("Display message information"); ?>"></a>
							</div>
							
							<div class="print-anchor" style="float:left; margin-right:5px;">
								<a id='nodePrintAnchor' href="#" title="<?php echo $this->translate("Print Message"); ?>"><strong><img src="<?php echo $this->siteBaseUrl; ?>images/icons/print.png" alt="Print" style="padding-top: 4px;"/></strong></a>
							</div>
														
							<a id='nodeReplyAnchor' href="#"><strong style='padding-bottom: 4px'>&nbsp;</strong></a> 
							<div class="ReplyDrop">
								<ul class="nodeActionsDropdown" style="display:none;">
									<li id='displayimage'><a href="#"><?php print $this->translate('Display Images')?></a></li>
									<li id='replyall'><a href="#"><?php print $this->translate('Reply All')?></a></li>
									<li id='forward'><a href="#"><?php print $this->translate('Forward')?></a></li>
									<li id='forwardAsAttachment'><a href="#"><?php print $this->translate('Forward Attachment')?></a></li>
									<li id='markasread'><a href="#"><?php print $this->translate('Mark as Read')?></a></li>
									<li id='markasunread'><a href="#"><?php print $this->translate('Mark as Unread')?></a></li>
									<li id='addToAddressbook'><a href="#"><?php print $this->translate('Add to Contacts')?></a></li>
									<li id='viewHeaders' state="hide"><a href="#"><?php print $this->translate('View Headers')?></a></li>
									<li id='print'><a href="#"><?php print $this->translate('Print')?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
									<li id='download' class="bottom"><a href="#"><?php print $this->translate('Download Email')?></a></li>
								</ul>
							</div>
						</div>
						<!--
						<div class="msgIconDiv">
							<span id="msgIcon" class=""></span>
						</div>
					-->
					</div>
	               	<?php if( isset($ccEmailString) && $ccEmailString != '') : ?>
					<h3 class="showcc"><div><?php echo $this->translate('Cc:') ?> </div><?php echo $ccEmailString ?></h3>
                    <?php endif; ?>
					<?php if( isset($preparedMessageArray['headers']['x-atmail-bcc']) ) : ?>
					<h3 class="showcc"><div><?php echo $this->translate('Bcc:') ?> </div><?php echo $preparedMessageArray['headers']['x-atmail-bcc'] ?></h3>
                    <?php endif; ?>
	               	
	            </div>
                <div class="body">
	<?php 
		$timestr = timeago(strtotime($header['date'])); 
					if ($timestr != '')
					{
						$timeAgo = $timestr . ' ' . $this->translate('ago');
				
				$timestrapart = explode(' ',$timestr);
	$timestr = $timestrapart[0];
	$timestr = '-'.$timestr.' hours'; 
	$headerTime = htmlentities($header['date'], null, 'UTF-8');
	//$timeDate = date("jS F Y",strtotime($headerTime));
  //$timeDate = date("Y-m-d H:i",strtotime($headerTime));
  	$timeDate = date("m/d/Y H:i:s",strtotime($headerTime));
	//$timeDate = date('Y-m-d  H:i', strtotime($timestr));
	//echo $timeDate;
		}
					?>
	                <div class="messageHeadersInfo triangle-isosceles top" style="display:none;">
						<?php if( !empty($header['from']) ) : ?><div><strong><?php echo $this->translate('From') ?> </strong><?php echo htmlentities($header['from'], null, 'UTF-8')  ?></div><?php endif; ?>
						<?php if( !empty($header['to']) ) : ?><div><strong><?php echo $this->translate('To') ?> </strong><?php echo htmlentities($header['to'], null, 'UTF-8') ?></div><?php endif; ?>
						<?php if( !empty($header['cc']) ) : ?><div><strong><?php echo $this->translate('Cc') ?> </strong><?php echo htmlentities($header['cc'], null, 'UTF-8') ?></div><?php endif; ?>
						<?php if( !empty($header['date']) ) : ?><div><strong><?php echo $this->translate('Date') ?> </strong><?php echo $timeDate ?></div><?php endif; ?>
						<?php if( !empty($header['subject']) ) : ?><div><strong><?php echo $this->translate('Subject') ?> </strong><?php echo htmlentities($header['subject'], null, 'UTF-8') ?></div><?php endif; ?>
						<?php if( !empty($header['x-mailer']) ) : ?><div><strong><?php echo $this->translate('Client') ?> </strong><?php echo htmlentities($header['x-mailer'], null, 'UTF-8') ?></div><?php endif; ?>
					</div>
					
					<div class="messageHeadersRaw triangle-isosceles top" style="display:none;">
						<?php echo $this->partial('viewmessage/renderemailheaderraw.phtml', array('messageArray' => $preparedMessageArray) ); ?>
					</div>
									
					<?php echo $this->partial('viewmessage/recursivelyrendermessagebody.phtml', array('messageArray' => $preparedMessageArray, 'moduleBaseUrl' => $this->moduleBaseUrl, 'siteBaseUrl' => $this->siteBaseUrl, 'AtmailMailStorageMain' => $this->AtmailMailStorageMain, 'folderUTF7' => $this->folderUTF7, 'messagePanelContextName' => $this->messagePanelContextName ) ); ?>
				</div> <!-- EO div class body -->
				<?php 
					if( isset($this->currentThreadNode['_children']) ) { 
						foreach( $this->currentThreadNode['_children'] as $child ) {
							echo $this->partial('viewmessage/recursivelyrenderthreads.phtml', array('hasThreads' => $this->hasThreads, 'currentThreadNode' => $child, 'moduleBaseUrl' => $this->moduleBaseUrl, 'siteBaseUrl' => $this->siteBaseUrl, 'AtmailMailStorageMain' => $this->AtmailMailStorageMain, 'folderUTF7' => $this->folderUTF7, 'messagePanelContextName' => $this->messagePanelContextName ) );
					 
						}
					}
				?>
			<!--	<div class="quick-reply" style="display: none;">
					<span><input id="quick-reply" placeholder="Quick Reply" type="text"/></span>
				</div> -->
			</div> <!-- EO div class message_inner -->
		</div> <!-- EO div class message_outer -->
	</div> <!-- EO div class message --> 

<?php else : //just a thread info, not full message ?>
 <?php if( isset($currentUID) ) : ?>
	<?php
	$header = $this->currentThreadNode['_basicHeaders'];
	$header['name'] = array_key_exists('name', $header) ? $header['name'] : '';
	$header['email'] = array_key_exists('email', $header) ? $header['email'] : '';
	$header['from'] = array_key_exists('from', $header) ? $header['from'] : '';
	$header['cc'] = array_key_exists('cc', $header) ? $header['cc'] : '';
	
	if( empty($header['name']) && ($header['email'] == '@' || $header['email'] == '') ) 
	{
		if( !empty($header['from']) ) 
		{
			$gtPos = strpos($header['from'], '<', 0);
			if( $gtPos !== false && trim(substr($header['from'], 0, $gtPos)) != 'Unknown' )
				$addressString = '<strong>' . htmlentities(substr($header['from'], 0, $gtPos), null, 'UTF-8') . '</strong> ' . htmlentities(substr($header['from'], $gtPos), null, 'UTF-8');
			else
				$addressString = htmlentities($header['from'], null, 'UTF-8');
		} 
		elseif( !empty($header['reply-to']) )
		    $addressString = htmlentities($header['reply-to'], null, 'UTF-8');
		elseif( !empty($header['return-path']) )
			$addressString = htmlentities($header['return-path'], null, 'UTF-8');
	} 
	else
		$addressString = '<strong>' . htmlentities($header['name'], null, 'UTF-8') . '</strong> ' . htmlentities($header['email'], null, 'UTF-8');
	
	//remove double quotes cos autocomplete code doesnt like it
	$addressString = str_replace('"','', $addressString);
	
	if( isset($header['cc']) )
		$ccEmailString = htmlentities($header['cc'], null, 'UTF-8');
	if( strpos($this->currentThreadNode['_preview'], '-----') )
		$cutPos = mb_strpos($this->currentThreadNode['_preview'], '-----');
	else
		$cutPos = 300;
	if( array_key_exists('_preview', $this->currentThreadNode) ) //basic body preview, stripping after Original Message
		$preview = mb_substr(strip_tags($this->currentThreadNode['_preview']), 0, $cutPos);//strpos($this->currentThreadNode['_preview'], '-----') );
	else
		$preview = '';
	?>
    <div class="message contracted" msghref="<?php echo $this->moduleBaseUrl ?>viewmessage/index/folder/<?php echo $folderUTF7UrlencodedDouble ?>/uniqueId/<?php echo $currentUID ?>/inline/true/messagePanelContextName/<?php echo $this->messagePanelContextName; ?>">
		<div class="message_outer">
			<div class="message_inner">
				<div id='<?php echo $currentUID ?>' class="details details-showphoto">
					<div class="photo">
						<?php if( !empty($preparedMessageArray['headers']['UserPhoto']) ) : ?>
						<img id="fromPhoto" src="<?php echo $this->moduleBaseUrl . $preparedMessageArray['headers']['UserPhoto'] . "/1/1" ?>" style="max-height: 80px; max-width: 60px;" />
						<?php else : ?>
						<img id="fromPhoto" src="<?php echo $this->moduleBaseUrl . 'contacts/viewphoto/id/0' ?>" style="max-height: 80px; max-width: 60px;" />
						<?php endif ?> 
					</div>
			
					<h3 class="inner-address <?php if(!isset($this->currentThreadNode['FLAGS'][Zend_Mail_Storage::FLAG_SEEN])) { echo "unread"; } ?>"><span class="thread-address"><?php echo $addressString ?></span>
						<span class="unread-icon"></span>
						<div class="threadNodePreview"><?php echo $preview ?></div>
					</h3>
					<h1>
						<span id='viewmessageSubject' style="display: none;"><?php echo htmlentities($header['subject'], null, 'UTF-8') ?></span>
					</h1>
	               	<div class="meta">
	               		<div style="position: relative; float: left; padding: 6px 14px 0pt 0pt;">
	               	
				    <?php if( isset( $this->currentThreadNode['attachmentCount']) && $this->currentThreadNode['attachmentCount'] > 0 ) : ?>
						<h4 class="attachments">
						<?php $translatedAttachmentString = ($this->currentThreadNode['attachmentCount']>1?$this->translate('Attachments'):$this->translate('Attachment')) ?>
						<?php echo $this->currentThreadNode['attachmentCount'] ?> <?php print $translatedAttachmentString ?>
						</h4>
					<?php endif; ?>
	               		<h4 class="received <?php echo 'dateFormat' . $this->UserSettings['DateDisplay']; ?>" title="<?php echo htmlentities($header['date'], null, 'UTF-8') ?>">
						<?php $timestr=timeago(strtotime($header['date'])); if($timestr!='') echo $timestr . ' ' . $this->translate('ago'); ?>
						</h4>
						</div>
		               	<?php
						   	$to = addslashes( htmlentities(messageHandling::getUniqueAddresses($header['to']), ENT_QUOTES, 'UTF-8') );               		
							$replyTo = addslashes( htmlentities($header['from'], ENT_QUOTES, 'UTF-8') );
							$replyAllTo = addslashes( htmlentities(messageHandling::getUniqueAddresses($header['from'] . ', ' . $header['to']), ENT_QUOTES, 'UTF-8') );
							$replyAllCc = addslashes( htmlentities(messageHandling::getUniqueAddresses($header['cc']), ENT_QUOTES, 'UTF-8') );
							$sent = htmlentities($header['date'], ENT_QUOTES, 'UTF-8');
							$subjectOriginal = htmlentities($header['subject'], ENT_QUOTES, 'UTF-8');
							$subjectReply = htmlentities($this->AtmailMailStorageMain->reReply($header['subject']), ENT_QUOTES, 'UTF-8');
							$relatedMessageMessageId = htmlentities($header['message-id'], ENT_QUOTES, 'UTF-8');
		               	?>
						<div 
							class="button nodeActionsButtons" 
							to='<?php echo $to ?>' 
							replyto='<?php echo $replyTo ?>' 
							replyallto='<?php echo $replyAllTo ?>' 
							replyallcc='<?php echo $replyAllCc ?>' 
							uniqueid='<?php echo $currentUID ?>' 
							sent='<?php echo $sent ?>' 
							subjectOriginal='<?php echo $subjectOriginal ?>' 
							subjectReply='<?php echo $subjectReply ?>' 
							relatedMessageMessageId='<?php echo $relatedMessageMessageId ?>'
							folder='<?php echo addslashes($currentFolderGlobal) ?>' 
						>
							<?php 
							$uset = Zend_Registry::get('UserSettings');
							if($uset["DisplayEmailImages"] != 1) : ?>
							<div style="display:none; float:left; margin-right:5px;">
								<a id='nodeImagesAnchor' href="#" title="<?php echo $this->translate("Display blocked images"); ?>"><strong><img src="<?php echo $this->siteBaseUrl; ?>images/icons/display-images.png" alt="Info" style="padding-top: 4px; padding-right: 2px;"/></strong></a>
							</div>
							<?php endif; ?>
							<div class="node-actions">
							<div class="msgIconDiv"  style="float:left; margin-right:5px;">
								<a id='nodeReplyBtnAnchor' class="reply" href="#" title="<?php echo $this->translate("Reply Message"); ?>"></a>
							</div>
							
							<div class="msgIconDiv"  style="float:left; margin-right:5px;">
								<a id='nodeReplyAllBtnAnchor' class="reply-all" href="#" title="<?php echo $this->translate("Reply All"); ?>"></a>
							</div>
							
							<div class="msgIconDiv"  style="float:left; margin-right:5px;">
								<a id='nodeForwardBtnAnchor' class="forward" href="#" title="<?php echo $this->translate("Forward Message"); ?>"></a>
							</div>
							</div>
							
							<div class="separate-node"></div>
							
							<div class="info-anchor" style="float:left; margin-right:5px;">
								<a id='nodeInfoAnchor' href="#" title="<?php echo $this->translate("Display message information"); ?>"></a>
							</div>
							
							<div class="print-anchor" style="float:left; margin-right:5px;">
								<a id='nodePrintAnchor' href="#" title="<?php echo $this->translate("Print Message"); ?>"><strong><img src="<?php echo $this->siteBaseUrl; ?>images/icons/print.png" alt="Print" style="padding-top: 4px;"/></strong></a>
							</div>
														
						<a id='nodeReplyAnchor' href="#"><strong style='padding-bottom: 4px'>&nbsp;</strong></a> 
							<div class="ReplyDrop">
								<ul class="nodeActionsDropdown" style="display:none;">
									<li id='displayimage'><a href="#"><?php print $this->translate('Display Images')?></a></li>
									<li id='replyall'><a href="#"><?php print $this->translate('Reply All')?></a></li>
									<li id='forward'><a href="#"><?php print $this->translate('Forward')?></a></li>
									<li id='forwardAsAttachment'><a href="#"><?php print $this->translate('Forward As Attachment')?></a></li>
									<li id='markasread'><a href="#"><?php print $this->translate('Mark as Read')?></a></li>
									<li id='markasunread'><a href="#"><?php print $this->translate('Mark as Unread')?></a></li>
									<li id='addToAddressbook'><a href="#"><?php print $this->translate('Add to Contacts')?></a></li>
									<li id='viewHeaders' state="hide"><a href="#"><?php print $this->translate('View Headers')?></a></li>
									<li id='print'><a href="#"><?php print $this->translate('Print')?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
									<li id='download' class="bottom"><a href="#"><?php print $this->translate('Download Email')?></a></li>
								</ul>
							</div>
						</div>
	               	<?php
                    if(isset($this->currentThreadNode['FLAGS'][Zend_Mail_Storage::FLAG_ANSWERED]))
						$msgIcon = 'reply';
					else if(isset($this->currentThreadNode['FLAGS'][Zend_Mail_Storage::FLAG_SEEN]))
						$msgIcon = 'read';
					else
						$msgIcon = 'unread';
					?>

					<!--
					<div class="msgIconDiv">
						<span id="msgIcon" class="<?php echo $msgIcon; ?>"></span>
					</div>
				-->
	               	</div>
	               	<?php if( isset($ccEmailString) && $ccEmailString != ''): ?>
					<h3 class="showcc"><div><?php echo $this->translate('Cc:') ?> </div><?php echo $ccEmailString ?></h3>
					<?php endif; ?>               	
	            </div>

				<div class="body"><?php echo $this->translate('Loading...') ?><?php //echo $this->currentThreadNode['_preview'] ?>
				</div> <!-- EO div class body -->
				
			</div> <!-- EO div class message_inner -->
		</div> <!-- EO div class message_outer -->
	</div> <!-- EO div class message --> 
	<?php
		if( isset($this->currentThreadNode['_children']) ) { 
			foreach( $this->currentThreadNode['_children'] as $child ) {
				echo $this->partial('viewmessage/recursivelyrenderthreads.phtml', array('hasThreads' => $this->hasThreads, 'currentThreadNode' => $child, 'moduleBaseUrl' => $this->moduleBaseUrl, 'siteBaseUrl' => $this->siteBaseUrl, 'AtmailMailStorageMain' => $this->AtmailMailStorageMain, 'folderUTF7' => $this->folderUTF7, 'messagePanelContextName' => $this->messagePanelContextName ) );
			 
			}
		}
	?>
<?php 	else : 

			if( isset($this->currentThreadNode['_children']) ) 
			{ 
	
				foreach( $this->currentThreadNode['_children'] as $child ) 
				{
		
					echo $this->partial('viewmessage/recursivelyrenderthreads.phtml', array('currentThreadNode' => $child, 'moduleBaseUrl' => $this->moduleBaseUrl, 'siteBaseUrl' => $this->siteBaseUrl, 'AtmailMailStorageMain' => $this->AtmailMailStorageMain, 'folderUTF7' => $this->folderUTF7, 'messagePanelContextName' => $this->messagePanelContextName ) );

				}
		
			}   

		endif;  
endif;






