Exemple #1
0
 private function _messageToReplyResponse($params, \GO\Email\Model\ComposerMessage $message, $account = false)
 {
     $html = $params['content_type'] == 'html';
     $fullDays = GO::t('full_days');
     $replyTo = $message->reply_to->count() ? $message->reply_to : $message->from;
     $from = $replyTo->getAddress();
     $fromArr = $message->from->getAddress();
     $replyText = sprintf(GO::t('replyHeader', 'email'), $fullDays[date('w', $message->udate)], date(GO::user()->completeDateFormat, $message->udate), date(GO::user()->time_format, $message->udate), $fromArr['personal']);
     //for template loading so we can fill the template tags
     $params['to'] = $from['email'];
     $response = $this->loadTemplate($params);
     if ($html) {
         //saved messages always create temp files
         if ($message instanceof \GO\Email\Model\ImapMessage) {
             $message->createTempFilesForAttachments(true);
         }
         $oldMessage = $message->toOutputArray(true, false, true);
         if (!empty($oldMessage['smime_encrypted'])) {
             $oldMessage['htmlbody'] = '***';
         }
         $response['data']['htmlbody'] .= '<br /><br />' . htmlspecialchars($replyText, ENT_QUOTES, 'UTF-8') . '<br />' . $this->_quoteHtml($oldMessage['htmlbody']);
         // Fix for array_merge function on line below when the $response['data']['inlineAttachments'] do not exist
         if (empty($response['data']['inlineAttachments'])) {
             $response['data']['inlineAttachments'] = array();
         }
         $response['data']['inlineAttachments'] = array_merge($response['data']['inlineAttachments'], $oldMessage['inlineAttachments']);
     } else {
         $oldMessage = $message->toOutputArray(false, false, true);
         if (!empty($oldMessage['smime_encrypted'])) {
             $oldMessage['plainbody'] = '***';
         }
         $response['data']['plainbody'] .= "\n\n" . $replyText . "\n" . $this->_quoteText($oldMessage['plainbody']);
     }
     //will be set at send action
     //		$response['data']['in_reply_to'] = $message->message_id;
     if (stripos($message->subject, 'Re:') === false) {
         $response['data']['subject'] = 'Re: ' . $message->subject;
     } else {
         $response['data']['subject'] = $message->subject;
     }
     if (!isset($params['alias_id'])) {
         $params['alias_id'] = 0;
     }
     $recipients = new \GO\Base\Mail\EmailRecipients();
     $recipients->mergeWith($message->cc)->mergeWith($message->to);
     if (empty($params['keepHeaders'])) {
         $alias = $this->_findAliasFromRecipients($account, $recipients, $params['alias_id']);
         $response['data']['alias_id'] = $alias->id;
         if (!empty($params['replyAll'])) {
             $toList = new \GO\Base\Mail\EmailRecipients();
             $toList->mergeWith($replyTo)->mergeWith($message->to);
             //remove our own alias from the recipients.
             if ($toList->count() > 1) {
                 $toList->removeRecipient($alias->email);
                 $message->cc->removeRecipient($alias->email);
             }
             $response['data']['to'] = (string) $toList;
             $response['data']['cc'] = (string) $message->cc;
         } else {
             $response['data']['to'] = (string) $replyTo;
         }
     }
     //for saving sent items in actionSend
     if ($message instanceof \GO\Email\Model\ImapMessage) {
         $response['sendParams']['reply_uid'] = $message->uid;
         $response['sendParams']['reply_mailbox'] = $params['mailbox'];
         $response['sendParams']['reply_account_id'] = $params['account_id'];
         $response['sendParams']['in_reply_to'] = $message->message_id;
         //We need to link the contact if a manual link was made of the message to the sender.
         //Otherwise the new sent message may not be linked if an autolink tag is not present.
         if (GO::modules()->savemailas) {
             $from = $message->from->getAddress();
             $contact = \GO\Addressbook\Model\Contact::model()->findSingleByEmail($from['email'], \GO\Base\Db\FindParams::newInstance()->permissionLevel(Acl::WRITE_PERMISSION));
             if ($contact) {
                 $linkedMessage = \GO\Savemailas\Model\LinkedEmail::model()->findByImapMessage($message, $contact);
                 if ($linkedMessage) {
                     $tag = $this->_createAutoLinkTag($account, "GO\\Addressbook\\Model\\Contact", $contact->id);
                     if ($html) {
                         if (strpos($response['data']['htmlbody'], $tag) === false) {
                             $response['data']['htmlbody'] .= '<div style="display:none">' . $tag . '</div>';
                         }
                     } else {
                         if (strpos($response['data']['plainbody'], $tag) === false) {
                             $response['data']['plainbody'] .= "\n\n" . $tag . "\n\n";
                         }
                     }
                 }
                 //						$response['data']['link_text']=$contact->name;
                 //						$response['data']['link_value']=$contact->className().':'.$contact->id;
             }
         }
     }
     $this->_keepHeaders($response, $params);
     return $response;
 }