[Vtigercrm-commits] [vtiger-commits] r10482 - in /vtigercrm/branches/5.0.3: Smarty/templates/ modules/Webmails/ themes/alphagrey/ themes/bluelagoon/ themes/woodspice/

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Tue Mar 20 04:18:00 EDT 2007


Author: jerrydgeorge
Date: Tue Mar 20 02:17:20 2007
New Revision: 10482

Log:
Add/Remove Folder removed,
The selected mail has been highlighted,
Mail count made to display proper

Modified:
    vtigercrm/branches/5.0.3/Smarty/templates/Webmails.tpl
    vtigercrm/branches/5.0.3/modules/Webmails/ListView.php
    vtigercrm/branches/5.0.3/modules/Webmails/MailParse.php
    vtigercrm/branches/5.0.3/modules/Webmails/Webmails.js
    vtigercrm/branches/5.0.3/modules/Webmails/Webmails.php
    vtigercrm/branches/5.0.3/modules/Webmails/WebmailsAjax.php
    vtigercrm/branches/5.0.3/modules/Webmails/body.php
    vtigercrm/branches/5.0.3/themes/alphagrey/style.css
    vtigercrm/branches/5.0.3/themes/bluelagoon/style.css
    vtigercrm/branches/5.0.3/themes/woodspice/style.css

Modified: vtigercrm/branches/5.0.3/Smarty/templates/Webmails.tpl
==============================================================================
--- vtigercrm/branches/5.0.3/Smarty/templates/Webmails.tpl (original)
+++ vtigercrm/branches/5.0.3/Smarty/templates/Webmails.tpl Tue Mar 20 02:17:20 2007
@@ -54,7 +54,7 @@
 				   </tr>
 				   <tr>
 					<td rowspan="6" valign="top" class="hdrNameBg">
-						<img src="{$IMAGE_PATH}webmail_root.gif" align="absmiddle" />&nbsp;<span onmouseover="show_addfolder();" onmouseout="show_addfolder();" style="cursor:pointer;"><b class="txtGreen">{$MOD.LBL_MY_MAILS}</b>&nbsp;&nbsp;<span id="folderOpts" style="position:absolute;display:none">{$MOD.ADD_FOLDER}</span></span>
+						<img src="{$IMAGE_PATH}webmail_root.gif" align="absmiddle" />&nbsp;<span style="cursor:pointer;"><b class="txtGreen">{$MOD.LBL_MY_MAILS}</b>&nbsp;&nbsp;<span id="folderOpts" style="position:absolute;display:none">{$MOD.ADD_FOLDER}</span></span>
 
 						<ul style="list-style-type:none;">
 
@@ -94,11 +94,11 @@
 						Home Page"
 						class="webMnu">{$MOD.LBL_TO_GROUPS}</a>&nbsp; </li>
 						</ul><br />
-						<!-- img src="{$IMAGE_PATH}webmail_root.gif" align="absmiddle" />&nbsp;<b class="txtGreen">{$MOD.LBL_TRASH}</b>
+						<img src="{$IMAGE_PATH}webmail_root.gif" align="absmiddle" />&nbsp;<b class="txtGreen">{$MOD.LBL_TRASH}</b>
 						<ul style="list-style-type:none;">
 							<li class="lvtColData" onmouseover="this.className='lvtColDataHover'" onmouseout="this.className='lvtColData'">
 								<img src="{$IMAGE_PATH}webmail_trash.gif" align="absmiddle" />&nbsp;&nbsp;
-								<a href="#" class="webMnu">{$MOD.LBL_JUNK_MAILS}</a>&nbsp;<b></b -->
+								<a href="#" class="webMnu">{$MOD.LBL_JUNK_MAILS}</a>&nbsp;<b></b>
 							</li>
 						</ul>
 
@@ -141,7 +141,7 @@
 						<div id="rssScroll" style="height:220px;">
 
 				<!-- Table to display the mails list -	Starts -->
-	<form name="massdelete" method="post">
+				<form name="massdelete" method="post">
 				<table class="rssTable" cellspacing="0" cellpadding="0" border="0" width="100%" id="message_table">
 				   <tr>
 				<th><input type="checkbox" name="select_all" value="checkbox"  onclick="toggleSelect(this.checked,'selected_id');"/></th>
@@ -155,7 +155,7 @@
 						{/foreach}
 					{/foreach}
 				</table>
-	</form>
+				</form>
 				<!-- Table to display the mails list - Ends -->
 
 						</div>
@@ -194,11 +194,7 @@
 <tr><td width="20%" align="right"><b>{$MOD.LBL_CC}</b></td><td id="webmail_cc">&nbsp;</td></tr>
 
 						<tr><td align="right"><b>{$MOD.LBL_SUBJECT}</b></td><td id="webmail_subject"></td></tr>
-						<tr><td
-			   		align="right"><b>{$MOD.LBL_DATE}</b></td><td
-			   		id="webmail_date"></td>
-
-
+		<tr><td	align="right"><b>{$MOD.LBL_DATE}</b></td><td id="webmail_date"></td>
 	<tr><td align="right"><b>{$MOD.LBL_ATTACHMENT}</b></td><td id="webmail_attachment"></td>
 							<td id="full_view"><a href="javascript:;"> Full Email View</a></td></tr>
 						<tr><td align="right" style="border-bottom:1px solid #666666;" colspan="3">&nbsp;</td></tr>
@@ -267,7 +263,7 @@
 	if(gselected_mail != '')
 		$(gselected_mail).className = '';
 		
-	$(rowId).className = 'tabSelected';
+	$(rowId).className = 'mailSelected_select';
 	gselected_mail = rowId;
 }
 {/literal}

Modified: vtigercrm/branches/5.0.3/modules/Webmails/ListView.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Webmails/ListView.php (original)
+++ vtigercrm/branches/5.0.3/modules/Webmails/ListView.php Tue Mar 20 02:17:20 2007
@@ -56,7 +56,6 @@
 $degraded_service='false';
 if($MailBox->mail_protocol == "imap" || $MailBox->mail_protocol == "pop3")
 	$degraded_service='true';
-
 
 if($_POST["command"] == "check_mbox_all") {
 	exit();
@@ -100,18 +99,18 @@
         flush();
         exit();
 }
