/** * @param string $sValue * * @return string */ public static function UrlSafeBase64Decode($sValue) { $sData = \str_replace(array('-', '_', '.'), array('+', '/', '='), $sValue); $sMode = \strlen($sData) % 4; if ($sMode) { $sData .= \substr('====', $sMode); } return \MailSo\Base\Utils::Base64Decode($sData); }
/** * @param \RainLoop\Model\Account $oAccount * @param bool $bWithDraftInfo = true * * @return \MailSo\Mime\Message */ private function buildMessage($oAccount, $bWithDraftInfo = true) { $sIdentityID = $this->GetActionParam('IdentityID', ''); $sTo = $this->GetActionParam('To', ''); $sCc = $this->GetActionParam('Cc', ''); $sBcc = $this->GetActionParam('Bcc', ''); $sReplyTo = $this->GetActionParam('ReplyTo', ''); $sSubject = $this->GetActionParam('Subject', ''); $bTextIsHtml = '1' === $this->GetActionParam('TextIsHtml', '0'); $bReadReceiptRequest = '1' === $this->GetActionParam('ReadReceiptRequest', '0'); $bMarkAsImportant = '1' === $this->GetActionParam('MarkAsImportant', '0'); $sText = $this->GetActionParam('Text', ''); $aAttachments = $this->GetActionParam('Attachments', null); $aDraftInfo = $this->GetActionParam('DraftInfo', null); $sInReplyTo = $this->GetActionParam('InReplyTo', ''); $sReferences = $this->GetActionParam('References', ''); $oMessage = \MailSo\Mime\Message::NewInstance(); $oMessage->RegenerateMessageId(); $oMessage->SetXMailer('RainLoop/' . APP_VERSION); $oFromIdentity = $this->GetIdentityByID($oAccount, $sIdentityID); if ($oFromIdentity) { $oMessage->SetFrom(\MailSo\Mime\Email::NewInstance($oFromIdentity->Email(), $oFromIdentity->Name())); } else { $oMessage->SetFrom(\MailSo\Mime\Email::Parse($oAccount->Email())); } if (!empty($sReplyTo)) { $oReplyTo = \MailSo\Mime\EmailCollection::NewInstance($sReplyTo); if ($oReplyTo && 0 < $oReplyTo->Count()) { $oMessage->SetReplyTo($oReplyTo); } } if ($bReadReceiptRequest) { $oMessage->SetReadReceipt($oAccount->Email()); } if ($bMarkAsImportant) { $oMessage->SetPriority(\MailSo\Mime\Enumerations\MessagePriority::HIGH); } $oMessage->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); } $aFoundedCids = array(); $mFoundDataURL = array(); $aFoundedContentLocationUrls = array(); $sTextToAdd = $bTextIsHtml ? \MailSo\Base\HtmlUtils::BuildHtml($sText, $aFoundedCids, $mFoundDataURL, $aFoundedContentLocationUrls) : $sText; $this->Plugins()->RunHook($bTextIsHtml ? 'filter.message-html' : 'filter.message-plain', array($oAccount, &$oMessage, &$sTextToAdd)); if ($bTextIsHtml && 0 < \strlen($sTextToAdd)) { $sTextConverted = \MailSo\Base\HtmlUtils::ConvertHtmlToPlain($sTextToAdd); $this->Plugins()->RunHook('filter.message-plain', array($oAccount, &$oMessage, &$sTextConverted)); $oMessage->AddText($sTextConverted, false); } $oMessage->AddText($sTextToAdd, $bTextIsHtml); if (\is_array($aAttachments)) { foreach ($aAttachments as $sTempName => $aData) { $sFileName = (string) $aData[0]; $bIsInline = (bool) $aData[1]; $sCID = (string) $aData[2]; $sContentLocation = isset($aData[3]) ? (string) $aData[3] : ''; $rResource = $this->FilesProvider()->GetFile($oAccount, $sTempName); if (\is_resource($rResource)) { $iFileSize = $this->FilesProvider()->FileSize($oAccount, $sTempName); $oMessage->Attachments()->Add(\MailSo\Mime\Attachment::NewInstance($rResource, $sFileName, $iFileSize, $bIsInline, \in_array(trim(trim($sCID), '<>'), $aFoundedCids), $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]+);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', '.', $aMatch[1]); $rResource = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($sRaw); $sRaw = ''; unset($sRaw); unset($aMatch); $oMessage->Attachments()->Add(\MailSo\Mime\Attachment::NewInstance($rResource, $sFileName, $iFileSize, true, true, $sCID)); } } } } $this->Plugins()->RunHook('filter.build-message', array(&$oMessage)); $this->Plugins()->RunHook('filter.build-message[2]', array(&$oMessage, $oAccount)); return $oMessage; }
/** * @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 $sSensitivity = $this->getParamValue('Sensitivity', ''); // 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($sSensitivity) && in_array((int) $sSensitivity, array(\MailSo\Mime\Enumerations\Sensitivity::NOTHING, \MailSo\Mime\Enumerations\Sensitivity::CONFIDENTIAL, \MailSo\Mime\Enumerations\Sensitivity::PRIVATE_, \MailSo\Mime\Enumerations\Sensitivity::PERSONAL))) { $oMessage->SetSensitivity((int) $sSensitivity); } 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; }
/** * @param string $sBaseString * @param string $sEndBuffer * * @return string */ public static function InlineBase64Decode($sBaseString, &$sEndBuffer) { $sEndBuffer = ''; $sBaseString = str_replace(array("\r", "\n", "\t"), '', $sBaseString); $iBaseStringLen = strlen($sBaseString); $iBaseStringNormFloorLen = floor($iBaseStringLen / 4) * 4; if ($iBaseStringNormFloorLen < $iBaseStringLen) { $sEndBuffer = substr($sBaseString, $iBaseStringNormFloorLen); $sBaseString = substr($sBaseString, 0, $iBaseStringNormFloorLen); } return \MailSo\Base\Utils::Base64Decode($sBaseString); }