예제 #1
0
 /**
  * This function will be called when the $config['smtp_account_id'] is set in the Group-Office config file.
  * If the account cannot be found then this function will return an exception
  * 
  * @throws \GO\Base\Exception\NotFound
  */
 private function _setAccount()
 {
     $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl();
     $this->_account = \GO\Email\Model\Account::model()->findByPk(\GO::config()->smtp_account_id, $findParams, true);
     if (!$this->_account) {
         throw new \GO\Base\Exception\NotFound('The mailaccount given in the Group-Office config file cannot be found');
     }
     $this->_alias = $this->_account->defaultAlias;
     $this->setFrom($this->_alias->email, $this->_alias->name);
 }
예제 #2
0
 private function emailAccounts()
 {
     $accounts = Account::model()->findByAttributes(array('user_id' => $this->from));
     $success = true;
     foreach ($accounts as $item) {
         $item->user_id = $this->to;
         $success = $item->save() && $success;
     }
     return $success;
 }
예제 #3
0
 public static function aliasesStore(\GO\Email\Controller\AliasController $controller, &$response, \GO\Base\Data\Store $store, $params)
 {
     foreach ($response['results'] as &$alias) {
         $accountModel = \GO\Email\Model\Account::model()->findByPk($alias['account_id']);
         $cert = Model\Certificate::model()->findByPk($alias['account_id']);
         if ($cert && !empty($accountModel) && GO::user()->id === $accountModel->user_id) {
             $alias['has_smime_cert'] = true;
             $alias['always_sign'] = $cert->always_sign;
         }
     }
 }
예제 #4
0
 private function _sieveConnect($accountId)
 {
     $accountModel = \GO\Email\Model\Account::model()->findByPk($accountId);
     if (!empty($accountModel)) {
         $connectResponse = $this->_sieve->connect($accountModel->username, $accountModel->decryptPassword(), $accountModel->host, $accountModel->sieve_port, null, !empty($accountModel->sieve_usetls), array(), true);
     }
     if (empty($connectResponse)) {
         throw new \Exception('Sorry, manage sieve filtering not supported on ' . $accountModel->host . ' using port ' . $accountModel->sieve_port);
     }
     return true;
 }
예제 #5
0
 public static function initListeners()
 {
     $accountController = new \GO\Email\Controller\AccountController();
     $accountController->addListener('load', "GO\\Smime\\EventHandlers", "loadAccount");
     $accountController->addListener('submit', "GO\\Smime\\EventHandlers", "submitAccount");
     $messageController = new \GO\Email\Controller\MessageController();
     $messageController->addListener('beforesend', "GO\\Smime\\EventHandlers", "beforeSend");
     \GO\Email\Model\ImapMessage::model()->addListener('tooutputarray', "GO\\Smime\\EventHandlers", "toOutputArray");
     $aliasController = new \GO\Email\Controller\AliasController();
     $aliasController->addListener('store', "GO\\Smime\\EventHandlers", "aliasesStore");
     \GO\Email\Model\Account::model()->addListener('delete', "GO\\Smime\\EventHandlers", "deleteAccount");
     \GO\Base\Model\User::model()->addListener('delete', "GO\\Smime\\SmimeModule", "deleteUser");
 }
예제 #6
0
 private static function _setMailboxPassword($httpClient, $user, $domain)
 {
     //domain is, for example "intermesh.dev".
     \GO::debug("SERVERCLIENT: Updating password for mailbox " . $user->username . '@' . $domain);
     $username = $user->username;
     if (empty(\GO::config()->serverclient_dont_add_domain_to_imap_username)) {
         $username .= '@' . $domain;
     }
     $url = "postfixadmin/mailbox/submit";
     $response = $httpClient->request($url, array("r" => "postfixadmin/mailbox/setPassword", "username" => $username, "password" => $user->getUnencryptedPassword()));
     \GO::debug($response);
     $result = json_decode($response);
     if (!$result->success) {
         throw new \Exception("Could not set mailbox password on postfixadmin module. " . $result->feedback);
     }
     if (\GO::modules()->isInstalled('email')) {
         $stmt = \GO\Email\Model\Account::model()->findByAttributes(array('username' => $username));
         while ($account = $stmt->fetch()) {
             $account->password = $user->getUnencryptedPassword();
             $account->save();
         }
     }
 }
