[Csmail-patches] CVS: csmail/src/CSMail ChangeLog,1.4,1.5 InternetAddress.cs,1.2,1.3 InternetAddress
Status: Pre-Alpha
Brought to you by:
mastergaurav
From: Gaurav V. <mas...@us...> - 2002-07-26 06:54:16
|
Update of /cvsroot/csmail/csmail/src/CSMail In directory usw-pr-cvs1:/tmp/cvs-serv30511/src/CSMail Modified Files: ChangeLog InternetAddress.cs InternetAddressList.cs Log Message: 2002-07-26 Gaurav Vaish <mastergaurav> * CSMailAPI.xml : Removed InternetAddressList::Set(int, InternetAddress) Added parameter (bool) to InternetAddressList::FindByValue(string) Added parameter (bool) to InternetAddressList::RemoveFirst(string) Added parameter (bool) to InternetAddressList::Remove(string[]) Removed parameter (int) from InternetAddressList::ToString(int) * InternetAddressList.cs : Completed. Well almost. Index: ChangeLog =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ChangeLog,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ChangeLog 25 Jul 2002 11:24:14 -0000 1.4 +++ ChangeLog 26 Jul 2002 06:54:13 -0000 1.5 @@ -1,4 +1,8 @@ +2002-07-26 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * InternetAddressList.cs : Completed. Well almost. + 2002-07-25 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * Header.cs : Added comment for ToString() method. Index: InternetAddress.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/InternetAddress.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- InternetAddress.cs 25 Jul 2002 11:24:14 -0000 1.2 +++ InternetAddress.cs 26 Jul 2002 06:54:13 -0000 1.3 @@ -10,18 +10,26 @@ using System; +/** + * The class currently does not support the a full URL of the type + * prot://user:pass@hostname:port/filepath#ref + * As of now, it understands only prot://hostname + */ + namespace CSMail { public class InternetAddress { private string hostname; + private string protocol; private int[] ip; private bool isIP; - public InternetAddress(string hostname) + public InternetAddress(string hostname, string protocol) { hostname = hostname.Trim(); this.hostname = hostname; + this.protocol = procotol; if(CheckIfIP(hostname)) { isIP = true; @@ -33,12 +41,13 @@ /// the IP_V6 format IPs, I have to first go through the /// documentations. /// </summary> - public InternetAddress(int[] ip) + public InternetAddress(int[] ip, string protocol) { if(!ValidIP(ip)) { throw new ArgumentException(); } + this.protocol = procotol; this.ip = new int[4]; int i = 0; foreach(int current in ip) @@ -64,6 +73,14 @@ return isIP; } } + + public string Protocol + { + get + { + return protocol; + } + } public int[] getIP { @@ -113,6 +130,14 @@ return false; } return true; + } + + public override string ToString() + { + string retVal; + retVal = procotol + "://"; + retVal += hostname; + return retVal; } } } Index: InternetAddressList.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/InternetAddressList.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InternetAddressList.cs 25 Jul 2002 11:24:14 -0000 1.1 +++ InternetAddressList.cs 26 Jul 2002 06:54:13 -0000 1.2 @@ -46,7 +46,134 @@ } } } - - + + public int Count + { + get + { + return addresses.Count; + } + } + + public InternetAddress this[int index] + { + get + { + if(index < 0 || index > Count) + return null; + return addresses[index]; + } + } + + public int Add(InternetAddress address) + { + return addresses.Add(address); + } + + public int Add(InternetAddressList address) + { + foreach(InternetAddress current in address) + { + if(current != null) + { + addresses.Add(current); + } + } + return addresses.Count; + } + + public int IAddress.Add(IAddress address) + { + if(address is InternetAddress) + { + addresses.Add((InternetAddress)address); + } + return addresses.Count; + } + + public void Clear() + { + addresses.Clear(); + } + + public int IndexOf(InternetAddress address) + { + return addresses.IndexOf(address); + } + + public int FindByValue(string address, bool ignoreCase) + { + int i; + if(address != null && address.Length > 0) + { + i = 0; + foreach(InternetAddress current in this) + { + if(String.Compare(current.Hostname, current, ignoreCase) == 0) + { + return i; + } + i++; + } + } + return -1; + } + + public void Remove(InternetAddress address) + { + addresses.Remove(address); + } + + public void RemoveAt(int index) + { + if(index >= 0 && index < Count) + { + addresses.RemoveAt(index); + } + } + + public void RemoveFirst(string address, bool ignoreCase) + { + RemoveAt(FindByValue(address, ignoreCase)); + } + + public void Remove(string[] addresses, bool ignoreCase) + { + ArrayList delete = new ArrayList(); + int index; + foreach(string current in addresses) + { + if(current != null) + { + index = FindByValue(current, ignoreCase); + if(index >= 0 && index < Count) + { + if(!delete.Contains(this[index]) + { + delete.Add(this[index]); + } + } + } + } + + foreach(InternetAddress current in delete) + { + this.addresses.Remove(current); + } + } + + /// <summary> + /// Returns a CRLF separated list of Addresses. + /// Do I need to take care of anything??? + /// </summray> + public string ToString() + { + string retVal = String.Empty; + foreach(InternetAddress current in this) + { + retVal += (current.ToString() + "\r\n"); + } + return retVal; + } } } |