本文整理匯總了PHP中MailSo\Base\Utils::Utf8Clear方法的典型用法代碼示例。如果您正苦於以下問題:PHP Utils::Utf8Clear方法的具體用法?PHP Utils::Utf8Clear怎麽用?PHP Utils::Utf8Clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MailSo\Base\Utils
的用法示例。
在下文中一共展示了Utils::Utf8Clear方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ClearArrayUtf8Values
/**
* @param array $aInput
*/
public static function ClearArrayUtf8Values(&$aInput)
{
if (\is_array($aInput)) {
foreach ($aInput as $mKey => $mItem) {
if (\is_string($mItem)) {
$aInput[$mKey] = \MailSo\Base\Utils::Utf8Clear($mItem);
} else {
if (\is_array($mItem)) {
\MailSo\Base\Utils::ClearArrayUtf8Values($mItem);
$aInput[$mKey] = $mItem;
}
}
}
}
}
示例2: clearFileName
/**
* @param string $sFileName
* @param string $sContentType
* @param string $sMimeIndex = ''
*
* @return string
*/
public function clearFileName($sFileName, $sContentType, $sMimeIndex = '')
{
$sFileName = 0 === strlen($sFileName) ? preg_replace('/[^a-zA-Z0-9]/', '.', (empty($sMimeIndex) ? '' : $sMimeIndex . '.') . $sContentType) : $sFileName;
$sClearedFileName = preg_replace('/[\\s]+/', ' ', preg_replace('/[\\.]+/', '.', $sFileName));
$sExt = \MailSo\Base\Utils::GetFileExtension($sClearedFileName);
$iSize = 100;
if ($iSize < strlen($sClearedFileName) - strlen($sExt)) {
$sClearedFileName = substr($sClearedFileName, 0, $iSize) . (empty($sExt) ? '' : '.' . $sExt);
}
return \MailSo\Base\Utils::ClearFileName(\MailSo\Base\Utils::Utf8Clear($sClearedFileName));
}
示例3: NewInstance
//.........這裏部分代碼省略.........
if (null !== $aBodyStructure[4] && 'NIL' !== $aBodyStructure[4]) {
if (!\is_string($aBodyStructure[4])) {
return null;
}
$sDescription = $aBodyStructure[4];
}
if (null !== $aBodyStructure[5] && 'NIL' !== $aBodyStructure[5]) {
if (!\is_string($aBodyStructure[5])) {
return null;
}
$sMailEncodingName = $aBodyStructure[5];
}
if (\is_numeric($aBodyStructure[6])) {
$iSize = (int) $aBodyStructure[6];
} else {
$iSize = -1;
}
if (0 === \strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1]) {
// This is the only sub-part of the message (otherwise, it would be
// one of sub-parts of a multi-part, and partID would already be fully set up).
$sPartID .= '1';
}
$iExtraItemPos = 7;
if ('text' === $sBodyMainType) {
if ($iExtraItemPos < \count($aBodyStructure)) {
if (\is_numeric($aBodyStructure[$iExtraItemPos])) {
$iTextLineCount = (int) $aBodyStructure[$iExtraItemPos];
} else {
$iTextLineCount = -1;
}
} else {
$iTextLineCount = -1;
}
$iExtraItemPos++;
} else {
if ('message' === $sBodyMainType && 'rfc822' === $sBodySubType) {
if ($iExtraItemPos + 2 < \count($aBodyStructure)) {
if (\is_numeric($aBodyStructure[$iExtraItemPos + 2])) {
$iTextLineCount = (int) $aBodyStructure[$iExtraItemPos + 2];
} else {
$iTextLineCount = -1;
}
} else {
$iTextLineCount = -1;
}
$iExtraItemPos += 3;
}
}
$iExtraItemPos++;
// skip MD5 digest of the body because most mail servers leave it NIL anyway
}
$sContentType = $sBodyMainType . '/' . $sBodySubType;
$sDisposition = null;
$aDispositionParams = null;
$sFileName = null;
if ($iExtraItemPos < \count($aBodyStructure)) {
$aDispList = $aBodyStructure[$iExtraItemPos];
if (\is_array($aDispList) && 1 < \count($aDispList)) {
if (null !== $aDispList[0]) {
if (\is_string($aDispList[0]) && 'NIL' !== $aDispList[0]) {
$sDisposition = $aDispList[0];
} else {
return null;
}
}
}
$aDispParamList = $aDispList[1];
if (\is_array($aDispParamList)) {
$aDispositionParams = self::getKeyValueListFromArrayList($aDispParamList);
if (\is_array($aDispositionParams)) {
$sFileName = self::decodeAttrParamenter($aDispositionParams, 'filename', $sCharset);
}
}
}
$iExtraItemPos++;
$sLanguage = null;
if ($iExtraItemPos < count($aBodyStructure)) {
if (null !== $aBodyStructure[$iExtraItemPos] && 'NIL' !== $aBodyStructure[$iExtraItemPos]) {
if (\is_array($aBodyStructure[$iExtraItemPos])) {
$sLanguage = \implode(',', $aBodyStructure[$iExtraItemPos]);
} else {
if (\is_string($aBodyStructure[$iExtraItemPos])) {
$sLanguage = $aBodyStructure[$iExtraItemPos];
}
}
}
$iExtraItemPos++;
}
$sLocation = null;
if ($iExtraItemPos < \count($aBodyStructure)) {
if (null !== $aBodyStructure[$iExtraItemPos] && 'NIL' !== $aBodyStructure[$iExtraItemPos]) {
if (\is_string($aBodyStructure[$iExtraItemPos])) {
$sLocation = $aBodyStructure[$iExtraItemPos];
}
}
$iExtraItemPos++;
}
return new self($sContentType, $sCharset, $aBodyParams, $sContentID, $sDescription, $sMailEncodingName, $sDisposition, $aDispositionParams, \MailSo\Base\Utils::Utf8Clear(null === $sFileName || 0 === \strlen($sFileName) ? $sName : $sFileName), $sLanguage, $sLocation, $iSize, $iTextLineCount, $sPartID, $aSubParts);
}
}
示例4: responseObject
/**
* @param \CAccount $oAccount
* @param mixed $mResponse
* @param string $sParent
* @param array $aParameters = array()
*
* @return mixed
*/
protected function responseObject($oAccount, $mResponse, $sParent, $aParameters = array())
{
$mResult = $mResponse;
if (is_object($mResponse)) {
$sClassName = get_class($mResponse);
if ('CApiMailMessage' === $sClassName) {
$iTrimmedLimit = \CApi::GetConf('labs.message-body-size-limit', 0);
$oAttachments = $mResponse->getAttachments();
$iInternalTimeStampInUTC = $mResponse->getInternalTimeStamp();
$iReceivedOrDateTimeStampInUTC = $mResponse->getReceivedOrDateTimeStamp();
$aFlags = $mResponse->getFlagsLowerCase();
$mResult = array_merge($this->objectWrapper($oAccount, $mResponse, $sParent, $aParameters), array('Folder' => $mResponse->getFolder(), 'Uid' => $mResponse->getUid(), 'Subject' => $mResponse->getSubject(), 'MessageId' => $mResponse->getMessageId(), 'Size' => $mResponse->getSize(), 'TextSize' => $mResponse->getTextSize(), 'InternalTimeStampInUTC' => $iInternalTimeStampInUTC, 'ReceivedOrDateTimeStampInUTC' => $iReceivedOrDateTimeStampInUTC, 'TimeStampInUTC' => \CApi::GetConf('labs.use-date-from-headers', false) && 0 < $iReceivedOrDateTimeStampInUTC ? $iReceivedOrDateTimeStampInUTC : $iInternalTimeStampInUTC, 'From' => $this->responseObject($oAccount, $mResponse->getFrom(), $sParent, $aParameters), 'To' => $this->responseObject($oAccount, $mResponse->getTo(), $sParent, $aParameters), 'Cc' => $this->responseObject($oAccount, $mResponse->getCc(), $sParent, $aParameters), 'Bcc' => $this->responseObject($oAccount, $mResponse->getBcc(), $sParent, $aParameters), 'Sender' => $this->responseObject($oAccount, $mResponse->getSender(), $sParent, $aParameters), 'ReplyTo' => $this->responseObject($oAccount, $mResponse->getReplyTo(), $sParent, $aParameters), 'IsSeen' => in_array('\\seen', $aFlags), 'IsFlagged' => in_array('\\flagged', $aFlags), 'IsAnswered' => in_array('\\answered', $aFlags), 'IsForwarded' => false, 'HasAttachments' => $oAttachments && $oAttachments->hasNotInlineAttachments(), 'HasVcardAttachment' => $oAttachments && $oAttachments->hasVcardAttachment(), 'HasIcalAttachment' => $oAttachments && $oAttachments->hasIcalAttachment(), 'Priority' => $mResponse->getPriority(), 'DraftInfo' => $mResponse->getDraftInfo(), 'Sensitivity' => $mResponse->getSensitivity()));
$mResult['TrimmedTextSize'] = $mResult['TextSize'];
if (0 < $iTrimmedLimit && $mResult['TrimmedTextSize'] > $iTrimmedLimit) {
$mResult['TrimmedTextSize'] = $iTrimmedLimit;
}
$sLowerForwarded = strtolower(\CApi::GetConf('webmail.forwarded-flag-name', ''));
if (!empty($sLowerForwarded)) {
$mResult['IsForwarded'] = in_array($sLowerForwarded, $aFlags);
}
$mResult['Hash'] = \CApi::EncodeKeyValues(array('AccountID' => $oAccount ? $oAccount->IdAccount : 0, 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeType' => 'message/rfc822', 'FileName' => $mResult['Subject'] . '.eml'));
if ('MessageGet' === $sParent || 'MessagesGetBodies' === $sParent) {
$mResult['Headers'] = \MailSo\Base\Utils::Utf8Clear($mResponse->getHeaders());
$mResult['InReplyTo'] = $mResponse->getInReplyTo();
$mResult['References'] = $mResponse->getReferences();
$mResult['ReadingConfirmation'] = $mResponse->getReadingConfirmation();
if (!empty($mResult['ReadingConfirmation']) && in_array('$readconfirm', $aFlags)) {
$mResult['ReadingConfirmation'] = '';
}
$bHasExternals = false;
$aFoundedCIDs = array();
$sPlain = '';
$sHtml = trim($mResponse->getHtml());
if (0 === strlen($sHtml)) {
$sPlain = $mResponse->getPlain();
}
$aContentLocationUrls = array();
$aFoundedContentLocationUrls = array();
if ($oAttachments && 0 < $oAttachments->Count()) {
$aList =& $oAttachments->GetAsArray();
foreach ($aList as $oAttachment) {
if ($oAttachment) {
$sContentLocation = $oAttachment->getContentLocation();
if ($sContentLocation && 0 < \strlen($sContentLocation)) {
$aContentLocationUrls[] = $oAttachment->getContentLocation();
}
}
}
}
$iTextSizeLimit = 500000;
if ($iTextSizeLimit < \strlen($sHtml)) {
$iSpacePost = \strpos($sHtml, ' ', $iTextSizeLimit);
$sHtml = \substr($sHtml, 0, false !== $iSpacePost && $iSpacePost > $iTextSizeLimit ? $iSpacePost : $iTextSizeLimit);
}
if ($iTextSizeLimit < \strlen($sPlain)) {
$iSpacePost = \strpos($sPlain, ' ', $iTextSizeLimit);
$sPlain = \substr($sPlain, 0, false !== $iSpacePost && $iSpacePost > $iTextSizeLimit ? $iSpacePost : $iTextSizeLimit);
}
if (0 < \strlen($sHtml) && \CApi::GetConf('labs.webmail.display-inline-css', false)) {
include_once PSEVEN_APP_ROOT_PATH . 'libraries/other/CssToInlineStyles.php';
$oCssToInlineStyles = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($sHtml);
$oCssToInlineStyles->setEncoding('utf-8');
$oCssToInlineStyles->setUseInlineStylesBlock(true);
$mResult['Html'] = \MailSo\Base\HtmlUtils::ClearHtml($oCssToInlineStyles->convert(), $bHasExternals, $aFoundedCIDs, $aContentLocationUrls, $aFoundedContentLocationUrls, false, true);
} else {
$mResult['Html'] = 0 === strlen($sHtml) ? '' : \MailSo\Base\HtmlUtils::ClearHtml($sHtml, $bHasExternals, $aFoundedCIDs, $aContentLocationUrls, $aFoundedContentLocationUrls, false, true);
}
$mResult['Trimmed'] = false;
$mResult['Plain'] = 0 === strlen($sPlain) ? '' : \MailSo\Base\HtmlUtils::ConvertPlainToHtml($sPlain);
$mResult['PlainRaw'] = \trim($sPlain);
$mResult['Rtl'] = 0 < \strlen($mResult['Plain']) ? \MailSo\Base\Utils::IsRTL($mResult['Plain']) : false;
if (0 < $iTrimmedLimit && 'Messages' === $sParent) {
if ($iTrimmedLimit < strlen($mResult['Plain'])) {
$iPos = strpos($mResult['Plain'], ' ', $iTrimmedLimit);
if (false !== $iPos && $iTrimmedLimit <= $iPos) {
$mResult['Plain'] = substr($mResult['Plain'], 0, $iPos);
$mResult['Trimmed'] = true;
}
}
if ($iTrimmedLimit < strlen($mResult['Html'])) {
$iPos = strpos($mResult['Html'], ' <', $iTrimmedLimit);
if (false !== $iPos && $iTrimmedLimit <= $iPos) {
$mResult['Html'] = substr($mResult['Html'], 0, $iPos) . '<!-- cutted -->';
$mResult['Trimmed'] = true;
}
}
}
$mResult['ICAL'] = $this->responseObject($oAccount, $mResponse->getExtend('ICAL'), $sParent, $aParameters);
$mResult['VCARD'] = $this->responseObject($oAccount, $mResponse->getExtend('VCARD'), $sParent, $aParameters);
$mResult['Safety'] = $mResponse->getSafety();
$mResult['HasExternals'] = $bHasExternals;
$mResult['FoundedCIDs'] = $aFoundedCIDs;
//.........這裏部分代碼省略.........
示例5: responseObject
/**
* @param mixed $mResponse
* @param string $sParent
* @param array $aParameters = array()
*
* @return mixed
*/
protected function responseObject($mResponse, $sParent = '', $aParameters = array())
{
$mResult = $mResponse;
if (\is_object($mResponse)) {
$bHook = true;
$self = $this;
$sClassName = \get_class($mResponse);
$bHasSimpleJsonFunc = \method_exists($mResponse, 'ToSimpleJSON');
$bThumb = $this->GetCapa(false, \RainLoop\Enumerations\Capa::ATTACHMENT_THUMBNAILS);
$oAccountCache = null;
$fGetAccount = function () use($self, &$oAccountCache) {
if (null === $oAccountCache) {
$oAccount = $self->getAccountFromToken(false);
$oAccountCache = $oAccount;
}
return $oAccountCache;
};
$aCheckableFoldersCache = null;
$fGetCheckableFolder = function () use($self, &$aCheckableFoldersCache) {
if (null === $aCheckableFoldersCache) {
$oAccount = $self->getAccountFromToken(false);
$oSettingsLocal = $self->SettingsProvider(true)->Load($oAccount);
$sCheckable = $oSettingsLocal->GetConf('CheckableFolder', '[]');
$aCheckable = @\json_decode($sCheckable);
if (!\is_array($aCheckable)) {
$aCheckable = array();
}
$aCheckableFoldersCache = $aCheckable;
}
return $aCheckableFoldersCache;
};
if ($bHasSimpleJsonFunc) {
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), $mResponse->ToSimpleJSON(true));
} else {
if ('MailSo\\Mail\\Message' === $sClassName) {
$oAccount = \call_user_func($fGetAccount);
$iDateTimeStampInUTC = $mResponse->InternalTimeStampInUTC();
if (0 === $iDateTimeStampInUTC || !!$this->Config()->Get('labs', 'date_from_headers', false)) {
$iDateTimeStampInUTC = $mResponse->HeaderTimeStampInUTC();
if (0 === $iDateTimeStampInUTC) {
$iDateTimeStampInUTC = $mResponse->InternalTimeStampInUTC();
}
}
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Folder' => $mResponse->Folder(), 'Uid' => (string) $mResponse->Uid(), 'Subject' => \trim(\MailSo\Base\Utils::Utf8Clear($mResponse->Subject())), 'MessageId' => $mResponse->MessageId(), 'Size' => $mResponse->Size(), 'DateTimeStampInUTC' => $iDateTimeStampInUTC, 'ReplyTo' => $this->responseObject($mResponse->ReplyTo(), $sParent, $aParameters), 'From' => $this->responseObject($mResponse->From(), $sParent, $aParameters), 'To' => $this->responseObject($mResponse->To(), $sParent, $aParameters), 'Cc' => $this->responseObject($mResponse->Cc(), $sParent, $aParameters), 'Bcc' => $this->responseObject($mResponse->Bcc(), $sParent, $aParameters), 'Sender' => $this->responseObject($mResponse->Sender(), $sParent, $aParameters), 'DeliveredTo' => $this->responseObject($mResponse->DeliveredTo(), $sParent, $aParameters), 'Priority' => $mResponse->Priority(), 'Threads' => $mResponse->Threads(), 'Sensitivity' => $mResponse->Sensitivity(), 'ExternalProxy' => false, 'ReadReceipt' => ''));
$mResult['SubjectParts'] = $this->explodeSubject($mResult['Subject']);
$oAttachments = $mResponse->Attachments();
$iAttachmentsCount = $oAttachments ? $oAttachments->Count() : 0;
$mResult['HasAttachments'] = 0 < $iAttachmentsCount;
$mResult['AttachmentsSpecData'] = $mResult['HasAttachments'] ? $oAttachments->SpecData() : array();
$sSubject = $mResult['Subject'];
$mResult['Hash'] = \md5($mResult['Folder'] . $mResult['Uid']);
$mResult['RequestHash'] = \RainLoop\Utils::EncodeKeyValuesQ(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeType' => 'message/rfc822', 'FileName' => (0 === \strlen($sSubject) ? 'message-' . $mResult['Uid'] : \MailSo\Base\Utils::ClearXss($sSubject)) . '.eml'));
// Flags
$aFlags = $mResponse->FlagsLowerCase();
$mResult['IsSeen'] = \in_array('\\seen', $aFlags);
$mResult['IsFlagged'] = \in_array('\\flagged', $aFlags);
$mResult['IsAnswered'] = \in_array('\\answered', $aFlags);
$mResult['IsDeleted'] = \in_array('\\deleted', $aFlags);
$sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', '');
$sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
$mResult['IsForwarded'] = 0 < \strlen($sForwardedFlag) && \in_array(\strtolower($sForwardedFlag), $aFlags);
$mResult['IsReadReceipt'] = 0 < \strlen($sReadReceiptFlag) && \in_array(\strtolower($sReadReceiptFlag), $aFlags);
if (!$this->GetCapa(false, \RainLoop\Enumerations\Capa::COMPOSER, $oAccount)) {
$mResult['IsReadReceipt'] = true;
}
$mResult['TextPartIsTrimmed'] = false;
if ('Message' === $sParent) {
$oAttachments = $mResponse->Attachments();
$bHasExternals = false;
$mFoundedCIDs = array();
$aContentLocationUrls = array();
$mFoundedContentLocationUrls = array();
if ($oAttachments && 0 < $oAttachments->Count()) {
$aList =& $oAttachments->GetAsArray();
foreach ($aList as $oAttachment) {
if ($oAttachment) {
$sContentLocation = $oAttachment->ContentLocation();
if ($sContentLocation && 0 < \strlen($sContentLocation)) {
$aContentLocationUrls[] = $oAttachment->ContentLocation();
}
}
}
}
$sPlain = '';
$sHtml = \trim($mResponse->Html());
if (0 === \strlen($sHtml)) {
$sPlain = \trim($mResponse->Plain());
}
$mResult['DraftInfo'] = $mResponse->DraftInfo();
$mResult['InReplyTo'] = $mResponse->InReplyTo();
$mResult['References'] = $mResponse->References();
$fAdditionalDomReader = null;
if (0 < \strlen($sHtml) && $this->Config()->Get('labs', 'emogrifier', false)) {
//.........這裏部分代碼省略.........
示例6: InitByFetchResponse
//.........這裏部分代碼省略.........
if (0 < \strlen($sType) && 0 < \strlen($sFolder) && 0 < \strlen($sUid)) {
$this->aDraftInfo = array($sType, $sUid, $sFolder);
}
}
} else {
if ($oFetchResponse->GetEnvelope()) {
if (0 === \strlen($sCharset) && $oBodyStructure) {
$sCharset = $oBodyStructure->SearchCharset();
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
}
if (0 === \strlen($sCharset)) {
$sCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1;
}
// date, subject, from, sender, reply-to, to, cc, bcc, in-reply-to, message-id
$this->sMessageId = $oFetchResponse->GetFetchEnvelopeValue(9, '');
$this->sSubject = \MailSo\Base\Utils::DecodeHeaderValue($oFetchResponse->GetFetchEnvelopeValue(1, ''), $sCharset);
$this->oFrom = $oFetchResponse->GetFetchEnvelopeEmailCollection(2, $sCharset);
$this->oSender = $oFetchResponse->GetFetchEnvelopeEmailCollection(3, $sCharset);
$this->oReplyTo = $oFetchResponse->GetFetchEnvelopeEmailCollection(4, $sCharset);
$this->oTo = $oFetchResponse->GetFetchEnvelopeEmailCollection(5, $sCharset);
$this->oCc = $oFetchResponse->GetFetchEnvelopeEmailCollection(6, $sCharset);
$this->oBcc = $oFetchResponse->GetFetchEnvelopeEmailCollection(7, $sCharset);
$this->sInReplyTo = $oFetchResponse->GetFetchEnvelopeValue(8, '');
}
}
$aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : null;
if (\is_array($aTextParts) && 0 < \count($aTextParts)) {
if (0 === \strlen($sCharset)) {
$sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
}
$sHtmlParts = array();
$sPlainParts = array();
foreach ($aTextParts as $oPart) {
$sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oPart->PartID() . ']');
if (null === $sText) {
$sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oPart->PartID() . ']<0>');
if (\is_string($sText) && 0 < \strlen($sText)) {
$this->bTextPartIsTrimmed = true;
}
}
if (\is_string($sText) && 0 < \strlen($sText)) {
$sTextCharset = $oPart->Charset();
if (empty($sTextCharset)) {
$sTextCharset = $sCharset;
}
$sTextCharset = \MailSo\Base\Utils::NormalizeCharset($sTextCharset, true);
$sText = \MailSo\Base\Utils::DecodeEncodingValue($sText, $oPart->MailEncodingName());
$sText = \MailSo\Base\Utils::ConvertEncoding($sText, $sTextCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
$sText = \MailSo\Base\Utils::Utf8Clear($sText);
if ('text/html' === $oPart->ContentType()) {
$sHtmlParts[] = $sText;
} else {
$sPlainParts[] = $sText;
}
}
}
if (0 < \count($sHtmlParts)) {
$this->sHtml = \implode('<br />', $sHtmlParts);
} else {
$this->sPlain = \trim(\implode("\n", $sPlainParts));
}
$aMatch = array();
if (\preg_match('/-----BEGIN PGP SIGNATURE-----(.+)-----END PGP SIGNATURE-----/ism', $this->sPlain, $aMatch) && !empty($aMatch[0])) {
$this->sPgpSignature = \trim($aMatch[0]);
$this->bPgpSigned = true;
}
$aMatch = array();
if (\preg_match('/-----BEGIN PGP MESSAGE-----/ism', $this->sPlain, $aMatch) && !empty($aMatch[0])) {
$this->bPgpEncrypted = true;
}
unset($sHtmlParts, $sPlainParts, $aMatch);
}
// if (empty($this->sPgpSignature) && 'multipart/signed' === \strtolower($this->sContentType) &&
// 'application/pgp-signature' === \strtolower($oHeaders->ParameterValue(
// \MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
// \MailSo\Mime\Enumerations\Parameter::PROTOCOL
// )))
// {
// $aPgpSignatureParts = $oBodyStructure ? $oBodyStructure->SearchByContentType('application/pgp-signature') : null;
// if (\is_array($aPgpSignatureParts) && 0 < \count($aPgpSignatureParts) && isset($aPgpSignatureParts[0]))
// {
// $sPgpSignatureText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$aPgpSignatureParts[0]->PartID().']');
// if (\is_string($sPgpSignatureText) && 0 < \strlen($sPgpSignatureText) && 0 < \strpos($sPgpSignatureText, 'BEGIN PGP SIGNATURE'))
// {
// $this->sPgpSignature = \trim($sPgpSignatureText);
// $this->bPgpSigned = true;
// }
// }
// }
if ($oBodyStructure) {
$aAttachmentsParts = $oBodyStructure->SearchAttachmentsParts();
if ($aAttachmentsParts && 0 < count($aAttachmentsParts)) {
$this->oAttachments = AttachmentCollection::NewInstance();
foreach ($aAttachmentsParts as $oAttachmentItem) {
$this->oAttachments->Add(\MailSo\Mail\Attachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem));
}
}
}
return $this;
}
示例7: PopulateByVCard
public function PopulateByVCard($sVCard, $sEtag = '')
{
$this->Properties = array();
if (!empty($sEtag)) {
$this->Etag = $sEtag;
}
try {
$oVCard = \Sabre\VObject\Reader::read($sVCard);
} catch (\Exception $oExc) {
}
$aProperties = array();
if ($oVCard) {
$bOldVersion = empty($oVCard->VERSION) ? false : \in_array((string) $oVCard->VERSION, array('2.1', '2.0', '1.0'));
$this->IdContactStr = $oVCard->UID ? (string) $oVCard->UID : \Sabre\DAV\UUIDUtil::getUUID();
if (isset($oVCard->FN) && '' !== \trim($oVCard->FN)) {
$sValue = $this->getPropertyValueHelper($oVCard->FN, $bOldVersion);
$aProperties[] = new Property(PropertyType::FULLNAME, $sValue);
}
if (isset($oVCard->NICKNAME) && '' !== \trim($oVCard->NICKNAME)) {
$sValue = $sValue = $this->getPropertyValueHelper($oVCard->NICKNAME, $bOldVersion);
$aProperties[] = new Property(PropertyType::NICK_NAME, $sValue);
}
if (isset($oVCard->NOTE) && '' !== \trim($oVCard->NOTE)) {
$sValue = $this->getPropertyValueHelper($oVCard->NOTE, $bOldVersion);
$aProperties[] = new Property(PropertyType::NOTE, $sValue);
}
if (isset($oVCard->N)) {
$aNames = $oVCard->N->getParts();
foreach ($aNames as $iIndex => $sValue) {
$sValue = \trim($sValue);
if ($bOldVersion && !isset($oVCard->N->parameters['CHARSET'])) {
if (0 < \strlen($sValue)) {
$sEncValue = @\utf8_encode($sValue);
if (0 === \strlen($sEncValue)) {
$sEncValue = $sValue;
}
$sValue = $sEncValue;
}
}
$sValue = \MailSo\Base\Utils::Utf8Clear($sValue);
switch ($iIndex) {
case 0:
$aProperties[] = new Property(PropertyType::LAST_NAME, $sValue);
break;
case 1:
$aProperties[] = new Property(PropertyType::FIRST_NAME, $sValue);
break;
case 2:
$aProperties[] = new Property(PropertyType::MIDDLE_NAME, $sValue);
break;
case 3:
$aProperties[] = new Property(PropertyType::NAME_PREFIX, $sValue);
break;
case 4:
$aProperties[] = new Property(PropertyType::NAME_SUFFIX, $sValue);
break;
}
}
}
if (isset($oVCard->EMAIL)) {
$this->addArrayPropertyHelper($aProperties, $oVCard->EMAIL, PropertyType::EMAIl);
}
if (isset($oVCard->URL)) {
$this->addArrayPropertyHelper($aProperties, $oVCard->URL, PropertyType::WEB_PAGE);
}
if (isset($oVCard->TEL)) {
$this->addArrayPropertyHelper($aProperties, $oVCard->TEL, PropertyType::PHONE);
}
$this->Properties = $aProperties;
if (isset($oVCard->CATEGORIES)) {
$this->Tags = (array) $oVCard->CATEGORIES->getParts();
$this->Tags = \is_array($this->Tags) ? $this->Tags : array();
$this->Tags = \array_map('trim', $this->Tags);
}
}
$this->UpdateDependentValues();
}
示例8: InitByFetchResponse
//.........這裏部分代碼省略.........
// ReadingConfirmation
$this->sReadingConfirmation = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DISPOSITION_NOTIFICATION_TO);
if (0 === strlen($this->sReadingConfirmation)) {
$this->sReadingConfirmation = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_CONFIRM_READING_TO);
}
$this->sReadingConfirmation = trim($this->sReadingConfirmation);
$sDraftInfo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_DRAFT_INFO);
if (0 < strlen($sDraftInfo)) {
$sType = '';
$sFolder = '';
$sUid = '';
\MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo)->ForeachList(function ($oParameter) use(&$sType, &$sFolder, &$sUid) {
switch (strtolower($oParameter->Name())) {
case 'type':
$sType = $oParameter->Value();
break;
case 'uid':
$sUid = $oParameter->Value();
break;
case 'folder':
$sFolder = base64_decode($oParameter->Value());
break;
}
});
if (0 < strlen($sType) && 0 < strlen($sFolder) && 0 < strlen($sUid)) {
$this->aDraftInfo = array($sType, $sUid, $sFolder);
}
}
\CApi::Plugin()->RunHook('api-mail-message-headers-parse', array(&$this, $oHeaders));
}
if (is_array($aTextParts) && 0 < count($aTextParts)) {
if (0 === \strlen($sCharset)) {
$sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
}
$sHtmlParts = array();
$sPlainParts = array();
$iHtmlSize = 0;
$iPlainSize = 0;
foreach ($aTextParts as $oPart) {
if ($oPart) {
if ('text/html ' === $oPart->ContentType()) {
$iHtmlSize += $oPart->EstimatedSize();
} else {
$iPlainSize += $oPart->EstimatedSize();
}
}
$sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oPart->PartID() . ('' !== $sRfc822SubMimeIndex && is_numeric($sRfc822SubMimeIndex) ? '.1' : '') . ']');
// if (null === $sText)
// {
// $sText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$oPart->PartID().
// ('' !== $sRfc822SubMimeIndex && is_numeric($sRfc822SubMimeIndex) ? '.1' : '').']<0>');
// }
if (is_string($sText) && 0 < strlen($sText)) {
$sTextCharset = $oPart->Charset();
if (empty($sTextCharset)) {
$sTextCharset = $sCharset;
}
$sTextCharset = \MailSo\Base\Utils::NormalizeCharset($sTextCharset, true);
$sText = \MailSo\Base\Utils::DecodeEncodingValue($sText, $oPart->MailEncodingName());
$sText = \MailSo\Base\Utils::ConvertEncoding($sText, $sTextCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
$sText = \MailSo\Base\Utils::Utf8Clear($sText);
if ('text/html' === $oPart->ContentType()) {
$sHtmlParts[] = $sText;
} else {
$sPlainParts[] = $sText;
}
}
}
if (0 < count($sHtmlParts)) {
$this->sHtml = trim(implode('<br />', $sHtmlParts));
$this->iTextSize = strlen($this->sHtml);
} else {
$this->sPlain = trim(implode("\n", $sPlainParts));
$this->iTextSize = strlen($this->sPlain);
}
if (0 === $this->iTextSize) {
$this->iTextSize = 0 < $iHtmlSize ? $iHtmlSize : $iPlainSize;
}
unset($sHtmlParts, $sPlainParts);
}
if ($oBodyStructure) {
$aAttachmentsParts = $oBodyStructure->SearchAttachmentsParts();
if ($aAttachmentsParts && 0 < count($aAttachmentsParts)) {
$this->oAttachments = CApiMailAttachmentCollection::NewInstance();
foreach ($aAttachmentsParts as $oAttachmentItem) {
$this->oAttachments->Add(CApiMailAttachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem));
}
$this->oAttachments->ForeachList(function ($oAttachment) use($aAscPartsIds, $oFetchResponse) {
if ($oAttachment && in_array($oAttachment->MimeIndex(), $aAscPartsIds)) {
$mContent = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oAttachment->MimeIndex() . ']');
if (is_string($mContent)) {
$oAttachment->SetContent(\MailSo\Base\Utils::DecodeEncodingValue($mContent, $oAttachment->ContentTransferEncoding()));
}
}
});
}
}
\CApi::Plugin()->RunHook('api-mail-message-parse', array(&$this, $oFetchResponse, $oBodyStructure, $sRfc822SubMimeIndex));
return $this;
}
示例9: PopulateByVCard
public function PopulateByVCard($sUid, $sVCard, $sEtag = '', $oLogger = null)
{
if ("" === \substr($sVCard, 0, 3)) {
$sVCard = \substr($sVCard, 3);
}
$this->Properties = array();
if (!\class_exists('SabreForRainLoop\\DAV\\Client')) {
return false;
}
if (!empty($sEtag)) {
$this->Etag = $sEtag;
}
$this->IdContactStr = $sUid;
try {
$oVCard = \SabreForRainLoop\VObject\Reader::read($sVCard);
} catch (\Exception $oExc) {
if ($oLogger) {
$oLogger->WriteException($oExc);
$oLogger->WriteDump($sVCard);
}
}
// if ($oLogger)
// {
// $oLogger->WriteDump($sVCard);
// }
$bOwnCloud = false;
$aProperties = array();
if ($oVCard) {
$bOwnCloud = empty($oVCard->PRODID) ? false : false !== \strpos(\strtolower($oVCard->PRODID), 'owncloud');
$bOldVersion = empty($oVCard->VERSION) ? false : \in_array((string) $oVCard->VERSION, array('2.1', '2.0', '1.0'));
if (isset($oVCard->FN) && '' !== \trim($oVCard->FN)) {
$sValue = $this->getPropertyValueHelper($oVCard->FN, $bOldVersion);
$aProperties[] = new Property(PropertyType::FULLNAME, $sValue);
}
if (isset($oVCard->NICKNAME) && '' !== \trim($oVCard->NICKNAME)) {
$sValue = $sValue = $this->getPropertyValueHelper($oVCard->NICKNAME, $bOldVersion);
$aProperties[] = new Property(PropertyType::NICK_NAME, $sValue);
}
if (isset($oVCard->NOTE) && '' !== \trim($oVCard->NOTE)) {
$sValue = $this->getPropertyValueHelper($oVCard->NOTE, $bOldVersion);
$aProperties[] = new Property(PropertyType::NOTE, $sValue);
}
if (isset($oVCard->N)) {
$aNames = $oVCard->N->getParts();
foreach ($aNames as $iIndex => $sValue) {
$sValue = \trim($sValue);
if ($bOldVersion && !isset($oVCard->N->parameters['CHARSET'])) {
if (0 < \strlen($sValue)) {
$sEncValue = @\utf8_encode($sValue);
if (0 === \strlen($sEncValue)) {
$sEncValue = $sValue;
}
$sValue = $sEncValue;
}
}
$sValue = \MailSo\Base\Utils::Utf8Clear($sValue);
switch ($iIndex) {
case 0:
$aProperties[] = new Property(PropertyType::LAST_NAME, $sValue);
break;
case 1:
$aProperties[] = new Property(PropertyType::FIRST_NAME, $sValue);
break;
case 2:
$aProperties[] = new Property(PropertyType::MIDDLE_NAME, $sValue);
break;
case 3:
$aProperties[] = new Property(PropertyType::NAME_PREFIX, $sValue);
break;
case 4:
$aProperties[] = new Property(PropertyType::NAME_SUFFIX, $sValue);
break;
}
}
}
if (isset($oVCard->EMAIL)) {
$this->addArrayPropertyHelper($aProperties, $oVCard->EMAIL, PropertyType::EMAIl);
}
if (isset($oVCard->URL)) {
$this->addArrayPropertyHelper($aProperties, $oVCard->URL, PropertyType::WEB_PAGE);
}
if (isset($oVCard->TEL)) {
$this->addArrayPropertyHelper($aProperties, $oVCard->TEL, PropertyType::PHONE);
}
$sUidValue = $oVCard->UID ? (string) $oVCard->UID : \SabreForRainLoop\DAV\UUIDUtil::getUUID();
$aProperties[] = new Property(PropertyType::UID, $sUidValue);
if (empty($this->IdContactStr)) {
$this->IdContactStr = $sUidValue;
}
$this->Properties = $aProperties;
}
$this->UpdateDependentValues();
return true;
}
示例10: responseObject
/**
* @param mixed $mResponse
* @param string $sParent
* @param array $aParameters = array()
*
* @return mixed
*/
protected function responseObject($mResponse, $sParent = '', $aParameters = array())
{
$mResult = $mResponse;
if (\is_object($mResponse)) {
$bHook = true;
$sClassName = \get_class($mResponse);
$bHasSimpleJsonFunc = \method_exists($mResponse, 'ToSimpleJSON');
$bThumb = $this->GetCapa(false, \RainLoop\Enumerations\Capa::ATTACHMENT_THUMBNAILS);
if ($bHasSimpleJsonFunc) {
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), $mResponse->ToSimpleJSON(true));
} else {
if ('MailSo\\Mail\\Message' === $sClassName) {
$oAccount = $this->getAccountFromToken(false);
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array('Folder' => $mResponse->Folder(), 'Uid' => (string) $mResponse->Uid(), 'Subject' => \trim(\MailSo\Base\Utils::Utf8Clear($mResponse->Subject())), 'MessageId' => $mResponse->MessageId(), 'Size' => $mResponse->Size(), 'DateTimeStampInUTC' => !!$this->Config()->Get('labs', 'date_from_headers', false) ? $mResponse->HeaderTimeStampInUTC() : $mResponse->InternalTimeStampInUTC(), 'ReplyTo' => $this->responseObject($mResponse->ReplyTo(), $sParent, $aParameters), 'From' => $this->responseObject($mResponse->From(), $sParent, $aParameters), 'To' => $this->responseObject($mResponse->To(), $sParent, $aParameters), 'Cc' => $this->responseObject($mResponse->Cc(), $sParent, $aParameters), 'Bcc' => $this->responseObject($mResponse->Bcc(), $sParent, $aParameters), 'Sender' => $this->responseObject($mResponse->Sender(), $sParent, $aParameters), 'DeliveredTo' => $this->responseObject($mResponse->DeliveredTo(), $sParent, $aParameters), 'Priority' => $mResponse->Priority(), 'Threads' => $mResponse->Threads(), 'ThreadsLen' => $mResponse->ThreadsLen(), 'ParentThread' => $mResponse->ParentThread(), 'Sensitivity' => $mResponse->Sensitivity(), 'ExternalProxy' => false, 'ReadReceipt' => ''));
$mResult['SubjectParts'] = $this->explodeSubject($mResult['Subject']);
$oAttachments = $mResponse->Attachments();
$iAttachmentsCount = $oAttachments ? $oAttachments->Count() : 0;
$mResult['HasAttachments'] = 0 < $iAttachmentsCount;
$mResult['AttachmentsMainType'] = '';
if (0 < $iAttachmentsCount) {
switch (true) {
case $iAttachmentsCount === $oAttachments->ImageCount():
$mResult['AttachmentsMainType'] = 'image';
break;
case $iAttachmentsCount === $oAttachments->ArchiveCount():
$mResult['AttachmentsMainType'] = 'archive';
break;
case $iAttachmentsCount === $oAttachments->PdfCount():
$mResult['AttachmentsMainType'] = 'pdf';
break;
case $iAttachmentsCount === $oAttachments->DocCount():
$mResult['AttachmentsMainType'] = 'doc';
break;
case $iAttachmentsCount === $oAttachments->CertificateCount():
$mResult['AttachmentsMainType'] = 'certificate';
break;
}
}
$sSubject = $mResult['Subject'];
$mResult['Hash'] = \md5($mResult['Folder'] . $mResult['Uid']);
$mResult['RequestHash'] = \RainLoop\Utils::EncodeKeyValues(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'Folder' => $mResult['Folder'], 'Uid' => $mResult['Uid'], 'MimeType' => 'message/rfc822', 'FileName' => (0 === \strlen($sSubject) ? 'message-' . $mResult['Uid'] : \MailSo\Base\Utils::ClearXss($sSubject)) . '.eml'));
// Flags
$aFlags = $mResponse->FlagsLowerCase();
$mResult['IsSeen'] = \in_array('\\seen', $aFlags);
$mResult['IsFlagged'] = \in_array('\\flagged', $aFlags);
$mResult['IsAnswered'] = \in_array('\\answered', $aFlags);
$mResult['IsDeleted'] = \in_array('\\deleted', $aFlags);
$sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', '');
$sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
$mResult['IsForwarded'] = 0 < \strlen($sForwardedFlag) && \in_array(\strtolower($sForwardedFlag), $aFlags);
$mResult['IsReadReceipt'] = 0 < \strlen($sReadReceiptFlag) && \in_array(\strtolower($sReadReceiptFlag), $aFlags);
$mResult['TextPartIsTrimmed'] = false;
if ('Message' === $sParent) {
$oAttachments = $mResponse->Attachments();
$bHasExternals = false;
$mFoundedCIDs = array();
$aContentLocationUrls = array();
$mFoundedContentLocationUrls = array();
if ($oAttachments && 0 < $oAttachments->Count()) {
$aList =& $oAttachments->GetAsArray();
foreach ($aList as $oAttachment) {
if ($oAttachment) {
$sContentLocation = $oAttachment->ContentLocation();
if ($sContentLocation && 0 < \strlen($sContentLocation)) {
$aContentLocationUrls[] = $oAttachment->ContentLocation();
}
}
}
}
$sPlain = '';
$sHtml = \trim($mResponse->Html());
if (0 === \strlen($sHtml)) {
$sPlain = \trim($mResponse->Plain());
}
$mResult['DraftInfo'] = $mResponse->DraftInfo();
$mResult['InReplyTo'] = $mResponse->InReplyTo();
$mResult['References'] = $mResponse->References();
$fAdditionalExternalFilter = null;
if (!!$this->Config()->Get('labs', 'use_local_proxy_for_external_images', false)) {
$fAdditionalExternalFilter = function ($sUrl) {
return './?/ProxyExternal/' . \RainLoop\Utils::EncodeKeyValues(array('Rnd' => \md5(\microtime(true)), 'Token' => \RainLoop\Utils::GetConnectionToken(), 'Url' => $sUrl)) . '/';
};
}
$mResult['Html'] = 0 === \strlen($sHtml) ? '' : \MailSo\Base\HtmlUtils::ClearHtml($sHtml, $bHasExternals, $mFoundedCIDs, $aContentLocationUrls, $mFoundedContentLocationUrls, false, false, $fAdditionalExternalFilter);
$mResult['ExternalProxy'] = null !== $fAdditionalExternalFilter;
$mResult['Plain'] = $sPlain;
// $mResult['Plain'] = 0 === \strlen($sPlain) ? '' : \MailSo\Base\HtmlUtils::ConvertPlainToHtml($sPlain);
$mResult['TextHash'] = \md5($mResult['Html'] . $mResult['Plain']);
$mResult['TextPartIsTrimmed'] = $mResponse->TextPartIsTrimmed();
$mResult['PgpSigned'] = $mResponse->PgpSigned();
$mResult['PgpEncrypted'] = $mResponse->PgpEncrypted();
$mResult['PgpSignature'] = $mResponse->PgpSignature();
unset($sHtml, $sPlain);
//.........這裏部分代碼省略.........