Thread: [csmaild-cvs] csmaild/src/Imap/Commands AppendCommand.cs,1.1,1.2 AuthenticateCommand.cs,1.1,1.2 Capa
Brought to you by:
tamc
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 + ... [truncated message content] |