コード例 #1
0
 private void                    _setMimeVersion()
 {
     if (this is MimeMessage)
     {
         if (_fields["MIME-Version"] == null)
         {
             _fields.Add(new MimeField("MIME-Version", "1.0"));
         }
     }
 }
コード例 #2
0
        public MimeFields      ReadFields()
        {
            bool       xheader = true;
            MimeFields fields  = new MimeFields();

            while (ReadLine(true) && _curLength > 0)
            {
                int i = _curLineIndexOf(':');
                if (i < 0)
                {
                    throw new MimeException("Syntax error in field ':' not found).");
                }

                if (i < _curLength - 1 && _curLine[i + 1] != ' ')
                {
                    throw new MimeException("Syntax error in field ': ' not found).");
                }

                string Name  = _curLineToString(0, i);
                string Value = _curLineToString(i + 2, _curLength - (i + 2));

                if (xheader)
                {
                    if (Name.StartsWith("x-", StringComparison.Ordinal))
                    {
                        _positionBeginMessage = _position;
                    }
                    else
                    {
                        xheader = false;
                    }
                }

                fields.Add(new MimeField(Name, Value, true));
            }

            return(fields);
        }
コード例 #3
0
        protected void                MimeParse(string mimeValue, bool readOnly)
        {
            int Position = 0;

            if (mimeValue is null)
            {
                if (readOnly)
                {
                    throw new ArgumentNullException(nameof(mimeValue));
                }

                return;
            }

            try {
                MimeLexicalToken typeToken;
                MimeLexicalToken sepToken;
                MimeLexicalToken nameToken;
                MimeLexicalToken valueToken;

                typeToken = MimeLexicalToken.Parse(mimeValue, ref Position);

                if (typeToken.Type != MimeLexicalTokenType.Atom)
                {
                    throw new Exception("invalid type");
                }

                _type = typeToken.GetString(mimeValue);

                while ((sepToken = MimeLexicalToken.ParseSkipWhiteSpaceComment(mimeValue, ref Position)).Type == MimeLexicalTokenType.SemiColon)
                {
                    nameToken = MimeLexicalToken.ParseSkipWhiteSpaceComment(mimeValue, ref Position);
                    if (nameToken.Type != MimeLexicalTokenType.Atom)
                    {
                        throw new Exception("invalid paramater name.");
                    }

                    if (MimeLexicalToken.ParseSkipWhiteSpaceComment(mimeValue, ref Position).Type != MimeLexicalTokenType.Assign)
                    {
                        throw new Exception("invalid paramater name.");
                    }

                    valueToken = MimeLexicalToken.ParseSkipWhiteSpaceComment(mimeValue, ref Position);
                    if (valueToken.Type != MimeLexicalTokenType.Atom && valueToken.Type != MimeLexicalTokenType.QuotedString)
                    {
                        throw new Exception("invalid paramater value.");
                    }

                    if (_parameters == null)
                    {
                        _parameters = new MimeFields();
                    }

                    _parameters.Add(new MimeField(nameToken.GetString(mimeValue), valueToken.GetString(mimeValue)));
                }

                if (sepToken.Type != MimeLexicalTokenType.EOL)
                {
                    throw new Exception("extra data.");
                }

                if (readOnly)
                {
                    _readOnly = true;

                    if (_parameters != null)
                    {
                        _parameters.SetCollectionReadOnly();
                    }
                }
            }
            catch (Exception Err) {
                throw new MimeException("Invalid mime field value '" + mimeValue + "'," + Err.Message);
            }
        }