/** * parse headers and set 'date', 'from', 'to', 'cc', 'bcc', 'subject', 'sender' fields * * @param array $_headers * @return void */ public function parseHeaders(array $_headers) { // remove duplicate headers (which can't be set twice in real life) foreach (array('date', 'from', 'to', 'cc', 'bcc', 'subject', 'sender') as $field) { if (isset($_headers[$field]) && is_array($_headers[$field])) { $_headers[$field] = $_headers[$field][0]; } } $this->importance = isset($_headers['importance']) && strtolower($_headers['importance']) === 'high' ? true : false; $this->subject = isset($_headers['subject']) ? Expressomail_Message::convertText($_headers['subject']) : null; $this->reading_conf = array_key_exists('disposition-notification-to', $_headers) && $_headers['disposition-notification-to'] ? true : false; if (array_key_exists('date', $_headers)) { $this->sent = Expressomail_Message::convertDate($_headers['date']); } elseif (array_key_exists('resent-date', $_headers)) { $this->sent = Expressomail_Message::convertDate($_headers['resent-date']); } $punycodeConverter = Expressomail_Controller_Message::getInstance()->getPunycodeConverter(); foreach (array('to', 'cc', 'bcc', 'from', 'sender') as $field) { if (isset($_headers[$field])) { $value = Expressomail_Message::convertAddresses($_headers[$field], $punycodeConverter); switch ($field) { case 'from': $this->from_email = isset($value[0]) && array_key_exists('email', $value[0]) ? $value[0]['email'] : ''; $this->from_name = isset($value[0]) && array_key_exists('name', $value[0]) && !empty($value[0]['name']) ? $value[0]['name'] : $this->from_email; break; case 'sender': $this->sender = isset($value[0]) && array_key_exists('email', $value[0]) ? '<' . $value[0]['email'] . '>' : ''; if (isset($value[0]) && array_key_exists('name', $value[0]) && !empty($value[0]['name'])) { $this->sender = '"' . $value[0]['name'] . '" ' . $this->sender; } break; default: $this->{$field} = $value; } } } }
/** * Compare order of Expressomail_Model_Message acording to Tinebase_Model_Pagination * @param Expressomail_Model_Message $msg1 * @param Expressomail_Model_Message $msg2 * @return int * * @todo Convert int security value in Expressomail_Smime to corresponding string type */ public function compare($msg1, $msg2) { switch ($this->_pagination->sort) { case 'received': // Integer $value1 = $msg1[$this->_pagination->sort]; $value2 = $msg2[$this->_pagination->sort]; case 'sent': // Integer $value1 = isset($value1) ? $value1 : $msg1['header']['date']; $value2 = isset($value2) ? $value2 : $msg2['header']['date']; $value1 = intval(Expressomail_Message::convertDate($value1)->format("U")); $value2 = intval(Expressomail_Message::convertDate($value2)->format("U")); case 'size': // Integer $value1 = isset($value1) ? $value1 : intval($msg1[$this->_pagination->sort]); $value2 = isset($value2) ? $value2 : intval($msg2[$this->_pagination->sort]); return $this->compareIntegers($value1, $value2); case 'folder_id': // Strings $folders = array(); $translate = Tinebase_Translation::getTranslation('Expressomail'); foreach (array($msg1, $msg2) as $msg) { $folder = Expressomail_Backend_Folder::decodeFolderUid($msg[$this->_pagination->sort]); // Optimization! Only create the account object once for every sort operation. $account = array_key_exists($folder['accountId'], $this->_accountMap) ? $this->_accountMap[$folder['accountId']] : ($this->_accountMap[$folder['accountId']] = Expressomail_Controller_Account::getInstance()->get($folder['accountId'])); $aux1 = explode('/', $folder['globalName']); $aux2 = ''; foreach ($aux1 as $value) { $aux2 .= $translate->_($value) . '/'; } $folders[] = $account->name . '/' . substr($aux2, 0, strlen($aux2) - 1); } list($value1, $value2) = $folders; //TODO: Should use a static method implemented on Model_Message or Expressomail_Smime //TODO: Should use a static method implemented on Model_Message or Expressomail_Smime case 'smime': $value1 = isset($value1) ? $value1 : $this->processSmimeValue($msg1['structure']); $value2 = isset($value2) ? $value2 : $this->processSmimeValue($msg2['structure']); case 'flags': // Strings if (!isset($value1)) { sort($msg1['flags']); $value1 = implode(',', $msg1['flags']); } if (!isset($value2)) { sort($msg2['flags']); $value2 = implode(',', $msg2['flags']); } case 'subject': // Strings $value1 = isset($value1) ? $value1 : $msg1['header'][$this->_pagination->sort]; $value2 = isset($value2) ? $value2 : $msg2['header'][$this->_pagination->sort]; case 'id': // Strings $value1 = isset($value1) ? $value1 : $msg1[$this->_pagination->sort]; $value2 = isset($value2) ? $value2 : $msg2[$this->_pagination->sort]; return $this->compareStrings($value1, $value2); case 'sender': case 'to': case 'from_name': case 'from_email': // Strings list($header, $field) = explode('_', $this->_pagination->sort); $field = empty($field) ? 'email' : $field; $address1 = Expressomail_Message::convertAddresses($msg1['header'][$header]); $address2 = Expressomail_Message::convertAddresses($msg2['header'][$header]); return $this->compareStrings(isset($address1[0]) && array_key_exists($field, $address1[0]) ? $address1[0][$field] : '', isset($address2[0]) && array_key_exists($field, $address2[0]) ? $address2[0][$field] : ''); } }