[Csmail-patches] CVS: csmail/src/CSMail ChangeLog,1.55,1.56 ContentType.cs,1.7,1.8 EMailAddress.cs,1
Status: Pre-Alpha
Brought to you by:
mastergaurav
From: Gaurav V. <mas...@us...> - 2002-10-09 07:09:36
|
Update of /cvsroot/csmail/csmail/src/CSMail In directory usw-pr-cvs1:/tmp/cvs-serv13578 Modified Files: ChangeLog ContentType.cs EMailAddress.cs MimeBodyPart.cs ParameterList.cs Provider.cs Log Message: 2002-10-09 * ContentType.cs : ctor(string) - Implemented. : ctor(string, string) - Primary type cannot be null or empty. : SubType - Defaults to "*". : GetHashCode() - New definition. : ParameterList - Made writable. : operators ==, !=, : Equals(object), : Equals(ContentType), : Equals(string), : GetHashCode(), : ToString() - Revamp. * EMailAddress.cs : operators ==, !=, : Equals(IAddress), : Equals(object) - Revamp. : Equals(EMailAddress)- Implemented. * MimeBodyPart.cs : Fixed documentation bug. * ParameterList.cs : operators ==, != - Implemented. : Equals(...) - Implemented. : GetHashCode() - Implemented. : ToString() - Added space between two parameters. : ctor(string) - Stubbed. * Provider.cs : operators ==, !=, : Equals(object) - Revamp. Index: ChangeLog =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ChangeLog,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- ChangeLog 8 Oct 2002 12:30:56 -0000 1.55 +++ ChangeLog 9 Oct 2002 07:09:30 -0000 1.56 @@ -1,4 +1,32 @@ +2002-10-09 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * ContentType.cs : ctor(string) - Implemented. + : ctor(string, string) + - Primary type cannot be null or empty. + : SubType - Defaults to "*". + : GetHashCode() - New definition. + : ParameterList - Made writable. + : operators ==, !=, + : Equals(object), + : Equals(ContentType), + : Equals(string), + : GetHashCode(), + : ToString() - Revamp. + * EMailAddress.cs : operators ==, !=, + : Equals(IAddress), + : Equals(object) - Revamp. + : Equals(EMailAddress)- Implemented. + * MimeBodyPart.cs : Fixed documentation bug. + * ParameterList.cs : operators ==, != - Implemented. + : Equals(...) - Implemented. + : GetHashCode() - Implemented. + : ToString() + - Added space between two parameters. + : ctor(string) - Stubbed. + * Provider.cs : operators ==, !=, + : Equals(object) - Revamp. + 2002-10-08 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * ContentType.cs : Tokens - Removed member. Index: ContentType.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ContentType.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ContentType.cs 8 Oct 2002 12:29:09 -0000 1.7 +++ ContentType.cs 9 Oct 2002 07:09:30 -0000 1.8 @@ -32,6 +32,10 @@ /// </summary> public ContentType(string primary, string sub) { + if(primary == null || primary.Length == 0) + { + throw new ArgumentException("[ContentType] Primary type cannot be empty"); + } primaryType = primary; subType = sub; parameters = new ParameterList(); @@ -45,6 +49,10 @@ /// </summary> public ContentType(string primary, string sub, ParameterList parameters) { + if(primary == null || primary.Length == 0) + { + throw new ArgumentException("[ContentType] Primary type cannot be empty"); + } primaryType = primary; subType = sub; if(parameters != null) @@ -56,6 +64,11 @@ } } + /// <summary> + /// Creates an insance with the + /// <paramref name="headerValue"/> as read in + /// "Content-Type" header. + /// </summary> /// <remarks> /// <code> /// <paramref name="headerValue"/> := primarytype '/' subtype [plist] @@ -63,17 +76,47 @@ /// params := key '=' value /// </code> /// </remarks> - [MailTODO] + /// <param name="headerValue">The value of the header + /// "Content-Type". + /// </param> + /// <exception name="ParseException"> + /// <para> + /// When provided with invalid format header value. + /// </para> + /// </exception> public ContentType(string headerValue) { HeaderTokenizer ht = new HeaderTokenizer(headerValue, Constants.MIMEDelimiters); - throw new NotImplementedException(); + HeaderToken token = ht.Next; + if(token.TokenType != HeaderTokenType.Atom) + { + throw new ParseException("[ContentType] Cannot locate primary type"); + } + PrimaryType = token.Value; + + token = ht.Next; + if(token.Value[0] != '/') + { + throw new ParseException("[ContentType] Invalid content type declaration"); + } + + token = ht.Next; + if(token.TokenType != HeaderTokenType.Atom) + { + throw new ParseException("[ContentType] Cannot locate subtype"); + } + SubType = token.Value; + + Parameters = new ParameterList(ht.Remainder); } /// <summary> - /// Gets the primary type of the content. + /// Gets or sets the primary type of the content. /// </summary> + /// <value> + /// The primary-type associated with the content. + /// </value> /// <remarks> /// Returns an empty string, if a <b>null</b> was set /// </remarks> @@ -92,10 +135,14 @@ } /// <summary> - /// Returns the sub-type of the content. + /// Gets or sets the sub-type of the content. /// </summary> + /// <value> + /// The sub-type associated with the content. + /// </value> /// <remarks> - /// Returns an empty string, if a <b>null</b> was set + /// Returns a "*", if a <see langword="null"/> + /// was set. /// </remarks> public string SubType { @@ -103,7 +150,7 @@ { if(subType != null) return subType; - return String.Empty; + return "*"; } set { @@ -112,32 +159,89 @@ } /// <summary> - /// Returns the parameters. + /// Gets or sets the parameters. /// </summary> + /// <value> + /// The extra parameters associated with the + /// "Content-Type" header. + /// </value> public ParameterList Parameters { get { return parameters; } + set + { + parameters = value; + } } + /// <summary> + /// Compares two <see cref="T:CSMail.ContentType"/> + /// objects. + /// </summary> + /// <returns> + /// <see langword="true"/> if they represent the same + /// content type, <see langword="false"/> otherwise. + /// </returns> + /// <remarks> + /// <para> + /// Comparision is made on the basis of + /// primary type and subtype only. + /// </para> + /// <para> + /// It is however important to note that if subtype of + /// any one of them have a subtype "*", it + /// will match any subtype. + /// </para> + /// </remarks> + /// <param name="left">Operand on the left side of + /// the operator.</param> + /// <param name="right">Operand on the right side of + /// the operator.</param> public static bool operator == (ContentType left, ContentType right) { - if(left == null && right == null) + if((object)left == (object)right) return true; - if(left == null || right == null) + if(null == (object)left || null == (object)right) return false; bool retVal = true; retVal &= (String.Compare(left.PrimaryType, right.PrimaryType, false) == 0); - retVal &= (String.Compare(left.SubType, + if(left.SubType[0] == '*' || right.SubType[0] == '*') + return retVal; + + retVal &= (String.Compare(left.SubType, right.SubType, false) == 0); return retVal; } + /// <summary> + /// Compares two <see cref="T:CSMail.ContentType"/> + /// objects. + /// </summary> + /// <returns> + /// <see langword="true"/> if they represent the same + /// content type, <see langword="false"/> otherwise. + /// </returns> + /// <remarks> + /// <para> + /// Comparision is made on the basis of + /// primary type and subtype only. + /// </para> + /// <para> + /// It is however important to note that if subtype of + /// any one of them have a subtype "*", it + /// will match any subtype. + /// </para> + /// </remarks> + /// <param name="left">Operand on the left side of + /// the operator.</param> + /// <param name="right">Operand on the right side of + /// the operator.</param> public static bool operator != (ContentType left, ContentType right) { return !(left == right); @@ -151,12 +255,19 @@ /// <see cref="T:CSMail.ContentType"/> or /// <see cref="T:System.String"/>. /// </remarks> + /// <param name="obj">Object to match with.</param> public override bool Equals(object obj) { + if(null == obj) + { + return false; + } + if(obj is ContentType) { return Equals((ContentType)obj); } + if(obj is string) { return Equals((string)obj); @@ -169,11 +280,12 @@ /// </summary> /// <param name="cType">Content type to check /// against.</param> + /// <param name="cType">Object to match with.</param> public bool Equals(ContentType cType) { - if(cType != null) + if(null != (Object)cType) { - return Equals(cType.ToString()); + return (this == cType); } return false; } @@ -182,9 +294,31 @@ /// Checks for the equality with a string representation /// of the object. /// </summary> + /// <remarks> + /// This method is quite different in behaviour from othe + /// related methods and operators in that it checks also + /// for the equality of parameters. + /// </remarks> + /// <param name="cType">String representation of the + /// content type to matched with. + /// </param> public bool Equals(string cType) { - return (cType.Equals(this.ToString())); + if(cType == null || cType.Length == 0) + return false; + + try + { + ContentType that = new ContentType(cType); + if(this == that) + return false; + if(this.Parameters != that.Parameters) + return false; + } catch(ParseException) + { + return false; + } + return true; } /// <summary> @@ -199,13 +333,12 @@ public override string ToString() { string retVal; - retVal = primaryType; - if(primaryType != "") - retVal += "/"; + retVal = PrimaryType; + retVal += "/"; retVal += SubType; - if(retVal != "" && parameters!=null) + if(parameters!=null) { - retVal += ";"; + retVal += " ; "; retVal += parameters.ToString(); } return retVal; @@ -216,7 +349,7 @@ /// </summary> public override int GetHashCode() { - return (primaryType.GetHashCode() + subType.GetHashCode()); + return ToString().GetHashCode(); } } } Index: EMailAddress.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/EMailAddress.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- EMailAddress.cs 6 Sep 2002 09:30:27 -0000 1.4 +++ EMailAddress.cs 9 Oct 2002 07:09:30 -0000 1.5 @@ -112,16 +112,33 @@ /// </remarks> public bool Equals(IAddress address) { - if(address is EMailAddress) + if(address != null && address is EMailAddress) { EMailAddress that = (EMailAddress)address; - if(this.User == that.User && this.Host == that.Host) - return true; + return (this == that); } return false; } /// <summary> + /// Checks for equality with another address. + /// </summary> + /// <param name="address">Address to be compared with.</param> + /// <returns><c>true</c> if they are same, <c>false</c> + /// otherwise.</returns> + /// <remarks> + /// Two email addresses are equal if they share common + /// <c>user</c> and <c>host</c> parts. Comparision is currently + /// case sensitive, which I think <b>is a bug!</b> But right now, + /// I am too clumsy to correct this... will work on it later. + /// But have submitted the bug in the bug-tracker system! + /// </remarks> + public bool Equals(EMailAddress address) + { + return (this == address); + } + + /// <summary> /// Checks for equality with another object. /// </summary> /// <param name="address">Address to be compared with.</param> @@ -136,11 +153,9 @@ /// </remarks> public override bool Equals(object address) { - if(address is EMailAddress) + if(address != null && address is EMailAddress) { - EMailAddress that = (EMailAddress)address; - if(this.User == that.User && this.Host == that.Host) - return true; + return (this == (EMailAddress)address); } return false; } @@ -157,14 +172,15 @@ /// </returns> public static bool operator == (EMailAddress left, EMailAddress right) { - if(left == null && right == null) - { + if((object)left == (object)right) return true; - } - if(left != null && right != null) - { - return left.Equals(right); - } + + if(null == (object)left || null == (object)right) + return false; + + if(left.User == right.User && left.Host == right.Host) + return true; + return false; } Index: MimeBodyPart.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/MimeBodyPart.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- MimeBodyPart.cs 1 Oct 2002 10:33:20 -0000 1.8 +++ MimeBodyPart.cs 9 Oct 2002 07:09:30 -0000 1.9 @@ -300,7 +300,7 @@ /// confused as to where and when will it be used. /// </para> /// <para> - /// May be just before <see cref="Write(TextWriter)"/> is + /// May be just before <see cref="Write(StreamWriter)"/> is /// called. /// </para> /// </remarks> Index: ParameterList.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ParameterList.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ParameterList.cs 30 Sep 2002 04:01:37 -0000 1.3 +++ ParameterList.cs 9 Oct 2002 07:09:30 -0000 1.4 @@ -8,6 +8,7 @@ * (C) Gaurav Vaish (2002) */ +using System; using System.Collections; namespace CSMail @@ -21,6 +22,11 @@ parameters = new Hashtable(); } + public ParameterList(string value) + { + throw new NotImplementedException(); + } + public ParameterList(Parameter parameter) { parameters = new Hashtable(); @@ -77,6 +83,17 @@ Remove(parameter.Name); } + // FIXME: To checking of key should be case insensitive. + // Should I create my own definition of HashTable? + // But wait, why do I need a HashTable? Should a simple + // ArrayList should do? Now, to search in the ArrayList + // would be a difficult job, unless I have a sorted one. + // So, the class that implements such a list, should + // have something like this: + // Hashtable keys := (key, index) + // ArrayList values := (values) + // Now, when I have to search, I use sorted keys, + // and to return the value, I directly acess values[index] public void Remove(string name) { if(parameters.ContainsKey(name)) @@ -91,14 +108,43 @@ return (IEnumerator)(parameters.Keys); } + public static bool operator == (ParameterList left, + ParameterList right) + { + throw new NotImplementedException(); + //if(left == null && right == null) + // return + } + + public static bool operator != (ParameterList left, + ParameterList right) + { + return !(left == right); + } + + public override bool Equals(object obj) + { + if(obj != null && obj is ParameterList) + { + return (this == (ParameterList)obj); + } + return false; + } + + public override int GetHashCode() + { + return ToString().GetHashCode(); + } + public override string ToString() { - string retVal = ""; + string retVal = String.Empty; foreach(string key in this) { retVal += (key + "=\"" + this[key] + "\";"); + retVal += ' '; } - retVal = retVal.Substring(0, retVal.Length - 1); + retVal = retVal.Substring(0, retVal.Length - 2); return retVal; } } Index: Provider.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/Provider.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Provider.cs 6 Sep 2002 11:52:29 -0000 1.7 +++ Provider.cs 9 Oct 2002 07:09:30 -0000 1.8 @@ -157,32 +157,28 @@ { if(obj != null && obj is Provider) { - Provider prov = (Provider)obj; - bool retVal = true; - retVal &= (this.assembly == prov.assembly); - retVal &= (this.className == prov.className); - retVal &= (this.protocol == prov.protocol); - retVal &= (this.type == prov.type); - retVal &= (this.vendor == prov.vendor); - retVal &= (this.version == prov.version); - - return retVal; + return (this == (Provider)obj; } return false; } - public static bool operator == (Provider obj1, Provider obj2) + public static bool operator == (Provider left, Provider right) { - if(obj1 == null && obj2 == null) - { + if((object)left == (object)right) return true; - } - if(obj1 != null && obj2 != null) - { - return obj1.Equals(obj2); - } - return false; + if(null == (object)left || null == (object)right) + return false; + + bool retVal = true; + retVal &= (left.assembly == right.assembly); + retVal &= (left.className == right.className); + retVal &= (left.protocol == right.protocol); + retVal &= (left.type == right.type); + retVal &= (left.vendor == right.vendor); + retVal &= (left.version == right.version); + + return retVal; } public static bool operator != (Provider obj1, Provider obj2) |