예제 #7
0
 public function checkEmailAccounts($user, $host, $imapUsername, $password)
 {
     $stmt = \GO\Email\Model\Account::model()->findByAttributes(array('host' => $host, 'username' => $imapUsername));
     $foundAccount = false;
     while ($account = $stmt->fetch()) {
         \GO::debug("IMAPAUTH: Updating account " . $account->id);
         if ($account->user_id == $user->id) {
             $foundAccount = true;
         }
         $account->password = $password;
         $account->store_password = !isset($this->config['store_password']) || !empty($this->config['store_password']) ? 1 : 0;
         $account->store_smtp_password = !empty($account->store_password) && !empty($this->config['smtp_use_login_credentials']) ? 1 : 0;
         if (!empty($this->config['smtp_use_login_credentials'])) {
             \GO::debug("IMAPAUTH: Setting SMTP password too");
             $account->smtp_username = $imapUsername;
             $account->smtp_password = $password;
         }
         if (!$account->save()) {
             throw new \Exception("Could not save e-mail account: " . implode("\n", $account->getValidationErrors()));
         }
     }
     return $foundAccount;
 }
예제 #8
0
 public function actionCreateManyUsers($params)
 {
     if (!\GO::user()->isAdmin()) {
         throw new \Exception("You must be logged in as admin");
     }
     \GO::config()->password_validate = false;
     \GO::session()->closeWriting();
     $amount = 50;
     $prefix = 'user';
     $domain = 'intermesh.dev';
     echo '<pre>';
     for ($i = 1; $i <= $amount; $i++) {
         echo "Creating {$prefix}{$i}\n";
         $user = \GO\Base\Model\User::model()->findSingleByAttribute('username', $prefix . $i);
         if (!$user) {
             $user = new \GO\Base\Model\User();
             $user->username = $prefix . $i;
             $user->email = $prefix . $i . '@' . $domain;
             $user->password = $prefix . $i;
             $user->first_name = $prefix;
             $user->last_name = $i;
             if (!$user->save()) {
                 var_dump($user->getValidationErrors());
                 exit;
             }
             $user->checkDefaultModels();
         }
         if (\GO::modules()->isInstalled('email') && \GO::modules()->isInstalled('postfixadmin')) {
             $domainModel = \GO\Postfixadmin\Model\Domain::model()->findSingleByAttribute('domain', $domain);
             if (!$domainModel) {
                 $domainModel = new \GO\Postfixadmin\Model\Domain();
                 $domainModel->domain = $domain;
                 $domainModel->save();
             }
             $mailboxModel = \GO\Postfixadmin\Model\Mailbox::model()->findSingleByAttributes(array('domain_id' => $domainModel->id, 'username' => $user->email));
             if (!$mailboxModel) {
                 $mailboxModel = new \GO\Postfixadmin\Model\Mailbox();
                 $mailboxModel->domain_id = $domainModel->id;
                 $mailboxModel->username = $user->email;
                 $mailboxModel->password = $prefix . $i;
                 $mailboxModel->name = $user->name;
                 $mailboxModel->save();
             }
             $accountModel = \GO\Email\Model\Account::model()->findSingleByAttributes(array('user_id' => $user->id, 'username' => $user->email));
             if (!$accountModel) {
                 $accountModel = new \GO\Email\Model\Account();
                 $accountModel->user_id = $user->id;
                 $accountModel->host = "localhost";
                 $accountModel->port = 143;
                 $accountModel->name = $user->name;
                 $accountModel->username = $user->email;
                 $accountModel->password = $prefix . $i;
                 $accountModel->smtp_host = 'localhost';
                 $accountModel->smtp_port = 25;
                 $accountModel->save();
                 $accountModel->addAlias($user->email, $user->name);
             }
         }
     }
     echo "Done\n\n";
 }
