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"); ! } ! ! } ! } |