-
+//This is invoked from Webmails.js as a result of the periodic event function call, checks only for NEW mails; this in turn checks for new mails in all the mailboxes
 if($_POST["command"] == "check_mbox") {
         $adb->println("Inside check_mbox AJAX command");
 
-	$criteria = 'NEW';
-        $search = imap_search($MailBox->mbox, $criteria);
+	$search = imap_search($MailBox->mbox, 'NEW');
+
         //if($search === false) {echo "failed";flush();exit();}
 
 	$adb->println("imap_search($MailBox->mbox, $criteria) ===> ");
 	$adb->println($search);
 	
-        $data = imap_fetch_overview($MailBox->mbox,implode(',',$search));
+	$data = imap_fetch_overview($MailBox->mbox,implode(',',$search));
         $num=sizeof($data);
 
 	$adb->println("fetched data using imap_fetch_overview ==>");
@@ -159,7 +158,15 @@
 
 <script type="text/javascript">
 // Pass our PHP variables to js.
-<?php if($degraded_service == 'true') { echo 'var degraded_service="true";';}else{echo 'var degraded_service="false";';};?>
+<?php if($degraded_service == 'true')
+				{
+					echo 'var degraded_service="true";';
+				}
+else
+{
+	echo 'var degraded_service="false";';
+};
+?>
 var mailbox = "<?php echo $MailBox->mailbox;?>";
 var box_refresh=<?php echo $MailBox->box_refresh;?>;
 var webmail = new Array();
@@ -206,8 +213,9 @@
 $elist = $MailBox->mailList;
 $numEmails = $elist["count"];
 $headers = $elist["headers"];
-
 $mails_per_page = $MailBox->mails_per_page;
+
+
 if($start == 1 || $start == "") {
 	$start_message=$numEmails;
 } else {
@@ -266,7 +274,7 @@
 }
 echo "</script>";
 
-$listview_header = array("<th>".$mod_strings['LBL_INFO']."</th>","<th>".$mod_strings['LBL_LIST_SUBJECT']."</th>","<th>".$mod_strings['LABEL_DATE']."</th>","<th>".$mod_strings['LABEL_FROM']."</th>","<th>".$mod_strings['LBL_DEL']."</th>");
+$listview_header = array("<th width='10%'>".$mod_strings['LBL_INFO']."</th>","<th width='45%'>".$mod_strings['LBL_LIST_SUBJECT']."</th>","<th width='25%'>".$mod_strings['LABEL_DATE']."</th>","<th width='10%'>".$mod_strings['LABEL_FROM']."</th>","<th>".$mod_strings['LBL_DEL']."</th>");
 $listview_entries = array();
 
 $displayed_msgs=0;
@@ -279,16 +287,12 @@
 	$searchstring = $_REQUEST["search_type"].' "'.$_REQUEST["search_input"].'"';
 	//echo $searchstring."<br>";
 	$searchlist = imap_search($MailBox->mbox,$searchstring);
-//	if($searchlist === false)
-  //		echo "The search failed";
-
 	$num_searches = count($searchlist);
 
 		$c=$numEmails;
 }
 
 flush();
-
 // MAIN LOOP
 // Main loop to create listview entries
 
@@ -319,7 +323,7 @@
 if (is_array($list)) {
       	$boxes = '<select name="mailbox" id="mailbox_select" onChange="move_messages();">';
         $boxes .= '<option value="move_to" SELECTED>'.$mod_strings['LBL_MOVE_TO'].'</option>';
-        foreach ($list as $key => $val) {
+	foreach ($list as $key => $val) {
 		$tmpval = preg_replace(array("/\{.*?\}/i"),array(""),$val->name);
 		if(preg_match("/trash/i",$tmpval))
 			$img = "webmail_trash.gif";
@@ -331,25 +335,26 @@
 		$i++;
 
 		if ($_REQUEST["mailbox"] == $tmpval) {
-	if($tmpval != "INBOX")
-                        $boxes .= '<option value="'.$tmpval.'">'.$tmpval;
+			if($tmpval != "INBOX")
+				$boxes .= '<option value="'.$tmpval.'">'.$tmpval;
 			$_SESSION["mailboxes"][$tmpval] = $new_msgs;
 
 			if($numEmails==0) {$num=$numEmails;} else {$num=($numEmails-1);}
-			$folders .= '<li class="tabUnSelected" style="padding-left:0px;"><img src="'.$image_path.'/'.$img.'"align="absmiddle" />&nbsp;&nbsp;<a href="javascript:changeMbox(\''.$tmpval.'\');" class="webMnu" onmouseover="show_remfolder(\''.$tmpval.'\');" onmouseout="show_remfolder(\''.$tmpval.'\');">'.$tmpval.'</a>&nbsp;&nbsp;<span id="'.$tmpval.'_count" style="font-weight:bold">';
-	if($new_msgs > 0)
-			$folders .= '(<span id="'.$tmpval.'_unread">'.$new_msgs.'</span>)</span>&nbsp;&nbsp;<span id="remove_'.$tmpval.'" style="position:relative;display:none">Remove</span></li>';
+			$folders .= '<li class="tabUnSelected" style="padding-left:0px;"><img src="'.$image_path.'/'.$img.'"align="absmiddle" />&nbsp;&nbsp;<a href="javascript:changeMbox(\''.$tmpval.'\');" class="webMnu">'.$tmpval.'</a>&nbsp;&nbsp;<span id="'.$tmpval.'_count" style="font-weight:bold">';
+			if($new_msgs > 0)
+				$folders .= '(<span id="'.$tmpval.'_unread">'.$new_msgs.'</span>)</span>&nbsp;&nbsp;<span id="remove_'.$tmpval.'" style="position:relative;display:none">Remove</span></li>';
+
 		} else {
 			$box = imap_status($MailBox->mbox, "{".$MailBox->imapServerAddress."}".$tmpval, SA_ALL);
 			$_SESSION["mailboxes"][$tmpval] = $box->unseen;
 
 			if($box->messages==0) {$num=$box->messages;} else {$num=($box->messages-1);}
-                      	$boxes .= '<option value="'.$tmpval.'">'.$tmpval;
+			$boxes .= '<option value="'.$tmpval.'">'.$tmpval;
 			$folders .= '<li class="lvtColData" onmouseover="this.className=\'lvtColDataHover\'" onmouseout="this.className=\'lvtColData\'"><img src="'.$image_path.'/'.$img.'" align="absmiddle" />&nbsp;&nbsp;<a href="javascript:changeMbox(\''.$tmpval.'\');" class="webMnu">'.$tmpval.'</a>&nbsp;<span id="'.$tmpval.'_count" style="font-weight:bold">';
-	if($box->unseen > 0)
+			if($box->unseen > 0)
 				$folders .= '(<span id="'.$tmpval.'_unread">'.$box->unseen.'</span>)</span></li>';
 		}
- 	}
+	}
         $boxes .= '</select>';
 }
 

Modified: vtigercrm/branches/5.0.3/modules/Webmails/MailParse.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Webmails/MailParse.php (original)
+++ vtigercrm/branches/5.0.3/modules/Webmails/MailParse.php Tue Mar 20 02:17:20 2007
@@ -47,7 +47,7 @@
 	}
 	else
 	{
-	$flags = "<tr onmouseover='this.className=\"tabSelected\"' onmouseout='this.className=\"\"' id='row_".$num."'><td width='2px'><input type='checkbox' name='selected_id'	value='$num' onclick='toggleSelectAll(this.name,\"select_all\")' class='msg_check'></td><td colspan='1'>";
+	$flags = "<tr id='row_".$num."'><td width='2px'><input type='checkbox' name='selected_id' value='$num' onclick='toggleSelectAll(this.name,\"select_all\")' class='msg_check'></td><td colspan='1'>";
 
 	}
 
