[Csmail-patches] CVS: csmail/src/CSMail Constants.cs,NONE,1.1 ChangeLog,1.11,1.12 Provider.cs,1.3,1.
Status: Pre-Alpha
Brought to you by:
mastergaurav
From: Gaurav V. <mas...@us...> - 2002-08-29 11:32:34
|
Update of /cvsroot/csmail/csmail/src/CSMail In directory usw-pr-cvs1:/tmp/cvs-serv27597 Modified Files: ChangeLog Provider.cs ProviderList.cs ProviderType.cs Session.cs Added Files: Constants.cs Log Message: 2002-08-29 * Constants.cs : Added class. * Provider.cs : Modified/Added the following : ctor(...) - Added parameter assembly : ctor(string) - Implemented : IsRequiredSet - Implemented : SetProperly(...) - Implemented : ParseType(...) - Implemented : AssemblyName - Implemented : Equals - Implemented : operator == - Implemented : operator != - Implemented : GetHashcode() - Implemented * ProviderCollected / ProviderList : Previous change reverted. * ProviderType.cs : Added element "NotSet" * Session.cs : LoadProviders() - Implemented : LoadProviders(string) - Implemented : LoadProviders(string, bool) - Stubbed : LoadAddressMap() - Stubbed : SetDirsToSearch() - Implemented --- NEW FILE --- /** * Namespace: CSMail * Class: Constants * * Author: Gaurav Vaish * Maintainer: mastergaurav AT users DOT sf DOT net * * (C) Gaurav Vaish (2002) */ namespace CSMail { public class Constants { public const string ProviderFile = "CSMail.providers"; public const string ProviderFileDefault = "CSMail.providers.default"; public const string AddressMapFile = "CSMail.adress.map"; public const string AddressMapFileDefault = "CSMail.adress.map.default"; public const int Pop3PortDefault = 110; public const int ImapPortDefault = 143; public const int SmtpPortDefault = 25; public const int NntpPortDefault = 119; } } Index: ChangeLog =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ChangeLog,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ChangeLog 29 Aug 2002 07:03:03 -0000 1.11 +++ ChangeLog 29 Aug 2002 11:32:31 -0000 1.12 @@ -1,6 +1,35 @@ 2002-08-29 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * Constants.cs : Added class. + * Provider.cs : Modified/Added the following + : ctor(...) - Added parameter assembly + : ctor(string) - Implemented + : IsRequiredSet - Implemented + : SetProperly(...) - Implemented + : ParseType(...) - Implemented + : AssemblyName - Implemented + : Equals - Implemented + : operator == - Implemented + : operator != - Implemented + : GetHashcode() - Implemented + * ProviderCollected / ProviderList + : Previous change reverted. + * ProviderType.cs : Added element "NotSet" + * Session.cs : LoadProviders() - Implemented + : LoadProviders(string) + - Implemented + : LoadProviders(string, bool) + - Stubbed + : LoadAddressMap() - Stubbed + : SetDirsToSearch() - Implemented + +2002-08-29 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * ProviderType.cs : Added property "NotSet". + +2002-08-29 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * ProviderCollection.cs : Renamed to ProviderList * ProviderList.cs : Renamed version of ProviderCollection * Session.cs : Stubbed LoadProviders, LoadAddressMap Index: Provider.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/Provider.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Provider.cs 29 Aug 2002 04:10:11 -0000 1.3 +++ Provider.cs 29 Aug 2002 11:32:31 -0000 1.4 @@ -9,6 +9,7 @@ */ using System; +using CSMail.Utils; namespace CSMail { @@ -16,20 +17,91 @@ { private string className; private string protocol; + private string assembly; private ProviderType type; private string vendor; private string version; - public Provider(ProviderType type, string protocol, string className, - string vendor, string version) + public Provider(ProviderType type, string assembly, string protocol, + string className, string vendor, string version) { this.type = type; + this.assembly = assembly; this.protocol = protocol; this.className = className; this.vendor = vendor; this.version = version; } + /// <summary> + /// Format of rawline: + /// protocol = <proto>; type = <type>; class = <class>; + /// vendor = <vendor>; version = <version> + /// Note that they may appear in any order. Vendor and version + /// may be missing. '=' may be replaced by a ':' + /// </summary> + internal Provider(string rawLine) + { + rawLine = rawLine.Trim(); + string[] pairs = rawLine.Split(new char[] { ';' }); + if(pairs == null || pairs.Length < 3) + throw new ArgumentException("[Provider] Failed to extract minimal parameters"); + string key; + string value; + + foreach(string current in pairs) + { + string trimmed = current.Trim(); + Properties.GetKeyValue(current, out key, out value); + if(key != null && value != null && key.Length > 0 && value.Length > 0) + { + SetProperly(key, value); + } + } + if(!IsRequiredSet()) + throw new ArgumentException("[Provider] Failed to extract required parameters"); + } + + private bool IsRequiredSet() + { + bool retVal = true; + retVal &= (this.type != ProviderType.NotSet); + retVal &= (this.protocol != null); + retVal &= (this.className != null); + + return retVal; + } + + private void SetProperly(string key, string value) + { + key = key.ToLower(); + switch(key) + { + case "protocol": this.protocol = value; + break; + case "type" : this.type = ParseType(value); + break; + case "class" : this.className = value; + break; + case "vendor" : this.vendor = value; + break; + case "version" : this.version = value; + break; + default : break; + } + } + + private ProviderType ParseType(string typeStr) + { + typeStr = typeStr.ToLower(); + switch(typeStr) + { + case "store" : return ProviderType.Store; + case "transport": return ProviderType.Transport; + } + return ProviderType.NotSet; + } + public string ClassName { get @@ -38,6 +110,14 @@ } } + public string AssemblyName + { + get + { + return assembly; + } + } + public string Protocol { get @@ -68,6 +148,43 @@ { return version; } + } + + public override bool Equals(object obj) + { + 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 false; + } + + public static bool operator == (Provider obj1, Provider obj2) + { + if(obj1 != null && obj2 != null) + { + return obj1.Equals(obj2); + } + return false; + } + + public static bool operator != (Provider obj1, Provider obj2) + { + return !(obj1 == obj2); + } + + public override int GetHashCode() + { + return ToString().GetHashCode(); } public override string ToString() Index: ProviderList.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ProviderList.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ProviderList.cs 29 Aug 2002 07:03:04 -0000 1.1 +++ ProviderList.cs 29 Aug 2002 11:32:31 -0000 1.2 @@ -16,10 +16,10 @@ { private ArrayList providers = new ArrayList(); - public ProviderCollection() + public ProviderList() { } - + public IEnumerator GetEnumerator() { return providers.GetEnumerator(); Index: ProviderType.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ProviderType.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ProviderType.cs 20 Jun 2002 02:43:25 -0000 1.1 +++ ProviderType.cs 29 Aug 2002 11:32:31 -0000 1.2 @@ -12,7 +12,8 @@ { public enum ProviderType { + NotSet, Store, Transport } -} +} \ No newline at end of file Index: Session.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/Session.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Session.cs 29 Aug 2002 07:03:04 -0000 1.6 +++ Session.cs 29 Aug 2002 11:32:31 -0000 1.7 @@ -10,6 +10,7 @@ using System; using System.Collections; +using System.IO; using CSMail.Utils; namespace CSMail @@ -27,7 +28,8 @@ private static Session defaultSession; - private const string CSMailVersion = "0.1"; + private ArrayList dirsToSearch; + private bool areDirsSet; private Session() { @@ -38,12 +40,14 @@ this.properties = properties; this.authenticator = authenticator; this.debug = false; + this.areDirsSet = false; - authTable = new Hashtable(); - providers = new ArrayList(); - provByProto = new Hashtable(); - provByClass = new Hashtable(); - addrMap = new Properties(); + authTable = new Hashtable(); + providers = new ArrayList(); + provByProto = new Hashtable(); + provByClass = new Hashtable(); + addrMap = new Properties(); + dirsToSearch = new ArrayList(); debug = bool.Parse(this.properties["CSMail.debug"]); @@ -99,12 +103,32 @@ /// 3. $PWD/config/CSMail.properties /// 4. $PWD/config/CSMail.properties.default /// 5. Load default providers* - /// + /// /// * To be provided later by CSMail itself. /// </summary> private void LoadProviders() { // Load from the file. + if(!areDirsSet) + SetDirsToSearch(); + foreach(string current in dirsToSearch) + { + LoadProviders(current); + } + } + + private void LoadProviders(string path) + { + LoadProviders(path, false); + LoadProviders(path, true); + } + + [MailTODO] + private void LoadProviders(string path, bool fromDefault) + { + string file = path + Path.DirectorySeparatorChar; + file += (fromDefault ? Constants.ProviderFileDefault : Constants.ProviderFile); + throw new NotImplementedException(); } /// <summary> @@ -114,12 +138,39 @@ /// 3. $PWD/config/CSMail.adress.map /// 4. $PWD/config/CSMail.adress.map.default /// 5. Load default map* - /// + /// /// * To be provided later by CSMail itself. /// </summary> + [MonoTODO] private void LoadAddressMap() { // Load from the file. + if(!areDirsSet) + SetDirsToSearch(); + throw new NotImplementedException(); + } + + private void SetDirsToSearch() + { + string cshome = properties["CSMail.home"]; + string[] cspath = StringUtils.SeparatePath(properties["CSMail.path"]); + string cwd = Environment.CurrentDirectory; + string configP = Path.DirectorySeparatorChar + "config"; + + dirsToSearch.Add(cshome + configP); + foreach(string current in cspath) + { + if(!dirsToSearch.Contains(current + configP)) + { + dirsToSearch.Add(current + configP); + } + } + if(!dirsToSearch.Contains(cwd + configP)) + { + dirsToSearch.Add(cwd + configP); + } + + this.areDirsSet = true; } } } |