You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
(7) |
May
|
Jun
|
Jul
(79) |
Aug
(49) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
Update of /cvsroot/csmaild/csmaild/src/Imap/Commands In directory sc8-pr-cvs1:/tmp/cvs-serv32149/src/Imap/Commands Modified Files: AppendCommand.cs AuthenticateCommand.cs CapabilityCommand.cs CheckCommand.cs CloseCommand.cs CommandPart.cs CopyCommand.cs CreateCommand.cs DeleteCommand.cs ExamineCommand.cs ExpungeCommand.cs FetchCommand.cs ImapCommand.cs ListCommand.cs LoginCommand.cs LogoutCommand.cs LsubCommand.cs NoopCommand.cs RenameCommand.cs SearchCommand.cs SelectCommand.cs StarttlsCommand.cs StatusCommand.cs StoreCommand.cs SubscribeCommand.cs UidCommand.cs UnsubscribeCommand.cs Log Message: Long time, no commit. Upgraded to VS.NET 2003 Lots of code changes, still pre-pre-pre-alpha, so who's keeping track Index: AppendCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/AppendCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AppendCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- AppendCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class AppendCommand : ImapCommand { ! public AppendCommand() : base("APPEND", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class AppendCommand : ImapCommand { ! public AppendCommand(ImapServer svr) : base(svr, "APPEND", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: AuthenticateCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/AuthenticateCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AuthenticateCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- AuthenticateCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class AuthenticateCommand : ImapCommand { ! public AuthenticateCommand() : base("AUTHENTICATE", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class AuthenticateCommand : ImapCommand { ! public AuthenticateCommand(ImapServer svr) : base(svr, "AUTHENTICATE", ImapConnectionState.NotAuthenticated) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: CapabilityCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/CapabilityCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CapabilityCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- CapabilityCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Text; namespace Imap.Commands *************** *** 8,18 **** public class CapabilityCommand : ImapCommand { ! public CapabilityCommand() : base("CAPABILITY", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 9,39 ---- public class CapabilityCommand : ImapCommand { ! public CapabilityCommand(ImapServer svr) : base(svr, "CAPABILITY", ImapCommand.AnyState) { } ! override public void Process() { ! if(mArguments != string.Empty) ! { ! InvalidArguments(); ! return; ! } ! ! StringBuilder sb = new StringBuilder(); ! sb.Append(" * "); ! ! for(int idx=0; idx < Server.Capabilities.Length; ++idx) ! { ! sb.Append(Server.Capabilities[idx]); ! ! if(idx != Server.Capabilities.Length-1) ! sb.Append(" "); ! } ! mConnection.Connection.WriteLine(sb.ToString()); ! mConnection.SendTaggedMessage("OK CAPABILITY completed"); ! ! // done ! mConnection.ReadCommand(); } } Index: CheckCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/CheckCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CheckCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- CheckCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class CheckCommand : ImapCommand { ! public CheckCommand() : base("CHECK", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,27 ---- public class CheckCommand : ImapCommand { ! public CheckCommand(ImapServer svr) : base(svr, "CHECK", ImapConnectionState.Selected) { } ! override public void Process() { ! if(mArguments != string.Empty) ! { ! InvalidArguments(); ! return; ! } ! ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: CloseCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/CloseCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CloseCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- CloseCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class CloseCommand : ImapCommand { ! public CloseCommand() : base("CLOSE", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,27 ---- public class CloseCommand : ImapCommand { ! public CloseCommand(ImapServer svr) : base(svr, "CLOSE", ImapConnectionState.Selected) { } ! override public void Process() { ! if(mArguments != string.Empty) ! { ! InvalidArguments(); ! return; ! } ! ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: CommandPart.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/CommandPart.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CommandPart.cs 11 Apr 2003 07:21:42 -0000 1.1 --- CommandPart.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 1,3 **** --- 1,5 ---- using System; + using System.IO; + using System.Text.RegularExpressions; namespace Imap.Commands *************** *** 9,12 **** --- 11,97 ---- { abstract override public string ToString(); + abstract public void Parse(TextReader input); + + #region 'Valid characters for different string types' definitions + // quoted-specials = DQUOTE / "\" + public static string QuotedSpecials = "\"\\"; + // list-wildcards = "%" / "*" + public static string ListWildcards = "%*"; + // resp-specials = "]" + public static string RespSpecials = "]"; + // CTL = assumed to be all control characters (ASCII < 32) + public static string CTL = Range(0, 31); + // CHAR8 = %x01-ff ; any OCTET except NUL, %x00 + public static string CHAR8 = Range(1, 255); + // atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards / quoted-specials / resp-specials + public static string AtomSpecials = CombineChars("(){ ", CTL, ListWildcards, QuotedSpecials, RespSpecials); + // ATOM-CHAR = <any CHAR except atom-specials> + public static string AtomChar = RemoveChars(CHAR8, AtomSpecials); + // ASTRING-CHAR = ATOM-CHAR / resp-specials + public static string AStringChar = CombineChars(AtomChar, RespSpecials); + // tag = 1*<any ASTRING-CHAR except "+"> + public static string Tag = RemoveChars(AStringChar, "+"); + // TEXT-CHAR = <any CHAR except CR and LF> + public static string TextChar = RemoveChars(CHAR8, "\r\n"); + // QUOTED-CHAR = <any TEXT-CHAR except quoted specials> / "\" + public static string QuotedChar = RemoveChars(TextChar, QuotedSpecials); + + // digit-nz = %x31-39 ; 1-9 + public static string DigitNz = "123456789"; + // DIGIT + public static string Digit = "0123456798"; + + + protected static string Range(int low, int high) + { + string rng = string.Empty; + for(int idx=low; idx<=high; ++idx) + rng += Convert.ToChar(idx); + + return rng; + } + protected static string RemoveChars(string source, params string[] toRemoveStrings) + { + // not efficient, but it only happens once, so who cares - for now + // TODO: make a tad more efficient + int idx = 0; + foreach(string toRemoveString in toRemoveStrings) + foreach(char toRemove in toRemoveString) + while((idx = source.IndexOf(toRemove)) != -1) + source = source.Remove(idx, 1); + + return source; + } + private static string CombineChars(string source, params string[] toCombineStrings) + { + // not efficient, but it only happens once, so who cares - for now + // TODO: make a tad more efficient + foreach(string toCombineString in toCombineStrings) + foreach(char toCombine in toCombineString) + if(source.IndexOf(toCombine) == -1) + source += toCombine; + + return source; + } + + protected static bool ValidateString(string str, string validChars) + { + foreach(char c in str) + if(validChars.IndexOf(c) == -1) + return false; + + return true; + } + + public static bool ValidateTagCharacters(string tag) + { + return ValidateString(tag, Tag); + } + + public static bool IsLiteralStart(string str) + { + return Regex.IsMatch(str, "^{[0-9]+}$"); + } + #endregion } *************** *** 23,32 **** } ! static public CommandAtom Parse(string str) { // TODO: implement sytax rules for atoms ! CommandAtom rv = new CommandAtom(); ! rv.mString = str; ! return rv; } } --- 108,115 ---- } ! override public void Parse(TextReader input) { // TODO: implement sytax rules for atoms ! mString = input.ReadToEnd(); } } *************** *** 44,58 **** } ! static public CommandNumber Parse(string str) { // TODO: implement sytax rules for numbers ! CommandNumber rv = new CommandNumber(); ! rv.mNumber = int.Parse(str); ! return rv; } } /// <summary> ! /// Represents a string /// </summary> public class CommandString : CommandPart --- 127,168 ---- } ! override public void Parse(TextReader input) { // TODO: implement sytax rules for numbers ! mNumber = int.Parse(input.ReadToEnd()); } } /// <summary> ! /* ! 4.3. String ! ! A string is in one of two forms: either literal or quoted ! string. The literal form is the general form of string. The ! quoted string form is an alternative that avoids the overhead of ! processing a literal at the cost of limitations of characters ! which may be used. ! ! A literal is a sequence of zero or more octets (including CR and ! LF), prefix-quoted with an octet count in the form of an open ! brace ("{"), the number of octets, close brace ("}"), and CRLF. ! In the case of literals transmitted from server to client, the ! CRLF is immediately followed by the octet data. In the case of ! literals transmitted from client to server, the client MUST wait ! to receive a command continuation request (described later in ! this document) before sending the octet data (and the remainder ! of the command). ! ! A quoted string is a sequence of zero or more 7-bit characters, ! excluding CR and LF, with double quote (<">) characters at each ! end. ! ! The empty string is represented as either "" (a quoted string ! with zero characters between double quotes) or as {0} followed ! by CRLF (a literal with an octet count of 0). ! ! Note: Even if the octet count is 0, a client transmitting a ! literal MUST wait to receive a command continuation request. ! */ /// </summary> public class CommandString : CommandPart *************** *** 65,74 **** } ! static public CommandString Parse(string str) { // TODO: implement sytax rules for strings ! CommandString rv = new CommandString(); ! rv.mString = str; ! return rv; } } --- 175,220 ---- } ! override public void Parse(TextReader input) { + // astring = 1*ASTRING-CHAR / string + // string = quoted / literal + // literal = "{" number "}" CRLF *CHAR8 ; Number represents the number of CHAR8s + // quoted = DQUOTE *QUOTED-CHAR DQUOTE + + // it's gotta start with a '"' + if(input.Peek() != '"') + throw new Exception("Not a string"); + + input.Read(); // skip the quote + // TODO: implement sytax rules for strings ! while(input.Peek() != '"' && input.Peek() != -1) ! mString += (char)input.Read(); ! ! // it must end with a '"' ! if(input.Peek() != '"') ! throw new Exception("Not a string"); ! ! input.Read(); // skip the quote ! } ! } ! ! public class CommandAtomString : CommandPart ! { ! private CommandPart mCommandPart; ! ! override public string ToString() ! { ! return mCommandPart.ToString(); ! } ! ! override public void Parse(TextReader input) ! { ! if(input.Peek() == '"') ! mCommandPart = new CommandString(); ! else ! mCommandPart = new CommandAtom(); ! ! mCommandPart.Parse(input); } } Index: CopyCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/CopyCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CopyCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- CopyCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class CopyCommand : ImapCommand { ! public CopyCommand() : base("COPY", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class CopyCommand : ImapCommand { ! public CopyCommand(ImapServer svr) : base(svr, "COPY", ImapConnectionState.Selected) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: CreateCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/CreateCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CreateCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- CreateCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class CreateCommand : ImapCommand { ! public CreateCommand() : base("CREATE", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class CreateCommand : ImapCommand { ! public CreateCommand(ImapServer svr) : base(svr, "CREATE", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: DeleteCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/DeleteCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DeleteCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- DeleteCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class DeleteCommand : ImapCommand { ! public DeleteCommand() : base("DELETE", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class DeleteCommand : ImapCommand { ! public DeleteCommand(ImapServer svr) : base(svr, "DELETE", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: ExamineCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/ExamineCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExamineCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- ExamineCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class ExamineCommand : ImapCommand { ! public ExamineCommand() : base("EXAMINE", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class ExamineCommand : ImapCommand { ! public ExamineCommand(ImapServer svr) : base(svr, "EXAMINE", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: ExpungeCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/ExpungeCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExpungeCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- ExpungeCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class ExpungeCommand : ImapCommand { ! public ExpungeCommand() : base("EXPUNGE", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,27 ---- public class ExpungeCommand : ImapCommand { ! public ExpungeCommand(ImapServer svr) : base(svr, "EXPUNGE", ImapConnectionState.Selected) { } ! override public void Process() { ! if(mArguments != string.Empty) ! { ! InvalidArguments(); ! return; ! } ! ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: FetchCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/FetchCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FetchCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- FetchCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class FetchCommand : ImapCommand { ! public FetchCommand() : base("FETCH", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class FetchCommand : ImapCommand { ! public FetchCommand(ImapServer svr) : base(svr, "FETCH", ImapConnectionState.Selected) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: ImapCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/ImapCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ImapCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- ImapCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 1,2 **** --- 1,4 ---- + using Imap.NetworkManager; + using System; *************** *** 8,14 **** abstract public class ImapCommand { private string mCommand; ! private CommandPart[] mCommandParts; ! private Imap.ImapConnectionState mMinimumState; public string Command --- 10,28 ---- abstract public class ImapCommand { + public static ImapConnectionState AnyState = ImapConnectionState.Authenticated | ImapConnectionState.Selected | ImapConnectionState.NotAuthenticated; + public static ImapConnectionState AuthSelectedState = ImapConnectionState.Authenticated | ImapConnectionState.Selected; + + protected event ReadAStringDelegate mReadAStringEvent; + protected delegate void ReadAStringDelegate(bool valid, string str); + private string mCommand; ! private ImapConnectionState mValidStates; ! private ImapServer mServer; ! private bool mReadLiteralSuccess; ! private string mReadLiteralString; ! ! protected string mArguments; ! protected int mArgumentIndex; ! protected ImapConnection mConnection; public string Command *************** *** 20,31 **** } ! public ImapCommand(string command, Imap.ImapConnectionState minimumState, params CommandPart[] commandParts) { mCommand = command; ! mMinimumState = minimumState; ! mCommandParts = commandParts; } ! abstract public void Process(ImapConnection con, string tag); } } --- 34,227 ---- } ! public ImapServer Server ! { ! get ! { ! return mServer; ! } ! } ! ! public ImapCommand(ImapServer svr, string command, Imap.ImapConnectionState validStates) { + mServer = svr; mCommand = command; ! mValidStates = validStates; } ! public void Initialize(string arguments, ImapConnection con) ! { ! mArguments = arguments; ! mConnection = con; ! } ! ! public bool ValidateState() ! { ! return ((mConnection.State & mValidStates) == mConnection.State); ! } ! ! abstract public void Process(); ! ! protected void InvalidArguments() ! { ! mConnection.SendTaggedMessage("BAD"); ! mConnection.ReadCommand(); ! } ! ! protected void ReadAString(ReadAStringDelegate handler, bool includesPrecedingSpace) ! { ! mReadAStringEvent = null; // hopefully will unsubscribe the last guy ! ! if(includesPrecedingSpace) ! ++mArgumentIndex; // move past the space at the beginning ! ! if(mArguments == string.Empty) ! handler(false, string.Empty); ! else if(mArguments[mArgumentIndex] == '{') // literal string ! ReadLiteralString(handler); ! else if(mArguments[mArgumentIndex] == '"') // quoted string ! { ! string str; ! if(ReadQuotedString(out str)) ! handler(true, str); ! else ! handler(false, string.Empty); ! } ! else // atom ! { ! string str; ! if(ReadAtom(out str)) ! handler(true, str); ! else ! handler(false, string.Empty); ! } ! } ! ! protected void ReadLiteralString(ReadAStringDelegate callback) ! { ! ++mArgumentIndex; // move past '{' ! ! int literalSize; ! ! // read digit-nz ! if(CommandPart.DigitNz.IndexOf(mArguments[mArgumentIndex]) != -1) ! { ! literalSize = int.Parse(mArguments[mArgumentIndex] + string.Empty); ! ! // read the rest of the digits ! for(++mArgumentIndex; mArgumentIndex < mArguments.Length; ++mArgumentIndex) ! { ! if(mArguments[mArgumentIndex] == '}') ! { ! ++mArgumentIndex; ! if(mArgumentIndex != mArguments.Length) ! callback(false, string.Empty); // literal size line must end after the '}' ! else ! { ! mReadAStringEvent += callback; ! mConnection.SendContinueMessage("Ready"); ! mConnection.Connection.ReadBlock(new byte[literalSize], 0, literalSize, new ReceivedBlockDelegate(ReceivedLiteralString)); ! break; ! } ! } ! else if(CommandPart.Digit.IndexOf(mArguments[mArgumentIndex]) != -1) ! { ! literalSize *= 10; ! literalSize += int.Parse(mArguments[mArgumentIndex] + string.Empty); ! } ! else // not a valid digit ! callback(false, string.Empty); ! } ! } ! else // not a valid digit ! callback(false, string.Empty); ! } ! ! protected bool ReadAtom(out string atomString) ! { ! bool isGood = true; // will determine whether we've read a valid atom ! atomString = string.Empty; // will store the atom as we "read" it ! ! for(; mArgumentIndex < mArguments.Length; ++ mArgumentIndex) ! { ! if(CommandPart.AtomChar.IndexOf(mArguments[mArgumentIndex]) != -1) ! atomString += mArguments[mArgumentIndex]; ! else // not found, bad char ! { ! isGood = false; ! ++mArgumentIndex; ! break; ! } ! } ! ! return isGood; ! } ! ! protected bool ReadQuotedString(out string quotedString) ! { ! bool readEscape = false; // keeps track of whether or not we just read the escape character "\" ! bool isGood = false; // will determine whether we've read a valid quoted string ! quotedString = string.Empty; // will store the quoted string as we "read" it ! ! for(++mArgumentIndex; mArgumentIndex < mArguments.Length; ++mArgumentIndex) ! { ! if(mArguments[mArgumentIndex] == '"') ! { ! if(readEscape) ! quotedString += mArguments[mArgumentIndex]; ! else ! { ! isGood = true; // only good when we read an unescaped quote ! ++mArgumentIndex; ! break; // done ! } ! } ! else if(mArguments[mArgumentIndex] == '\\') ! { ! if(readEscape) ! quotedString += mArguments[mArgumentIndex]; ! else ! readEscape = true; ! } ! else ! { ! if(CommandPart.TextChar.IndexOf(mArguments[mArgumentIndex]) != -1) // it's found, good char ! quotedString += mArguments[mArgumentIndex]; ! else // not found, bad char ! { ! ++mArgumentIndex; ! break; ! } ! } ! } ! ! return isGood; ! } ! ! private void ReceivedLiteralString(Connection con, byte[] block) ! { ! mReadLiteralSuccess = true; ! mReadLiteralString = System.Text.Encoding.ASCII.GetString(block); ! for(int idx = 0; idx < mReadLiteralString.Length; ++idx) ! { ! if(CommandPart.CHAR8.IndexOf(mReadLiteralString[idx]) == -1) ! { ! mReadLiteralSuccess = false; ! break; ! } ! } ! ! mConnection.Connection.ReadLine(new ReceivedLineDelegate(ReceivedLineAfterLiteral)); ! } ! ! private void ReceivedLineAfterLiteral(Connection con, string line) ! { ! mArgumentIndex = 0; ! mArguments = line; ! ! if(mReadLiteralSuccess) ! mReadAStringEvent(true, mReadLiteralString); ! else ! mReadAStringEvent(false, string.Empty); ! } } } Index: ListCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/ListCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ListCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- ListCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 1,2 **** --- 1,4 ---- + using Common; + using System; *************** *** 8,18 **** public class ListCommand : ImapCommand { ! public ListCommand() : base("LIST", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 10,27 ---- public class ListCommand : ImapCommand { ! public ListCommand(ImapServer svr) : base(svr, "LIST", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! // TODO: actually handle the arguments ! foreach(Mailbox box in Server.MailstoreProvider.GetMailboxes()) ! mConnection.SendUntaggedMessage("LIST() \"/\" \"" + box.Name + "\""); ! ! mConnection.SendTaggedMessage("OK LIST completed"); ! ! // done ! mConnection.ReadCommand(); } } Index: LoginCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/LoginCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LoginCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- LoginCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 1,2 **** --- 1,4 ---- + using Imap.NetworkManager; + using System; *************** *** 8,18 **** public class LoginCommand : ImapCommand { ! public LoginCommand() : base("LOGIN", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 10,45 ---- public class LoginCommand : ImapCommand { ! public LoginCommand(ImapServer svr) : base(svr, "LOGIN", ImapConnectionState.NotAuthenticated) { } ! override public void Process() { ! ReadAString(new ReadAStringDelegate(ReceivedUsername), true); ! } ! ! private void ReceivedUsername(bool valid, string str) ! { ! if(valid) // good so far, now get the password ! ReadAString(new ReadAStringDelegate(ReceivedPassword), true); ! else ! { ! mConnection.SendTaggedMessage("BAD"); ! mConnection.ReadCommand(); ! } ! } ! ! private void ReceivedPassword(bool valid, string str) ! { ! if(valid) // good, yay, go security ! { ! mConnection.State = ImapConnectionState.Authenticated; ! mConnection.SendTaggedMessage("OK LOGIN completed"); ! } ! else ! mConnection.SendTaggedMessage("BAD"); ! ! // done ! mConnection.ReadCommand(); } } Index: LogoutCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/LogoutCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LogoutCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- LogoutCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class LogoutCommand : ImapCommand { ! public LogoutCommand() : base("LOGOUT", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,27 ---- public class LogoutCommand : ImapCommand { ! public LogoutCommand(ImapServer svr) : base(svr, "LOGOUT", ImapCommand.AnyState) { } ! override public void Process() { ! if(mArguments != string.Empty) ! { ! InvalidArguments(); ! return; ! } ! ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: LsubCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/LsubCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LsubCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- LsubCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class LsubCommand : ImapCommand { ! public LsubCommand() : base("LSUB", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class LsubCommand : ImapCommand { ! public LsubCommand(ImapServer svr) : base(svr, "LSUB", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: NoopCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/NoopCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NoopCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- NoopCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class NoopCommand : ImapCommand { ! public NoopCommand() : base("NOOP", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,27 ---- public class NoopCommand : ImapCommand { ! public NoopCommand(ImapServer svr) : base(svr, "NOOP", ImapCommand.AnyState) { } ! override public void Process() { ! if(mArguments != string.Empty) ! { ! InvalidArguments(); ! return; ! } ! ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: RenameCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/RenameCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RenameCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- RenameCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class RenameCommand : ImapCommand { ! public RenameCommand() : base("RENAME", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class RenameCommand : ImapCommand { ! public RenameCommand(ImapServer svr) : base(svr, "RENAME", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: SearchCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/SearchCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SearchCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- SearchCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class SearchCommand : ImapCommand { ! public SearchCommand() : base("SEARCH", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class SearchCommand : ImapCommand { ! public SearchCommand(ImapServer svr) : base(svr, "SEARCH", ImapConnectionState.Selected) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: SelectCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/SelectCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SelectCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- SelectCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class SelectCommand : ImapCommand { ! public SelectCommand() : base("SELECT", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class SelectCommand : ImapCommand { ! public SelectCommand(ImapServer svr) : base(svr, "SELECT", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: StarttlsCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/StarttlsCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StarttlsCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- StarttlsCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class StarttlsCommand : ImapCommand { ! public StarttlsCommand() : base("STARTTLS", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,27 ---- public class StarttlsCommand : ImapCommand { ! public StarttlsCommand(ImapServer svr) : base(svr, "STARTTLS", ImapConnectionState.NotAuthenticated) { } ! override public void Process() { ! if(mArguments != string.Empty) ! { ! InvalidArguments(); ! return; ! } ! ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: StatusCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/StatusCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StatusCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- StatusCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class StatusCommand : ImapCommand { ! public StatusCommand() : base("STATUS", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class StatusCommand : ImapCommand { ! public StatusCommand(ImapServer svr) : base(svr, "STATUS", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: StoreCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/StoreCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StoreCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- StoreCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class StoreCommand : ImapCommand { ! public StoreCommand() : base("STORE", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class StoreCommand : ImapCommand { ! public StoreCommand(ImapServer svr) : base(svr, "STORE", ImapConnectionState.Selected) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: SubscribeCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/SubscribeCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SubscribeCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- SubscribeCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class SubscribeCommand : ImapCommand { ! public SubscribeCommand() : base("SUBSCRIBE", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class SubscribeCommand : ImapCommand { ! public SubscribeCommand(ImapServer svr) : base(svr, "SUBSCRIBE", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: UidCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/UidCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** UidCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- UidCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class UidCommand : ImapCommand { ! public UidCommand() : base("UID", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class UidCommand : ImapCommand { ! public UidCommand(ImapServer svr) : base(svr, "UID", ImapConnectionState.Selected) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } Index: UnsubscribeCommand.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/UnsubscribeCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** UnsubscribeCommand.cs 11 Apr 2003 07:21:42 -0000 1.1 --- UnsubscribeCommand.cs 24 Jul 2003 04:32:14 -0000 1.2 *************** *** 8,18 **** public class UnsubscribeCommand : ImapCommand { ! public UnsubscribeCommand() : base("UNSUBSCRIBE", Imap.ImapConnectionState.NotAuthenticated, null) { } ! override public void Process(ImapConnection con, string tag) { ! con.Connection.WriteLine(tag + " OK"); } } --- 8,21 ---- public class UnsubscribeCommand : ImapCommand { ! public UnsubscribeCommand(ImapServer svr) : base(svr, "UNSUBSCRIBE", ImapCommand.AuthSelectedState) { } ! override public void Process() { ! mConnection.SendTaggedMessage("OK"); ! ! // done ! mConnection.ReadCommand(); } } |
From: <ta...@us...> - 2003-07-24 04:30:37
|
Update of /cvsroot/csmaild/csmaild/src/Common/MailstoreProviders In directory sc8-pr-cvs1:/tmp/cvs-serv31892/MailstoreProviders Log Message: Directory /cvsroot/csmaild/csmaild/src/Common/MailstoreProviders added to the repository |
From: <ta...@us...> - 2003-07-24 04:30:32
|
Update of /cvsroot/csmaild/csmaild/src/TestClient In directory sc8-pr-cvs1:/tmp/cvs-serv31867/TestClient Log Message: Directory /cvsroot/csmaild/csmaild/src/TestClient added to the repository |
From: <bk...@us...> - 2003-04-12 18:10:19
|
Update of /cvsroot/csmaild/csmaild/src/Imap/NetworkManager In directory sc8-pr-cvs1:/tmp/cvs-serv17506/src/Imap/NetworkManager Modified Files: Connection.cs Log Message: Fix comment typo. Index: Connection.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/NetworkManager/Connection.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Connection.cs 11 Apr 2003 01:29:26 -0000 1.2 --- Connection.cs 12 Apr 2003 18:10:15 -0000 1.3 *************** *** 32,36 **** #region Events /// <summary> ! /// Fires whnever a line is received from the client /// </summary> public event ReceivedLineDelegate ReceivedLineEvent; --- 32,36 ---- #region Events /// <summary> ! /// Fires whenever a line is received from the client /// </summary> public event ReceivedLineDelegate ReceivedLineEvent; |
From: <ta...@us...> - 2003-04-11 07:21:46
|
Update of /cvsroot/csmaild/csmaild/src/Imap In directory sc8-pr-cvs1:/tmp/cvs-serv15772/src/Imap Modified Files: Connection.cs Imap.csproj Server.cs Log Message: Index: Connection.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Connection.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Connection.cs 11 Apr 2003 01:29:25 -0000 1.2 --- Connection.cs 11 Apr 2003 07:21:41 -0000 1.3 *************** *** 37,40 **** --- 37,48 ---- } + public Connection Connection + { + get + { + return mConnection; + } + } + /// <summary> /// Creates a new ImapConnection object, starts in NotAuthenticated state *************** *** 43,47 **** public ImapConnection(Connection con) { ! mConnection = mConnection; mState = ImapConnectionState.NotAuthenticated; } --- 51,55 ---- public ImapConnection(Connection con) { ! mConnection = con; mState = ImapConnectionState.NotAuthenticated; } Index: Imap.csproj =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Imap.csproj,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Imap.csproj 11 Apr 2003 01:29:25 -0000 1.3 --- Imap.csproj 11 Apr 2003 07:21:42 -0000 1.4 *************** *** 93,96 **** --- 93,121 ---- /> <File + RelPath = "Commands\AppendCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\AuthenticateCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\CapabilityCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\CheckCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\CloseCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Commands\CommandPart.cs" SubType = "Code" *************** *** 98,102 **** --- 123,227 ---- /> <File + RelPath = "Commands\CopyCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\CreateCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\DeleteCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\ExamineCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\ExpungeCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\FetchCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Commands\ImapCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\ListCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\LoginCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\LogoutCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\LsubCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\NoopCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\RenameCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\SearchCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\SelectCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\StarttlsCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\StatusCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\StoreCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\SubscribeCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\UidCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\UnsubscribeCommand.cs" SubType = "Code" BuildAction = "Compile" Index: Server.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Server.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Server.cs 11 Apr 2003 01:29:25 -0000 1.3 --- Server.cs 11 Apr 2003 07:21:42 -0000 1.4 *************** *** 1,3 **** --- 1,4 ---- using System; + using Imap.Commands; using Imap.NetworkManager; using System.Collections; *************** *** 12,15 **** --- 13,17 ---- private NetworkManager.NetworkManager mNetwork; private Hashtable mImapConnections = new Hashtable(); + private Hashtable mImapCommands = new Hashtable(); public Server() *************** *** 17,20 **** --- 19,50 ---- mNetwork = new NetworkManager.NetworkManager(); mImapConnections = new Hashtable(); + + #region Register handlers + mImapCommands.Add("APPEND", new AppendCommand()); + mImapCommands.Add("AUTHENTICATE", new AuthenticateCommand()); + mImapCommands.Add("CAPABILITY", new CapabilityCommand()); + mImapCommands.Add("CHECK", new CheckCommand()); + mImapCommands.Add("CLOSE", new CloseCommand()); + mImapCommands.Add("COPY", new CopyCommand()); + mImapCommands.Add("CREATE", new CreateCommand()); + mImapCommands.Add("DELETE", new DeleteCommand()); + mImapCommands.Add("EXAMINE", new ExamineCommand()); + mImapCommands.Add("EXPUNGE", new ExpungeCommand()); + mImapCommands.Add("FETCH", new FetchCommand()); + mImapCommands.Add("LIST", new ListCommand()); + mImapCommands.Add("LOGIN", new LoginCommand()); + mImapCommands.Add("LOGOUT", new LogoutCommand()); + mImapCommands.Add("LSUB", new LsubCommand()); + mImapCommands.Add("NOOP", new NoopCommand()); + mImapCommands.Add("RENAME", new RenameCommand()); + mImapCommands.Add("SEARCH", new SearchCommand()); + mImapCommands.Add("SELECT", new SelectCommand()); + mImapCommands.Add("STARTTLS", new StarttlsCommand()); + mImapCommands.Add("STATUS", new StatusCommand()); + mImapCommands.Add("STORE", new StoreCommand()); + mImapCommands.Add("SUBSCRIBE", new SubscribeCommand()); + mImapCommands.Add("UID", new UidCommand()); + mImapCommands.Add("UNSUBSCRIBE", new UnsubscribeCommand()); + #endregion } *************** *** 56,59 **** --- 86,96 ---- string tag = line.Substring(0, idxTag); string cmd = line.Substring(idxTag+1, idxCommand-idxTag-1); + string args = line.Substring(idxCommand+1); + + ImapCommand command = (ImapCommand)mImapCommands[cmd]; + if(command != null) + command.Process((ImapConnection)mImapConnections[con], tag); + else + ((ImapConnection)mImapConnections[con]).Connection.WriteLine(tag + " BAD"); con.ReadLine(); |
Update of /cvsroot/csmaild/csmaild/src/Imap/Commands In directory sc8-pr-cvs1:/tmp/cvs-serv15772/src/Imap/Commands Added Files: AppendCommand.cs AuthenticateCommand.cs CapabilityCommand.cs CheckCommand.cs CloseCommand.cs CommandPart.cs CopyCommand.cs CreateCommand.cs DeleteCommand.cs ExamineCommand.cs ExpungeCommand.cs FetchCommand.cs ImapCommand.cs ListCommand.cs LoginCommand.cs LogoutCommand.cs LsubCommand.cs NoopCommand.cs RenameCommand.cs SearchCommand.cs SelectCommand.cs StarttlsCommand.cs StatusCommand.cs StoreCommand.cs SubscribeCommand.cs UidCommand.cs UnsubscribeCommand.cs Log Message: --- NEW FILE: AppendCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for AppendCommand. /// </summary> public class AppendCommand : ImapCommand { public AppendCommand() : base("APPEND", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: AuthenticateCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for AuthenticateCommand. /// </summary> public class AuthenticateCommand : ImapCommand { public AuthenticateCommand() : base("AUTHENTICATE", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: CapabilityCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for CapabilityCommand. /// </summary> public class CapabilityCommand : ImapCommand { public CapabilityCommand() : base("CAPABILITY", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: CheckCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for CheckCommand. /// </summary> public class CheckCommand : ImapCommand { public CheckCommand() : base("CHECK", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: CloseCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for CloseCommand. /// </summary> public class CloseCommand : ImapCommand { public CloseCommand() : base("CLOSE", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: CommandPart.cs --- using System; namespace Imap.Commands { /// <summary> /// Base class for all command part types /// </summary> abstract public class CommandPart { abstract override public string ToString(); } /// <summary> /// Represents an atom /// </summary> public class CommandAtom : CommandPart { private string mString; override public string ToString() { return mString; } static public CommandAtom Parse(string str) { // TODO: implement sytax rules for atoms CommandAtom rv = new CommandAtom(); rv.mString = str; return rv; } } /// <summary> /// Represents a number /// </summary> public class CommandNumber : CommandPart { private int mNumber; override public string ToString() { return mNumber.ToString(); } static public CommandNumber Parse(string str) { // TODO: implement sytax rules for numbers CommandNumber rv = new CommandNumber(); rv.mNumber = int.Parse(str); return rv; } } /// <summary> /// Represents a string /// </summary> public class CommandString : CommandPart { private string mString; override public string ToString() { return mString; } static public CommandString Parse(string str) { // TODO: implement sytax rules for strings CommandString rv = new CommandString(); rv.mString = str; return rv; } } } --- NEW FILE: CopyCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for CopyCommand. /// </summary> public class CopyCommand : ImapCommand { public CopyCommand() : base("COPY", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: CreateCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for CreateCommand. /// </summary> public class CreateCommand : ImapCommand { public CreateCommand() : base("CREATE", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: DeleteCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for DeleteCommand. /// </summary> public class DeleteCommand : ImapCommand { public DeleteCommand() : base("DELETE", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: ExamineCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for ExamineCommand. /// </summary> public class ExamineCommand : ImapCommand { public ExamineCommand() : base("EXAMINE", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: ExpungeCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for ExpungeCommand. /// </summary> public class ExpungeCommand : ImapCommand { public ExpungeCommand() : base("EXPUNGE", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: FetchCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for FetchCommand. /// </summary> public class FetchCommand : ImapCommand { public FetchCommand() : base("FETCH", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: ImapCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Base class for all commands /// </summary> abstract public class ImapCommand { private string mCommand; private CommandPart[] mCommandParts; private Imap.ImapConnectionState mMinimumState; public string Command { get { return mCommand; } } public ImapCommand(string command, Imap.ImapConnectionState minimumState, params CommandPart[] commandParts) { mCommand = command; mMinimumState = minimumState; mCommandParts = commandParts; } abstract public void Process(ImapConnection con, string tag); } } --- NEW FILE: ListCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for ListCommand. /// </summary> public class ListCommand : ImapCommand { public ListCommand() : base("LIST", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: LoginCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for LoginCommand. /// </summary> public class LoginCommand : ImapCommand { public LoginCommand() : base("LOGIN", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: LogoutCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for LogoutCommand. /// </summary> public class LogoutCommand : ImapCommand { public LogoutCommand() : base("LOGOUT", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: LsubCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for LsubCommand. /// </summary> public class LsubCommand : ImapCommand { public LsubCommand() : base("LSUB", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: NoopCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for NoopCommand. /// </summary> public class NoopCommand : ImapCommand { public NoopCommand() : base("NOOP", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: RenameCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for RenameCommand. /// </summary> public class RenameCommand : ImapCommand { public RenameCommand() : base("RENAME", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: SearchCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for SearchCommand. /// </summary> public class SearchCommand : ImapCommand { public SearchCommand() : base("SEARCH", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: SelectCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for SelectCommand. /// </summary> public class SelectCommand : ImapCommand { public SelectCommand() : base("SELECT", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: StarttlsCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for StarttlsCommand. /// </summary> public class StarttlsCommand : ImapCommand { public StarttlsCommand() : base("STARTTLS", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: StatusCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for StatusCommand. /// </summary> public class StatusCommand : ImapCommand { public StatusCommand() : base("STATUS", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: StoreCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for StoreCommand. /// </summary> public class StoreCommand : ImapCommand { public StoreCommand() : base("STORE", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: SubscribeCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for SubscribeCommand. /// </summary> public class SubscribeCommand : ImapCommand { public SubscribeCommand() : base("SUBSCRIBE", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: UidCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for UidCommand. /// </summary> public class UidCommand : ImapCommand { public UidCommand() : base("UID", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } --- NEW FILE: UnsubscribeCommand.cs --- using System; namespace Imap.Commands { /// <summary> /// Summary description for UnsubscribeCommand. /// </summary> public class UnsubscribeCommand : ImapCommand { public UnsubscribeCommand() : base("UNSUBSCRIBE", Imap.ImapConnectionState.NotAuthenticated, null) { } override public void Process(ImapConnection con, string tag) { con.Connection.WriteLine(tag + " OK"); } } } |
From: <ta...@us...> - 2003-04-11 07:20:53
|
Update of /cvsroot/csmaild/csmaild/src/Imap/Commands In directory sc8-pr-cvs1:/tmp/cvs-serv15349/Commands Log Message: Directory /cvsroot/csmaild/csmaild/src/Imap/Commands added to the repository |
From: <ta...@us...> - 2003-04-11 01:29:29
|
Update of /cvsroot/csmaild/csmaild/src/Imap In directory sc8-pr-cvs1:/tmp/cvs-serv31710/src/Imap Modified Files: Connection.cs Imap.csproj Server.cs Log Message: Just for historical purposes. Index: Connection.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Connection.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Connection.cs 8 Apr 2003 03:01:33 -0000 1.1 --- Connection.cs 11 Apr 2003 01:29:25 -0000 1.2 *************** *** 2,62 **** using System.Net.Sockets; using System.Text; namespace Imap { /// <summary> ! /// Represents a single client connection /// </summary> ! public class Connection { ! private Socket mClient; ! private byte[] mReceiveBuffer; ! private StringBuilder mWorkingLine; ! public Socket Socket { get { ! return mClient; } ! } ! ! public byte[] ReceiveBuffer ! { ! get { ! return mReceiveBuffer; } } - public void AddToWorkingLine(string add) - { - mWorkingLine.Append(add); - } - - /// <summary> - /// Get's the current working line - /// </summary> - /// <param name="onlyPeek">True if you want keep the current working line as is</param> - /// <returns></returns> - public string GetWorkingLine(bool onlyPeek) - { - string rv = mWorkingLine.ToString(); - - if(!onlyPeek) - mWorkingLine = new StringBuilder(998); - - return rv; - } - /// <summary> ! /// Creates a new Connection object /// </summary> ! /// <param name="client">The Socket for this Connection</param> ! public Connection(Socket client) { ! mClient = client; ! mReceiveBuffer = new byte[4096]; ! mWorkingLine = new StringBuilder(998); } } --- 2,48 ---- using System.Net.Sockets; using System.Text; + using Imap.NetworkManager; namespace Imap { /// <summary> ! /// The various states an ImapConnection can be in /// </summary> ! public enum ImapConnectionState : byte { ! NotAuthenticated, /// user is not authenticated, generally right after a connect ! Authenticated, /// user is authenticated, but no mailboxes are selected ! Selected, /// user has selected an active mailbox ! Logout /// not much of a state, but eh ! } ! /// <summary> ! /// Represents an IMAP connection ! /// </summary> ! public class ImapConnection ! { ! private Connection mConnection; ! private ImapConnectionState mState; ! ! public ImapConnectionState State { get { ! return mState; } ! set { ! mState = value; } } /// <summary> ! /// Creates a new ImapConnection object, starts in NotAuthenticated state /// </summary> ! /// <param name="client">The network connection for this</param> ! public ImapConnection(Connection con) { ! mConnection = mConnection; ! mState = ImapConnectionState.NotAuthenticated; } } Index: Imap.csproj =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Imap.csproj,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Imap.csproj 9 Apr 2003 05:00:31 -0000 1.2 --- Imap.csproj 11 Apr 2003 01:29:25 -0000 1.3 *************** *** 83,87 **** --- 83,102 ---- /> <File + RelPath = "Connection.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Server.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\CommandPart.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Commands\ImapCommand.cs" SubType = "Code" BuildAction = "Compile" Index: Server.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/Server.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Server.cs 9 Apr 2003 05:00:32 -0000 1.2 --- Server.cs 11 Apr 2003 01:29:25 -0000 1.3 *************** *** 1,67 **** ! //using System; ! //using System.Collections; //using System.IO; //using System.Net.Sockets; //using System.Text; ! // ! //namespace Imap ! //{ ! // public class Server ! // { ! // private TcpListener mListener; ! // private ArrayList mConnections = new ArrayList(); ! // ! // public Server() ! // { ! // mListener = new TcpListener(143); ! // mListener.Start(); ! // } ! // ! // public void ServerLoop() ! // { ! // while(true) ! // { ! // Socket socket = mListener.AcceptSocket(); ! // Connection con = new Connection(socket); ! // ! // byte[] buf = Encoding.ASCII.GetBytes("* OK Welcome!!\r\n"); ! // ! // socket.BeginSend(buf, 0, buf.Length, SocketFlags.None, new AsyncCallback(SendStuffFromClient), con); ! // socket.BeginReceive(con.ReceiveBuffer, 0, con.ReceiveBuffer.Length, SocketFlags.None, new AsyncCallback(GetStuffFromClient), con); ! // } ! // } ! // ! // public void GetStuffFromClient(IAsyncResult result) ! // { ! // Connection con = (Connection)result.AsyncState; ! // ! // int got = con.Socket.EndReceive(result); ! // ! // if(got == 0) // connection was closed ! // { ! // System.Console.WriteLine(con.Socket.Handle.ToString() + ": closed!"); ! // con.Socket.Close(); ! // } ! // else ! // { ! // con.Socket.BeginReceive(con.ReceiveBuffer, 0, con.ReceiveBuffer.Length, SocketFlags.None, new AsyncCallback(GetStuffFromClient), con); ! // string str = Encoding.ASCII.GetString(con.ReceiveBuffer, 0, got); ! // ! // int idx = str.IndexOf("\r\n"); ! // if(idx >= 0) ! // { ! // con.AddToWorkingLine(str.Substring(0, idx)); ! // System.Console.WriteLine(con.Socket.Handle.ToString() + ": get stuff: " + con.GetWorkingLine(false)); ! // } ! // else ! // con.AddToWorkingLine(str); ! // } ! // } ! // ! // public void SendStuffFromClient(IAsyncResult result) ! // { ! // Connection con = (Connection)result.AsyncState; ! // System.Console.WriteLine(con.Socket.Handle.ToString() + ": send stuff"); ! // } ! // } ! //} --- 1,78 ---- ! using System; ! using Imap.NetworkManager; ! using System.Collections; //using System.IO; //using System.Net.Sockets; //using System.Text; ! ! namespace Imap ! { ! public class Server ! { ! private NetworkManager.NetworkManager mNetwork; ! private Hashtable mImapConnections = new Hashtable(); ! ! public Server() ! { ! mNetwork = new NetworkManager.NetworkManager(); ! mImapConnections = new Hashtable(); ! } ! ! public void Start() ! { ! Listener li = mNetwork.StartListener(143); // TODO: global configuration ! li.AcceptedConnection += new AcceptDelegate(NewConnectionHandler); ! } ! ! private void SendWelcomeMessage(Connection con) ! { ! con.WriteLine("* OK domain.tld IMAP4rev1 csmaild dev ready"); ! System.Console.WriteLine(con + " S: * OK domain.tld IMAP4rev1 csmaild.dev ready"); ! } ! ! private void NewConnectionHandler(Connection con) ! { ! mImapConnections.Add(con, new ImapConnection(con)); ! ! con.ConnectionClosedEvent += new ConnectionClosedDelegate(Connection_Closed); ! con.ReceivedLineEvent += new ReceivedLineDelegate(Connection_ReceivedLine); ! con.ReceivedBlockEvent += new ReceivedBlockDelegate(Connection_ReceivedBlock); ! con.SentDataEvent += new SentDataDelegate(Connection_SentData); ! ! SendWelcomeMessage(con); ! ! con.ReadLine(); ! } ! ! private void Connection_ReceivedLine(Connection con, string line) ! { ! System.Console.WriteLine(con + " C: " + line); ! ! line += " "; // to alleviate invalid input parsing ! ! int idxTag = line.IndexOf(' '); ! int idxCommand = line.IndexOf(' ', idxTag+1); ! ! string tag = line.Substring(0, idxTag); ! string cmd = line.Substring(idxTag+1, idxCommand-idxTag-1); ! ! con.ReadLine(); ! } ! ! private void Connection_ReceivedBlock(Connection con, byte[] block) ! { ! System.Console.WriteLine(con + " C: " + block); ! } ! ! private void Connection_SentData(Connection con) ! { ! } ! ! private void Connection_Closed(Connection con) ! { ! mImapConnections.Remove(con); ! System.Console.WriteLine(con + " Closed"); ! } ! ! } ! } |
From: <ta...@us...> - 2003-04-11 01:29:29
|
Update of /cvsroot/csmaild/csmaild/src/Imap/NetworkManager In directory sc8-pr-cvs1:/tmp/cvs-serv31710/src/Imap/NetworkManager Modified Files: Connection.cs Listener.cs NetworkManager.cs Log Message: Just for historical purposes. Index: Connection.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/NetworkManager/Connection.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Connection.cs 9 Apr 2003 05:00:32 -0000 1.1 --- Connection.cs 11 Apr 2003 01:29:26 -0000 1.2 *************** *** 17,20 **** --- 17,21 ---- public class Connection { + #region Variables private Socket mClient; // the communication socket private NetworkStream mSocketStream; // a stream wrapping the com socket *************** *** 26,29 **** --- 27,34 ---- private int mReadingBlockSize; // the size of the block we are reading (if we're reading a block) + private Listener mListener; // the listener that created us + #endregion + + #region Events /// <summary> /// Fires whnever a line is received from the client *************** *** 45,64 **** /// </summary> public event ConnectionClosedDelegate ConnectionClosedEvent; /// <summary> /// Creates a new Connection object /// </summary> /// <param name="client">The Socket for this Connection</param> ! internal Connection(Socket client) { mClient = client; ! mSocketStream = new NetworkStream(mClient, true); mReceiveBuffer = new byte[4096]; mBlockStream = new MemoryStream(); } /// <summary> ! /// Writes the message to the socket /// </summary> /// <param name="msg">The message to write</param> --- 50,75 ---- /// </summary> public event ConnectionClosedDelegate ConnectionClosedEvent; + #endregion + #region Constructor /// <summary> /// Creates a new Connection object /// </summary> /// <param name="client">The Socket for this Connection</param> ! /// <param name="listener">The Listener that created us</param> ! internal Connection(Socket client, Listener listener) { mClient = client; ! mListener = listener; + mSocketStream = new NetworkStream(mClient, true); mReceiveBuffer = new byte[4096]; mBlockStream = new MemoryStream(); } + #endregion + #region Public methods /// <summary> ! /// Writes the message to the socket asynchronosously /// </summary> /// <param name="msg">The message to write</param> *************** *** 69,72 **** --- 80,86 ---- } + /// <summary> + /// Reads a line from the socket asynchronously + /// </summary> public void ReadLine() { *************** *** 76,79 **** --- 90,97 ---- } + /// <summary> + /// Reads a block of data from the socket asynchronously + /// </summary> + /// <param name="size">The size of the block to read</param> public void ReadBlock(int size) { *************** *** 92,97 **** mSocketStream.BeginRead(mReceiveBuffer, 0, (int)Math.Min(mReceiveBuffer.Length, mReadingBlockSize-mBlockStream.Position), new AsyncCallback(ReceiveCallback), null); } ! public virtual void OnReadLine(string line) { if(ReceivedLineEvent != null) --- 110,121 ---- mSocketStream.BeginRead(mReceiveBuffer, 0, (int)Math.Min(mReceiveBuffer.Length, mReadingBlockSize-mBlockStream.Position), new AsyncCallback(ReceiveCallback), null); } + #endregion ! #region Protected methods ! /// <summary> ! /// Fires the related event, called when a line has been read ! /// </summary> ! /// <param name="line">The line that was read</param> ! protected virtual void OnReadLine(string line) { if(ReceivedLineEvent != null) *************** *** 99,103 **** } ! public virtual void OnReadBlock(byte[] block) { if(ReceivedBlockEvent != null) --- 123,131 ---- } ! /// <summary> ! /// Fires the related event, called when a block has been read ! /// </summary> ! /// <param name="block">The block that was read</param> ! protected virtual void OnReadBlock(byte[] block) { if(ReceivedBlockEvent != null) *************** *** 105,109 **** } ! public virtual void OnSent() { if(SentDataEvent != null) --- 133,140 ---- } ! /// <summary> ! /// Fires the related event, called called when the data has been sent ! /// </summary> ! protected virtual void OnSent() { if(SentDataEvent != null) *************** *** 111,120 **** } ! public virtual void OnClosed() { if(ConnectionClosedEvent != null) ConnectionClosedEvent(this); } private void SendCallback(IAsyncResult result) { --- 142,156 ---- } ! /// <summary> ! /// Fires when the socket is closed ! /// </summary> ! protected virtual void OnClosed() { if(ConnectionClosedEvent != null) ConnectionClosedEvent(this); } + #endregion + #region Private methods private void SendCallback(IAsyncResult result) { *************** *** 183,191 **** --- 219,230 ---- } } + #endregion + #region Overridden methods public override string ToString() { return mClient.RemoteEndPoint.ToString(); } + #endregion } } Index: Listener.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/NetworkManager/Listener.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Listener.cs 9 Apr 2003 05:00:32 -0000 1.1 --- Listener.cs 11 Apr 2003 01:29:26 -0000 1.2 *************** *** 29,34 **** private void AcceptCallback(IAsyncResult result) { // do the final accpet and wait for another ! Connection con = new Connection(mListenSocket.EndAccept(result)); mListenSocket.BeginAccept(new AsyncCallback(AcceptCallback), null); --- 29,37 ---- private void AcceptCallback(IAsyncResult result) { + if(mListenSocket == null) + return; + // do the final accpet and wait for another ! Connection con = new Connection(mListenSocket.EndAccept(result), this); mListenSocket.BeginAccept(new AsyncCallback(AcceptCallback), null); Index: NetworkManager.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/NetworkManager/NetworkManager.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NetworkManager.cs 9 Apr 2003 05:00:32 -0000 1.1 --- NetworkManager.cs 11 Apr 2003 01:29:26 -0000 1.2 *************** *** 43,79 **** public void Listener_AcceptedConnection(Connection con) { - System.Console.WriteLine(con + " Accepted"); - con.ConnectionClosedEvent += new ConnectionClosedDelegate(Connection_Closed); - con.ReceivedLineEvent += new ReceivedLineDelegate(Connection_ReceivedLine); - con.ReceivedBlockEvent += new ReceivedBlockDelegate(Connection_ReceivedBlock); - con.SentDataEvent += new SentDataDelegate(Connection_SentData); - - con.WriteLine("* OK Welcome!!"); - System.Console.WriteLine(con + " Sent: * OK Welcome!!"); - - con.ReadLine(); - mConnections.Add(con); } - public void Connection_ReceivedLine(Connection con, string line) - { - System.Console.WriteLine(con + " Line(" + line.Length + "): " + line); - con.ReadBlock(100); - } - - public void Connection_ReceivedBlock(Connection con, byte[] block) - { - System.Console.WriteLine(con + " Block(" + block.Length + "): " + block); - } - - public void Connection_SentData(Connection con) - { - } - public void Connection_Closed(Connection con) { ! System.Console.WriteLine(con); } } --- 43,53 ---- public void Listener_AcceptedConnection(Connection con) { con.ConnectionClosedEvent += new ConnectionClosedDelegate(Connection_Closed); mConnections.Add(con); } public void Connection_Closed(Connection con) { ! mConnections.Remove(con); } } |
From: <ta...@us...> - 2003-04-11 01:29:28
|
Update of /cvsroot/csmaild/csmaild/src/Engine In directory sc8-pr-cvs1:/tmp/cvs-serv31710/src/Engine Modified Files: Engine.cs Log Message: Just for historical purposes. Index: Engine.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Engine/Engine.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Engine.cs 9 Apr 2003 05:00:31 -0000 1.2 --- Engine.cs 11 Apr 2003 01:29:25 -0000 1.3 *************** *** 1,4 **** using System; ! using Imap.NetworkManager; namespace Engine --- 1,4 ---- using System; ! using Imap; namespace Engine *************** *** 20,29 **** public void RunStuff() { ! NetworkManager nm = new NetworkManager(); ! nm.StartListener(143); ! char c = '\0'; ! while(c != 'q') ! c = Char.ToLower(Convert.ToChar(System.Console.Read())); } } --- 20,31 ---- public void RunStuff() { ! Server svr = new Server(); ! svr.Start(); ! string input = string.Empty; ! while(input != "quit") ! { ! input = System.Console.ReadLine().ToLower(); ! } } } |