Exemplo n.º 1
0
        public override void Set(string name, string value)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (name == string.Empty)
            {
                throw new ArgumentException(string.Format(Strings.net_emptystringcall, nameof(name)), nameof(name));
            }

            if (value == string.Empty)
            {
                throw new ArgumentException(string.Format(Strings.net_emptystringcall, nameof(value)), nameof(name));
            }

            if (!MimeBasePart.IsAscii(name, false))
            {
                throw new FormatException(string.Format(Strings.InvalidHeaderName));
            }

            // normalize the case of well known headers
            name = MailHeaderInfo.NormalizeCase(name);

            MailHeaderID id = MailHeaderInfo.GetID(name);

            value = value.Normalize(NormalizationForm.FormC);

            if (id == MailHeaderID.ContentType && _part != null)
            {
                _part.ContentType.Set(value.ToLower(CultureInfo.InvariantCulture), this);
            }
            else if (id == MailHeaderID.ContentDisposition && _part is MimePart)
            {
                ((MimePart)_part).ContentDisposition.Set(value.ToLower(CultureInfo.InvariantCulture), this);
            }
            else
            {
                base.Set(name, value);
            }
        }
Exemplo n.º 2
0
        private static void EncodeToBuffer(string value, StringBuilder builder, bool allowUnicode)
        {
            Encoding encoding = MimeBasePart.DecodeEncoding(value);

            if (encoding != null) // Manually encoded elsewhere, pass through
            {
                builder.Append('"').Append(value).Append('"');
            }
            else if ((allowUnicode && !MailBnfHelper.HasCROrLF(value)) || // Unicode without CL or LF's
                     MimeBasePart.IsAscii(value, false)) // Ascii
            {
                MailBnfHelper.GetTokenOrQuotedString(value, builder, allowUnicode);
            }
            else
            {
                // MIME Encoding required
                encoding = Encoding.GetEncoding(MimeBasePart.DefaultCharSet);
                builder.Append('"').Append(MimeBasePart.EncodeHeaderValue(value, encoding, MimeBasePart.ShouldUseBase64Encoding(encoding))).Append('"');
            }
        }
Exemplo n.º 3
0
 internal MimePartAsyncResult(MimeBasePart part, object state, AsyncCallback callback) : base(part, state, callback)
 {
 }