fetch_array($mailInfo); if($temprow["mail_protocol"] == 'POP') { $ServerName = "{".$temprow["mail_servername"]."/pop3:110/notls}INBOX"; } else { $ServerName = "{".$temprow["mail_servername"]."/imap:143/notls}INBOX"; // For a IMAP connection (PORT 143) } $UserName = $temprow["mail_username"]; $PassWord = $temprow["mail_password"]; $mbox = imap_open($ServerName, $UserName,$PassWord) or die("Could not open Mailbox - try again later!"); if ($hdr = imap_check($mbox)) { echo "Total Messages :-> " . $hdr->Nmsgs ."\n\n

"; $msgCount = $hdr->Nmsgs; } else { echo "failed"; } $MN=$msgCount; $overview=imap_fetch_overview($mbox,"1:$MN",0); $mime_type = get_mime_type($overview); //$size=sizeof($overview); $size = imap_num_msg($mbox); global $app_strings,$current_user; if(isset($_REQUEST['view']) && $_REQUEST['view']!='') { $msgid = $_REQUEST['view']; $header = @imap_headerinfo($mbox, $msgid, 80, 80); $fromaddress[$msgid] = $header->from[0]->host; $domain = $fromaddress[$msgid]; $fromname[$msgid] = $header->from[0]->mailbox; $sendername=$fromname[$msgid]; $from[$msgid]= $fromname[$msgid]."@".$fromaddress[$msgid]; $totalfromaddress = $sendername ."@".$domain; $val=$overview[$msgid-1]; $msg=$val->msgno; $from=$val->from; $date=$val->date; $subj=$val->subject; //transformHTML($subj); $seen=$val->seen; $from = ereg_replace("\"","",$from); echo ''; // MAKE DANISH DATE DISPLAY list($dayName,$day,$month,$year,$time) = split(" ",$date); $time = substr($time,0,5); $date = $day ." ". $month ." ". $year . " ". $time; if ($bgColor == "#F0F0F0") { $bgColor = "#FFFFFF"; } else { $bgColor = "#F0F0F0"; } if (strlen($subj) > 60) { $subj = substr($subj,0,59) ."..."; get_part(); } echo get_module_title("Emails",'Emails', true); echo "
"; echo "
"; echo ''; echo ''; echo ""; echo ""; echo ""; echo "
Email Information
From:" . $from ."
Date:" .$date ."
Subject:" .$subj."
Mail body:"; $content = get_part($mbox,$msg,$mime_type); echo nl2br($content); echo "
"; //get the attachment $struct = imap_fetchstructure($mbox,$msg); $contentParts = count($struct->parts); if ($contentParts >= 2) { for ($i=2;$i<=$contentParts;$i++) { $att[$i-2] = imap_bodystruct($mbox,$msg,$i); } for ($k=0;$kparameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") { if ($att[$k]->parameters[1]->value != "") { $selectBoxDisplay[$k] = $att[$k]->parameters[1]->value; } } elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") { $selectBoxDisplay[$k] = $att[$k]->parameters[0]->value; } } } if (sizeof($selectBoxDisplay) > 0) { echo "
"; } echo ' ; '; $date_fmt = Array(); list($mday,$mmon,$myear,$mtime)=split(" ",$date); $maildate = strtotime($mday." ".$mmon." ".$myear); list($date_fmt[0],$date_fmt[1],$date_fmt[2]) = split("-",$current_user->date_format); for($i=0;$i<=2;$i++) { if(stristr($date_fmt[$i],"d")) $date_fmt[$i] = "d"; elseif(stristr($date_fmt[$i],"m")) $date_fmt[$i] = "m"; elseif(stristr($date_fmt[$i],"y")) $date_fmt[$i] = "Y"; } #echo date("$date_fmt[0]-$date_fmt[1]-$date_fmt[2]",$maildate); echo '
Add to vtiger CRM
Delete from Mail Server
'; echo '
 