@@ -99,15 +99,15 @@
 
 	if ($mails[$start_message]->deleted)
 	{
-		$listview_entries[$num][] = '<td width="20%" nowrap align="left" id="deleted_subject_'.$num.'"><s><a href="javascript:;" onclick="load_webmail(\''.$num.'\');">'.substr($mails[$start_message]->subject,0,50).'</a></s></td>';
-		$listview_entries[$num][] = '<td width="10%" nowrap align="left" nowrap id="deleted_date_'.$num.'"><s>'.substr($mails[$start_message]->date,0,30).'</s></td>';
-		$listview_entries[$num][] = '<td width="10%" nowrap align="left" id="deleted_from_'.$num.'"><s>'.substr($from,0,20).'</s></td>';
+		$listview_entries[$num][] = '<td nowrap align="left" style="cursor:pointer;" id="deleted_subject_'.$num.'" onclick="load_webmail(\''.$num.'\');"><s><a href="javascript:;" >'.substr($mails[$start_message]->subject,0,50).'</a></s></td>';
+		$listview_entries[$num][] = '<td nowrap align="left" style="cursor:pointer;" onClick="load_webmail(\''.$num.'\');" nowrap id="deleted_date_'.$num.'"><s>'.substr($mails[$start_message]->date,0,30).'</s></td>';
+		$listview_entries[$num][] = '<td nowrap align="left" id="deleted_from_'.$num.'" style="cursor:pointer;" onClick="load_webmail(\''.$num.'\');"><s>'.substr($from,0,20).'</s></td>';
 	}
 	elseif(!$mails[$start_message]->seen || $mails[$start_message]->recent)
 	{
-		$listview_entries[$num][] = '<td width="20%" nowrap align="left" ><a href="javascript:;" onclick="load_webmail(\''.$num.'\');" id="ndeleted_subject_'.$num.'"><font id="fnt_subject_'.$num.'" color="green">'.substr($mails[$start_message]->subject,0,50).'</font></a></td>';
-		$listview_entries[$num][] = '<td width="10%" nowrap align="left" nowrap id="ndeleted_date_'.$num.'"><font id="fnt_date_'.$num.'" color="green">'.substr($mails[$start_message]->date,0,30).' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</font></td>';
-		$listview_entries[$num][] = '<td  width="10%" nowrap align="left" id="ndeleted_from_'.$num.'"><font id="fnt_from_'.$num.'">'.substr($from,0,20).'</font></td>';
+		$listview_entries[$num][] = '<td nowrap align="left" onclick="load_webmail(\''.$num.'\');" style="cursor:pointer;" ><a href="javascript:;" id="ndeleted_subject_'.$num.'"><font id="fnt_subject_'.$num.'" color="green">'.substr($mails[$start_message]->subject,0,50).'</font></a></td>';
+		$listview_entries[$num][] = '<td nowrap align="left" nowrap id="ndeleted_date_'.$num.'" style="cursor:pointer;" onClick="load_webmail(\''.$num.'\');" ><font id="fnt_date_'.$num.'" color="green">'.substr($mails[$start_message]->date,0,30).' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</font></td>';
+		$listview_entries[$num][] = '<td  nowrap align="left" id="ndeleted_from_'.$num.'"><font id="fnt_from_'.$num.'" style="cursor:pointer;" onClick="load_webmail(\''.$num.'\');" >'.substr($from,0,20).'</font></td>';
 	}
 	else
 	{
@@ -132,9 +132,9 @@
 		//Option 2 - Ends
 		//Added to shown the original UTF-8 characters - Mickie - 30-11-06 - Ends
 
-		$listview_entries[$num][] = '<td width="20%" nowrap align="left" ><a href="javascript:;" onclick="load_webmail(\''.$num.'\');" id="ndeleted_subject_'.$num.'">'.substr($mails[$start_message]->subject,0,50).'</a></td>';
-		$listview_entries[$num][] = '<td width="10%" npwrap align="left" nowrap id="ndeleted_date_'.$num.'">'.substr($mails[$start_message]->date,0,30).'</td>';
-		$listview_entries[$num][] = '<td width="10%" nowrap align="left" id="ndeleted_from_'.$num.'">'.substr($from,0,20).'</td>';
+		$listview_entries[$num][] = '<td nowrap align="left" onclick="load_webmail(\''.$num.'\');" style="cursor:pointer;" ><a href="javascript:;" id="ndeleted_subject_'.$num.'">'.substr($mails[$start_message]->subject,0,50).'</a></td>';
+		$listview_entries[$num][] = '<td npwrap align="left" nowrap id="ndeleted_date_'.$num.'" style="cursor:pointer;" onClick="load_webmail(\''.$num.'\');" >'.substr($mails[$start_message]->date,0,30).'</td>';
+		$listview_entries[$num][] = '<td nowrap align="left" id="ndeleted_from_'.$num.'" style="cursor:pointer;" onClick="load_webmail(\''.$num.'\');" >'.substr($from,0,20).'</td>';
 	}
 
 