예제 #9
0
 private function _createMailbox($domainModel, $demo)
 {
     $demoMailbox = \GO\Postfixadmin\Model\Mailbox::model()->findSingleByAttribute('username', $demo->email);
     if (!$demoMailbox) {
         $demoMailbox = new \GO\Postfixadmin\Model\Mailbox();
         $demoMailbox->domain_id = $domainModel->id;
         $demoMailbox->username = $demo->email;
         $demoMailbox->password = '******';
         $demoMailbox->name = $demo->name;
         $demoMailbox->save();
     }
     $accountModel = \GO\Email\Model\Account::model()->findSingleByAttribute('username', $demoMailbox->username);
     if (!$accountModel) {
         $accountModel = new \GO\Email\Model\Account();
         $accountModel->user_id = $demo->id;
         //			$accountModel->checkImapConnectionOnSave=false;
         $accountModel->host = 'localhost';
         $accountModel->port = 143;
         $accountModel->username = $demoMailbox->username;
         $accountModel->password = '******';
         $accountModel->smtp_host = "localhost";
         $accountModel->smtp_port = 25;
         $accountModel->save();
         $accountModel->addAlias($accountModel->username, $demoMailbox->name);
     }
 }
예제 #10
0
파일: Event.php 프로젝트: ajaboa/crmpuan
 /**
  * Will import an attendee from a VObject to a given event. If the attendee
  * already exists it will update it.
  * 
  * @param Event $event
  * @param Sabre\VObject\Property $vattendee
  * @param boolean $isOrganizer
  * @return Participant 
  */
 public function importVObjectAttendee(Event $event, Sabre\VObject\Property $vattendee, $isOrganizer = false)
 {
     $attributes = $this->_vobjectAttendeeToParticipantAttributes($vattendee);
     $attributes['is_organizer'] = $isOrganizer;
     if ($isOrganizer) {
         $attributes['status'] = Participant::STATUS_ACCEPTED;
     }
     $p = Participant::model()->findSingleByAttributes(array('event_id' => $event->id, 'email' => $attributes['email']));
     if (!$p) {
         $p = new Participant();
         $p->is_organizer = $isOrganizer;
         $p->event_id = $event->id;
         if (\GO::modules()->email) {
             $account = \GO\Email\Model\Account::model()->findByEmail($attributes['email']);
             if ($account) {
                 $p->user_id = $account->user_id;
             }
         }
         if (!$p->user_id) {
             $user = \GO\Base\Model\User::model()->findSingleByAttribute('email', $attributes['email']);
             if ($user) {
                 $p->user_id = $user->id;
             }
         }
     } else {
         //the organizer might be added as a participant too. We don't want to
         //import that a second time but we shouldn't update the is_organizer flag if
         //we found an existing participant.
         unset($attributes['is_organizer']);
     }
     $p->setAttributes($attributes);
     $p->save();
     return $p;
 }
예제 #11
0
 protected function actionMoveToInbox($params)
 {
     $accountModel = \GO\Email\Model\Account::model()->findByPk($params['account_id']);
     $imap = $accountModel->openImapConnection('Spam');
     if (!$imap->move(array($params['mail_uid']), 'INBOX')) {
         $imap->disconnect();
         throw new \Exception('Could not move message');
     }
     $response = array('success' => true);
     echo json_encode($response);
 }
예제 #12
0
 protected function actionLoadAddress($params)
 {
     $accountModel = GO\Email\Model\Account::model()->find(GO\Base\Db\FindParams::newInstance()->single()->select('t.*,al.name,al.email')->ignoreAcl()->joinModel(array('model' => 'GO\\Email\\Model\\Alias', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'account_id', 'tableAlias' => 'al'))->criteria(GO\Base\Db\FindCriteria::newInstance()->addCondition('id', $params['id'])->addCondition('default', '1', '=', 'al')));
     $response = array('success' => true, 'data' => array('name' => $accountModel->name, 'email' => $accountModel->email));
     echo json_encode($response);
 }
예제 #13
0
 protected function actionAcceptInvitation($params)
 {
     //todo calendar should be associated with mail account!
     //\GO::user()->id must be replaced with $account->calendar->user_id
     //		$vevent = $this->_getVObjectFromMail($params);
     $account = \GO\Email\Model\Account::model()->findByPk($params['account_id']);
     $message = \GO\Email\Model\ImapMessage::model()->findByUid($account, $params['mailbox'], $params['uid']);
     $vcalendar = $message->getInvitationVcalendar();
     $vevent = $vcalendar->vevent[0];
     //if a recurrence-id if passed then convert it to a unix time stamp.
     //it is an update just for a particular occurrence.
     //todo check if $vevent->{'recurrence-id'} works
     $recurrenceDate = false;
     $recurrence = $vevent->select('recurrence-id');
     //var_dump($recurrence);exit();
     if (count($recurrence)) {
         $firstMatch = array_shift($recurrence);
         $recurrenceDate = $firstMatch->getDateTime()->format('U');
     }
     switch ($vcalendar->method) {
         case 'REPLY':
             return $this->_handleIcalendarReply($vevent, $recurrenceDate, $account);
             break;
         case 'REQUEST':
             //$status = !empty($params['status']) ? $params['status'] : false;
             return $this->_handleIcalendarRequest($vevent, $recurrenceDate, $account);
             break;
         case 'CANCEL':
             return $this->_handleIcalendarCancel($vevent, $recurrenceDate, $account);
             break;
         default:
             throw new \Exception("Unsupported method: " . $vcalendar->method);
     }
 }
