Esempio n. 1
0
#pragma warning disable CS8765 // Nullability of parameters 'name' and 'value' don't match overridden member
        public override void Set(string name, string value)
#pragma warning restore CS8765
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

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

            if (name.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(name)), nameof(name));
            }

            if (value.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(value)), nameof(value));
            }

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

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

            value = value.Normalize(NormalizationForm.FormC);

            base.Set(name, value);
        }
Esempio n. 2
0
        public override void Set(string name, string value)
        {
            if (Logging.On)
            {
                Logging.PrintInfo(Logging.Web, this, "Set", name.ToString() + "=" + value.ToString());
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

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

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

            if (value == string.Empty)
            {
                throw new ArgumentException(SR.GetString(SR.net_emptystringcall, nameof(value)), nameof(value));
            }

            if (!MimeBasePart.IsAscii(name, false))
            {
                throw new FormatException(SR.GetString(SR.InvalidHeaderName));
            }

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

            MailHeaderID id = MailHeaderInfo.GetID(name);

            value = value.Normalize(Text.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);
            }
        }
Esempio n. 3
0
#pragma warning disable CS8610 // Nullability of reference types in type of parameter doesn't match overridden member.
        public override void Set(string name, string value)
#pragma warning restore CS8610
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

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

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

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

            if (!MimeBasePart.IsAscii(name, false))
            {
                throw new FormatException(SR.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.ToLowerInvariant(), this);
            }
            else if (id == MailHeaderID.ContentDisposition && _part is MimePart)
            {
                ((MimePart)_part).ContentDisposition !.Set(value.ToLowerInvariant(), this);
            }
            else
            {
                base.Set(name, value);
            }
        }
Esempio n. 4
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(SR.Format(SR.net_emptystringcall, nameof(name)), nameof(name));
            }

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

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

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

            MailHeaderID id = MailHeaderInfo.GetID(name);

            // TODO https://github.com/dotnet/corefx/issues/11747: Uncomment once we can use NormalizationForm
            //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);
            }
        }
Esempio n. 5
0
#pragma warning disable CS8765 // Nullability of parameters 'name' and 'value' don't match overridden member
        public override void Set(string name, string value)
#pragma warning restore CS8765
        {
            ArgumentException.ThrowIfNullOrEmpty(name);
            ArgumentException.ThrowIfNullOrEmpty(value);

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

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

            value = value.Normalize(NormalizationForm.FormC);

            base.Set(name, value);
        }
        public override void Set(string name, string value)
        {
            if (Logging.On)
            {
                Logging.PrintInfo(Logging.Web, this, "Set", name.ToString() + "=" + value.ToString());
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (name == string.Empty)
            {
                throw new ArgumentException(SR.GetString("net_emptystringcall", new object[] { "name" }), "name");
            }
            if (value == string.Empty)
            {
                throw new ArgumentException(SR.GetString("net_emptystringcall", new object[] { "value" }), "name");
            }
            if (!MimeBasePart.IsAscii(name, false))
            {
                throw new FormatException(SR.GetString("InvalidHeaderName"));
            }
            name = MailHeaderInfo.NormalizeCase(name);
            MailHeaderID iD = MailHeaderInfo.GetID(name);

            if ((iD == MailHeaderID.ContentType) && (this.part != null))
            {
                this.part.ContentType.Set(value.ToLower(CultureInfo.InvariantCulture), this);
            }
            else if ((iD == MailHeaderID.ContentDisposition) && (this.part is MimePart))
            {
                ((MimePart)this.part).ContentDisposition.Set(value.ToLower(CultureInfo.InvariantCulture), this);
            }
            else
            {
                base.Set(name, value);
            }
        }
Esempio n. 7
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('"');
            }
        }