[Csmail-patches] CVS: csmail/src/CSMail BodyPart.cs,1.9,1.10 ChangeLog,1.50,1.51 Constants.cs,1.3,1.
Status: Pre-Alpha
Brought to you by:
mastergaurav
Update of /cvsroot/csmail/csmail/src/CSMail In directory usw-pr-cvs1:/tmp/cvs-serv13164 Modified Files: BodyPart.cs ChangeLog Constants.cs IPart.cs Message.cs MimeBodyPart.cs MimeMessage.cs NewsAddressList.cs Session.cs Log Message: 2002-10-01 * BodyPart.cs : Write(TextWriter) - Changed parameter type to "StreamWriter". * Constants.cs : Added following constants - * StoreProcotol * TransportProtocol * StrictCheck * Debug * IPart.cs : Write(TextWriter) - Changed parameter type to "StreamWriter". * Message.cs : CType - Renamed to contentType. : Recipients - Changed type to "EMailAddressList" from "IAddressList". : NewsGroups - Added property. : Write(TextWriter) - Changed parameter type to "StreamWriter". : ReplyTo - Made abstract. * MimeBodyPart.cs : Write(TextWriter) - Changed parameter type to "StreamWriter". * MimeMessage.cs : CType - Renamed to contentType. : ctor(Folder, int), : ctor(Folder, StreamReader, int) : ctor(Folder, HeaderList, byte[], int) - Implemented. : ReadHeaders(TextReader), : ReadContent(TextReader), : CreateContentStream(StreamReader) - Implemented. : Write(TextWriter) - Changed parameter type to "StreamWriter". : ctor(MimeMessage) - Removed. : ReplyTo { get; set; } - Stubbed. * NewsAddressList.cs : Index(NewsAddress) - Fixed bug. Parameter should be of type NewsAddress. : Contains(NewsAddress) - Implemented. : operator +(...) - Implemented. * Session.cs : Now uses the new constants defined. Index: BodyPart.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/BodyPart.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- BodyPart.cs 30 Sep 2002 12:27:22 -0000 1.9 +++ BodyPart.cs 1 Oct 2002 10:33:20 -0000 1.10 @@ -123,10 +123,6 @@ /// <summary> /// When implemented by a class, writes the content to the writer. /// </summary> - /// <remarks> - /// I wonder shouldn't a <see cref="T:System.IO.StreamWriter"/> - /// be preferred over a <see cref="T:System.IO.TextWriter"/>? - /// </remarks> - public abstract void Write(TextWriter writer); + public abstract void Write(StreamWriter writer); } } Index: ChangeLog =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/ChangeLog,v retrieving revision 1.50 retrieving revision 1.51 diff -u -r1.50 -r1.51 --- ChangeLog 30 Sep 2002 12:27:22 -0000 1.50 +++ ChangeLog 1 Oct 2002 10:33:20 -0000 1.51 @@ -1,4 +1,45 @@ +2002-10-01 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * BodyPart.cs : Write(TextWriter) - Changed parameter type + to "StreamWriter". + * Constants.cs : Added following constants - + * StoreProcotol + * TransportProtocol + * StrictCheck + * Debug + * IPart.cs : Write(TextWriter) - Changed parameter type + to "StreamWriter". + * Message.cs : CType - Renamed to contentType. + : Recipients - Changed type to + "EMailAddressList" from "IAddressList". + : NewsGroups - Added property. + : Write(TextWriter) - Changed parameter type + to "StreamWriter". + : ReplyTo - Made abstract. + * MimeBodyPart.cs : Write(TextWriter) - Changed parameter type + to "StreamWriter". + * MimeMessage.cs : CType - Renamed to contentType. + : ctor(Folder, int), + : ctor(Folder, StreamReader, int) + : ctor(Folder, HeaderList, byte[], int) + - Implemented. + : ReadHeaders(TextReader), + : ReadContent(TextReader), + : CreateContentStream(StreamReader) + - Implemented. + : Write(TextWriter) - Changed parameter type + to "StreamWriter". + : ctor(MimeMessage) - Removed. + : ReplyTo { get; set; } + - Stubbed. + * NewsAddressList.cs : Index(NewsAddress) - Fixed bug. Parameter + should be of type NewsAddress. + : Contains(NewsAddress) + - Implemented. + : operator +(...) - Implemented. + * Session.cs : Now uses the new constants defined. + 2002-09-30 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * EMailAddressList.cs : operator + - Stubbed. Index: Constants.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/Constants.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Constants.cs 26 Sep 2002 11:52:00 -0000 1.3 +++ Constants.cs 1 Oct 2002 10:33:20 -0000 1.4 @@ -36,19 +36,19 @@ public const string AddressMapFileDefault = "CSMail.adress.map.default"; /// <summary> - /// The default port number for POP3 protocol + /// The default port number for POP3 protocol. /// </summary> public const int Pop3PortDefault = 110; /// <summary> - /// The default port number for IMAP protocol + /// The default port number for IMAP protocol. /// </summary> public const int ImapPortDefault = 143; /// <summary> - /// The default port number for SMTP protocol + /// The default port number for SMTP protocol. /// </summary> public const int SmtpPortDefault = 25; /// <summary> - /// The default port number for NNTP protocol + /// The default port number for NNTP protocol. /// </summary> public const int NntpPortDefault = 119; @@ -56,5 +56,22 @@ /// The standard CRLF (0x13,0x10) value. /// </summary> public const string CRLF = "\r\f"; + + /// <summary> + /// Key that holds class-name for store service provider. + /// </summary> + public const string StoreProtocol = "CSMail.store.protocol"; + /// <summary> + /// Key that holds class-name for transport service provider. + /// </summary> + public const string TransportProtocol = "CSMail.transport.protocol"; + /// <summary> + /// Key that holds value for strictness during checking addresses. + /// </summary> + public const string StrictCheck = "CSMail.mime.address.strict"; + /// <summary> + /// Key that holds value for debug mode during operations. + /// </summary> + public const string Debug = "CSMail.debug"; } } Index: IPart.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/IPart.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- IPart.cs 30 Sep 2002 12:27:22 -0000 1.4 +++ IPart.cs 1 Oct 2002 10:33:20 -0000 1.5 @@ -60,10 +60,6 @@ /// <summary> /// When implemented, writes the content. /// </summary> - /// <remarks> - /// Should <code>TextWriter</code> be replaced by - /// <code>StreamWriter</code>? - /// </remarks> - void Write(TextWriter writer); + void Write(StreamWriter writer); } } Index: Message.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/Message.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Message.cs 30 Sep 2002 12:27:22 -0000 1.10 +++ Message.cs 1 Oct 2002 10:33:20 -0000 1.11 @@ -37,7 +37,7 @@ /// <summary> /// Holds the content type for the message. /// </summary> - protected ContentType CType; + protected ContentType contentType; protected Message() { @@ -59,18 +59,19 @@ { get { - return CType; + return contentType; } set { - CType = value; + contentType = value; } } public abstract MessageFlags Flags { get; set; } public abstract EMailAddressList From { get; set; } public abstract DateTime ReceivedDate { get; } - public abstract IAddressList Recipients { get; } + public abstract EMailAddressList Recipients { get; } + public abstract NewsAddressList NewsGroups { get; } public abstract DateTime SentDate { get; set; } public abstract string Subject { get; set; } @@ -90,10 +91,11 @@ public abstract string Filename { get; set; } public abstract HeaderList Headers { get; set; } public abstract long Size { get; } + public abstract EMailAddressList ReplyTo { get; set; } //public abstract int AddHeader(Header header); //public abstract int AddHeaders(HeaderList headers); - public abstract void Write(TextWriter writer); + public abstract void Write(StreamWriter writer); public virtual Folder Folder { @@ -108,14 +110,6 @@ get { return isExpunged; - } - } - - public virtual IAddressList ReplyTo - { - get - { - return (IAddressList)From; } } Index: MimeBodyPart.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/MimeBodyPart.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MimeBodyPart.cs 30 Sep 2002 12:27:22 -0000 1.7 +++ MimeBodyPart.cs 1 Oct 2002 10:33:20 -0000 1.8 @@ -314,12 +314,8 @@ /// Writes the headers and content to the given /// writer. /// </summary> - /// <remarks> - /// I am thinking of moving from <see cref="TextWriter"/> - /// to <see cref="StreamWriter"/>. - /// </remarks> [MailTODO] - public override void Write(TextWriter writer) + public override void Write(StreamWriter writer) { throw new NotImplementedException(); } Index: MimeMessage.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/MimeMessage.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MimeMessage.cs 30 Sep 2002 12:27:22 -0000 1.4 +++ MimeMessage.cs 1 Oct 2002 10:33:20 -0000 1.5 @@ -22,7 +22,7 @@ protected MessageFlags flags = MessageFlags.None; protected bool isModified = false; protected bool isSaved = false; - protected StreamReader reader = null; + //protected StreamReader reader = null; protected EMailAddressList toList = new EMailAddressList(); protected EMailAddressList ccList = new EMailAddressList(); @@ -35,58 +35,100 @@ public MimeMessage(Session session) : base(session) { Initialize(); - CType = new ContentType("multipart", "mixed"); + contentType = new ContentType("multipart", "mixed"); } public MimeMessage(Session session, StreamReader reader) : base(session) { Initialize(); - this.reader = reader; - ParseMessage(); + //this.reader = reader; + ParseMessage(reader); isSaved = true; } +/* [MailTODO] public MimeMessage(MimeMessage message) : base(message.session) { flags = message.flags; isStrict = message.isStrict; isModified = false; - throw new NotImplementedException(); - //isSaved = true; + ParseMessage(message.contentReader); + isSaved = true; + } +*/ + protected MimeMessage(Folder folder, int index) : base(folder, index) + { + isModified = false; + isSaved = true; + isStrict = true; + Initialize(); + } + + protected MimeMessage(Folder folder, StreamReader reader, + int index) : this(folder, index) + { + Initialize(); + //this.reader = reader; + ParseMessage(reader); + } + + protected MimeMessage(Folder folder, HeaderList headers, + byte[] content, int index) : this(folder, index) + { + this.headers = headers; + this.content = content; + Initialize(); } - [MailTODO] private void Initialize() { if(session != null) { - String strict = (string)session.Properties["CSMail.mime.address.scrict"]; + String strict = (string)session.Properties[Constants.StrictCheck]; isStrict = (strict == null || String.Compare(strict, "false", false) != 0); } - throw new NotImplementedException(); } - [MailTODO] - protected virtual void ParseMessage() + protected virtual void ParseMessage(StreamReader reader) + { + CreateContentStream(reader); + ReadHeaders(reader); + contentType = new ContentType(headers["Content-Type"]); + ReadContent(reader); + } + + private void CreateContentStream(StreamReader reader) + { + Stream baseStream = reader.BaseStream; + contentReader = new StreamReader(baseStream); + } + + private void ReadHeaders(StreamReader reader) { headers = new HeaderList(reader); - CType = new ContentType(headers["Content-Type"]); - ReadContent(); - // Create the "contentStream" - throw new NotImplementedException(); } - private void ReadContent() + private void ReadContent(StreamReader reader) { - string data = reader.ReadToEnd(); - content = new byte[data.Length]; - for(int i = 0; i < content.Length; i++) + try + { + string data = reader.ReadToEnd(); + content = new byte[data.Length]; + for(int i = 0; i < content.Length; i++) + { + content[i] = (byte)data[i]; + } + } catch(OutOfMemoryException oome) + { + throw new MessagingException("Out of memory reading content", oome); + } catch(IOException ioe) { - content[i] = (byte)data[i]; + throw new MessagingException("Error reading content", ioe); } + isModified = false; } [MailTODO] @@ -118,11 +160,19 @@ { get { - return new EMailAddressList(headers["From"]); + string fromHeader = headers["From"]; + if(fromHeader == null) + fromHeader = headers["Sender"]; + if(fromHeader != null) + return new EMailAddressList(fromHeader); + return null; } set { - headers["From"] = value.ToString(); + if(value == null) + headers.RemoveAll("From", true); + else + headers["From"] = value.ToString(); } } @@ -134,15 +184,22 @@ } } - [MailTODO] - public override IAddressList Recipients + public override EMailAddressList Recipients { get { - throw new NotImplementedException(); + return (toList + ccList); } } - + + public override NewsAddressList NewsGroups + { + get + { + return ngroupList; + } + } + public override DateTime SentDate { get @@ -221,9 +278,9 @@ { get { - if(reader != null) + if(contentReader != null) { - Stream baseStream = reader.BaseStream; + Stream baseStream = contentReader.BaseStream; if(baseStream != null) { try @@ -238,6 +295,19 @@ } } + [MailTODO] + public override EMailAddressList ReplyTo + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + public override HeaderList Headers { get @@ -372,7 +442,7 @@ replyList = new EMailAddressList(); if(toAll) { - replyList = toList + ccList + bccList; + replyList = toList + ccList; } else { replyList = toList; @@ -382,7 +452,18 @@ public override IAddressList GetRecipients(RecipientType type) { - throw new NotImplementedException(); + if(!Enum.IsDefined(typeof(RecipientType), type)) + { + throw new ArgumentException("[GetRecipients] Illegal value in parameter"); + } + switch(type) + { + case RecipientType.To : return (IAddressList)toList; + case RecipientType.Cc : return (IAddressList)ccList; + case RecipientType.Bcc : return (IAddressList)bccList; + case RecipientType.NewsGroup : return (IAddressList)ngroupList; + default : throw new ArgumentException("[GetRecipients] Illegal value in parameter"); + } } public override void SaveChanges() @@ -390,7 +471,7 @@ throw new NotImplementedException(); } - public override void Write(TextWriter writer) + public override void Write(StreamWriter writer) { throw new NotImplementedException(); } Index: NewsAddressList.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/NewsAddressList.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- NewsAddressList.cs 30 Sep 2002 12:27:22 -0000 1.2 +++ NewsAddressList.cs 1 Oct 2002 10:33:20 -0000 1.3 @@ -8,6 +8,7 @@ * (C) Gaurav Vaish (2002) */ +using System; using System.Collections; namespace CSMail @@ -104,11 +105,16 @@ return news.Count; } - public int IndexOf(NewsAddressList address) + public int IndexOf(NewsAddress address) { return news.IndexOf(address); } + public bool Contains(NewsAddress address) + { + return (IndexOf(address) >= 0); + } + public void AddAt(int index, NewsAddressList address) { news.Insert(index, address); @@ -132,6 +138,68 @@ public IEnumerator GetEnumerator() { return news.GetEnumerator(); + } + + public static NewsAddressList operator +(NewsAddressList one, + NewsAddressList two) + { + if(one == null && two == null) + { + return null; + } + + NewsAddressList retVal = null; + if(one == null) + { + retVal = two; + } + + if(two == null) + { + retVal = one; + } + + if(one != null && two != null) + { + retVal = one; + foreach(NewsAddress current in two) + { + if(!retVal.Contains(current)) + retVal.Add(current); + } + } + return retVal; + } + + public static NewsAddressList operator +(NewsAddress address, + NewsAddressList list) + { + return (list + address); + } + + public static NewsAddressList operator +(NewsAddressList list, + NewsAddress address) + { + if(list == null && address == null) + { + return null; + } + + NewsAddressList retVal = new NewsAddressList(); + if(address != null) + { + retVal.Add(address); + } + + if(list != null) + { + foreach(NewsAddress current in list) + { + if(!retVal.Contains(current)) + retVal.Add(current); + } + } + return retVal; } } } Index: Session.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail/Session.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- Session.cs 10 Sep 2002 10:43:37 -0000 1.16 +++ Session.cs 1 Oct 2002 10:33:20 -0000 1.17 @@ -29,7 +29,7 @@ private static Session defaultSession; - private ArrayList dirsToSearch; + private ArrayList dirsToSearch = null; private bool areDirsSet; private Session() @@ -54,7 +54,7 @@ public Store GetStore() { - return GetStore("mail.store.protocol"); + return GetStore(Constants.StoreProtocol); } public Store GetStore(string protocol) @@ -84,7 +84,7 @@ public Transport GetTransport() { - return GetTransport("mail.transport.protocol"); + return GetTransport(Constants.TransportProtocol); } public Transport GetTransport(string protocol) @@ -141,10 +141,10 @@ addrMap = new Properties(); dirsToSearch = new ArrayList(); - debug = bool.Parse((string)this.properties["CSMail.debug"]); + debug = this.properties.GetBool(Constants.Debug, true); - this.LoadProviders(); - this.LoadAddressMap(); + LoadProviders(); + LoadAddressMap(); } public bool Debug @@ -174,7 +174,11 @@ { if(defaultSession == null) { - defaultSession = new Session(properties, authenticator); + lock(defaultSession) + { + if(defaultSession == null) + defaultSession = new Session(properties, authenticator); + } } else { if(defaultSession.authenticator != authenticator) @@ -201,9 +205,13 @@ private void LoadProviders() { // Load from the file. - if(!areDirsSet) + if(!areDirsSet || dirsToSearch == null) { - SetDirsToSearch(); + lock(dirsToSearch) + { + if(dirsToSearch == null) + SetDirsToSearch(); + } } foreach(string current in dirsToSearch) { @@ -254,8 +262,14 @@ private void LoadAddressMap() { // Load from the file. - if(!areDirsSet) - SetDirsToSearch(); + if(!areDirsSet || dirsToSearch == null) + { + lock(dirsToSearch) + { + if(dirsToSearch == null) + SetDirsToSearch(); + } + } foreach(string current in dirsToSearch) { LoadAddressMap(current); |