コード例 #1
0
ファイル: SearchController.php プロジェクト: ajaboa/crmpuan
 private function _formatContact(&$response, $contact)
 {
     $record['name'] = $contact->name;
     $record['contact_id'] = $contact->id;
     $record['user_id'] = $contact->go_user_id;
     if ($contact->email != "") {
         $l = new \GO\Base\Mail\EmailRecipients();
         $l->addRecipient($contact->email, $record['name']);
         $record['info'] = htmlspecialchars((string) $l . ' (' . sprintf(\GO::t('contactFromAddressbook', 'addressbook'), $contact->addressbook->name) . ')', ENT_COMPAT, 'UTF-8');
         if (!empty($contact->department)) {
             $record['info'] .= ' (' . htmlspecialchars($contact->department, ENT_COMPAT, 'UTF-8') . ')';
         }
         $record['full_email'] = htmlspecialchars((string) $l, ENT_COMPAT, 'UTF-8');
         $response['results'][] = $record;
     }
     if ($contact->email2 != "") {
         $l = new \GO\Base\Mail\EmailRecipients();
         $l->addRecipient($contact->email2, $record['name']);
         $record['info'] = htmlspecialchars((string) $l . ' (' . sprintf(\GO::t('contactFromAddressbook', 'addressbook'), $contact->addressbook->name) . ')', ENT_COMPAT, 'UTF-8');
         if (!empty($contact->department)) {
             $record['info'] .= ' (' . htmlspecialchars($contact->department, ENT_COMPAT, 'UTF-8') . ')';
         }
         $record['full_email'] = htmlspecialchars((string) $l, ENT_COMPAT, 'UTF-8');
         $response['results'][] = $record;
     }
     if ($contact->email3 != "") {
         $l = new \GO\Base\Mail\EmailRecipients();
         $l->addRecipient($contact->email3, $record['name']);
         $record['info'] = htmlspecialchars((string) $l . ' (' . sprintf(\GO::t('contactFromAddressbook', 'addressbook'), $contact->addressbook->name) . ')', ENT_COMPAT, 'UTF-8');
         if (!empty($contact->department)) {
             $record['info'] .= ' (' . htmlspecialchars($contact->department, ENT_COMPAT, 'UTF-8') . ')';
         }
         $record['full_email'] = htmlspecialchars((string) $l, ENT_COMPAT, 'UTF-8');
         $response['results'][] = $record;
     }
 }
コード例 #2
0
ファイル: MessageController.php プロジェクト: ajaboa/crmpuan
 /**
  *
  * @param Account $account
  * @param \GO\Base\Mail\EmailRecipients $recipients
  * @return \GO\Email\Model\Alias|false 
  */
 private function _findAliasFromRecipients($account, \GO\Base\Mail\EmailRecipients $recipients, $alias_id = 0, $allAvailableAliases = false)
 {
     $alias = false;
     $defaultAlias = false;
     $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*')->joinModel(array('model' => 'GO\\Email\\Model\\AccountSort', 'foreignField' => 'account_id', 'localField' => 'account_id', 'type' => 'LEFT'))->permissionLevel(Acl::CREATE_PERMISSION)->ignoreAdminGroup()->order('order', 'DESC');
     //find the right sender alias
     $stmt = !$allAvailableAliases && $account && $account->checkPermissionLevel(Acl::CREATE_PERMISSION) ? $account->aliases : \GO\Email\Model\Alias::model()->find($findParams);
     while ($possibleAlias = $stmt->fetch()) {
         if (!$defaultAlias) {
             $defaultAlias = $possibleAlias;
         }
         if ($recipients->hasRecipient($possibleAlias->email)) {
             $alias = $possibleAlias;
             break;
         }
     }
     if (!$alias) {
         $alias = empty($alias_id) ? $defaultAlias : \GO\Email\Model\Alias::model()->findByPk($alias_id);
     }
     return $alias;
 }