예제 #14
0
 public static function deleteUser($user)
 {
     Model\Account::model()->deleteByAttribute('user_id', $user->id);
 }
예제 #15
0
 public function actionVerify($params)
 {
     $response['success'] = true;
     $params['email'] = strtolower($params['email']);
     //if file was already stored somewhere after decryption
     if (!empty($params['cert_id'])) {
         $cert = \GO\Smime\Model\PublicCertificate::model()->findByPk($params['cert_id']);
         $certData = $cert->cert;
     } else {
         //			if (!empty($params['filepath'])) {
         //				$srcFile = new \GO\Base\Fs\File(\GO::config()->tmpdir.$params['filepath']);
         if (!empty($params['account_id'])) {
             $account = \GO\Email\Model\Account::model()->findByPk($params['account_id']);
             $imapMessage = \GO\Email\Model\ImapMessage::model()->findByUid($account, $params['mailbox'], $params['uid']);
             $srcFile = \GO\Base\Fs\File::tempFile();
             if (!$imapMessage->saveToFile($srcFile->path())) {
                 throw new \Exception("Could not fetch message from IMAP server");
             }
             $this->_decryptFile($srcFile, $account);
         }
         //			throw new \Exception($srcFile->path());
         $pubCertFile = \GO\Base\Fs\File::tempFile();
         //Command line:
         //openssl smime -verify -in msg.txt
         $valid = openssl_pkcs7_verify($srcFile->path(), null, $pubCertFile->path(), $this->_getRootCertificates());
         //Adding the PKCS7_NOVERIFY flag was used for testing some messages that could not be verified by openssl but did in Mozilla thunderbird.
         //Error msg: error:21075075:PKCS7 routines:PKCS7_verify:certificate verify error
         //
         //			$valid = openssl_pkcs7_verify($srcFile->path(), PKCS7_NOVERIFY, $pubCertFile->path(), $this->_getRootCertificates());
         //			throw new \Exception($srcFile->path());
         $srcFile->delete();
         if ($valid) {
             if ($pubCertFile->exists()) {
                 $certData = $pubCertFile->getContents();
                 $arr = openssl_x509_parse($certData);
                 $senderEmailStr = !empty($arr['extensions']['subjectAltName']) ? $arr['extensions']['subjectAltName'] : $arr['subject']['emailAddress'];
                 $senderEmails = explode(',', $senderEmailStr);
                 $emails = array();
                 foreach ($senderEmails as $emailRaw) {
                     $email = strtolower(\GO\Base\Util\String::get_email_from_string($emailRaw));
                     if ($email) {
                         $emails[] = $email;
                     }
                 }
                 $pubCertFile->delete();
                 $this->_savePublicCertificate($certData, $emails);
             } else {
                 throw new \Exception('Certificate appears to be valid but could not get certificate from signature. SSL Error: ' . openssl_error_string());
             }
             if (empty($certData)) {
                 throw new \Exception('Certificate appears to be valid but could not get certificate from signature.');
             }
         }
     }
     if (!isset($arr) && isset($certData)) {
         $arr = openssl_x509_parse($certData);
         $senderEmailStr = !empty($arr['extensions']['subjectAltName']) ? $arr['extensions']['subjectAltName'] : $arr['subject']['emailAddress'];
         $emails = array();
         foreach ($senderEmails as $emailRaw) {
             $email = strtolower(\GO\Base\Util\String::get_email_from_string($emailRaw));
             if ($email) {
                 $emails[] = $email;
             }
         }
     } else {
         if (empty($emails)) {
             $emails = array('unknown');
         }
     }
     $response['html'] = '';
     $response['cls'] = '';
     $response['text'] = '';
     if (isset($params['account_id'])) {
         if (!$valid) {
             $response['cls'] = 'smi-invalid';
             $response['text'] = \GO::t('invalidCert', 'smime');
             $response['html'] .= '<h1 class="smi-invalid">' . \GO::t('invalidCert', 'smime') . '</h1>';
             $response['html'] .= '<p>';
             while ($msg = openssl_error_string()) {
                 $response['html'] .= $msg . "<br />\n";
             }
             $response['html'] .= '</p>';
         } else {
             if (!in_array($params['email'], $emails)) {
                 $response['cls'] = 'smi-certemailmismatch';
                 $response['text'] = \GO::t('certEmailMismatch', 'smime');
                 $response['html'] .= $response['short_html'] = '<h1 class="smi-certemailmismatch">' . \GO::t('certEmailMismatch', 'smime') . '</h1>';
             } else {
                 $response['cls'] = 'smi-valid';
                 $response['text'] = \GO::t('validCert', 'smime');
                 $response['html'] .= $response['short_html'] = '<h1 class="smi-valid">' . \GO::t('validCert', 'smime') . '</h1>';
             }
         }
     }
     if (!isset($params['account_id']) || $valid) {
         $response['html'] .= '<table>';
         $response['html'] .= '<tr><td width="100">' . \GO::t('name') . ':</td><td>' . $arr['name'] . '</td></tr>';
         $response['html'] .= '<tr><td width="100">' . \GO::t('email', 'smime') . ':</td><td>' . implode(', ', $emails) . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('hash', 'smime') . ':</td><td>' . $arr['hash'] . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('serial_number', 'smime') . ':</td><td>' . $arr['serialNumber'] . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('version', 'smime') . ':</td><td>' . $arr['version'] . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('issuer', 'smime') . ':</td><td>';
         foreach ($arr['issuer'] as $skey => $svalue) {
             if (is_array($svalue)) {
                 foreach ($svalue as $sv) {
                     $response['html'] .= $skey . ':' . $sv . '; ';
                 }
             } else {
                 $response['html'] .= $skey . ':' . $svalue . '; ';
             }
         }
         $response['html'] .= '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('valid_from', 'smime') . ':</td><td>' . \GO\Base\Util\Date::get_timestamp($arr['validFrom_time_t']) . '</td></tr>';
         $response['html'] .= '<tr><td>' . \GO::t('valid_to', 'smime') . ':</td><td>' . \GO\Base\Util\Date::get_timestamp($arr['validTo_time_t']) . '</td></tr>';
         $response['html'] .= '</table>';
     }
     return $response;
 }
