/** * @param \MailSo\Mime\EmailCollection $oEmails * * @return \MailSo\Mime\EmailCollection */ public function MergeWithOtherCollection(\MailSo\Mime\EmailCollection $oEmails) { $aEmails =& $oEmails->GetAsArray(); foreach ($aEmails as $oEmail) { $this->Add($oEmail); } return $this; }
/** * @param int $iIndex * @param string $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1 * * @return \MailSo\Mime\EmailCollection|null */ public function GetFetchEnvelopeEmailCollection($iIndex, $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1) { $oResult = null; $aEmails = $this->GetFetchEnvelopeValue($iIndex, null); if (is_array($aEmails) && 0 < count($aEmails)) { $oResult = \MailSo\Mime\EmailCollection::NewInstance(); foreach ($aEmails as $aEmailItem) { if (is_array($aEmailItem) && 4 === count($aEmailItem)) { $sDisplayName = \MailSo\Base\Utils::DecodeHeaderValue(self::findEnvelopeIndex($aEmailItem, 0, ''), $sParentCharset); $sRemark = \MailSo\Base\Utils::DecodeHeaderValue(self::findEnvelopeIndex($aEmailItem, 1, ''), $sParentCharset); $sLocalPart = self::findEnvelopeIndex($aEmailItem, 2, ''); $sDomainPart = self::findEnvelopeIndex($aEmailItem, 3, ''); if (0 < strlen($sLocalPart) && 0 < strlen($sDomainPart)) { $oResult->Add(\MailSo\Mime\Email::NewInstance($sLocalPart . '@' . $sDomainPart, $sDisplayName, $sRemark)); } } } } return $oResult; }
/** * @return string */ public function EncodedValue() { $sResult = $this->sFullValue; if ($this->IsSubject()) { if (!\MailSo\Base\Utils::IsAscii($sResult) && \MailSo\Base\Utils::IsIconvSupported() && \function_exists('iconv_mime_encode')) { $aPreferences = array('scheme' => \MailSo\Base\Enumerations\Encoding::BASE64_SHORT, 'input-charset' => \MailSo\Base\Enumerations\Charset::UTF_8, 'output-charset' => \MailSo\Base\Enumerations\Charset::UTF_8, 'line-length' => \MailSo\Mime\Enumerations\Constants::LINE_LENGTH, 'line-break-chars' => \MailSo\Mime\Enumerations\Constants::CRLF); return \iconv_mime_encode($this->Name(), $sResult, $aPreferences); } } else { if ($this->IsParameterized() && $this->oParameters && 0 < $this->oParameters->Count()) { $sResult = $this->sValue . '; ' . $this->oParameters->ToString(true); } else { if ($this->IsEmail()) { $oEmailCollection = \MailSo\Mime\EmailCollection::NewInstance($this->sFullValue); if ($oEmailCollection && 0 < $oEmailCollection->Count()) { $sResult = $oEmailCollection->ToString(true, false); } } } } return $this->NameWithDelimitrom() . $this->wordWrapHelper($sResult); }
/** * @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); }
/** * @return \MailSo\Mime\EmailCollection */ public function GetRcpt() { $oResult = \MailSo\Mime\EmailCollection::NewInstance(); if (isset($this->aHeadersValue[\MailSo\Mime\Enumerations\Header::TO_]) && $this->aHeadersValue[\MailSo\Mime\Enumerations\Header::TO_] instanceof \MailSo\Mime\EmailCollection) { $oResult->MergeWithOtherCollection($this->aHeadersValue[\MailSo\Mime\Enumerations\Header::TO_]); } if (isset($this->aHeadersValue[\MailSo\Mime\Enumerations\Header::CC]) && $this->aHeadersValue[\MailSo\Mime\Enumerations\Header::CC] instanceof \MailSo\Mime\EmailCollection) { $oResult->MergeWithOtherCollection($this->aHeadersValue[\MailSo\Mime\Enumerations\Header::CC]); } if (isset($this->aHeadersValue[\MailSo\Mime\Enumerations\Header::BCC]) && $this->aHeadersValue[\MailSo\Mime\Enumerations\Header::BCC] instanceof \MailSo\Mime\EmailCollection) { $oResult->MergeWithOtherCollection($this->aHeadersValue[\MailSo\Mime\Enumerations\Header::BCC]); } return $oResult->Unique(); }
/** * @param string $sHeaderName * @param bool $bCharsetAutoDetect = false * @return string */ public function GetAsEmailCollection($sHeaderName, $bCharsetAutoDetect = false) { $oResult = null; $sValue = $this->ValueByName($sHeaderName, $bCharsetAutoDetect); if (0 < \strlen($sValue)) { $oResult = \MailSo\Mime\EmailCollection::NewInstance($sValue); } return $oResult && 0 < $oResult->Count() ? $oResult : null; }
/** * @param \RainLoop\Model\Account $oAccount * * @return \MailSo\Mime\Message */ private function buildReadReceiptMessage($oAccount) { $sReadReceipt = $this->GetActionParam('ReadReceipt', ''); $sSubject = $this->GetActionParam('Subject', ''); $sText = $this->GetActionParam('Text', ''); $oIdentity = $this->GetAccountIdentity($oAccount); if (empty($sReadReceipt) || empty($sSubject) || empty($sText) || !$oIdentity) { throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::UnknownError); } $oMessage = \MailSo\Mime\Message::NewInstance(); $oMessage->RegenerateMessageId(); $oMessage->SetXMailer('RainLoop/' . APP_VERSION); $oMessage->SetFrom(\MailSo\Mime\Email::NewInstance($oIdentity->Email(), $oIdentity->Name())); $sReplyTo = $oIdentity->ReplyTo(); 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; }
<?php include '../lib/MailSo/MailSo.php'; echo '<pre>'; $oLogger = \MailSo\Log\Logger::SingletonInstance()->Add(\MailSo\Log\Drivers\Inline::NewInstance("\r\n", true)); $sEmails = 'User Name1 <*****@*****.**>, User D\'Name2 <*****@*****.**>, "User Name3" <*****@*****.**>'; $oData = \MailSo\Mime\EmailCollection::NewInstance($sEmails); $oLogger->WriteDump($oData);
/** * @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; }
public function testNewInstance1() { $oMails = \MailSo\Mime\EmailCollection::NewInstance('User Name <*****@*****.**>, User D\'Name <*****@*****.**>, "User Name" <*****@*****.**>'); $this->assertEquals(3, $oMails->Count()); }
/** * @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; }