Index: branches/2.0/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- branches/2.0/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 2103)
+++ branches/2.0/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 2106)
@@ -709,12 +709,21 @@
 			}
 
-			$content = '';
-			if (strtolower($msg->structure[$msg_number]->subtype) == "plain")
+			$content = $this->decodeBody(
+				imap_body( $this -> mbox, $msg_number, FT_UID ),
+				$msg -> encoding[ $msg_number ][ 0 ],
+				$msg -> charset[ $msg_number ][ 0 ]
+			);
+
+			if ( strtolower( $msg -> structure[ $msg_number ] -> subtype ) == 'plain' )
 			{
-				$content .= '<span style="font-family: monospace">' . nl2br($this->decodeBody((imap_body($this->mbox, $msg_number, FT_UID)), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0])) . '</span>';
-			}
-			else if (strtolower($msg->structure[$msg_number]->subtype) == "html")
-			{
-				$content .= $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]);
+				$content = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $content );
+				$content = nl2br( htmlentities( $content ) );
+				$content = $this -> replace_links( $content );
+				$content = str_replace( array( ' #$&lt;$# ', ' #$&gt;$# ' ), array( '&lt;', '&gt;' ), $content );
+				$content = '<span style="font-family: monospace">' . $content . '</span>';
+
+				$return[ 'body' ] = $content;
+
+				return $return;
 			}
 		}
@@ -778,32 +787,65 @@
 					$att = new imap_attachment();
 					$attachments =  $att -> get_attachment_info($this->mbox,$msg_number);
-					if($attachments['number_attachments'] > 0) {												
-						foreach($attachments ['attachment'] as $index => $attachment){
-							if(strtolower($attachment['type']) == "delivery-status" ||
-								strtolower($attachment['type']) == "rfc822" ||								
-								strtolower($attachment['type']) == "rfc822-headers" ||
-								strtolower($attachment['type']) == "plain"
-							){
-								$obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]);					
-								$content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>";					
-								$content .= "<br><table  style='margin:2px;border:1px solid black;background:#EAEAEA'>";
-								$content .= "<tr><td><b>".$this->functions->getLang("Subject").":</b></td><td>".$this->decode_string($obj->subject)."</td></tr>";
-								$content .= "<tr><td><b>".$this->functions->getLang("From").":</b></td><td>".$this->decode_string($obj->from[0]->mailbox."@".$obj->from[0]->host)."</td></tr>";
-								$content .= "<tr><td><b>".$this->functions->getLang("Date").":</b></td><td>".$obj->date."</td></tr>";
-								$content .= "<tr><td><b>".$this->functions->getLang("TO").":</b></td><td>".$this->decode_string($obj->to[0]->mailbox."@".$obj->to[0]->host)."</td></tr>";
-								$content .= !$obj->cc ? "</table><br>" :"<tr><td><b>".$this->functions->getLang("CC").":</b></td><td>".$this->decode_string($obj->cc[0]->mailbox."@".$obj->cc[0]->host)."</td></tr></table><br>";								
-								$content .= $this->decodeBody( 
-      								imap_fetchbody( 
- 										$this->mbox, 
- 										$msg_number, 
- 										( $attachment['part_in_msg'] + ( 
- 											( strtolower( $attachment[ 'type' ] ) == 'delivery-status' ) ? 0 : 1 ) 
- 											) . ".1", 
- 											FT_UID 
- 										), 
- 										$msg->encoding[ $msg_number ][ $values ], 
- 										$msg->charset[ $msg_number ][ $values ] 
- 								); 
-								break;			
+					if($attachments['number_attachments'] > 0) {
+						foreach($attachments ['attachment'] as $index => $attachment)
+						{
+							if ( in_array( strtolower( $attachment[ 'type' ] ), array( 'delivery-status', 'rfc822', 'rfc822-headers', 'plain' ) ) )
+							{
+								$obj = imap_rfc822_parse_headers( imap_fetchbody( $this -> mbox, $msg_number, $msg_part, FT_UID ), $msg -> encoding[ $msg_number ][ $values ] );
+
+								$content .= '<hr align="left" width="95%" style="border:1px solid #DCDCDC">';
+								$content .= '<br><table  style="margin:2px;border:1px solid black;background:#EAEAEA">';
+
+								$content .= '<tr><td><b>' . $this->functions->getLang("Subject")
+									. ':</b></td><td>' .$this->decode_string($obj->subject) . '</td></tr>';
+
+								$content .= '<tr><td><b>' . $this -> functions -> getLang( 'From' ) . ':</b></td><td>'
+									. $this -> replace_links( $this -> decode_string( $obj -> from[ 0 ] -> mailbox . '@' . $obj -> from[ 0 ] -> host) )
+									. '</td></tr>';
+
+								$content .= '<tr><td><b>' . $this->functions->getLang("Date") . ':</b></td><td>' . $obj->date . '</td></tr>';
+
+								$content .= '<tr><td><b>' . $this -> functions -> getLang( 'TO' ) . ':</b></td><td>'
+									. $this -> replace_links( $this -> decode_string( $obj -> to[ 0 ] -> mailbox . '@' . $obj -> to[ 0 ] -> host ) )
+									. '</td></tr>';
+
+								if ( $obj->cc )
+									$content .= '<tr><td><b>' . $this -> functions -> getLang( 'CC' ) . ':</b></td><td>'
+										. $this -> replace_links( $this -> decode_string( $obj -> cc[ 0 ] -> mailbox . '@' . $obj -> cc[ 0 ] -> host ) )
+										. '</td></tr>';
+
+								$content .= '</table><br>';
+
+
+								$id = ( ( strtolower( $attachment[ 'type' ] ) == 'delivery-status' ) ? false : true );
+								if ( strtolower( $msg->structure[$msg_number]->parts[1]->parts[0]->subtype ) == 'plain' )
+								{
+									$id = !$id;
+									if ( $msg->structure[$msg_number]->parts[1]->parts[0]->encoding == 4 )
+										$msg->encoding[ $msg_number ][ $values ] = 'quoted-printable';
+								}
+
+								$body = $this->decodeBody(
+									imap_fetchbody(
+										$this->mbox,
+										$msg_number,
+										( $attachment['part_in_msg'] + ( ( int ) $id ) ) . ".1",
+										FT_UID
+									),
+									$msg->encoding[ $msg_number ][ $values ],
+									$msg->charset[ $msg_number ][ $values ]
+								);
+
+								if ( strtolower( $msg->structure[$msg_number]->parts[1]->parts[0]->subtype ) == 'plain' )
+								{
+									$body = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $body );
+									$body = nl2br( htmlentities( $body ) );
+									$body = $this -> replace_links( $body );
+									$body = str_replace( array( ' #$&lt;$# ', ' #$&gt;$# ' ), array( '&lt;', '&gt;' ), $body );
+									$body = '<span style="font-family: monospace">' . $body . '</span>';
+								}
+
+								$content .= $body;
+								break;
 							}
 						}
