Index: branches/5.2.x/core/kernel/utility/email.php =================================================================== diff -u -N -r15225 -r15230 --- branches/5.2.x/core/kernel/utility/email.php (.../email.php) (revision 15225) +++ branches/5.2.x/core/kernel/utility/email.php (.../email.php) (revision 15230) @@ -1,6 +1,6 @@ sender->SetEncodedHeader($header_name, $header_value); } - // 2. set body + if ( $this->_storeEmailLog() ) { + // 2. prepare log + $log_fields_hash = Array ( + 'From' => $this->fromName . ' (' . $this->fromEmail . ')', + 'To' => $this->toName . ' (' . $this->toEmail . ')', + 'OtherRecipients' => serialize($this->recipients), + 'Subject' => $message_subject, + 'SentOn' => TIMENOW, + 'EventName' => $this->emailEvent->GetDBField('Event'), + 'EventParams' => serialize($this->_getCustomParams()), + ); + + $this->params['email_access_key'] = $this->_generateAccessKey($log_fields_hash); + } + + // 3. set body $html_message_body = $this->_getMessageBody(true); $plain_message_body = $this->_getMessageBody(false); @@ -258,22 +273,48 @@ $this->_changeLanguage(true); - // 3. set log - $log_fields_hash = Array ( - 'fromuser' => $this->fromName . ' (' . $this->fromEmail . ')', - 'addressto' => $this->toName . ' (' . $this->toEmail . ')', - 'subject' => $message_subject, - 'timestamp' => TIMENOW, - 'event' => $this->emailEvent->GetDBField('Event'), - 'EventParams' => serialize($this->_getCustomParams()), - ); + if ( $this->_storeEmailLog() ) { + // 4. set log + $log_fields_hash['HtmlBody'] = $html_message_body; + $log_fields_hash['TextBody'] = $plain_message_body; + $log_fields_hash['AccessKey'] = $this->params['email_access_key']; + $this->sender->setLogData($log_fields_hash); + } - $this->sender->setLogData($log_fields_hash); - return $this->sender->Deliver(null, $immediate_send); } /** + * Determines whatever we should keep e-mail log or not + * + * @return bool + * @access protected + */ + protected function _storeEmailLog() + { + return $this->Application->ConfigValue('EmailLogRotationInterval') != ''; + } + + /** + * Generates access key for accessing e-mail later + * + * @param Array $log_fields_hash + * @return string + * @access protected + */ + protected function _generateAccessKey($log_fields_hash) + { + $ret = ''; + $use_fields = Array ('From', 'To', 'Subject'); + + foreach ($use_fields as $use_field) { + $ret .= $log_fields_hash[$use_field] . ':'; + } + + return md5($ret . microtime(true)); + } + + /** * Processes email sender * * @return void @@ -373,25 +414,24 @@ ); $default_email = $this->Application->ConfigValue('DefaultEmailSender'); + $this->recipients = array_map(Array ($this, '_transformRecipientsIntoPairs'), $this->recipients); foreach ($this->recipients as $recipient_type => $recipients) { // add recipients to email - $pairs = $this->_transformRecipientsIntoPairs($recipients); - - if ( !$pairs ) { + if ( !$recipients ) { continue; } if ( $recipient_type == EmailEvent::RECIPIENT_TYPE_TO ) { - $this->toEmail = $pairs[0]['email'] ? $pairs[0]['email'] : $default_email; - $this->toName = $pairs[0]['name'] ? $pairs[0]['name'] : $this->toEmail; + $this->toEmail = $recipients[0]['email'] ? $recipients[0]['email'] : $default_email; + $this->toName = $recipients[0]['name'] ? $recipients[0]['name'] : $this->toEmail; } $header_name = $header_mapping[$recipient_type]; - foreach ($pairs as $pair) { - $email = $pair['email'] ? $pair['email'] : $default_email; - $name = $pair['name'] ? $pair['name'] : $email; + foreach ($recipients as $recipient) { + $email = $recipient['email'] ? $recipient['email'] : $default_email; + $name = $recipient['name'] ? $recipient['name'] : $email; $this->sender->AddRecipient($header_name, $email, $name); } @@ -683,6 +723,7 @@ * @param bool $is_html * @return string * @access protected + * @todo maybe ConvertToText will strip all