'; } else { echo get_module_title("Emails",'Emails', true); echo "
"; echo "
"; echo '
'; echo get_form_header("Received Emails", "
", false ); echo "
"; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; for($i=$size-1;$i>=0;$i--) { $j = $i+1; $header = @imap_headerinfo($mbox, $j, 80, 80); $fromaddress[$j] = $header->from[0]->host; $domain = $fromaddress[$j]; $fromname[$j] = $header->from[0]->mailbox; $sendername=$fromname[$j]; $sender[$j]= $fromname[$j]."@".$fromaddress[$j]; $totalfromaddress = $sendername ."@".$domain; $val=$overview[$i]; $msg=$val->msgno; $from=$val->from; $date=$val->date; $subj=$val->subject; //transformHTML($subj); $seen=$val->seen; //imap_delete($mbox, 1); //imap_expunge($mbox); $from = ereg_replace("\"","",$from); // MAKE DANISH DATE DISPLAY list($dayName,$day,$month,$year,$time) = split(" ",$date); $time = substr($time,0,5); $date = $day ." ". $month ." ". $year . " ". $time; if ($bgColor == "#F0F0F0") { $bgColor = "#FFFFFF"; $rowClass = "oddListRow"; } else { $bgColor = "#F0F0F0"; $rowClass = "evenListrow"; } if (strlen($subj) > 60) { $subj = substr($subj,0,59) ."..."; get_part(); } echo "\n "; } echo "
SenderSubjectDate
$msg$sendername$totalfromaddress $subj $date
"; echo "
"; } imap_close($mbox); function get_mime_type(&$structure) { $primary_mime_type = array("TEXT", "MULTIPART","MESSAGE", "APPLICATION", "AUDIO","IMAGE", "VIDEO", "OTHER"); if($structure->subtype) { return $primary_mime_type[(int) $structure->type] . '/' .$structure->subtype; } return "TEXT/PLAIN"; } function get_part($stream, $msg_number, $mime_type, $structure = false,$part_number = false) { if(!$structure) { $structure = imap_fetchstructure($stream, $msg_number); } if($structure) { if($mime_type == get_mime_type($structure)) { if(!$part_number) { $part_number = "1"; } $text = imap_fetchbody($stream, $msg_number, $part_number); if($structure->encoding == 3) { return imap_base64($text); } else if($structure->encoding == 4) { return imap_qprint($text); } else { return $text; } } if($structure->type == 1) /* multipart */ { while(list($index, $sub_structure) = each($structure->parts)) { if($part_number) { //$prefix = $part_number . '.'; $prefix = $part_number ; } $data = get_part($stream, $msg_number, $mime_type, $sub_structure,$prefix . ($index + 1)); if($data) { return $data; } } // END OF WHILE } // END OF MULTIPART } // END OF STRUTURE return false; } // END OF FUNCTION /* // GET TEXT BODY $dataTxt = get_part($mbox, $msgno, "TEXT/PLAIN"); // GET HTML BODY $dataHtml = get_part($mbox, $msgno, "TEXT/HTML"); if ($dataHtml != "") { $msgBody = $dataHtml; $mailformat = "html"; } else { $msgBody = ereg_replace("\n","
",$dataTxt); $mailformat = "text"; } // To out put the message body to the user simply print $msgBody like this. if ($mailformat == "text") { echo "Messagebody$msgBody"; } else { echo $msgBody; // It contains all HTML HEADER tags so we don't have to make them. } */ function transformHTML($str) { if ((strpos($str,"\n"; if ((strpos($str,""; } else { $str = $makeHeader . $str ."\n"; } } else { $str = "\n". $str; } return $str; } if ($dataHtml != "") { $msgBody = transformHTML($dataHtml); } else { $msgBody = ereg_replace("\n","
",$dataTxt); $msgBody = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i","$1http://$2", $msgBody); $msgBody = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","$1", $msgBody); $msgBody = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","$1",$msgBody); } ?>