diff --git a/mail/inc/class.mail_bo.inc.php b/mail/inc/class.mail_bo.inc.php index e3121a1adc..a5a034bd6d 100644 --- a/mail/inc/class.mail_bo.inc.php +++ b/mail/inc/class.mail_bo.inc.php @@ -2625,6 +2625,47 @@ class mail_bo return true; } + /** + * get flags for a Message + * + * @param mixed string _messageUID array of id to retrieve the flags for + * + * @return null/array flags + */ + function getFlags ($_messageUID) { + $flags = $this->icServer->getFlags($_messageUID, true); + if (PEAR::isError($flags)) { + error_log(__METHOD__.__LINE__.'Failed to retrieve Flags for Messages with UID(s)'.array2string($_messageUID).' Server returned:'.$flags->message); + return null; + } + return $flags; + } + + /** + * get and parse the flags response for the Notifyflag for a Message + * + * @param string _messageUID array of id to retrieve the flags for + * @param array flags - to avoid additional server call + * + * @return null/boolean + */ + function getNotifyFlags ($_messageUID, $flags=null) + { + if($flags===null) $flags = $this->icServer->getFlags($_messageUID, true); + if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags)); + if (PEAR::isError($flags)) + { + return null; + } + if ( stripos( array2string($flags),'MDNSent')!==false) + return true; + + if ( stripos( array2string($flags),'MDNnotSent')!==false) + return false; + + return null; + } + /** * flag a Message * @@ -3789,12 +3830,72 @@ class mail_bo } /** - * getMessageRawHeader + * getMessageEnvelope * get parsed headers from message * @param string/int $_uid the messageuid, * @param string/int $_partID='' , the partID, may be omitted * @param boolean $decode flag to do the decoding on the fly - * @return string the message header + * @return array the message header + */ + function getMessageEnvelope($_uid, $_partID = '',$decode=false) + { + if($_partID == '') { + if( PEAR::isError($envelope = $this->icServer->getEnvelope('', $_uid, true)) ) { + return false; + } + //if ($decode) _debug_array($envelope[0]); + return ($decode ? self::decode_header($envelope[0],true): $envelope[0]); + } else { + if( PEAR::isError($headers = $this->icServer->getParsedHeaders($_uid, true, $_partID, true)) ) { + return false; + } + //_debug_array($headers); + $newData = array( + 'DATE' => $headers['DATE'], + 'SUBJECT' => ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']), + 'MESSAGE_ID' => $headers['MESSAGE-ID'] + ); + //_debug_array($newData); + $recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY_TO'); + foreach($recepientList as $recepientType) { + if(isset($headers[$recepientType])) { + if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType],true); + $addresses = imap_rfc822_parse_adrlist($headers[$recepientType], ''); + foreach($addresses as $singleAddress) { + $addressData = array( + 'PERSONAL_NAME' => $singleAddress->personal ? $singleAddress->personal : 'NIL', + 'AT_DOMAIN_LIST' => $singleAddress->adl ? $singleAddress->adl : 'NIL', + 'MAILBOX_NAME' => $singleAddress->mailbox ? $singleAddress->mailbox : 'NIL', + 'HOST_NAME' => $singleAddress->host ? $singleAddress->host : 'NIL', + 'EMAIL' => $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox, + ); + if($addressData['PERSONAL_NAME'] != 'NIL') { + $addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal); + } else { + $addressData['RFC822_EMAIL'] = 'NIL'; + } + $newData[$recepientType][] = $addressData; + } + } else { + if($recepientType == 'SENDER' || $recepientType == 'REPLY_TO') { + $newData[$recepientType] = $newData['FROM']; + } else { + $newData[$recepientType] = array(); + } + } + } + //if ($decode) _debug_array($newData); + return $newData; + } + } + + /** + * getMessageHeader + * get parsed headers from message + * @param string/int $_uid the messageuid, + * @param string/int $_partID='' , the partID, may be omitted + * @param boolean $decode flag to do the decoding on the fly + * @return array the message header */ function getMessageHeader($_uid, $_partID = '',$decode=false) { diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 196bd7ed5e..2d868d1d20 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -26,6 +26,7 @@ class mail_ui ( 'index' => True, 'displayHeader' => True, + 'displayMessage' => True, 'saveMessage' => True, 'vfsSaveMessage' => True, 'loadEmailBody' => True, @@ -1087,7 +1088,7 @@ unset($query['actions']); $rows = $this->header2gridelements($sortResult['header'],$cols, $_folderName, $folderType,$previewMessage); //error_log(__METHOD__.__LINE__.array2string($rows)); $endtime = microtime(true) - $starttime; - error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Start:'.$query['start'].' NumRows:'.$query['num_rows'].' Took:'.$endtime); + //error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Start:'.$query['start'].' NumRows:'.$query['num_rows'].' Took:'.$endtime); return $rowsFetched['messages']; } @@ -1475,6 +1476,73 @@ unset($query['actions']); } + /** + * display messages + * + * all params are passed as GET Parameters + */ + function displayMessage() + { + if(isset($_GET['id'])) $rowID = $_GET['id']; + if(isset($_GET['part'])) $partID = $_GET['part']; + + $hA = self::splitRowID($rowID); + $uid = $hA['msgUID']; + $mailbox = $hA['folder']; + + //$transformdate =& CreateObject('felamimail.transformdate'); + //$htmlFilter =& CreateObject('felamimail.htmlfilter'); + //$uiWidgets =& CreateObject('felamimail.uiwidgets'); + $this->mail_bo->reopen($mailbox); + // retrieve the flags of the message, before touching it. + $headers = $this->mail_bo->getMessageHeader($uid, $partID); + if (PEAR::isError($headers)) { + $error_msg[] = lang("ERROR: Message could not be displayed."); + $error_msg[] = lang("In Mailbox: %1, with ID: %2, and PartID: %3",$mailbox,$uid,$partID); + $error_msg[] = $headers->message; + $error_msg[] = array2string($headers->backtrace[0]); + } + if (!empty($uid)) $flags = $this->mail_bo->getFlags($uid); + $envelope = $this->mail_bo->getMessageEnvelope($uid, $partID,true); + $rawheaders = $this->mail_bo->getMessageRawHeader($uid, $partID); + $fetchEmbeddedImages = false; + if ($htmlOptions !='always_display') $fetchEmbeddedImages = true; + $attachments = $this->mail_bo->getMessageAttachments($uid, $partID, '',$fetchEmbeddedImages); +//_debug_array($headers); + $webserverURL = $GLOBALS['egw_info']['server']['webserver_url']; + + $nonDisplayAbleCharacters = array('[\016]','[\017]', + '[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]', + '[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]'); + + #print "
";print_r($rawheaders);print"
";exit; + $mailBody = $this->get_load_email_data($uid, $partID, $mailbox,false); + $this->mail_bo->closeConnection(); + $etpl = new etemplate_new('mail.display'); + + // Set cell attributes directly +/* + $etpl->set_cell_attribute('nm[foldertree]','actions', array( + 'drop_move_mail' => array( + 'type' => 'drop', + 'acceptedTypes' => 'mail', + 'icon' => 'move', + 'caption' => 'Move to', + 'onExecute' => 'javaScript:app.mail.mail_move' + ), + )); +*/ + $subject = mail_bo::htmlspecialchars($this->mail_bo->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT']),false), + mail_bo::$displayCharset); + if (empty($subject)) $subject = lang('no subject'); + +$content['msg'] = (is_array($error_msg)?implode("
",$error_msg):$error_msg); +$content['mail_displaysubject'] = $subject; +$content['mail_displaybody'] = $mailBody; +$readonlys = $preserv = $content; + echo $etpl->exec('mail.mail_ui.displayMessage',$content,$sel_options,$readonlys,$preserv,2); + } + /** * save messages on disk or filemanager, or display it in popup * @@ -1559,7 +1627,7 @@ unset($query['actions']); } - function get_load_email_data($uid, $partID, $mailbox) + function get_load_email_data($uid, $partID, $mailbox,$fullHeader=true) { // seems to be needed, as if we open a mail from notification popup that is // located in a different folder, we experience: could not parse message @@ -1595,22 +1663,22 @@ $this->partID = $partID; // Compose the content of the frame $frameHtml = - $this->get_email_header($this->mail_bo->getStyles($bodyParts)). - $this->showBody($this->getdisplayableBody($bodyParts), false); + $this->get_email_header($this->mail_bo->getStyles($bodyParts),$fullHeader). + $this->showBody($this->getdisplayableBody($bodyParts), false,$fullHeader); //IE10 eats away linebreaks preceeded by a whitespace in PRE sections $frameHtml = str_replace(" \r\n","\r\n",$frameHtml); return $frameHtml; } - static function get_email_header($additionalStyle='') + static function get_email_header($additionalStyle='',$fullHeader=true) { //error_log(__METHOD__.__LINE__.$additionalStyle); - return ' + $header = ($fullHeader?' - + ':'').'