Example #1
0
 internal bool IsItemCharsetKnownWithoutDetection(BodyCharsetFlags flags, Charset userCharset, out Charset targetCharset)
 {
     targetCharset = null;
     if (userCharset == null)
     {
         userCharset = this.detectionOptions.PreferredCharset;
     }
     if (userCharset == null)
     {
         return(false);
     }
     if (this.IsCharsetDetectionDisabled(flags))
     {
         targetCharset = this.OverrideCharset(flags, userCharset);
         return(true);
     }
     if (userCharset.CodePage == 54936)
     {
         targetCharset = userCharset;
         return(true);
     }
     if (BodyCharsetFlags.PreserveUnicode == (BodyCharsetFlags.PreserveUnicode & flags))
     {
         Charset charset = this.OverrideCharset(flags, userCharset);
         if (charset.CodePage == 65000 || charset.CodePage == 65001)
         {
             targetCharset = charset;
             return(true);
         }
     }
     return(false);
 }
Example #2
0
 private int OverrideCodePage(BodyCharsetFlags charsetFlags, int cpid)
 {
     if (cpid == 936)
     {
         if ((charsetFlags & BodyCharsetFlags.PreferGB18030) != BodyCharsetFlags.PreferGB18030)
         {
             return(936);
         }
         return(54936);
     }
     else if (cpid == 28591)
     {
         if ((charsetFlags & BodyCharsetFlags.PreferIso885915) != BodyCharsetFlags.PreferIso885915)
         {
             return(28591);
         }
         return(28605);
     }
     else if (cpid == 932)
     {
         if ((charsetFlags & BodyCharsetFlags.DoNotPreferIso2022jp) == BodyCharsetFlags.DoNotPreferIso2022jp)
         {
             return(932);
         }
         return(this.detectionOptions.PreferredInternetCodePageForShiftJis);
     }
     else
     {
         if (cpid == 1200 || cpid == 1201)
         {
             return(65001);
         }
         return(cpid);
     }
 }
Example #3
0
        private Charset OverrideCharset(BodyCharsetFlags flags, Charset charset)
        {
            int num = this.OverrideCodePage(flags, charset.CodePage);

            if (charset.CodePage != num)
            {
                return(Charset.GetCharset(num));
            }
            return(charset);
        }
 public void SetTargetFormat(BodyFormat targetFormat, Charset targetCharset, BodyCharsetFlags flags)
 {
     EnumValidator.ThrowIfInvalid <BodyFormat>(targetFormat, "targetFormat");
     if (targetCharset == null && (flags & BodyCharsetFlags.CharsetDetectionMask) == BodyCharsetFlags.DisableCharsetDetection)
     {
         throw new ArgumentNullException("targetCharset");
     }
     this.targetCharset      = targetCharset;
     this.targetFormat       = targetFormat;
     this.targetCharsetFlags = flags;
 }
        // Token: 0x06002FC0 RID: 12224 RVA: 0x00115C40 File Offset: 0x00113E40
        public static BodyCharsetFlags GetBodyCharsetOptions(UserContext userContext, out string charsetName)
        {
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            BodyCharsetFlags bodyCharsetFlags = BodyCharsetFlags.None;

            if (userContext.UseGB18030)
            {
                bodyCharsetFlags |= BodyCharsetFlags.PreferGB18030;
            }
            if (userContext.UseISO885915)
            {
                bodyCharsetFlags |= BodyCharsetFlags.PreferIso885915;
            }
            if (userContext.OutboundCharset == OutboundCharsetOptions.AlwaysUTF8)
            {
                bodyCharsetFlags |= BodyCharsetFlags.DisableCharsetDetection;
                charsetName       = "utf-8";
            }
            else
            {
                if (userContext.OutboundCharset == OutboundCharsetOptions.UserLanguageChoice)
                {
                    bodyCharsetFlags |= BodyCharsetFlags.DisableCharsetDetection;
                }
                else
                {
                    bodyCharsetFlags = bodyCharsetFlags;
                }
                CultureInfo userCulture = Microsoft.Exchange.Clients.Owa.Core.Culture.GetUserCulture();
                Microsoft.Exchange.Data.Globalization.Culture culture = null;
                if (Microsoft.Exchange.Data.Globalization.Culture.TryGetCulture(userCulture.Name, out culture))
                {
                    Charset mimeCharset = culture.MimeCharset;
                    if (mimeCharset.IsAvailable)
                    {
                        charsetName = mimeCharset.Name;
                        return(bodyCharsetFlags);
                    }
                }
                charsetName = Microsoft.Exchange.Data.Globalization.Culture.Default.MimeCharset.Name;
            }
            return(bodyCharsetFlags);
        }
        public void SetTargetFormat(BodyFormat targetFormat, string targetCharsetName, BodyCharsetFlags flags)
        {
            EnumValidator.ThrowIfInvalid <BodyFormat>(targetFormat, "targetFormat");
            Charset charset = null;

            if (!string.IsNullOrEmpty(targetCharsetName))
            {
                charset = ConvertUtils.GetCharsetFromCharsetName(targetCharsetName);
            }
            this.SetTargetFormat(targetFormat, charset, flags);
        }
        // Token: 0x06002FC9 RID: 12233 RVA: 0x0011611C File Offset: 0x0011431C
        internal static bool SetBody(Item item, string body, Markup markup, StoreObjectType storeObjectType, UserContext userContext)
        {
            bool flag = false;

            switch (markup)
            {
            case Markup.Html:
            {
                string                 targetCharsetName;
                BodyCharsetFlags       bodyCharsetOptions     = BodyConversionUtilities.GetBodyCharsetOptions(userContext, out targetCharsetName);
                BodyFormat             targetFormat           = (storeObjectType != StoreObjectType.CalendarItem && storeObjectType != StoreObjectType.MeetingMessage) ? BodyFormat.TextHtml : BodyFormat.ApplicationRtf;
                BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(BodyFormat.TextHtml);
                bodyWriteConfiguration.SetTargetFormat(targetFormat, targetCharsetName, bodyCharsetOptions);
                OwaSafeHtmlInboundCallbacks owaSafeHtmlInboundCallbacks = null;
                owaSafeHtmlInboundCallbacks = new OwaSafeHtmlInboundCallbacks(item, userContext);
                bodyWriteConfiguration.SetHtmlOptions(HtmlStreamingFlags.None, owaSafeHtmlInboundCallbacks);
                try
                {
                    Body body2 = item.Body;
                    if (userContext.IsIrmEnabled && Utilities.IsIrmDecrypted(item))
                    {
                        body2 = ((RightsManagedMessageItem)item).ProtectedBody;
                    }
                    using (TextWriter textWriter = body2.OpenTextWriter(bodyWriteConfiguration))
                    {
                        textWriter.Write(body);
                    }
                }
                catch (InvalidCharsetException innerException)
                {
                    throw new OwaEventHandlerException(LocalizedStrings.GetNonEncoded(1825027020), LocalizedStrings.GetNonEncoded(1825027020), innerException);
                }
                catch (TextConvertersException innerException2)
                {
                    throw new OwaEventHandlerException(LocalizedStrings.GetNonEncoded(1825027020), LocalizedStrings.GetNonEncoded(1825027020), innerException2);
                }
                Utilities.MakeModifiedCalendarItemOccurrence(item);
                bool flag2 = false;
                if (owaSafeHtmlInboundCallbacks != null)
                {
                    flag2 = owaSafeHtmlInboundCallbacks.AttachmentNeedsSave();
                }
                if (flag2 && !Utilities.IsClearSigned(item))
                {
                    flag = AttachmentUtility.ApplyAttachmentsUpdates(item, owaSafeHtmlInboundCallbacks);
                    item.Load();
                }
                break;
            }

            case Markup.PlainText:
                ItemUtility.SetItemBody(item, BodyFormat.TextPlain, body);
                flag = AttachmentUtility.PromoteInlineAttachments(item);
                if (flag)
                {
                    item.Load();
                }
                break;
            }
            return(flag);
        }
