예제 #1
0
        /// <summary>
        /// Called when the headers change in some way.
        /// </summary>
        /// <remarks>
        /// Whenever a header is changed, this method will be called in order to allow
        /// custom <see cref="MimeEntity"/> subclasses to update their state.
        /// </remarks>
        /// <param name="action">The type of change.</param>
        /// <param name="header">The header being added, changed or removed.</param>
        protected virtual void OnHeadersChanged(HeaderListChangedAction action, Header header)
        {
            switch (action)
            {
            case HeaderListChangedAction.Added:
            case HeaderListChangedAction.Changed:
                switch (header.Id)
                {
                case HeaderId.ContentDisposition:
                    if (disposition != null)
                    {
                        disposition.Changed -= ContentDispositionChanged;
                    }

                    if (ContentDisposition.TryParse(Headers.Options, header.RawValue, out disposition))
                    {
                        disposition.Changed += ContentDispositionChanged;
                    }
                    break;

                case HeaderId.ContentId:
                    contentId = MimeUtils.EnumerateReferences(header.RawValue, 0, header.RawValue.Length).FirstOrDefault();
                    break;
                }
                break;

            case HeaderListChangedAction.Removed:
                switch (header.Id)
                {
                case HeaderId.ContentDisposition:
                    if (disposition != null)
                    {
                        disposition.Changed -= ContentDispositionChanged;
                    }

                    disposition = null;
                    break;

                case HeaderId.ContentId:
                    contentId = null;
                    break;
                }
                break;

            case HeaderListChangedAction.Cleared:
                if (disposition != null)
                {
                    disposition.Changed -= ContentDispositionChanged;
                }

                disposition = null;
                contentId   = null;
                break;

            default:
                throw new ArgumentOutOfRangeException("action");
            }
        }
예제 #2
0
        /// <summary>
        /// Called when the headers change in some way.
        /// </summary>
        /// <remarks>
        /// <para>Whenever a header is added, changed, or removed, this method will
        /// be called in order to allow custom <see cref="MimeEntity"/> subclasses
        /// to update their state.</para>
        /// <para>Overrides of this method should call the base method so that their
        /// superclass may also update its own state.</para>
        /// </remarks>
        /// <param name="action">The type of change.</param>
        /// <param name="header">The header being added, changed or removed.</param>
        protected virtual void OnHeadersChanged(HeaderListChangedAction action, Header header)
        {
            string text;

            switch (action)
            {
            case HeaderListChangedAction.Added:
            case HeaderListChangedAction.Changed:
                switch (header.Id)
                {
                case HeaderId.ContentDisposition:
                    if (disposition != null)
                    {
                        disposition.Changed -= ContentDispositionChanged;
                    }

                    if (ContentDisposition.TryParse(Headers.Options, header.RawValue, out disposition))
                    {
                        disposition.Changed += ContentDispositionChanged;
                    }
                    break;

                case HeaderId.ContentLocation:
                    text = header.Value.Trim();

                    if (Uri.IsWellFormedUriString(text, UriKind.Absolute))
                    {
                        location = new Uri(text, UriKind.Absolute);
                    }
                    else if (Uri.IsWellFormedUriString(text, UriKind.Relative))
                    {
                        location = new Uri(text, UriKind.Relative);
                    }
                    else
                    {
                        location = null;
                    }
                    break;

                case HeaderId.ContentBase:
                    text = header.Value.Trim();

                    if (Uri.IsWellFormedUriString(text, UriKind.Absolute))
                    {
                        baseUri = new Uri(text, UriKind.Absolute);
                    }
                    else
                    {
                        baseUri = null;
                    }
                    break;

                case HeaderId.ContentId:
                    contentId = MimeUtils.EnumerateReferences(header.RawValue, 0, header.RawValue.Length).FirstOrDefault();
                    break;
                }
                break;

            case HeaderListChangedAction.Removed:
                switch (header.Id)
                {
                case HeaderId.ContentDisposition:
                    if (disposition != null)
                    {
                        disposition.Changed -= ContentDispositionChanged;
                    }

                    disposition = null;
                    break;

                case HeaderId.ContentLocation:
                    location = null;
                    break;

                case HeaderId.ContentBase:
                    baseUri = null;
                    break;

                case HeaderId.ContentId:
                    contentId = null;
                    break;
                }
                break;

            case HeaderListChangedAction.Cleared:
                if (disposition != null)
                {
                    disposition.Changed -= ContentDispositionChanged;
                }

                disposition = null;
                contentId   = null;
                location    = null;
                baseUri     = null;
                break;

            default:
                throw new ArgumentOutOfRangeException("action");
            }
        }