コード例 #3
0
ファイル: Message.php プロジェクト: ajaboa/crmpuan
    /**
     * handleEmailFormInput
     * 
     * This method can be used in Models and Controllers. It puts the email body
     * and inline (image) attachments from the client in the message, which can
     * then be used for storage in the database or sending emails.
     * 
     * @param Array $params Must contain elements: body (string) and
     * 
     * inlineAttachments (string).
     */
    public function handleEmailFormInput($params)
    {
        if (!empty($params['subject'])) {
            $this->setSubject($params['subject']);
        }
        if (!empty($params['to'])) {
            $to = new EmailRecipients($params['to']);
            foreach ($to->getAddresses() as $email => $personal) {
                $this->addTo($email, $personal);
            }
        }
        if (!empty($params['cc'])) {
            $cc = new EmailRecipients($params['cc']);
            foreach ($cc->getAddresses() as $email => $personal) {
                $this->addCc($email, $personal);
            }
        }
        if (!empty($params['bcc'])) {
            $bcc = new EmailRecipients($params['bcc']);
            foreach ($bcc->getAddresses() as $email => $personal) {
                $this->addBcc($email, $personal);
            }
        }
        if (isset($params['alias_id'])) {
            $alias = \GO\Email\Model\Alias::model()->findByPk($params['alias_id']);
            $this->setFrom($alias->email, $alias->name);
            if (!empty($params['notification'])) {
                $this->setReadReceiptTo(array($alias->email => $alias->name));
            }
        }
        if (isset($params['priority'])) {
            $this->setPriority($params['priority']);
        }
        if (isset($params['in_reply_to'])) {
            $headers = $this->getHeaders();
            $headers->addTextHeader('In-Reply-To', $params['in_reply_to']);
            $headers->addTextHeader('References', $params['in_reply_to']);
        }
        if ($params['content_type'] == 'html') {
            $params['htmlbody'] = $this->_embedPastedImages($params['htmlbody']);
            //inlineAttachments is an array(array('url'=>'',tmp_file=>'relative/path/');
            if (!empty($params['inlineAttachments'])) {
                $inlineAttachments = json_decode($params['inlineAttachments']);
                /* inline attachments must of course exist as a file, and also be used in
                 * the message body
                 */
                if (count($inlineAttachments)) {
                    foreach ($inlineAttachments as $ia) {
                        //$tmpFile = new \GO\Base\Fs\File(\GO::config()->tmpdir.$ia['tmp_file']);
                        if (empty($ia->tmp_file)) {
                            continue;
                            // Continue to the next inline attachment for processing.
                            //throw new Exception("No temp file for inline attachment ".$ia->name);
                        }
                        $path = empty($ia->from_file_storage) ? \GO::config()->tmpdir . $ia->tmp_file : \GO::config()->file_storage_path . $ia->tmp_file;
                        $tmpFile = new \GO\Base\Fs\File($path);
                        if ($tmpFile->exists()) {
                            //Different browsers reformat URL's to absolute or relative. So a pattern match on the filename.
                            //$filename = rawurlencode($tmpFile->name());
                            $result = preg_match('/="([^"]*' . preg_quote($ia->token) . '[^"]*)"/', $params['htmlbody'], $matches);
                            if ($result) {
                                $img = \Swift_EmbeddedFile::fromPath($tmpFile->path());
                                $img->setContentType($tmpFile->mimeType());
                                $contentId = $this->embed($img);
                                //$tmpFile->delete();
                                $params['htmlbody'] = \GO\Base\Util\String::replaceOnce($matches[1], $contentId, $params['htmlbody']);
                            } else {
                                //this may happen when an inline image was attached but deleted in the editor afterwards.
                                //
                                //throw new \Exception("Error: inline attachment could not be found in text: ".$ia->token);
                            }
                        } else {
                            throw new \Exception("Error: inline attachment missing on server: " . $tmpFile->stripTempPath() . ".<br /><br />The temporary files folder is cleared on each login. Did you relogin?");
                        }
                    }
                }
            }
            $params['htmlbody'] = $this->_fixRelativeUrls($params['htmlbody']);
            $htmlTop = '<html>
<head>
<style type="text/css">
body,p,td,div,span{
	' . \GO::config()->html_editor_font . '
};
body p{
	margin:0px;
}
</style>
</head>
<body>';
            $htmlBottom = '</body></html>';
            $this->setHtmlAlternateBody($htmlTop . $params['htmlbody'] . $htmlBottom);
        } else {
            $this->setBody($params['plainbody'], 'text/plain');
        }
        if (!empty($params['attachments'])) {
            $attachments = json_decode($params['attachments']);
            foreach ($attachments as $att) {
                $path = empty($att->from_file_storage) ? \GO::config()->tmpdir . $att->tmp_file : \GO::config()->file_storage_path . $att->tmp_file;
                $tmpFile = new \GO\Base\Fs\File($path);
                if ($tmpFile->exists()) {
                    $file = \Swift_Attachment::fromPath($tmpFile->path());
                    $file->setContentType($tmpFile->mimeType());
                    $file->setFilename($att->fileName);
                    $this->attach($file);
                    //$tmpFile->delete();
                } else {
                    throw new \Exception("Error: attachment missing on server: " . $tmpFile->stripTempPath() . ".<br /><br />The temporary files folder is cleared on each login. Did you relogin?");
                }
            }
        }
    }