Example #8
0
        public BodyCharsetDetectionStream(Stream outputStream, BodyCharsetDetectionStream.DetectCharsetCallback callback, ICoreItem coreItem, BodyStreamFormat format, Charset contentCharset, Charset userCharset, BodyCharsetFlags charsetFlags, string extraData, bool trustHtmlMetaTag) : base(StreamBase.Capabilities.Writable)
        {
            this.outputStream = outputStream;
            this.callback     = callback;
            this.coreItem     = coreItem;
            this.userCharset  = userCharset;
            this.charsetFlags = charsetFlags;
            Charset charset;

            this.isDetectingCharset = !this.coreItem.CharsetDetector.IsItemCharsetKnownWithoutDetection(charsetFlags, userCharset, out charset);
            if (this.isDetectingCharset)
            {
                this.CreateDetectionStream(format, contentCharset, extraData, trustHtmlMetaTag);
                return;
            }
            this.CalculateCharset();
        }
Example #9
0
        public Charset SetCachedBodyDataAndDetectCharset(char[] cachedBodyData, Charset userCharset, BodyCharsetFlags charsetFlags)
        {
            this.cachedBodyData = cachedBodyData;
            this.CharsetFlags   = charsetFlags;
            if (userCharset == null)
            {
                userCharset = this.detectionOptions.PreferredCharset;
            }
            Charset charset;

            if (this.IsItemCharsetKnownWithoutDetection(charsetFlags, userCharset, out charset))
            {
                this.SetItemCharset(charset);
                return(charset);
            }
            MemoryStream memoryStream;
            int          num = this.DetectCpidWithOptions(userCharset, out memoryStream);

            if (!Charset.TryGetCharset(num, out charset) || !charset.IsAvailable)
            {
                ExTraceGlobals.StorageTracer.TraceError <int>((long)this.GetHashCode(), "SetCachedBodyAndDetectCharset: stamping codepage {0} not a valid charset", num);
            }
            this.SetItemCharset(charset);
            return(charset);
        }
Example #10
0
 private bool IsCharsetDetectionDisabled(BodyCharsetFlags flags)
 {
     return(this.DetectionOptions.RequiredCoverage == 0 || (flags & BodyCharsetFlags.CharsetDetectionMask) == BodyCharsetFlags.DisableCharsetDetection);
 }