/// <summary> /// Default constructor. /// </summary> /// <param name="referenceName">Owner IMAP session.</param> /// <param name="referenceName">Folder Path. Eg. Inbox\.</param> /// <param name="folder">Folder name.</param> public IMAP_Folders(IMAP_Session session, string referenceName, string folder) { m_pSession = session; m_Mailboxes = new ArrayList(); m_RefName = referenceName; m_Mailbox = folder; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Owner IMAP session.</param> /// <param name="folderName">Folder name which ACL to get.</param> public IMAP_GETACL_eArgs(IMAP_Session session, string folderName) { m_pSession = session; m_pFolderName = folderName; m_ACLs = new Hashtable(); }
/// <summary> /// Starts writing response to the specified stream. /// </summary> /// <param name="session">Owner IMAP session.</param> /// <param name="stream">Stream where to store response.</param> /// <param name="mailboxEncoding">Specifies how mailbox name is encoded.</param> /// <param name="completedAsyncCallback">Callback to be called when this method completes asynchronously.</param> /// <returns>Returns true is method completed asynchronously(the completedAsyncCallback is raised upon completion of the operation). /// Returns false if operation completed synchronously.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception> protected virtual bool ToStreamAsync(IMAP_Session session, Stream stream, IMAP_Mailbox_Encoding mailboxEncoding, EventHandler <EventArgs <Exception> > completedAsyncCallback) { if (stream == null) { throw new ArgumentNullException("stream"); } string responseS = ToString(mailboxEncoding); byte[] response = Encoding.UTF8.GetBytes(responseS); // Log. if (session != null) { session.LogAddWrite(response.Length, responseS.TrimEnd()); } // Starts writing response to stream. IAsyncResult ar = stream.BeginWrite( response, 0, response.Length, delegate(IAsyncResult r){ if (r.CompletedSynchronously) { return; } try{ stream.EndWrite(r); if (completedAsyncCallback != null) { completedAsyncCallback(this, new EventArgs <Exception>(null)); } } catch (Exception x) { if (completedAsyncCallback != null) { completedAsyncCallback(this, new EventArgs <Exception>(x)); } } }, null ); // Completed synchronously, process result. if (ar.CompletedSynchronously) { stream.EndWrite(ar); return(false); } // Completed asynchronously, stream.BeginWrite AsyncCallback will continue processing. else { return(true); } }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="userName">Username.</param> /// <param name="passwData">Password data.</param> /// <param name="data">Authentication specific data(as tag).</param> /// <param name="authType">Authentication type.</param> public AuthUser_EventArgs(IMAP_Session session, string userName, string passwData, string data, AuthType authType) { m_pSession = session; m_UserName = userName; m_PasswData = passwData; m_Data = data; m_AuthType = authType; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Owner IMAP session.</param> /// <param name="folderName">Folder name which ACL to set.</param> /// <param name="userName">User name which ACL to set.</param> /// <param name="flagsSetType">Specifies how flags must be stored.</param> /// <param name="aclFlags">Flags which to store.</param> public IMAP_SETACL_eArgs(IMAP_Session session, string folderName, string userName, IMAP_Flags_SetType flagsSetType, IMAP_ACL_Flags aclFlags) { m_pSession = session; m_pFolderName = folderName; m_UserName = userName; m_FlagsSetType = flagsSetType; m_ACL_Flags = aclFlags; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Reference to current IMAP session.</param> /// <param name="messageInfo">Message info what message items to get.</param> /// <param name="messageItems">Specifies message items what must be filled.</param> public IMAP_eArgs_MessageItems(IMAP_Session session, IMAP_Message messageInfo, IMAP_MessageItems_enum messageItems) { m_pSession = session; m_pMessageInfo = messageInfo; m_MessageItems = messageItems; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">IMAP session what calls this search.</param> /// <param name="folder">IMAP folder name which messages to search.</param> /// <param name="matcher">Matcher what must be used to check if message matches searching criterial.</param> public IMAP_eArgs_Search(IMAP_Session session, string folder, IMAP_SearchMatcher matcher) { m_pSession = session; m_Folder = folder; m_pMatcher = matcher; m_pMessages = new IMAP_Messages(folder); }
/// <summary> /// Starts sending response to the specified IMAP session remote endpoint. /// </summary> /// <param name="session">Stream where to store response.</param> /// <param name="completedAsyncCallback">Callback to be called when this method completes asynchronously.</param> /// <returns>Returns true is method completed asynchronously(the completedAsyncCallback is raised upon completion of the operation). /// Returns false if operation completed synchronously.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>session</b> is null reference.</exception> internal bool SendAsync(IMAP_Session session, EventHandler <EventArgs <Exception> > completedAsyncCallback) { if (session == null) { throw new ArgumentNullException("session"); } return(ToStreamAsync(session, session.TcpStream, session.MailboxEncoding, completedAsyncCallback)); }
/// <summary> /// Raises event GetMessageItems. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="messageInfo">Message info what message items to get.</param> /// <param name="messageItems">Specifies message items what must be filled.</param> /// <returns></returns> internal protected IMAP_eArgs_MessageItems OnGetMessageItems(IMAP_Session session, IMAP_Message messageInfo, IMAP_MessageItems_enum messageItems) { IMAP_eArgs_MessageItems eArgs = new IMAP_eArgs_MessageItems(session, messageInfo, messageItems); if (this.GetMessageItems != null) { this.GetMessageItems(session, eArgs); } return(eArgs); }
internal IMAP_SETACL_eArgs OnSetFolderACL(IMAP_Session session, string folderName, string userName, IMAP_Flags_SetType flagsSetType, IMAP_ACL_Flags aclFlags) { IMAP_SETACL_eArgs eArgs = new IMAP_SETACL_eArgs(session, folderName, userName, flagsSetType, aclFlags); if (this.SetFolderACL != null) { this.SetFolderACL(session, eArgs); } return(eArgs); }
/// <summary> /// Raises event 'GetMailboxes'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="referenceName">Mailbox reference.</param> /// <param name="mailBox">Mailbox search pattern or mailbox.</param> /// <returns></returns> internal IMAP_Folders OnGetMailboxes(IMAP_Session session, string referenceName, string mailBox) { IMAP_Folders retVal = new IMAP_Folders(referenceName, mailBox); if (this.GetFolders != null) { this.GetFolders(session, retVal); } return(retVal); }
/// <summary> /// Raises event AuthUser. /// </summary> /// <param name="session">Reference to current IMAP session.</param> /// <param name="userName">User name.</param> /// <param name="passwordData">Password compare data,it depends of authentication type.</param> /// <param name="data">For md5 eg. md5 calculation hash.It depends of authentication type.</param> /// <param name="authType">Authentication type.</param> /// <returns>Returns true if user is authenticated ok.</returns> internal bool OnAuthUser(IMAP_Session session, string userName, string passwordData, string data, AuthType authType) { AuthUser_EventArgs oArgs = new AuthUser_EventArgs(session, userName, passwordData, data, authType); if (this.AuthUser != null) { this.AuthUser(this, oArgs); } return(oArgs.Validated); }
internal IMAP_eArgs_GetQuota OnGetUserQuota(IMAP_Session session) { IMAP_eArgs_GetQuota eArgs = new IMAP_eArgs_GetQuota(session); if (this.GetUserQuota != null) { this.GetUserQuota(session, eArgs); } return(eArgs); }
internal IMAP_GetUserACL_eArgs OnGetUserACL(IMAP_Session session, string folderName, string userName) { IMAP_GetUserACL_eArgs eArgs = new IMAP_GetUserACL_eArgs(session, folderName, userName); if (this.GetUserACL != null) { this.GetUserACL(session, eArgs); } return(eArgs); }
internal IMAP_DELETEACL_eArgs OnDeleteFolderACL(IMAP_Session session, string folderName, string userName) { IMAP_DELETEACL_eArgs eArgs = new IMAP_DELETEACL_eArgs(session, folderName, userName); if (this.DeleteFolderACL != null) { this.DeleteFolderACL(session, eArgs); } return(eArgs); }
internal SharedRootFolders_EventArgs OnGetSharedRootFolders(IMAP_Session session) { SharedRootFolders_EventArgs eArgs = new SharedRootFolders_EventArgs(session); if (this.GetSharedRootFolders != null) { this.GetSharedRootFolders(session, eArgs); } return(eArgs); }
/// <summary> /// Raises event 'GetMessagesInfo'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="folder">Folder which messages info to get.</param> /// <returns></returns> internal IMAP_eArgs_GetMessagesInfo OnGetMessagesInfo(IMAP_Session session, IMAP_SelectedFolder folder) { IMAP_eArgs_GetMessagesInfo eArgs = new IMAP_eArgs_GetMessagesInfo(session, folder); if (this.GetMessagesInfo != null) { this.GetMessagesInfo(session, eArgs); } return(eArgs); }
/// <summary> /// Raises event 'StoreMessageFlags'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="msg">Message which flags to store.</param> /// <returns></returns> internal string OnStoreMessageFlags(IMAP_Session session, IMAP_Message msg) { Message_EventArgs eArgs = new Message_EventArgs(session.SelectedMailbox, msg); if (this.StoreMessageFlags != null) { this.StoreMessageFlags(session, eArgs); } return(eArgs.ErrorText); }
/// <summary> /// Raises event 'GetMessagesInfo'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="mailbox">Mailbox which messages info to get.</param> /// <returns></returns> internal IMAP_Messages OnGetMessagesInfo(IMAP_Session session, string mailbox) { IMAP_Messages messages = new IMAP_Messages(mailbox); if (this.GetMessagesInfo != null) { this.GetMessagesInfo(session, messages); } return(messages); }
/// <summary> /// Raises event 'CopyMessage'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="msg">Message which to copy.</param> /// <param name="location">New message location.</param> /// <returns></returns> internal string OnCopyMessage(IMAP_Session session, IMAP_Message msg, string location) { Message_EventArgs eArgs = new Message_EventArgs(session.SelectedMailbox, msg, location); if (this.CopyMessage != null) { this.CopyMessage(session, eArgs); } return(eArgs.ErrorText); }
/// <summary> /// Raises event 'DeleteMessage'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="message">Message which to delete.</param> /// <returns></returns> internal string OnDeleteMessage(IMAP_Session session, IMAP_Message message) { Message_EventArgs eArgs = new Message_EventArgs(session.SelectedMailbox, message); if (this.DeleteMessage != null) { this.DeleteMessage(session, eArgs); } return(eArgs.ErrorText); }
/// <summary> /// Raises event 'GetMessage'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="msg">Message which to get.</param> /// <param name="headersOnly">Specifies if message header or full message is wanted.</param> /// <returns></returns> internal Message_EventArgs OnGetMessage(IMAP_Session session, IMAP_Message msg, bool headersOnly) { Message_EventArgs eArgs = new Message_EventArgs(session.SelectedMailbox, msg, headersOnly); if (this.GetMessage != null) { this.GetMessage(session, eArgs); } return(eArgs); }
/// <summary> /// Raises event 'StoreMessage'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="folder">Folder where to store.</param> /// <param name="msg">Message which to store.</param> /// <param name="messageData">Message data which to store.</param> /// <returns></returns> internal string OnStoreMessage(IMAP_Session session, string folder, IMAP_Message msg, byte[] messageData) { Message_EventArgs eArgs = new Message_EventArgs(folder, msg); eArgs.MessageData = messageData; if (this.StoreMessage != null) { this.StoreMessage(session, eArgs); } return(eArgs.ErrorText); }
/// <summary> /// Raises event 'DeleteMailbox'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="mailbox">Mailbox which to delete.</param> /// <returns></returns> internal string OnDeleteMailbox(IMAP_Session session, string mailbox) { if (this.DeleteFolder != null) { Mailbox_EventArgs eArgs = new Mailbox_EventArgs(mailbox); this.DeleteFolder(session, eArgs); return(eArgs.ErrorText); } return(null); }
/// <summary> /// Raises event 'RenameMailbox'. /// </summary> /// <param name="session">Reference to IMAP session.</param> /// <param name="mailbox">Mailbox which to rename.</param> /// <param name="newMailboxName">New mailbox name.</param> /// <returns></returns> internal string OnRenameMailbox(IMAP_Session session, string mailbox, string newMailboxName) { if (this.RenameFolder != null) { Mailbox_EventArgs eArgs = new Mailbox_EventArgs(mailbox, newMailboxName); this.RenameFolder(session, eArgs); return(eArgs.ErrorText); } return(null); }
public SessionHandler(IMAP_Session session, IServiceScopeFactory serviceScopeFactory) { this.session = session; session.List += Session_List; session.Login += Session_Login; session.Fetch += Session_Fetch; session.GetMessagesInfo += Session_GetMessagesInfo; session.Capabilities.Remove("QUOTA"); session.Capabilities.Remove("NAMESPACE"); session.Store += Session_Store; session.Select += Session_Select; this.serviceScopeFactory = serviceScopeFactory; }
/// <summary> /// Initialize and start new session here. Session isn't added to session list automatically, /// session must add itself to server session list by calling AddSession(). /// </summary> /// <param name="socket">Connected client socket.</param> /// <param name="bindInfo">BindInfo what accepted socket.</param> protected override void InitNewSession(Socket socket, IPBindInfo bindInfo) { // Check maximum conncurent connections from 1 IP. if (m_MaxConnectionsPerIP > 0) { lock (this.Sessions){ int nSessions = 0; foreach (SocketServerSession s in this.Sessions) { IPEndPoint ipEndpoint = s.RemoteEndPoint; if (ipEndpoint != null) { if (ipEndpoint.Address.Equals(((IPEndPoint)socket.RemoteEndPoint).Address)) { nSessions++; } } // Maimum allowed exceeded if (nSessions >= m_MaxConnectionsPerIP) { socket.Send(System.Text.Encoding.ASCII.GetBytes("* NO Maximum connections from your IP address is exceeded, try again later !\r\n")); socket.Shutdown(SocketShutdown.Both); socket.Close(); return; } } } } string sessionID = Guid.NewGuid().ToString(); SocketEx socketEx = new SocketEx(socket); if (LogCommands) { socketEx.Logger = new SocketLogger(socket, this.SessionLog); socketEx.Logger.SessionID = sessionID; } IMAP_Session session = new IMAP_Session(sessionID, socketEx, bindInfo, this); }
/// <summary> /// Default constructor. /// </summary> public SharedRootFolders_EventArgs(IMAP_Session session) { m_pSession = session; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Owner IMAP session.</param> public IMAP_eArgs_GetQuota(IMAP_Session session) { m_pSession = session; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Owner IMAP session.</param> /// <param name="initialCmdLine">IMAP client initial command line.</param> /// <param name="charset">IMAP literal strings charset encoding.</param> /// <exception cref="ArgumentNullException">Is raised when <b>session</b>,<b>initialCmdLine</b> or <b>charset</b> is null reference.</exception> public _CmdReader(IMAP_Session session,string initialCmdLine,Encoding charset) { if(session == null){ throw new ArgumentNullException("session"); } if(initialCmdLine == null){ throw new ArgumentNullException("initialCmdLine"); } if(charset == null){ throw new ArgumentNullException("charset"); } m_pSession = session; m_InitialCmdLine = initialCmdLine; m_pCharset = charset; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Owner IMAP session.</param> /// <param name="folderName">Folder name which ACL to get.</param> /// <param name="userName">User name which ACL to get.</param> public IMAP_GetUserACL_eArgs(IMAP_Session session, string folderName, string userName) { m_pSession = session; m_pFolderName = folderName; m_UserName = userName; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Owner IMAP session.</param> /// <exception cref="ArgumentNullException">Is raised when <b>session</b> is null reference.</exception> public ResponseSender(IMAP_Session session) { if(session == null){ throw new ArgumentNullException("session"); } m_pImap = session; m_pResponses = new Queue<QueueItem>(); }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Owner IMAP session.</param> /// <param name="folderName">Folder name which ACL to delete.</param> /// <param name="userName">User name which ACL to delete.</param> public IMAP_DELETEACL_eArgs(IMAP_Session session, string folderName, string userName) { m_pSession = session; m_pFolderName = folderName; m_UserName = userName; }
/// <summary> /// Default constructor. /// </summary> public IMAP_eArgs_GetMessagesInfo(IMAP_Session session, IMAP_SelectedFolder folder) { m_pSession = session; m_pFolderInfo = folder; }