Modified: vtigercrm/branches/5.0.3/modules/Webmails/Webmails.js
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Webmails/Webmails.js (original)
+++ vtigercrm/branches/5.0.3/modules/Webmails/Webmails.js Tue Mar 20 02:17:20 2007
@@ -17,8 +17,8 @@
 
 	}
 	if(node.className == "mailSelected") {
-		var unread  = parseInt($(mailbox+"_unread").innerHTML);
-		if(unread != 0)
+	var unread  = parseInt($(mailbox+"_unread").innerHTML);
+	if(unread != 0)
 	{
 			var curUnread;
 			curUnread = unread -1;
@@ -89,7 +89,7 @@
         $("full_view").removeChild($("full_view").firstChild);
         $("full_view").appendChild(Builder.node('a',{href: 'javascript:;', onclick: 'OpenCompose('+mid+',\'full_view\')'},'Full Email View'));
 
-	node.className = 'mailSelected' 
+	makeSelected(node.id)
 }
 function displayAttachments(mid) {
         var url = "index.php?module=Webmails&action=dlAttachments&mailid="+mid+"&mailbox="+mailbox;
@@ -363,17 +363,38 @@
         if(confirm(alert_arr.SURE_TO_DELETE))
 		runEmailCommand("delete_multi_msg",nids);
 }
-
-function move_messages() {
+function move_messages()
+{
+	var nid = '';
+	$("status").style.display = "block";
+	var chkname=document.getElementsByName("selected_id");
+	var mvmbox = $("mailbox_select").value;
+	for(var m=0;m<chkname.length;m++)
+	{
+		if(chkname[m].checked)
+			nid =  chkname[m].value;
+	}
+	  new Ajax.Request(
+                          'index.php',
+                          {queue: {position: 'end', scope: 'command'},
+                          method: 'post',
+                          postBody: 'module=Webmails&action=WebmailsAjax&file=ListView&mailbox=INBOX&command=move_msg&ajax=true&mailid='+nid+'&mvbox='+mvmbox,
+                          onComplete: function(t) {
+				window.location=window.location.href;
+				$("status").style.display = "none";
+                           }
+                         }
+                      );
+}
+
+/*function move_messages() {
         $("status").style.display="block";
         var els = document.getElementsByTagName("INPUT");
         var cnt = (els.length-1);
         for(var i=cnt;i>0;i--) {
                 if(els[i].type == "checkbox" && els[i].name.indexOf("_")) {
                         if(els[i].checked) {
-         //  var nid = els[i].name.substr((els[i].name.indexOf("_")+1),els[i].name.length);
-
-         var nid = els[i].value;
+                                var nid = els[i].name.substr((els[i].name.indexOf("_")+1),els[i].name.length);
                                 var mvmbox = $("mailbox_select").value;
                                 var row = $("row_"+nid);
                                 new Effect.Fade(row,{queue: {position: 'end', scope: 'effect'},duration: '0.5'});
@@ -393,7 +414,7 @@
 	$('mailbox_select').selectedIndex=0;
         //runEmailCommand('expunge','');
         $("status").style.display="none";
-}
+}*/
 function search_emails() {
 	// TODO: find a way to search in degraded functionality mode.
         var search_query = $("search_input").value;
@@ -411,7 +432,7 @@
                         postBody: 'module=Webmails&action=WebmailsAjax&command='+command+'&mailid='+id+'&mailbox='+mailbox,
                         onComplete: function(t) {
                                 resp = t.responseText;
-	id=resp;
+				id=resp;
                                 if(resp.match(/ajax failed/)) {return;}
                                 switch(command) {
                                     case 'expunge':

Modified: vtigercrm/branches/5.0.3/modules/Webmails/Webmails.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Webmails/Webmails.php (original)
+++ vtigercrm/branches/5.0.3/modules/Webmails/Webmails.php Tue Mar 20 02:17:20 2007
@@ -12,9 +12,18 @@
 
 include_once('config.php');
 require_once('include/logging.php');
+require_once('modules/Webmails/conf.php');
+require_once('modules/Webmails/functions.php');
 require_once('include/database/PearDatabase.php');
 require_once('data/SugarBean.php');
 require_once('data/CRMEntity.php');
+class result
+{
+	  var $text = "";
+	    var $charset = "";
+}
+
+
 
 class Webmails extends CRMEntity {
         var $log;
@@ -37,6 +46,7 @@
 	var $body;
 	var $attachments = array();
 	var $inline = array();
+	var $attachtab = array();
 	var $mbox;
 	var $email;
 	var $relationship = array();
@@ -79,18 +89,25 @@
 		imap_delete($this->mbox, $this->mailid);
 	}
 
-	function loadMail() {
-		$this->email = $this->load_mail();
+	function loadMail($attach_tab) {
+		
+		$this->email = $this->load_mail($attach_tab);
+		/* commented out by richie
 		$this->inline = $this->email["inline"];
 		$this->attachments = $this->email["attachments"];
 		$this->body = $this->email["content"]["body"];
 		$this->relationship = $this->find_relationships();
+		 */
+		$this->body = $this->email["body"];
+		$this->attachtab = $this->email["attachtab"];
+		$this->att= $this->email["att"];
+		//echo ' body is ssssssssssssssss '.$this->email["body"];
 	}
 
 	function replyBody() {
-		$tmp = "<br><br><p style='font-weight:bold'>".$mod_strings['IN_REPLY_TO_THE_MESSAGE'].$this->reply_name." on ".$this->date."</p>";
-		$tmp .= "<blockquote style='border-left:1px solid blue;padding-left:5px'>".$this->body."</blockquote>";
-		return $tmp;
+		$tmpvar = "<br><br><p style='font-weight:bold'>".$mod_strings['IN_REPLY_TO_THE_MESSAGE'].$this->reply_name." on ".$this->date."</p>";
+		$tmpvar .= "<blockquote style='border-left:1px solid blue;padding-left:5px'>".$this->body."</blockquote>";
+		return $tmpvar;
 	}
 
 	function unDeleteMsg() {
@@ -121,7 +138,7 @@
 	// get the header info
 	$mailHeader=Array();
 	$theader = @imap_headerinfo($this->mbox, $this->mailid);
-	$tmp = imap_mime_header_decode($theader->fromaddress);
+	$tmpvar = imap_mime_header_decode($theader->fromaddress);
 
 	for($p=0;$p<count($theader->to);$p++) {
 		$mailHeader['to'][] = $theader->to[$p]->mailbox.'@'.$theader->to[$p]->host;
@@ -220,7 +237,7 @@
     
 	function dl_inline()
 	{
-		$struct = imap_fetchstructure($this->mbox, $this->mailid);
+		$struct = @imap_fetchstructure($this->mbox, $this->mailid);
 		$parts = $struct->parts;
 
 		$i = 0;
@@ -292,7 +309,7 @@
 	function dl_attachments()
 	{
 
-		$struct = imap_fetchstructure($this->mbox, $this->mailid);
+		$struct = @imap_fetchstructure($this->mbox, $this->mailid);
 		$parts = $struct->parts;
 
 		$i = 0;
@@ -351,109 +368,501 @@
 	}
 
 
-	function load_mail()
+
+
+
+	function graphicalsmilies($body) {
+		$user_prefs = $_SESSION['nocc_user_prefs'];
+		if (isset($user_prefs->graphical_smilies) && $user_prefs->graphical_smilies) {
+			$body = ereg_replace("\;-?\)","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/wink.png\" alt=\"wink\"/>", $body);
+			$body = ereg_replace("\;-?D","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/grin.png\" alt=\"grin\"/>", $body);
+			$body = ereg_replace(":\'\(?","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/cry.png\" alt=\"cry\"/>", $body);
+			$body = ereg_replace(":-?[xX]","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/confused.png\" alt=\"confused\"/>", $body);
+			$body = ereg_replace(":-?\[\)","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/embarassed.png\" alt=\"embarassed\"/>", $body);
+			$body = ereg_replace(":-?\*","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/love.png\" alt=\"love\"/>", $body);
+			$body = ereg_replace(":-?[pP]","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/tongue.png\" alt=\"tongue\"/>", $body);
+			$body = ereg_replace(":-?\)","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/happy.png\" alt=\"happy\"/>", $body);
+			$body = ereg_replace(":-?\(","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/unhappy.png\" alt=\"unhappy\"/>", $body);
+			$body = ereg_replace(":-[oO]","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/surprised.png\" alt=\"surprised\"/>", $body);
+			$body = ereg_replace("8-?\)","<img src=\"themes/" . $_SESSION['nocc_theme'] . "/img/smilies/cool.png\" alt=\"cool\"/>", $body);
+		}
+		return ($body);
+	}
+
+// based on a function from matt at bonneau.net
+function GetPart(&$attach_tab, &$this_part, $part_no, &$display_rfc822)
+{
+    $att_name = '[unknown]';
+    if ($this_part->ifdescription == true)
+    {
+	    $att_name = $this_part->description;
+    }
+    for ($i = 0; $i < count($this_part->parameters); $i++)
+    {
+        // PHP 5.x doesn't allow to convert a stdClass object to an array
+	// We sometimes have this issue with Mailer daemon reports
+	if (!(get_class($this_part->parameters) == "stdClass") &&
+		!(get_class($this_part->parameters) == "stdclass")) 
+	{ 
+            $param = $this_part->parameters[$i];
+            if ((($param->attribute == 'NAME') || ($param->attribute == 'name')) && ($param->value != ''))
+            {
+                $att_name = $param->value;
+                break;
+            }
+	}
+    }
+    if (isset($this_part->type))
+    {
+        switch ($this_part->type)
+        {
+            case 0:
+                $mime_type = 'text';
+                break;
+            case 1:
+		    $mime_type = 'multipart';
+                for ($i = 0; $i < count($this_part->parts); $i++)
+	{
+                    if ($part_no != '')
+                        $part_no = $part_no . '.';
+                    // if it's an alternative, we skip the text part to only keep the HTML part
+                    if ($this_part->subtype == 'ALTERNATIVE')// && $read == true)
+                        $this->GetPart($attach_tab, $this_part->parts[++$i], $part_no . ($i + 1), $display_rfc822);
+                    else 
+                        $this->GetPart($attach_tab, $this_part->parts[$i], $part_no . ($i + 1), $display_rfc822);
+                }
+                break;
+            case 2:
+                $mime_type = 'message';
+                // well it's a message we have to parse it to find attachments or text message
+		if(isset($this_part->parts[0]->parts)) 
+		{
+                    $num_parts = count($this_part->parts[0]->parts);
+		    for ($i = 0; $i < $num_parts; $i++)
+		{
+			    $this->GetPart($attach_tab, $this_part->parts[0]->parts[$i], $part_no . '.' . ($i + 1), $display_rfc822);
+		    }
+                }
+                break;
+            // Maybe we can do something with the mime types later ??
+            case 3:
+                $mime_type = 'application';
+                break;
+            case 4:
+                $mime_type = 'audio';
+                break;
+            case 5:
+                $mime_type = 'image';
+                break;
+            case 6:
+                $mime_type = 'video';
+                break;
+            case 7:
+                $mime_type = 'other';
+                break;
+            default:
+                $mime_type = 'unknown';
+        }
+    }
+			else 
+    {	
+		    $mime_type = 'text';
+    }
+	$full_mime_type = $mime_type . '/' . $this_part->subtype;
+    if (isset($this_part->encoding))
+    {
+        switch ($this_part->encoding)
+        {
+            case 0:
+                $encoding = '7BIT';
+                break;
+            case 1:
+                $encoding = '8BIT';
+                break;
+            case 2:
+                $encoding = 'BINARY';
+                break;
+            case 3:
+                $encoding = 'BASE64';
+                break;
+            case 4:
+                $encoding = 'QUOTED-PRINTABLE';
+                break;
+            case 5:
+                $encoding = 'OTHER';
+                break;
+            default:
+                $encoding = 'none';
+                break;
+        }
+		}
+		else
+		{
+	    $encoding = '7BIT';
+    }
+
+    if (($full_mime_type == 'message/RFC822' && $display_rfc822 == true) || ($mime_type != 'multipart' && $full_mime_type != 'message/RFC822'))
+    {
+        $charset = '';
+        if ($this_part->ifparameters)
+            while ($obj = array_pop($this_part->parameters))
+                if (strtolower($obj->attribute) == 'charset')
+                {
+                    $charset = $obj->value;
+                    break;
+                }
+        $tmp = Array(
+            'number' => ($part_no != '' ? $part_no : 1),
+            'id' => $this_part->ifid ? $this_part->id : 0,
+            'name' => $att_name,
+            'mime' => $full_mime_type,
+            'transfer' => $encoding,
+            'disposition' => $this_part->ifdisposition ? $this_part->disposition : '',
+            'charset' => $charset,
+            'size' => ($this_part->bytes > 1000) ? ceil($this_part->bytes / 1000) : 1
+        );
+
+        array_unshift($attach_tab, $tmp);
+    }
+}
+
+function GetCodeScoreAll($Data,$beg_charset) {
+	global $cad_StatsTableWin, $cad_StatsTableKoi;
+	$PairSize = 2;
+
+	$Data=substr($Data,$beg_charset,100);
+	$Data=preg_replace('/[\n\r]/','',$Data);
+	setlocale(LC_CTYPE,'ru_RU.KOI8-R');
+
+	$Mark_koi=0;
+	$Mark_win=0;
+	$cnt=0;
+	$max_detect_limit=10;
+
+	$sp=preg_split('/[\.\,\-\s\:\;\?\!\'\"\(\)\d<>]+/',$Data);
+	while ( list($key2,$val2) = each($sp) ) {
+		$rc=preg_match("/(.*)([\x7F-\xFF]+)/x",$val2);
+		if($rc == 0) {
+			continue;
+		}
+
+		if($cnt > $max_detect_limit) {
+			break;
+		} else {
+			$cnt++;
+		}
+		$dlina=strlen($val2)-$PairSize;
+		if($dlina < 1) {$cnt--; continue;}
+		$val3=strtolower($val2);
+		if (ucfirst($val3) == $val2) {
+			$scaleK=2;
+		} else {
+			$scaleK=1;
+		}
+		if(substr($val3,0,1).strtoupper(substr($val2,1,strlen($val2))) == $val2) {
+			$scaleW=2;
+		} else {
+			$scaleW=1;
+		}
+		$Cur_mark_koi=0;
+		$Cur_mark_win=0;
+		for ($i=0; $i<$dlina; $i++ ) {
+			$pp=substr ($val3, $i, $PairSize);
+			if (isset($cad_StatsTableKoi[$pp])) {
+				$Cur_mark_koi += $cad_StatsTableKoi[$pp];
+			}
+			if (isset($cad_StatsTableWin[$pp])) {
+				$Cur_mark_win += $cad_StatsTableWin[$pp];
+			}
+		}
+		$Mark_koi+=$Cur_mark_koi*$scaleK;
+		$Mark_win+=$Cur_mark_win*$scaleW;
+	}
+	$Mark_list=array($Mark_koi,$Mark_win);
+	//setlocale(LC_CTYPE,$old_locale);
+	return $Mark_list;
+}
+
+
+
+
+
+
+
+
+
+
+
+/* lxnt:  patched to return charset names that iconv() understands*/
+function detect_charset($Data,$dbg_fl = 0) {
+	/* for many small pices of text -  list of sender/subject*/
+	$rc=preg_match("/(.*)([\x7F-\xFF]+)/xU",$Data,$tst_ar);
+	if($rc == 0) {
+		return 'US-ASCII';
+	} else {
+		$beg_charset=strpos($Data,$tst_ar[2]);
+	}
+	list($KoiMark,$WinMark) = GetCodeScoreAll($Data,$beg_charset);
+	$Ratio['koi8-r'] =  $KoiMark/($WinMark + 1);
+	$Ratio['windows-1251'] =  $WinMark/($KoiMark + 1);
+
+	list($MaxRation,$MaxRatioKey)=max_from_ratio($Ratio);
+	return $MaxRatioKey;
+}
+
+
+
+
+
+
+
+function mime_header_decode(&$header)
+{
+	$output_charset = $GLOBALS['charset'];
+	$source = imap_mime_header_decode($header);
+	$result[] = new result;
+	$result[0]->text='';
+	$result[0]->charset='ISO-8859-1';
+	for ($j = 0; $j < count($source); $j++ )
+       	{
+	$element_charset =  ($source[$j]->charset == "default") ? $this->detect_charset($source[$j]->text) : $source[$j]->charset;
+		if ($element_charset == 'x-unknown')
+			$element_charset = 'ISO-8859-1';
+
+		$element_converted = @iconv( $element_charset, $output_charset, $source[$j]->text);
+		$result[$j]->text = $element_converted;
+		$result[$j]->charset = $output_charset;
+	}
+	return $result;
+}
+
+
+
+
+function link_att(&$mail, $attach_tab, &$display_part_no,$ev)
+{
+	sort($attach_tab);
+	$link = '';
+	while ($tmp = array_shift($attach_tab))
+		if (!empty($tmp['name']))
+			{
+			$mime = str_replace('/', '-', $tmp['mime']);
+			if ($display_part_no == true)
+				$link .= $tmp['number'] . '&nbsp;&nbsp;';
+			unset($att_name);
+			$att_name_array = imap_mime_header_decode($tmp['name']);
+			for ($i=0; $i<count($att_name_array); $i++) {
+				$att_name .= $att_name_array[$i]->text;
+			}
+			$att_name_dl = $att_name;
+			$att_name = $this->convertLang2Html($att_name);
+			$link .= '<a href="index.php?module=Webmails&action=download&part=' . $tmp['number'] . '&mailid='.$ev.'&transfer=' . $tmp['transfer'] . '&filename=' . base64_encode($att_name_dl) . '&mime=' . $mime . '">' . $att_name . '</a>&nbsp;&nbsp;' . $tmp['mime'] . '&nbsp;&nbsp;' . $tmp['size'] . '<br/>';
+		}
+	return ($link);
+}
+
+
+
+
+
+
+
+
+
+
+
+// Convert mail data (from, to, ...) to HTML
+function convertMailData2Html($maildata, $cutafter = 0)
+				{
+	if (($cutafter > 0) && (strlen($maildata) > $cutafter)) 
+					{
+       		return htmlspecialchars(substr($maildata, 0, $cutafter)) . '&hellip;';
+					}
+					else
+					{
+             return htmlspecialchars($maildata);
+					}
+				}
+
+// Convert a language string to HTML
+ function convertLang2Html($langstring) {
+   global $charset;
+     return htmlentities($langstring, 2, $charset);
+					}
+
+
+
+
+
+
+
+
+	function load_mail($attach_tab)
 	{
 		// parse the message
-		$struct = imap_fetchstructure($this->mbox, $this->mailid);
-		$parts = $struct->parts;
-
-		$content = array();
-		$i = 0;
-		if (!$parts)
-		{
-			/* Simple message, only 1 piece */
-			$attachment = array(); /* No vtiger_attachments */
-			$bod=imap_body($this->mbox, $this->mailid);
-			if(preg_match("/\<br\>/",$bod))
-				$content['body'] = $bod;
-			else 
-				$content['body'] = nl2br($bod);
-		}
+	$ref_contenu_message =  imap_headerinfo($this->mbox, $this->mailid);
+		$struct_msg = imap_fetchstructure($this->mbox, $this->mailid);
+		$mail = $this->mbox;
+		$ev = $this->mailid;
+$conf->display_rfc822 = true;
+		if ($struct_msg->type == 3 || (isset($struct_msg->parts) && (sizeof($struct_msg->parts) > 0)))
+					{
+			$this->GetPart($attach_tab, $struct_msg, NULL, $conf->display_rfc822);
+					}
 		else
-		{
-
-			$stack = array(); 
-			$attachment = array();
-
-			$endwhile = false;
-
-			while (!$endwhile)
-			{
-				if (!$parts[$i])
-				{
-					if (count($stack) > 0)
-					{
-						$parts = $stack[count($stack)-1]["p"];
-						$i    = $stack[count($stack)-1]["i"] + 1;
-						array_pop($stack);
-					}
-					else
-					{
-						$endwhile = true;
-					}
-				}
-				$search = array("/=20=/","/=20/","/=\r\n/","/=3D/","@&(<a|<A);@i","/=0A/i","/=A0/i");
-				$replace = array("","","","=","<a target='_blank' ","");
-				if (!$endwhile)
-				{
-
-					$partstring = "";
-					foreach ($stack as $s)
-					{
-						$partstring .= ($s["i"]+1) . ".";
-					}
-					$partstring .= ($i+1);
-
-					$type='';
-					if (strtoupper($parts[$i]->disposition) == "INLINE" && strtoupper($parts[$i]->subtype) != "PLAIN")
-					{
-						$inline[] = array("filename" => $parts[$i]->dparameters[0]->value,"subtype"=>$parts[$i]->subtype,"filesize"=>$parts[$i]->bytes);
-					}
-					elseif (strtoupper($parts[$i]->disposition) == "ATTACHMENT")
-					{
-						$attachment[] = array("filename" => $parts[$i]->dparameters[0]->value,"subtype"=>$parts[$i]->subtype,"filesize"=>$parts[$i]->bytes);
-
-					}
-					elseif (strtoupper($parts[$i]->subtype) == "HTML")
-					{
-						$content['body'] = preg_replace($search,$replace,imap_fetchbody($this->mbox, $this->mailid, $partstring));
-						$stat="done";
-					}
-					elseif (strtoupper($parts[$i]->subtype) == "TEXT" && !$stat == "done")
-					{
-						$content['body'] = nl2br(imap_fetchbody($this->mbox, $this->mailid, $partstring));
-						$stat="done";
-					}
-					elseif (strtoupper($parts[$i]->subtype) == "PLAIN" && !$stat == "done")
-					{
-						$content['body'] = nl2br(imap_fetchbody($this->mbox, $this->mailid, $partstring));
-						$stat="done";
-					}
-					elseif (!$stat == "done")
-					{
-						$content['body'] = nl2br(imap_fetchbody($this->mbox, $this->mailid, $partstring));
-					}
-				}
-
-				if ($parts[$i]->parts)
-				{
-					$stack[] = array("p" => $parts, "i" => $i);
-					$parts = $parts[$i]->parts;
-					$i = 0;
+					{
+			$pop_fetchheader_mail_ev = imap_fetchheader($mail, $ev);
+			$pop_body_mail_ev = imap_body($mail, $ev);
+			GetSinglePart($attach_tab, $struct_msg, $pop_fetchheader_mail_ev, $pop_body_mail_ev);
+		}
+		$conf->use_verbose = true;
+		$header = "";
+		if (($verbose == 1) && ($conf->use_verbose == true)) {
+			$header = imap_fetchheader($mail, $ev);
+		}
+
+		$tmpvar = array_pop($attach_tab);
+		if ($struct_msg->type == 3)
+		{
+			$body = '';
+					}
+		else
+					{
+			$body = imap_fetchbody($mail,$ev,$tmpvar['number']);
+
+					}
+
+
+
+		if (eregi('text/html', $tmpvar['mime']) || eregi('text/plain', $tmpvar['mime']))
+					{
+			if ($tmpvar['transfer'] == 'QUOTED-PRINTABLE')
+				$body = imap_qprint($body);
+			if ($tmpvar['transfer'] == 'BASE64')
+				$body = base64_decode($body);
+			$body = remove_stuff($body, $tmpvar['mime']);
+			$body_charset =  ($tmpvar['charset'] == "default") ? $this->detect_charset($body) : $tmpvar['charset'];
+
+
+			if (strtolower($body_charset) == "us-ascii") {
+				$body_charset = "ISO-8859-1";
+					}
+
+			if ($body_charset == "" || $body_charset == null) {
+				if (isset($conf->default_charset) && $conf->default_charset != "") {
+					$body_charset = $conf->default_charset;
+				} else {
+					$body_charset = "ISO-8859-1";
+					}
+					}
+
+			if (isset($_REQUEST['user_charset']) && $_REQUEST['user_charset'] != '') {
+				$body_charset = $_REQUEST['user_charset'];
+				}
+
+			$body_converted = @iconv( $body_charset, $GLOBALS['charset'], $body);
+			$body = ($body_converted===FALSE) ? $body : $body_converted;
+			$tmpvar['charset'] = ($body_converted===FALSE) ? $body_charset : $GLOBALS['charset'];
 				}
 				else
 				{
-					$i++;
-				}
+			array_push($attach_tab, $tmpvar);
+				}
+		$link_att = '';
+$conf->display_part_no = true;
+		if ($struct_msg->subtype != 'ALTERNATIVE' && $struct_msg->subtype != 'RELATED')
+		{
+			switch (sizeof($attach_tab))
+			{
+			case 0:
+				$link_att = '<span id="webmail_cont" style="display:none;"><tr><th class="mailHeaderLabel right"></th><td class="mailHeaderData"></td></tr></span>';
+				break;
+			case 1:
+				$link_att = '<span id="webmail_cont" style="display:none;"><tr><th class="mailHeaderLabel right">' . $html_att . ':</th><td class="mailHeaderData">' . $this->link_att($mail, $attach_tab, $conf->display_part_no,$ev) . '</td></tr></span>';
+				break;
+			default:
+				$link_att = '<span id="webmail_cont" style="display:none;"><tr><th class="mailHeaderLabel right">' . $html_atts . ':</th><td class="mailHeaderData">' . $this->link_att($mail, $attach_tab, $conf->display_part_no,$ev) . '</td></tr></span>';
+				break;
 			} 
+		}else
+			{
+				$link_att = '<span id="webmail_cont" style="display:none;"><tr><th class="mailHeaderLabel right"></th><td class="mailHeaderData"></td></tr></span>';
 		} 
-		if($struct->encoding==3)
-			$content['body'] = base64_decode($content['body']);
-		if($struct->encoding==4)
-			$content['body'] = quoted_printable_decode($content['body']);
-
-		$ret = Array("content" => $content,"attachments"=>$attachment,"inline"=>$inline);
-		return $ret;
+
+		$struct_msg = imap_fetchstructure($mail, $ev);
+		$msg_charset = '';
+		if ($struct_msg->ifparameters) {
+			while ($obj = array_pop($struct_msg->parameters)) {
+				if (strtolower($obj->attribute) == 'charset') {
+					$msg_charset = $obj->value;
+					break;
+				}
+			}
+		}
+		if ($msg_charset == '') {
+			$msg_charset = 'ISO-8859-1';
+		}
+
+
+	$subject_header = str_replace('x-unknown', $msg_charset, $ref_contenu_message->subject);
+	$subject_array = $this->mime_header_decode($subject_header);
+	for ($j = 0; $j < count($subject_array); $j++)
+			$subject .= $subject_array[$j]->text;
+
+	$from_header = str_replace('x-unknown', $msg_charset, $ref_contenu_message->fromaddress);
+	$from_array = $this->mime_header_decode($from_header);
+	for ($j = 0; $j < count($from_array); $j++)
+		$from .= $from_array[$j]->text;
+
+	$to_header = str_replace('x-unknown', $msg_charset, $ref_contenu_message->toaddress);
+	$to_array = $this->mime_header_decode($to_header);
+	for ($j = 0; $j < count($to_array); $j++)
+		$to .= $to_array[$j]->text;
+	$to = str_replace(',', ', ', $to);
+
+	$cc_header = isset($ref_contenu_message->ccaddress) ? $ref_contenu_message->ccaddress : '';
+	$cc_header = str_replace('x-unknown', $msg_charset, $cc_header);
+	$cc_array = isset($ref_contenu_message->ccaddress) ? imap_mime_header_decode($cc_header) :0;
+	if ($cc_array != 0) {
+		for ($j = 0; $j < count($cc_array); $j++)
+			$cc .= $cc_array[$j]->text;
+	}
+	$cc = str_replace(',', ', ', $cc);
+
+	$reply_to_header = isset($ref_contenu_message->reply_toaddress) ? $ref_contenu_message->reply_toaddress : '';
+	$reply_to_header = str_replace('x-unknown', $msg_charset, $reply_to_header);
+	$reply_to_array = isset($ref_contenu_message->reply_toaddress) ? imap_mime_header_decode($reply_to_header) : 0;
+	if ($reply_to_array != 0) {
+		for ($j = 0; $j < count($reply_to_array); $j++)
+			$reply_to .= $reply_to_array[$j]->text;
+	}
+
+	$timestamp = chop($ref_contenu_message->udate);
+	$date = format_date($timestamp, $lang);
+	$time = format_time($timestamp, $lang);
+	$content = Array(
+		'from' => $from,
+		'to' => $to,
+		'cc' => $cc,
+		'reply_to' => $reply_to,
+		'subject' => $subject,
+		'date' => $date,
+		'time' => $time,
+		'complete_date' => $date,
+		'att' => $link_att,
+		'body' => $this->graphicalsmilies($body),
+		'body_mime' => $this->convertLang2Html($tmpvar['mime']),
+		'body_transfer' => $this->convertLang2Html($tmpvar['transfer']),
+		'header' => $header,
+		'verbose' => $verbose,
+		'prev' => $prev_msg,
+		'next' => $next_msg,
+		'msgnum' => $mail,
+		'attachtab' => $attach_tab,
+		'charset' => $body_charset
+	);
+return ($content);
+
 	}
 
 

Modified: vtigercrm/branches/5.0.3/modules/Webmails/WebmailsAjax.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Webmails/WebmailsAjax.php (original)
+++ vtigercrm/branches/5.0.3/modules/Webmails/WebmailsAjax.php Tue Mar 20 02:17:20 2007
@@ -42,6 +42,17 @@
     $command = $_REQUEST["command"];
     if($command == "expunge") {
     	$MailBox = new MailBox($mailbox);
+	/*
+	$search = imap_search($MailBox->mbox,'DELETED');
+	$data = imap_fetch_overview($MailBox->mbox,implode(',',$search));
+	for($i=0;$i<$num;$i++)
+	{
+        	if($data[$i]->deleted != 0)
+		{
+			imap_delete($MailBox->mbox,$data[$i]->message_id);
+		}
+	}
+	 */
     	imap_expunge($MailBox->mbox);
 	imap_close($MailBox->mbox);
 	flush();
@@ -50,9 +61,8 @@
     if($command == "delete_msg") {
 	$adb->println("DELETE SINGLE WEBMAIL MESSAGE $mailid");
     	$MailBox = new MailBox($mailbox);
-        imap_mail_move($MailBox->mbox,$mailid,"Trash");
+        imap_mail_move($MailBox->mbox,$mailid,"Deleted");
 	$email = new Webmails($MailBox->mbox,$mailid);
-       	$email->delete();
 	imap_close($MailBox->mbox);
 	echo $mailid;
 	flush();

Modified: vtigercrm/branches/5.0.3/modules/Webmails/body.php
==============================================================================
--- vtigercrm/branches/5.0.3/modules/Webmails/body.php (original)
+++ vtigercrm/branches/5.0.3/modules/Webmails/body.php Tue Mar 20 02:17:20 2007
@@ -14,6 +14,7 @@
 require_once('include/utils/UserInfoUtil.php');
 require_once('modules/Webmails/Webmails.php');
 require_once('modules/Webmails/MailBox.php');
+global $mod_strings;
 
 if(!isset($_SESSION["authenticated_user_id"]) || $_SESSION["authenticated_user_id"] != $current_user->id) {echo "ajax failed";flush();exit();}
 $mailid=$_REQUEST["mailid"];
@@ -26,7 +27,9 @@
 	$mailbox="INBOX";
 }
 $MailBox = new MailBox($mailbox);
+$mail = $MailBox->mbox;
 $email = new Webmails($MailBox->mbox,$mailid);
+$status=imap_setflag_full($MailBox->mbox,$mailid,"\\Seen");
 ?>
 <script type="text/javascript">
 function show_inline(num) {
@@ -38,61 +41,79 @@
 }
 </script>
 <?php
+function view_part_detail($mail,$mailid,$part_no, &$transfer, &$msg_charset, &$charset)
+{
+	$text = imap_fetchbody($mail,$mailid,$part_no);
+	if ($transfer == 'BASE64')
+		$str = nl2br(imap_base64($text));
+	elseif($transfer == 'QUOTED-PRINTABLE')
+		$str = nl2br(quoted_printable_decode($text));
+	else
+		$str = nl2br($text);
+	return ($str);
+}
+$attach_tab=array();
+$email->loadMail($attach_tab);
+$content['body'] = '<span id="webmail_body">'.$email->body.'</span>';
+$content['attachtab'] = $email->attachtab;
+//Need to put this along with the subject block
+echo $email->att;
+echo $content['body'];
 
-$email->loadMail();
+//test added by Richie
+if (!isset($_REQUEST['display_images']) || $_REQUEST['display_images'] != 1)
+{
+	$content['body'] = eregi_replace('src="[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]"', 'src="none"', $content['body']);
+	$content['body'] = eregi_replace('src=[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]', 'src="none"', $content['body']);
+}
 
-//Added to get the UTF-8 string - 30-11-06 - Mickie
-$email->body = utf8_decode(imap_utf8($email->body));
+//Display embedded HTML images
+$tmp_attach_tab=$content['attachtab'];
+$i = 0;
+$conf->display_img_attach = true;
+$conf->display_text_attach = true;
 
-echo $email->body;
-echo "<br><br>";
-
-if(is_array($email->inline))
+while ($tmp = array_pop($tmp_attach_tab)) 
 {
-	$inline = $email->downloadInlineAttachments();
-	$num=sizeof($inline);
-	echo "<p style='border-bottom:1px solid black;font-weight:bold'>Inline Attachments:</p>";
-	
-	for($i=0;$i<$num;$i++)
+	if ($conf->display_img_attach && (eregi('image', $tmp['mime']) && ($tmp['number'] != '')))
 	{
-		//var_dump($inline[$i]);
-		// PLAIN TEXT
-		if($inline[$i]["subtype"] == "RFC822")
+		$exploded = explode('/', $tmp['mime']);
+		$img_type = array_pop($exploded);
+		if (eregi('JPEG', $img_type) || eregi('JPG', $img_type) || eregi('GIF', $img_type) || eregi ('PNG', $img_type))
 		{
-			echo "<br>".($i+1).") <a href='javascript:show_inline(".$i.");'>".$inline[$i]["filename"]."</a><blockquote id='block_".$i."' style='border:1px solid gray;padding:6px;background-color:#FFFFCC;display:none'>";
-			echo nl2br($inline[$i]["filedata"]);
-			echo "</blockquote>";
+			$new_img_src = 'src="get_img.php?mail=' . $mailid.'&num=' . $tmp['number'] . '&mime=' . $img_type . '&transfer=' . $tmp['transfer'] . '"';
+			$img_id = str_replace('<', '', $tmp['id']);
+			$img_id = str_replace('>', '', $img_id);
+			$content['body'] = str_replace('src="cid:'.$img_id.'"', $new_img_src, $content['body']);
+			$content['body'] = str_replace('src=cid:'.$img_id, $new_img_src, $content['body']);
 		}
-		elseif($inline[$i]["subtype"] == "JPEG" || $inline[$i]["subtype"] == "GIF")
-		{
-			echo "<br>".($i+1).") <a href='javascript:show_inline(".$i.");'>".$inline[$i]["filename"]."</a><br><br><div id='block_".$i."' style='border:1px solid gray;padding:6px;background-color:#FFFFCC;display:none;width:95%;overflow:auto'>";
-			global $root_directory;
-			$save_path=$root_directory.'/modules/Webmails/tmp';
-			
-			if(!is_dir($save_path))
-				mkdir($save_path);
-				
-			$save_dir=$save_path."/cache";
-			
-			if(!is_dir($save_dir))
-				mkdir($save_dir);
-		
-			$fp = fopen($save_dir.'/'.$inline[$i]["filename"], "w") or die("Can't open file");
-			fputs($fp, base64_decode($inline[$i]["filedata"]));
-			$filename = 'modules/Webmails/tmp/cache/'.$inline[$i]['filename'];
-			fclose($fp);
-			echo '<img src="'.$filename.'" border="0" >';
-			echo '</div>';
 		}
-		else 
+}
+while ($tmp = array_pop($content['attachtab']))
+{
+	if ((!eregi('ATTACHMENT', $tmp['disposition'])) && $conf->display_text_attach && (eregi('text/plain', $tmp['mime'])))
+		echo '<hr />'.view_part_detail($mail, $mailid, $tmp['number'], $tmp['transfer'], $tmp['charset'], $charset);
+	if ($conf->display_img_attach && (eregi('image', $tmp['mime']) && ($tmp['number'] != '')))
+	{
+		$exploded = explode('/', $tmp['mime']);
+		$img_type = array_pop($exploded);
+		if (eregi('JPEG', $img_type) || eregi('JPG', $img_type) || eregi('GIF', $img_type) || eregi ('PNG', $img_type))
                         {
-                                echo "<br>".($i+1).") <a target='_BLANK' href='index.php?module=Webmails&action=dlAttachments&inline=true&num=".$i."&mailbox=".$mailbox."&mailid=".$mailid."'>".$inline[$i]["filename"]."</a>
-			<br>";
-//                      echo "<br>".($i+1).") <a target='_BLANK' href='index.php?module=Webmails&action=dlAttachments&inline=true&num=".$i."&mailid=".$mailid."'>".$inline[$i]["filename"]."</a> <br>";
+			echo '<hr />';
+			echo '<center>';
+			echo $mod_strings['LBL_LOADING_IMAGE'];
+			echo '..........<br>';
+			echo '<img src="index.php?module=Webmails&action=get_img&mail=' . $mailid.'&num=' . $tmp['number'] . '&mime=' . $img_type . '&transfer=' . $tmp['transfer'] . '" />';
+			echo '</center>';
 	}                
 }                    
 }
+
+
+//test ended by Richie
+
 imap_close($MailBox->mbox);
 
 
 ?>
+<script>parent.document.getElementById('webmail_attachment').innerHTML=document.getElementById('webmail_cont').innerHTML</script>

Modified: vtigercrm/branches/5.0.3/themes/alphagrey/style.css
==============================================================================
--- vtigercrm/branches/5.0.3/themes/alphagrey/style.css (original)
+++ vtigercrm/branches/5.0.3/themes/alphagrey/style.css Tue Mar 20 02:17:20 2007
@@ -1639,7 +1639,7 @@
 	padding-bottom:2px;
 	
 }
-.mailSelected:hover {
+.mailSelected_select {
 	background:#E1DCB3 url(images/tabSelectedBg.gif) repeat-x;
 	background-color:#1F5EFF;
 	font-family:  Arial, Helvetica, sans-serif;

Modified: vtigercrm/branches/5.0.3/themes/bluelagoon/style.css
==============================================================================
--- vtigercrm/branches/5.0.3/themes/bluelagoon/style.css (original)
+++ vtigercrm/branches/5.0.3/themes/bluelagoon/style.css Tue Mar 20 02:17:20 2007
@@ -2228,7 +2228,7 @@
 	padding-bottom:2px;
 	
 }
-.mailSelected:hover {
+.mailSelected_select {
 	background:#E1DCB3 url(images/tabSelectedBg.gif) repeat-x;
 	background-color:#1F5EFF;
 	font-family:  Arial, Helvetica, sans-serif;

Modified: vtigercrm/branches/5.0.3/themes/woodspice/style.css
==============================================================================
--- vtigercrm/branches/5.0.3/themes/woodspice/style.css (original)
+++ vtigercrm/branches/5.0.3/themes/woodspice/style.css Tue Mar 20 02:17:20 2007
@@ -1681,7 +1681,7 @@
 	padding-bottom:2px;
 	
 }
-.mailSelected:hover {
+.mailSelected_select {
 	background:#E1DCB3 url(images/tabSelectedBg.gif) repeat-x;
 	background-color:#1F5EFF;
 	font-family:  Arial, Helvetica, sans-serif;





More information about the vtigercrm-commits mailing list