コード例 #1
0
 public void AddInjectedText(string prefix, string suffix, BodyInjectionFormat format)
 {
     if (prefix == null && suffix == null)
     {
         throw new ArgumentException("Either prefix or suffix should be non-null");
     }
     EnumValidator.ThrowIfInvalid <BodyInjectionFormat>(format, "format");
     this.injectPrefix = prefix;
     this.injectSuffix = suffix;
     this.injectFormat = format;
 }
コード例 #2
0
        public void CopyBodyInjectingText(IBody targetBody, BodyInjectionFormat injectionFormat, string prefixInjectionText, string suffixInjectionText)
        {
            if (string.IsNullOrEmpty(prefixInjectionText) && string.IsNullOrEmpty(suffixInjectionText))
            {
                return;
            }
            BodyFormat bodyFormat = this.Format;

            if (bodyFormat == BodyFormat.ApplicationRtf)
            {
                bodyFormat = BodyFormat.TextHtml;
            }
            using (Stream stream = this.OpenReadStream(new BodyReadConfiguration(bodyFormat, this.Charset)))
            {
                BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(bodyFormat, this.Charset);
                bodyWriteConfiguration.SetTargetFormat(this.Format, this.Charset);
                bodyWriteConfiguration.AddInjectedText(prefixInjectionText, suffixInjectionText, injectionFormat);
                using (Stream stream2 = targetBody.OpenWriteStream(bodyWriteConfiguration))
                {
                    Util.StreamHandler.CopyStreamData(stream, stream2, null, 0, 65536);
                }
            }
        }
コード例 #3
0
        private static void InternalCopyBody(Body source, Body target, CultureInfo cultureInfo, bool removeMungageData, string prefix, BodyInjectionFormat prefixFormat, bool disableCharsetDetection = false)
        {
            BodyReadConfiguration  bodyReadConfiguration  = new BodyReadConfiguration(source.RawFormat, source.RawCharset.Name);
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(source.RawFormat, source.RawCharset.Name);

            if (disableCharsetDetection)
            {
                bodyWriteConfiguration.SetTargetFormat(source.RawFormat, source.Charset, BodyCharsetFlags.DisableCharsetDetection);
            }
            else
            {
                bodyWriteConfiguration.SetTargetFormat(source.RawFormat, source.Charset);
            }
            if (!string.IsNullOrEmpty(prefix))
            {
                bodyWriteConfiguration.AddInjectedText(prefix, null, prefixFormat);
            }
            bool flag = false;

            if (removeMungageData)
            {
                flag = Body.CopyBodyWithoutMungage(source, target, cultureInfo, bodyReadConfiguration, bodyWriteConfiguration);
            }
            if (!flag)
            {
                using (Stream stream = source.OpenReadStream(bodyReadConfiguration))
                {
                    using (Stream stream2 = target.OpenWriteStream(bodyWriteConfiguration))
                    {
                        Util.StreamHandler.CopyStreamData(stream, stream2, null, 0, 16384);
                    }
                }
            }
        }
コード例 #4
0
 public void AddBodyPrefix(string bodyPrefix, BodyInjectionFormat bodyPrefixFormat)
 {
     EnumValidator.ThrowIfInvalid <BodyInjectionFormat>(bodyPrefixFormat, "bodyPrefixFormat");
     this.bodyPrefix       = bodyPrefix;
     this.bodyPrefixFormat = bodyPrefixFormat;
 }