/** * @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 * @param \CFetcher $oFetcher = null * @param bool $bWithDraftInfo = true * @param \CIdentity $oIdentity = null * * @return \MailSo\Mime\Message */ private function buildMessage($oAccount, $oFetcher = null, $bWithDraftInfo = true, $oIdentity = null) { $sTo = $this->getParamValue('To', ''); $sCc = $this->getParamValue('Cc', ''); $sBcc = $this->getParamValue('Bcc', ''); $sSubject = $this->getParamValue('Subject', ''); $bTextIsHtml = '1' === $this->getParamValue('IsHtml', '0'); $sText = $this->getParamValue('Text', ''); $aAttachments = $this->getParamValue('Attachments', null); $aDraftInfo = $this->getParamValue('DraftInfo', null); $sInReplyTo = $this->getParamValue('InReplyTo', ''); $sReferences = $this->getParamValue('References', ''); $sImportance = $this->getParamValue('Importance', ''); // 1 3 5 $sSensivity = $this->getParamValue('Sensivity', ''); // 0 1 2 3 4 $bReadingConfirmation = '1' === $this->getParamValue('ReadingConfirmation', '0'); $oMessage = \MailSo\Mime\Message::NewInstance(); $oMessage->RegenerateMessageId(); $sXMailer = \CApi::GetConf('webmail.xmailer-value', ''); if (0 < strlen($sXMailer)) { $oMessage->SetXMailer($sXMailer); } if ($oIdentity) { $oFrom = \MailSo\Mime\Email::NewInstance($oIdentity->Email, $oIdentity->FriendlyName); } else { $oFrom = $oFetcher ? \MailSo\Mime\Email::NewInstance($oFetcher->Email, $oFetcher->Name) : \MailSo\Mime\Email::NewInstance($oAccount->Email, $oAccount->FriendlyName); } $oMessage->SetFrom($oFrom)->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); } if ($bWithDraftInfo && is_array($aDraftInfo) && !empty($aDraftInfo[0]) && !empty($aDraftInfo[1]) && !empty($aDraftInfo[2])) { $oMessage->SetDraftInfo($aDraftInfo[0], $aDraftInfo[1], $aDraftInfo[2]); } if (0 < strlen($sInReplyTo)) { $oMessage->SetInReplyTo($sInReplyTo); } if (0 < strlen($sReferences)) { $oMessage->SetReferences($sReferences); } if (0 < strlen($sImportance) && in_array((int) $sImportance, array(\MailSo\Mime\Enumerations\MessagePriority::HIGH, \MailSo\Mime\Enumerations\MessagePriority::NORMAL, \MailSo\Mime\Enumerations\MessagePriority::LOW))) { $oMessage->SetPriority((int) $sImportance); } if (0 < strlen($sSensivity) && in_array((int) $sSensivity, array(\MailSo\Mime\Enumerations\Sensitivity::NOTHING, \MailSo\Mime\Enumerations\Sensitivity::CONFIDENTIAL, \MailSo\Mime\Enumerations\Sensitivity::PRIVATE_, \MailSo\Mime\Enumerations\Sensitivity::PERSONAL))) { $oMessage->SetSensitivity((int) $sSensivity); } if ($bReadingConfirmation) { $oMessage->SetReadConfirmation($oFetcher ? $oFetcher->Email : $oAccount->Email); } $aFoundCids = array(); \CApi::Plugin()->RunHook('webmail.message-text-html-raw', array($oAccount, &$oMessage, &$sText, &$bTextIsHtml)); if ($bTextIsHtml) { $sTextConverted = \MailSo\Base\HtmlUtils::ConvertHtmlToPlain($sText); \CApi::Plugin()->RunHook('webmail.message-plain-part', array($oAccount, &$oMessage, &$sTextConverted)); $oMessage->AddText($sTextConverted, false); } $mFoundDataURL = array(); $aFoundedContentLocationUrls = array(); $sTextConverted = $bTextIsHtml ? \MailSo\Base\HtmlUtils::BuildHtml($sText, $aFoundCids, $mFoundDataURL, $aFoundedContentLocationUrls) : $sText; \CApi::Plugin()->RunHook($bTextIsHtml ? 'webmail.message-html-part' : 'webmail.message-plain-part', array($oAccount, &$oMessage, &$sTextConverted)); $oMessage->AddText($sTextConverted, $bTextIsHtml); if (is_array($aAttachments)) { foreach ($aAttachments as $sTempName => $aData) { if (is_array($aData) && isset($aData[0], $aData[1], $aData[2], $aData[3])) { $sFileName = (string) $aData[0]; $sCID = (string) $aData[1]; $bIsInline = '1' === (string) $aData[2]; $bIsLinked = '1' === (string) $aData[3]; $sContentLocation = isset($aData[4]) ? (string) $aData[4] : ''; $rResource = $this->ApiFileCache()->GetFile($oAccount, $sTempName); if (is_resource($rResource)) { $iFileSize = $this->ApiFileCache()->FileSize($oAccount, $sTempName); $sCID = trim(trim($sCID), '<>'); $bIsFounded = 0 < strlen($sCID) ? in_array($sCID, $aFoundCids) : false; if (!$bIsLinked || $bIsFounded) { $oMessage->Attachments()->Add(\MailSo\Mime\Attachment::NewInstance($rResource, $sFileName, $iFileSize, $bIsInline, $bIsLinked, $bIsLinked ? '<' . $sCID . '>' : '', array(), $sContentLocation)); } } } } } if ($mFoundDataURL && \is_array($mFoundDataURL) && 0 < \count($mFoundDataURL)) { foreach ($mFoundDataURL as $sCidHash => $sDataUrlString) { $aMatch = array(); $sCID = '<' . $sCidHash . '>'; if (\preg_match('/^data:(image\\/[a-zA-Z0-9]+\\+?[a-zA-Z0-9]+);base64,(.+)$/i', $sDataUrlString, $aMatch) && !empty($aMatch[1]) && !empty($aMatch[2])) { $sRaw = \MailSo\Base\Utils::Base64Decode($aMatch[2]); $iFileSize = \strlen($sRaw); if (0 < $iFileSize) { $sFileName = \preg_replace('/[^a-z0-9]+/i', '.', \MailSo\Base\Utils::NormalizeContentType($aMatch[1])); // fix bug #68532 php < 5.5.21 or php < 5.6.5 $sRaw = $this->FixBase64EncodeOmitsPaddingBytes($sRaw); $rResource = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($sRaw); $sRaw = ''; unset($sRaw); unset($aMatch); $oMessage->Attachments()->Add(\MailSo\Mime\Attachment::NewInstance($rResource, $sFileName, $iFileSize, true, true, $sCID)); } } } } \CApi::Plugin()->RunHook('webmail.build-message', array(&$oMessage)); return $oMessage; }