예제 #16
0
 protected function actionBatchSend($params)
 {
     $this->requireCli();
     $this->_sentEmails = array();
     \GO::$disableModelCache = true;
     $mailing = \GO\Addressbook\Model\SentMailing::model()->findByPk($params['mailing_id']);
     if (!$mailing) {
         throw new \Exception("Mailing not found!\n");
     }
     \GO::session()->runAs($mailing->user_id);
     echo 'Status: ' . $mailing->status . "\n";
     if (empty($mailing->status)) {
         echo "Starting mailing at " . \GO\Base\Util\Date::get_timestamp(time()) . "\n";
         $mailing->reset();
     } elseif (!empty($params['restart'])) {
         echo "Restarting mailing at " . \GO\Base\Util\Date::get_timestamp(time()) . "\n";
         $mailing->reset();
     } elseif ($mailing->status == \GO\Addressbook\Model\SentMailing::STATUS_PAUSED) {
         echo "Resuming mailing at " . \GO\Base\Util\Date::get_timestamp(time()) . "\n";
         $mailing->status = \GO\Addressbook\Model\SentMailing::STATUS_RUNNING;
         $mailing->save();
     }
     $htmlToText = new \GO\Base\Util\Html2Text();
     //$addresslist = \GO\Addressbook\Model\Addresslist::model()->findByPk($mailing->addresslist_id);
     $mimeData = file_get_contents(\GO::config()->file_storage_path . $mailing->message_path);
     $message = \GO\Base\Mail\Message::newInstance()->loadMimeMessage($mimeData);
     $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addRawCondition('t.id', 'a.account_id');
     $findParams = \GO\Base\Db\FindParams::newInstance()->single()->join(\GO\Email\Model\Alias::model()->tableName(), $joinCriteria, 'a')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('id', $mailing->alias_id, '=', 'a'));
     if ($mailing->campaign_id > 0 && \GO::modules()->isAvailable('campaigns')) {
         $account = new \GO\Email\Model\Account();
         $account->username = \GO::config()->campaigns_imap_user;
         $account->password = \GO::config()->campaigns_imap_pass;
         $account->host = \GO::config()->campaigns_imap_server;
         $account->port = \GO::config()->campaigns_imap_port;
         $account->smtp_username = \GO::config()->campaigns_smtp_user;
         $account->smtp_password = \GO::config()->campaigns_smtp_pass;
         $account->smtp_host = \GO::config()->campaigns_smtp_server;
         $account->smtp_port = \GO::config()->campaigns_smtp_port;
         $message->setFrom(\GO::config()->campaigns_from);
     } else {
         $account = \GO\Email\Model\Account::model()->find($findParams);
         if (!$account->store_password && !empty($mailing->temp_pass)) {
             $account->smtp_password = $mailing->temp_pass;
         }
     }
     $mailer = \GO\Base\Mail\Mailer::newGoInstance(\GO\Email\Transport::newGoInstance($account));
     echo "Will send emails from " . $account->username . ".\n";
     if (empty(\GO::config()->mailing_messages_per_minute)) {
         \GO::config()->mailing_messages_per_minute = 30;
     }
     //Rate limit to 100 emails per-minute
     $mailer->registerPlugin(new \Swift_Plugins_ThrottlerPlugin(\GO::config()->mailing_messages_per_minute, \Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE));
     // Use AntiFlood to re-connect after 50 emails
     $mailer->registerPlugin(new \Swift_Plugins_AntiFloodPlugin(\GO::config()->mailing_messages_per_minute));
     echo 'Sending a maximum of ' . \GO::config()->mailing_messages_per_minute . ' messages per minute' . "\n";
     $failedRecipients = array();
     $bodyWithTags = $message->getBody();
     foreach ($mailing->contacts as $contact) {
         $sentMailingContactModel = \GO\Addressbook\Model\SentMailingContact::model()->findSingleByAttributes(array('sent_mailing_id' => $mailing->id, 'contact_id' => $contact->id));
         if (!$sentMailingContactModel->sent) {
             $errors = 1;
             $unsubscribeHref = \GO::url('addressbook/sentMailing/unsubscribe', array('addresslist_id' => $mailing->addresslist_id, 'contact_id' => $contact->id, 'token' => md5($contact->ctime . $contact->addressbook_id . $contact->firstEmail)), false, true);
             $body = str_replace('%unsubscribe_href%', $unsubscribeHref, $bodyWithTags);
             //curly brackets don't work inside links in browser wysiwyg editors.
             $templateModel = \GO\Addressbook\Model\Template::model();
             $templateModel->htmlSpecialChars = false;
             $body = $templateModel->replaceCustomTags($body, array('unsubscribe_link' => '<a href="' . $unsubscribeHref . '" target="_blank">' . \GO::t("unsubscription", "addressbook") . '</a>'), true);
             $templateModel->htmlSpecialChars = true;
             try {
                 if (!$contact->email_allowed) {
                     echo "Skipping contact " . $contact->firstEmail . " because newsletter sending is disabled in the addresslists tab.\n\n";
                 } elseif (empty($contact->firstEmail)) {
                     echo "Skipping contact " . $contact->name . " no e-mail address was set.\n\n";
                 } else {
                     $body = \GO\Addressbook\Model\Template::model()->replaceContactTags($body, $contact);
                     $message->setTo($contact->firstEmail, $contact->name);
                     $message->setBody($body);
                     $plainTextPart = $message->findPlainTextBody();
                     if ($plainTextPart) {
                         $htmlToText->set_html($body);
                         $plainTextPart->setBody($htmlToText->get_text());
                     }
                     // Check mail limit
                     $nSentMails = \GO::config()->get_setting('campaigns_number_sent_mails', 0);
                     if ($mailing->campaign_id > 0 && $nSentMails >= \GO::config()->campaigns_max_mails_per_period) {
                         $this->_pauseMailing($mailing->id);
                         echo "Error for " . $contact->firstEmail . ": \n";
                         echo str_replace('%maxMails', \GO::config()->campaigns_max_mails_per_period, \GO::t('sentMailLimitReached', 'campaigns'));
                         exit;
                     }
                     $this->_sendmail($message, $contact, $mailer, $mailing);
                     \GO::config()->save_setting('campaigns_number_sent_mails', $nSentMails + 1, 0);
                     $errors = 0;
                 }
             } catch (\Exception $e) {
                 echo "Error for " . $contact->firstEmail . ": " . $e->getMessage() . "\n";
             }
             if ($errors) {
                 $mailing->errors++;
                 $mailing->save();
             }
         }
     }
     foreach ($mailing->companies as $company) {
         $sentMailingCompanyModel = \GO\Addressbook\Model\SentMailingCompany::model()->findSingleByAttributes(array('sent_mailing_id' => $mailing->id, 'company_id' => $company->id));
         if (!$sentMailingCompanyModel->sent) {
             $errors = 1;
             $unsubscribeHref = \GO::url('addressbook/sentMailing/unsubscribe', array('addresslist_id' => $mailing->addresslist_id, 'company_id' => $company->id, 'token' => md5($company->ctime . $company->addressbook_id . $company->email)), true, true);
             $body = str_replace('%unsubscribe_href%', $unsubscribeHref, $bodyWithTags);
             //curly brackets don't work inside links in browser wysiwyg editors.
             $body = \GO\Addressbook\Model\Template::model()->replaceCustomTags($body, array('unsubscribe_link' => '<a href="' . $unsubscribeHref . '">' . \GO::t("unsubscription", "addressbook") . '</a>'), true);
             try {
                 if (!$company->email_allowed) {
                     echo "Skipping company " . $company->email . " because newsletter sending is disabled in the addresslists tab.\n\n";
                 } elseif (empty($company->email)) {
                     echo "Skipping company " . $company->name . " no e-mail address was set.\n\n";
                 } else {
                     $body = \GO\Addressbook\Model\Template::model()->replaceModelTags($body, $company);
                     $message->setTo($company->email, $company->name);
                     $message->setBody($body);
                     $plainTextPart = $message->findPlainTextBody();
                     if ($plainTextPart) {
                         $htmlToText->set_html($body);
                         $plainTextPart->setBody($htmlToText->get_text());
                     }
                     // Check mail limit
                     $nSentMails = \GO::config()->get_setting('campaigns_number_sent_mails', 0);
                     if ($mailing->campaign_id > 0 && $nSentMails >= \GO::config()->campaigns_max_mails_per_period) {
                         $this->_pauseMailing($mailing->id);
                         echo "Error for " . $contact->firstEmail . ": \n";
                         echo str_replace('%maxMails', \GO::config()->campaigns_max_mails_per_period, \GO::t('sentMailLimitReached', 'campaigns'));
                         exit;
                     }
                     $this->_sendmail($message, $company, $mailer, $mailing);
                     \GO::config()->save_setting('campaigns_number_sent_mails', $nSentMails + 1, 0);
                     $errors = 0;
                 }
             } catch (\Exception $e) {
                 echo "Error for " . $company->email . ": " . $e->getMessage() . "\n";
             }
             if ($errors) {
                 $mailing->errors++;
                 $mailing->save();
             }
         }
     }
     $mailing->status = \GO\Addressbook\Model\SentMailing::STATUS_FINISHED;
     // Unset the temp_pass
     if (!empty($mailing->temp_pass)) {
         $mailing->temp_pass = "";
     }
     $mailing->save();
     echo "Mailing finished at " . \GO\Base\Util\Date::get_timestamp(time()) . "\n";
 }
