/** * @param \MailSo\Mime\Message $oMessage */ public function FilterBuildMessage(&$oMessage) { if ($oMessage instanceof \MailSo\Mime\Message) { $sIP = $this->Manager()->Actions()->Http()->GetClientIp(!!$this->Config()->Get('plugin', 'check_proxy', false)); $oMessage->SetCustomHeader(\MailSo\Mime\Enumerations\Header::X_ORIGINATING_IP, $this->Manager()->Actions()->Http()->IsLocalhost($sIP) ? '127.0.0.1' : $sIP); } }
/** * @param string $sFrom * @param string $sTo * @param string $sSubject * @param string $sCc Default value is empty string. * @param string $sBcc Default value is empty string. * @param string $sMessageID Default value is empty string. * @param string $sReferences Default value is empty string. * * @return \MailSo\Mime\Message */ private function _buildMail($sFrom, $sTo, $sSubject, $sCc = '', $sBcc = '', $sMessageID = '', $sReferences = '') { $oMessage = \MailSo\Mime\Message::NewInstance(); if (empty($sMessageID)) { $oMessage->RegenerateMessageId(); } else { $oMessage->SetMessageId($sMessageID); } if (!empty($sReferences)) { $oMessage->SetReferences($sReferences); } $sXMailer = \CApi::GetConf('webmail.xmailer-value', ''); if (0 < strlen($sXMailer)) { $oMessage->SetXMailer($sXMailer); } $oMessage->SetFrom(\MailSo\Mime\Email::NewInstance($sFrom))->SetSubject($sSubject); $oToEmails = \MailSo\Mime\EmailCollection::NewInstance($sTo); if ($oToEmails && $oToEmails->Count()) { $oMessage->SetTo($oToEmails); } $oCcEmails = \MailSo\Mime\EmailCollection::NewInstance($sCc); if ($oCcEmails && $oCcEmails->Count()) { $oMessage->SetCc($oCcEmails); } $oBccEmails = \MailSo\Mime\EmailCollection::NewInstance($sBcc); if ($oBccEmails && $oBccEmails->Count()) { $oMessage->SetBcc($oBccEmails); } return $oMessage; }
/** * @return array */ public function AjaxAccountResetPassword() { $mResult = false; $oAccount = $this->getDefaultAccountFromParam(); $sUrlHash = $this->getParamValue('UrlHash', ''); $oTenant = null; if ($oAccount->Domain->IdTenant > 0) { $oTenant = $this->oApiTenants->getTenantById($oAccount->Domain->IdTenant); } else { $oTenant = $this->oApiTenants->getDefaultGlobalTenant(); } if ($oTenant) { $oNotificationAccount = $this->oApiUsers->GetAccountByEmail($oTenant->InviteNotificationEmailAccount); if ($oNotificationAccount) { $sPasswordResetUrl = rtrim(\api_Utils::GetAppUrl(), '/'); $sPasswordResetHash = \md5(\time() . \rand(1000, 9999) . \CApi::$sSalt); $oAccount->User->PasswordResetHash = $sPasswordResetHash; $this->oApiUsers->updateAccount($oAccount); $sSubject = \CApi::ClientI18N('ACCOUNT_PASSWORD_RESET/SUBJECT', $oAccount, array('SITE_NAME' => $oAccount->Domain->SiteName)); $sBody = \CApi::ClientI18N('ACCOUNT_PASSWORD_RESET/BODY', $oAccount, array('SITE_NAME' => $oAccount->Domain->SiteName, 'PASSWORD_RESET_URL' => $sPasswordResetUrl . '/?reset-pass='******'#' . $sUrlHash, 'EMAIL' => $oAccount->Email)); $oMessage = \MailSo\Mime\Message::NewInstance(); $oMessage->RegenerateMessageId(); $oMessage->DoesNotCreateEmptyTextPart(); $sXMailer = \CApi::GetConf('webmail.xmailer-value', ''); if (0 < strlen($sXMailer)) { $oMessage->SetXMailer($sXMailer); } $oMessage->SetFrom(\MailSo\Mime\Email::NewInstance($oTenant->InviteNotificationEmailAccount))->SetSubject($sSubject)->AddText($sBody, true); $oToEmails = \MailSo\Mime\EmailCollection::NewInstance($oAccount->Email); if ($oToEmails && $oToEmails->Count()) { $oMessage->SetTo($oToEmails); } if ($oMessage) { try { $mResult = $this->oApiMail->sendMessage($oNotificationAccount, $oMessage); } catch (\CApiManagerException $oException) { throw $oException; } } } } return $this->DefaultResponse($oAccount, __FUNCTION__, $mResult); }
/** * * @param \RainLoop\Model\Account $oAccount * @param \MailSo\Mime\Message $oMessage * @param resource $rMessageStream * @param bool $bDsn = false * @param bool $bAddHiddenRcpt = true * * @throws \RainLoop\Exceptions\ClientException * @throws \MailSo\Net\Exceptions\ConnectionException */ private function smtpSendMessage($oAccount, $oMessage, &$rMessageStream, &$iMessageStreamSize, $bDsn = false, $bAddHiddenRcpt = true) { $oRcpt = $oMessage->GetRcpt(); if ($oRcpt && 0 < $oRcpt->Count()) { $this->Plugins()->RunHook('filter.smtp-message-stream', array($oAccount, &$rMessageStream, &$iMessageStreamSize)); $this->Plugins()->RunHook('filter.message-rcpt', array($oAccount, &$oRcpt)); try { $oFrom = $oMessage->GetFrom(); $sFrom = $oFrom instanceof \MailSo\Mime\Email ? $oFrom->GetEmail() : ''; $sFrom = empty($sFrom) ? $oAccount->Email() : $sFrom; $this->Plugins()->RunHook('filter.smtp-from', array($oAccount, $oMessage, &$sFrom)); $aHiddenRcpt = array(); if ($bAddHiddenRcpt) { $this->Plugins()->RunHook('filter.smtp-hidden-rcpt', array($oAccount, $oMessage, &$aHiddenRcpt)); } $bUsePhpMail = $oAccount->Domain()->OutUsePhpMail(); $oSmtpClient = \MailSo\Smtp\SmtpClient::NewInstance()->SetLogger($this->Logger()); $oSmtpClient->SetTimeOuts(10, (int) \RainLoop\Api::Config()->Get('labs', 'smtp_timeout', 60)); $bLoggined = $oAccount->OutConnectAndLoginHelper($this->Plugins(), $oSmtpClient, $this->Config(), $bUsePhpMail); if ($bUsePhpMail) { if (\MailSo\Base\Utils::FunctionExistsAndEnabled('mail')) { $aToCollection = $oMessage->GetTo(); if ($aToCollection && $oFrom) { $sRawBody = @\stream_get_contents($rMessageStream); if (!empty($sRawBody)) { $sMailTo = \trim($aToCollection->ToString(true)); $sMailSubject = \trim($oMessage->GetSubject()); $sMailSubject = 0 === \strlen($sMailSubject) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(\MailSo\Base\Enumerations\Encoding::BASE64_SHORT, $sMailSubject); $sMailHeaders = $sMailBody = ''; list($sMailHeaders, $sMailBody) = \explode("\r\n\r\n", $sRawBody, 2); unset($sRawBody); if ($this->Config()->Get('labs', 'mail_func_clear_headers', true)) { $sMailHeaders = \MailSo\Base\Utils::RemoveHeaderFromHeaders($sMailHeaders, array(\MailSo\Mime\Enumerations\Header::TO_, \MailSo\Mime\Enumerations\Header::SUBJECT)); } if ($this->Config()->Get('debug', 'enable', false)) { $this->Logger()->WriteDump(array($sMailTo, $sMailSubject, $sMailBody, $sMailHeaders)); } $bR = $this->Config()->Get('labs', 'mail_func_additional_parameters', false) ? \mail($sMailTo, $sMailSubject, $sMailBody, $sMailHeaders, '-f' . $oFrom->GetEmail()) : \mail($sMailTo, $sMailSubject, $sMailBody, $sMailHeaders); if (!$bR) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSendMessage); } } } } else { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSendMessage); } } else { if ($oSmtpClient->IsConnected()) { if (!empty($sFrom)) { $oSmtpClient->MailFrom($sFrom, '', $bDsn); } $aRcpt =& $oRcpt->GetAsArray(); foreach ($aRcpt as $oEmail) { $oSmtpClient->Rcpt($oEmail->GetEmail(), $bDsn); } if ($bAddHiddenRcpt && \is_array($aHiddenRcpt) && 0 < \count($aHiddenRcpt)) { foreach ($aHiddenRcpt as $sEmail) { if (\preg_match('/^[^@\\s]+@[^@\\s]+$/', $sEmail)) { $oSmtpClient->Rcpt($sEmail); } } } $oSmtpClient->DataWithStream($rMessageStream); if ($bLoggined) { $oSmtpClient->Logout(); } $oSmtpClient->Disconnect(); } } } catch (\MailSo\Net\Exceptions\ConnectionException $oException) { if ($this->Config()->Get('labs', 'smtp_show_server_errors')) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ClientViewError, $oException); } else { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ConnectionError, $oException); } } catch (\MailSo\Smtp\Exceptions\LoginException $oException) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError, $oException); } catch (\Exception $oException) { if ($this->Config()->Get('labs', 'smtp_show_server_errors')) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ClientViewError, $oException); } else { throw $oException; } } } else { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::InvalidRecipients); } }
/** * Saves message to a specific folder. The method is primarily used for saving drafts. * * @param CAccount $oAccount Account object. * @param \MailSo\Mime\Message $oMessage Object representing message to be saved. * @param string $sDraftFolder Folder the message is saved to. * @param string $sDraftUid = ''. UID of the message to be replaced; saving new draft removes the previous version. * * @return array|bool Array containing name of the folder and UID of the message stored, or bool in case of failure. * * @throws CApiInvalidArgumentException */ public function saveMessage($oAccount, $oMessage, $sDraftFolder, $sDraftUid = '') { if (!$oAccount || !$oMessage || 0 === strlen($sDraftFolder)) { throw new CApiInvalidArgumentException(); } $oImapClient =& $this->_getImapClient($oAccount); $rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource(); $iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter($oMessage->ToStream(), array($rMessageStream), 8192, true, true); $mResult = false; if (false !== $iMessageStreamSize && is_resource($rMessageStream)) { rewind($rMessageStream); $iNewUid = 0; $oImapClient->MessageAppendStream($sDraftFolder, $rMessageStream, $iMessageStreamSize, array(\MailSo\Imap\Enumerations\MessageFlag::SEEN), $iNewUid); if (null === $iNewUid || 0 === $iNewUid) { $sMessageId = $oMessage->MessageId(); if (0 < strlen($sMessageId)) { $iNewUid = $this->getMessageUid($oAccount, $sDraftFolder, $sMessageId); } } $mResult = true; if (0 < strlen($sDraftFolder) && 0 < strlen($sDraftUid)) { $this->deleteMessage($oAccount, $sDraftFolder, array($sDraftUid)); } if (null !== $iNewUid && 0 < $iNewUid) { $mResult = array('NewFolder' => $sDraftFolder, 'NewUid' => $iNewUid); } } return $mResult; }
/** * @param CAccount $oAccount * @param string $sSubject * @param string $mHtml = null * @param string $mText = null * * @return \MailSo\Mime\Message */ private function createMessage($oAccount, $sSubject, $mHtml = null, $mText = null) { $oMessage = \MailSo\Mime\Message::NewInstance(); $oMessage->RegenerateMessageId(); $sXMailer = CApi::GetConf('webmail.xmailer-value', ''); if (0 < strlen($sXMailer)) { $oMessage->SetXMailer($sXMailer); } $oMessage->SetFrom(\MailSo\Mime\Email::NewInstance($oAccount->Email))->SetSubject($sSubject); $oToEmails = \MailSo\Mime\EmailCollection::NewInstance($oAccount->Email); if ($oToEmails && $oToEmails->Count()) { $oMessage->SetTo($oToEmails); } if ($mHtml !== null) { $oMessage->AddText($mHtml, true); } if ($mText !== null) { $oMessage->AddText($mText, false); } return $oMessage; }
/** * @param \RainLoop\Account $oAccount * * @return \MailSo\Mime\Message */ private function buildReadReceiptMessage($oAccount) { $sReadReceipt = $this->GetActionParam('ReadReceipt', ''); $sSubject = $this->GetActionParam('Subject', ''); $sText = $this->GetActionParam('Text', ''); if (empty($sReadReceipt) || empty($sSubject) || empty($sText)) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::UnknownError); } $oMessage = \MailSo\Mime\Message::NewInstance(); $oMessage->RegenerateMessageId(); $oMessage->SetXMailer('RainLoop/' . APP_VERSION); $oSettings = $this->SettingsProvider()->Load($oAccount); $sDisplayName = \trim($oSettings->GetConf('DisplayName', '')); $sReplyTo = \trim($oSettings->GetConf('ReplyTo', '')); $oMessage->SetFrom(\MailSo\Mime\Email::NewInstance($oAccount->Email(), $sDisplayName)); if (!empty($sReplyTo)) { $oReplyTo = \MailSo\Mime\EmailCollection::NewInstance($sReplyTo); if ($oReplyTo && $oReplyTo->Count()) { $oMessage->SetReplyTo($oReplyTo); } } $oMessage->SetSubject($sSubject); $oToEmails = \MailSo\Mime\EmailCollection::NewInstance($sReadReceipt); if ($oToEmails && $oToEmails->Count()) { $oMessage->SetTo($oToEmails); } $this->Plugins()->RunHook('filter.read-receipt-message-plain', array($oAccount, &$oMessage, &$sText)); $oMessage->AddText($sText, false); $this->Plugins()->RunHook('filter.build-read-receipt-message', array(&$oMessage, $oAccount)); return $oMessage; }
/** * @param \CAccount $oAccount * * @return \MailSo\Mime\Message * * @throws \MailSo\Base\Exceptions\InvalidArgumentException */ private function buildConfirmationMessage($oAccount) { $sConfirmation = $this->getParamValue('Confirmation', ''); $sSubject = $this->getParamValue('Subject', ''); $sText = $this->getParamValue('Text', ''); if (0 === strlen($sConfirmation) || 0 === strlen($sSubject) || 0 === strlen($sText)) { throw new \MailSo\Base\Exceptions\InvalidArgumentException(); } $oMessage = \MailSo\Mime\Message::NewInstance(); $oMessage->RegenerateMessageId(); $sXMailer = \CApi::GetConf('webmail.xmailer-value', ''); if (0 < strlen($sXMailer)) { $oMessage->SetXMailer($sXMailer); } $oTo = \MailSo\Mime\EmailCollection::Parse($sConfirmation); if (!$oTo || 0 === $oTo->Count()) { throw new \MailSo\Base\Exceptions\InvalidArgumentException(); } $sFrom = 0 < strlen($oAccount->FriendlyName) ? '"' . $oAccount->FriendlyName . '"' : ''; if (0 < strlen($sFrom)) { $sFrom .= ' <' . $oAccount->Email . '>'; } else { $sFrom .= $oAccount->Email; } $oMessage->SetFrom(\MailSo\Mime\Email::NewInstance($sFrom))->SetTo($oTo)->SetSubject($sSubject); $oMessage->AddText($sText, false); return $oMessage; }