// // BodyPartVisitor.cs // // Author: Jeffrey Stedfast // // Copyright (c) 2013-2020 .NET Foundation and Contributors // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // namespace MailKit { /// /// Represents a visitor for a tree of MIME body parts. /// /// /// This class is designed to be inherited to create more specialized classes whose /// functionality requires traversing, examining or copying a tree of MIME body parts. /// public abstract class BodyPartVisitor { /// /// Dispatches the entity to one of the more specialized visit methods in this class. /// /// /// Dispatches the entity to one of the more specialized visit methods in this class. /// /// The MIME body part. public virtual void Visit (BodyPart body) { if (body != null) body.Accept (this); } /// /// Visit the abstract MIME body part. /// /// /// Visits the abstract MIME body part. /// /// The MIME body part. protected internal virtual void VisitBodyPart (BodyPart entity) { } /// /// Visit the basic MIME body part. /// /// /// Visits the basic MIME body part. /// /// The basic MIME body part. protected internal virtual void VisitBodyPartBasic (BodyPartBasic entity) { VisitBodyPart (entity); } /// /// Visit the message contained within a message/rfc822 or message/news MIME entity. /// /// /// Visits the message contained within a message/rfc822 or message/news MIME entity. /// /// The body part representing the message/rfc822 message. protected virtual void VisitMessage (BodyPart message) { if (message != null) message.Accept (this); } /// /// Visit the message/rfc822 or message/news MIME entity. /// /// /// Visits the message/rfc822 or message/news MIME entity. /// /// The message/rfc822 or message/news body part. protected internal virtual void VisitBodyPartMessage (BodyPartMessage entity) { VisitBodyPartBasic (entity); VisitMessage (entity.Body); } /// /// Visit the children of a . /// /// /// Visits the children of a . /// /// The multipart. protected virtual void VisitChildren (BodyPartMultipart multipart) { for (int i = 0; i < multipart.BodyParts.Count; i++) multipart.BodyParts[i].Accept (this); } /// /// Visit the abstract multipart MIME entity. /// /// /// Visits the abstract multipart MIME entity. /// /// The multipart body part. protected internal virtual void VisitBodyPartMultipart (BodyPartMultipart multipart) { VisitBodyPart (multipart); VisitChildren (multipart); } /// /// Visit the text-based MIME part entity. /// /// /// Visits the text-based MIME part entity. /// /// The text-based body part. protected internal virtual void VisitBodyPartText (BodyPartText entity) { VisitBodyPartBasic (entity); } } }