예제 #17
0
 protected function actionSubmit($params)
 {
     $response = array('success' => true, 'id' => $params['accountId']);
     $mailboxPath = $params['mailboxPath'];
     $accountId = $params['accountId'];
     $checkUnseen = !empty($params['checkUnseen']);
     $accountModel = \GO\Email\Model\Account::model()->findByPk($accountId);
     $checkUnseenMailboxArray = explode(',', $accountModel->check_mailboxes);
     if ($checkUnseen && !in_array($mailboxPath, $checkUnseenMailboxArray)) {
         $checkUnseenMailboxArray[] = $mailboxPath;
         $accountModel->check_mailboxes = implode(',', $checkUnseenMailboxArray);
     } elseif (!$checkUnseen && in_array($mailboxPath, $checkUnseenMailboxArray)) {
         $arr = array();
         foreach ($checkUnseenMailboxArray as $k => $v) {
             if ($v != $mailboxPath) {
                 $arr[] = $v;
             }
         }
         $accountModel->check_mailboxes = implode(',', $arr);
     }
     $accountModel->save();
     return $response;
 }
예제 #18
0
 protected function actionHandleAttachedVCard($params)
 {
     $account = \GO\Email\Model\Account::model()->findByPk($params['account_id']);
     $imap = $account->openImapConnection($params['mailbox']);
     $tmpFile = \GO\Base\Fs\File::tempFile($params['filename']);
     $imap->save_to_file($params['uid'], $tmpFile->path(), $params['number'], $params['encoding']);
     if (!isset($params['importVCard'])) {
         \GO\Base\Util\Http::outputDownloadHeaders($tmpFile);
         echo $tmpFile->getContents();
         return;
     }
     $options = \Sabre\VObject\Reader::OPTION_FORGIVING + \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES;
     $card = \Sabre\VObject\Reader::read($tmpFile->getContents(), $options);
     $contact = new \GO\Addressbook\Model\Contact();
     $contact->importVObject($card, array(), false);
     //format utf-8 attributes
     foreach ($contact->getAttributes('raw') as $key => $value) {
         try {
             $contact->{$key} = utf8_decode($value);
         } catch (\Exception $e) {
         }
     }
     //GO\Base\Util\Http::outputDownloadHeaders($tmpFile);
     return array('success' => true, 'contacts' => array($contact->getAttributes()));
     //echo $tmpFile->getContents();
 }
