[Csmail-patches] CVS: csmail/src/CSMail BodyPartList.cs,1.4,1.5 ChangeLog,1.42,1.43 HeaderList.cs,1.
Status: Pre-Alpha
Brought to you by:
mastergaurav
From: Gaurav V. <mas...@us...> - 2002-09-19 08:16:18
|
Update of /cvsroot/csmail/csmail/src/CSMail In directory usw-pr-cvs1:/tmp/cvs-serv24603 Modified Files: BodyPartList.cs ChangeLog HeaderList.cs MimeMultipart.cs Log Message: 2002-09-17 * BodyPartList.cs : Added utility methods. Fairly complete. * MimeBodyPart.cs : ?? 2002-09-16 * BodyPartList.cs : Removing "MailTODO". * HeaderList.cs : GetHeaderByName(string) - Implemented * MimeMultipart.cs : Typo error. Index: BodyPartList.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/BodyPartList.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- BodyPartList.cs 13 Sep 2002 04:52:49 -0000 1.4 +++ BodyPartList.cs 19 Sep 2002 08:16:15 -0000 1.5 @@ -13,9 +13,9 @@ namespace CSMail { - // <summary> - // Container for a list of body parts. - // </summary> + /// <summary> + /// Container for a list of body parts. + /// </summary> public class BodyPartList : IEnumerable { private ArrayList parts; @@ -24,72 +24,118 @@ /// <summary> /// Initializes an instance of the BodyPartList. /// </summary> + /// <remarks> + /// The list is not read-only. + /// </remarks> public BodyPartList() { parts = new ArrayList(); isReadOnly = false; } - [MailTODO] + /// <summary> + /// Creates an instance of BodyPartList with given parts + /// and readonly option. + /// </summary> + /// <param name="parts">The body parts in the initial list.</param> + /// <param name="isReadOnly">Determines if the list is + /// readonly.</param> public BodyPartList(BodyPart[] parts, bool isReadOnly) { this.isReadOnly = isReadOnly; - throw new NotImplementedException(); + this.parts = new ArrayList(); + foreach(BodyPart current in parts) + { + if(current != null) + { + this.parts.Add(current); + } + } } /// <summary> /// Creates an instance with a specified entry. /// </summary> - [MailTODO] + /// <param name="part">Body part in the initial list.</param> + /// <remarks> + /// The list is not read-only. + /// </remarks> public BodyPartList(BodyPart part) { - throw new NotImplementedException(); + parts = new ArrayList(); + parts.Add(part); + this.isReadOnly = false; } /// <summary> /// Creates an instance using the list of parts provided. /// </summary> - [MailTODO] - public BodyPartList(BodyPart[] parts) - { - throw new NotImplementedException(); - } - - /// <summary> - /// Creates an instance using the list provided. - /// </summary> + /// <param name="parts">Body parts in the initial list.</param> /// <remarks> - /// Do I need this? Should I make it <c>ICloneable</c>? + /// The list is not read-only. /// </remarks> - [MailTODO] - public BodyPartList(BodyPartList parts) + public BodyPartList(BodyPart[] parts) : this(parts, false) { - this.isReadOnly = parts.IsReadOnly; - throw new NotImplementedException(); } - [MailTODO] + /// <summary> + /// Gets or sets the part at the given index. + /// </summary> + /// <param name="index">The index (zero based) under + /// consideration.</param> + /// <exception name="ArgumentOutOfRangeException"> + /// <c>index</c> is less than zero, + /// <p>-or-</p> + /// <c>index</c> is euqal to or greater than <see cref="Count"/>. + /// </exception> + /// <exception name="NotSupportedException"> + /// When trying to modify a read-only list. + /// </exception> public BodyPart this[int index] { get { - throw new NotImplementedException(); + if(index < 0 || index > this.parts.Count) + { + throw new ArgumentOutOfRangeException("[Index(int)] Index value beyond limits."); + } + return (BodyPart)parts[index]; } set { - throw new NotImplementedException(); + if(index < 0 || index > this.parts.Count) + { + throw new ArgumentOutOfRangeException("[Index(int)] Index value beyond limits."); + } + if(isReadOnly) + { + throw new NotSupportedException("[Index(int)] Cannot modify read only."); + } + parts[index] = value; } } - [MailTODO] + /// <summary> + /// Gets the body part with the specified contentID. + /// </summary> + /// <param name="contentID">The value of the "Content-ID" + /// header.</param> public BodyPart this[string contentID] { get { - throw new NotImplementedException(); + int index = IndexOf(contentID); + if(index >= 0) + { + return (BodyPart)parts[index]; + } + return null; } } + /// <summary> + /// Returns if the list is a read-only list. + /// </summary> public bool IsReadOnly { get @@ -109,15 +155,157 @@ } } + /// <summary> + /// Returns the associated enumerator. + /// </summary> + /// <returns> + /// The enumerator associated with the list. + /// </returns> public IEnumerator GetEnumerator() { return parts.GetEnumerator(); } + /// <summary> + /// Returns the index of body part with specified content-ID. + /// </summary> + /// <param name="contentID">The value of the "Content-ID" + /// header for the part.</param> + /// <returns> + /// Index at which the part is found, + /// -1 if not found. + /// </returns> + public int IndexOf(string contentID) + { + for(int i = 0; i < parts.Count; i++) + { + BodyPart cBody = (BodyPart)parts[i]; + Header found = cBody.Headers.GetHeaderByName("Content-ID", + true); + if(found != null) + { + if(String.Compare(contentID, found.Value, true) == 0) + return i; + } + } + return -1; + } + /** * Have to allow only Add(BodyPart body) etc. * No Add(object generic) sort of thing. * So, not deriving class from ArrayList. */ + + /// <summary> + /// Returns the index of the given part in the list. + /// </summary> + /// <param name="part">The part to look for in the list.</param> + /// <returns> + /// The index of the part in the list, + /// -1 if not found. + /// </returns> + public int IndexOf(BodyPart part) + { + return parts.IndexOf(part); + } + + /// <summary> + /// Adds a part to the list. + /// </summary> + /// <param name="part">Part to be added to the list.</param> + /// <returns> + /// The number of elements after adding.</returns> + /// <exception name="NotSupportedException"> + /// When trying to add to a read-only list. + /// </exception> + public int Add(BodyPart part) + { + if(isReadOnly) + { + throw new NotSupportedException("[Add(BodyPart)] Cannot modify read only."); + } + return parts.Add(part); + } + + /// <summary> + /// Adds a part at the given index. + /// </summary> + /// <param name="index">Index (zero based) at which + /// the part is to be added.</param> + /// <param name="part">Part to be added to the list.</param> + /// <exception name="NotSupportedException"> + /// When trying to insert to a read-only list. + /// </exception> + public void Insert(int index, BodyPart part) + { + if(isReadOnly) + { + throw new NotSupportedException("[Insert(int, BodyPart)] Cannot modify read only."); + } + parts.Insert(index, part); + } + + /// <summary> + /// Removes all parts from the list. + /// </summary> + /// <exception name="NotSupportedException"> + /// When trying to insert to a read-only list. + /// </exception> + public void Clear() + { + if(isReadOnly) + { + throw new NotSupportedException("[Clear()] Cannot modify read only."); + } + parts.Clear(); + } + + /// <summary> + /// Determines whether the given part exists in the list + /// or not. + /// </summary> + /// <returns> + /// <c>true</c> if the part exists in the list, + /// <c>false</c> otherwise. + /// </returns> + public bool Contains(BodyPart part) + { + return parts.Contains(part); + } + + /// <summary> + /// Tries to remove a part from the list. + /// </summary> + /// <param name="part">Part to be removed from the list.</param> + /// <exception name="NotSupportedException"> + /// When trying to insert to a read-only list. + /// </exception> + public void Remove(BodyPart part) + { + if(isReadOnly) + { + throw new NotSupportedException("[Remove(BodyPart)] Cannot modify read only."); + } + parts.Remove(part); + } + + /// <summary> + /// Tries to remove a part from the list at the + /// specified index. + /// </summary> + /// <param name="index">Index (zero based), the part at which + /// is to be removed from the list.</param> + /// <exception name="NotSupportedException"> + /// When trying to insert to a read-only list. + /// </exception> + public void RemoveAt(int index) + { + if(isReadOnly) + { + throw new NotSupportedException("[RemoveAt(int)] Cannot modify read only."); + } + parts.RemoveAt(index); + } } } Index: ChangeLog =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ChangeLog,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- ChangeLog 16 Sep 2002 11:22:47 -0000 1.42 +++ ChangeLog 19 Sep 2002 08:16:15 -0000 1.43 @@ -1,4 +1,15 @@ +2002-09-17 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * BodyPartList.cs : Added utility methods. Fairly complete. + * MimeBodyPart.cs : ?? + +2002-09-16 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * BodyPartList.cs : Removing "MailTODO". + * HeaderList.cs : GetHeaderByName(string) - Implemented + * MimeMultipart.cs : Typo error. + 2002-09-16 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * MessagingException.cs : "MailTODO" for Message { get; } Index: HeaderList.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/HeaderList.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- HeaderList.cs 6 Sep 2002 11:52:29 -0000 1.4 +++ HeaderList.cs 19 Sep 2002 08:16:15 -0000 1.5 @@ -276,6 +276,26 @@ } /// <summary> + /// Returns a header by its name. + /// </summary> + /// <param name="name">Header name to look for.</param> + /// <param name="ignoreCase">Whether or not to ignore case during + /// search.</param> + /// <returns> + /// The header instance with the given name, + /// null if not found. + /// </returns> + public Header GetHeaderByName(string name, bool ignoreCase) + { + foreach(Header current in this) + { + if(String.Compare(current.Name, name, ignoreCase) == 0) + return current; + } + return null; + } + + /// <summary> /// Removes the first matching header. /// </summary> /// <param name="fullHeader">Header to look for.</param> Index: MimeMultipart.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/MimeMultipart.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MimeMultipart.cs 13 Sep 2002 06:10:59 -0000 1.4 +++ MimeMultipart.cs 19 Sep 2002 08:16:15 -0000 1.5 @@ -44,7 +44,7 @@ public BodyPart GetBodyPart(int index) { if(index < 0 || index > BodyParts.Count) - throw new IndexOutOfRangeException("[GetBodyPart] Index value is beyong limits"); + throw new IndexOutOfRangeException("[GetBodyPart] Index value is beyond limits"); return BodyParts[index]; } |