예제 #19
0
<?php

$accountsStmt = \GO\Email\Model\Account::model()->find();
while ($accountModel = $accountsStmt->fetch()) {
    if (!empty($accountModel->smtp_password)) {
        try {
            // Trick the model this field has been modified, to circumvent
            $pwBuffer = $accountModel->smtp_password;
            $accountModel->smtp_password = "";
            $accountModel->smtp_password = $pwBuffer;
            $accountModel->save();
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
    }
}
예제 #20
0
 /**
  * Build the tree for the portlet folders
  * 
  * @param array $params
  * @return array $response
  */
 public function actionPortletTree($params)
 {
     \GO::session()->closeWriting();
     $response = array();
     if ($params['node'] == 'root') {
         $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*')->joinModel(array('model' => 'GO\\Email\\Model\\AccountSort', 'foreignField' => 'account_id', 'localField' => 'id', 'type' => 'LEFT', 'tableAlias' => 's', 'criteria' => \GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', \GO::user()->id, '=', 's')))->ignoreAdminGroup()->order('order', 'DESC');
         $stmt = \GO\Email\Model\Account::model()->find($findParams);
         // Loop throught the found accounts and build the accounts root node.
         while ($account = $stmt->fetch()) {
             $alias = $account->getDefaultAlias();
             if ($alias) {
                 $nodeId = 'account_' . $account->id;
                 $node = array('text' => $alias->email, 'name' => $alias->email, 'id' => $nodeId, 'isAccount' => true, 'hasError' => false, 'iconCls' => 'folder-account', 'expanded' => $this->_isExpanded($nodeId), 'noselect' => false, 'account_id' => $account->id, 'mailbox' => '', 'noinferiors' => false);
                 // Try to find the children
                 try {
                     $account->openImapConnection();
                     if ($node['expanded']) {
                         $node['children'] = $this->_getMailboxTreeNodes($account->getRootMailboxes(true));
                     }
                 } catch (\Exception $e) {
                     $this->_checkImapConnectException($e, $node);
                 }
                 $response[] = $node;
             }
         }
     } else {
         $parts = explode('_', $params['node']);
         $type = array_shift($parts);
         $accountId = array_shift($parts);
         $mailboxName = implode('_', $parts);
         $account = \GO\Email\Model\Account::model()->findByPk($accountId);
         if ($type == "account") {
             $response = $this->_getMailboxTreeNodes($account->getRootMailboxes(true));
         } else {
             $mailbox = new \GO\Email\Model\ImapMailbox($account, array('name' => $mailboxName));
             $response = $this->_getMailboxTreeNodes($mailbox->getChildren());
         }
     }
     return $response;
 }