예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        /// <summary>
        /// Gets messages marked for delete.
        /// </summary>
        /// <returns></returns>
        public IMAP_Message[] GetDeleteMessages()
        {
            ArrayList retVal = new ArrayList();

            foreach (IMAP_Message msg in m_Messages.GetValueList())
            {
                if (((int)IMAP_MessageFlags.Deleted & (int)msg.Flags) != 0)
                {
                    retVal.Add(msg);
                }
            }

            IMAP_Message[] messages = new IMAP_Message[retVal.Count];
            retVal.CopyTo(messages);

            return(messages);
        }
예제 #7
0
 /// <summary>
 /// GetMessage constructor.
 /// </summary>
 /// <param name="folder">IMAP folder which message is.</param>
 /// <param name="msg"></param>
 /// <param name="headersOnly">Specifies if messages headers or full message is needed.</param>
 public Message_EventArgs(string folder, IMAP_Message msg, bool headersOnly)
 {
     m_Folder      = folder;
     m_pMessage    = msg;
     m_HeadersOnly = headersOnly;
 }
예제 #8
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="folder">IMAP folder which message is.</param>
 /// <param name="msg"></param>
 /// <param name="copyLocation"></param>
 public Message_EventArgs(string folder, IMAP_Message msg, string copyLocation)
 {
     m_Folder       = folder;
     m_pMessage     = msg;
     m_CopyLocation = copyLocation;
 }
예제 #9
0
		/// <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;
		}
예제 #10
0
		/// <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;
		}
예제 #11
0
		/// <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;
		}
예제 #12
0
		/// <summary>
		/// Gets message 1-based index.
		/// </summary>
		/// <param name="message"></param>
		/// <returns></returns>
		public int IndexOf(IMAP_Message message)
		{
			return m_Messages.IndexOfValue(message) + 1;
		}
예제 #13
0
 /// <summary>
 /// Gets message 1-based index.
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public int IndexOf(IMAP_Message message)
 {
     return(m_Messages.IndexOfValue(message) + 1);
 }
예제 #14
0
 /// <summary>
 /// Removes message from list.
 /// </summary>
 /// <param name="msg">Message which to remove.</param>
 public void RemoveMessage(IMAP_Message msg)
 {
     m_Messages.RemoveAt(msg.MessageNo - 1);
 }
예제 #15
0
        /// <summary>
        /// Checks if message matches for specified search key.
        /// </summary>
        /// <param name="searchKey"></param>
        /// <param name="searchKeyValue"></param>
        /// <param name="messageInfo"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool MatchSearchKey(string searchKey, object searchKeyValue, IMAP_Message messageInfo, MimeParser msg)
        {
            // BEFORE <date>
            //	Messages whose internal date (disregarding time and timezone)
            //	is earlier than the specified date.
            if (searchKey == "BEFORE")
            {
                if (messageInfo.Date.Date < (DateTime)searchKeyValue)
                {
                    return(true);
                }
            }
            // BODY <string>
            //	Messages that contain the specified string in the body of the message.
            else if (searchKey == "BODY")
            {
                if (msg.BodyText.IndexOf((string)searchKeyValue) > -1)
                {
                    return(true);
                }
            }
            // HEADER <field-name> <string>
            //	Messages that have a header with the specified field-name (as
            //	defined in [RFC-2822]) and that contains the specified string
            //	in the text of the header (what comes after the colon).  If the
            //	string to search is zero-length, this matches all messages that
            //	have a header line with the specified field-name regardless of
            //	the contents.
            else if (searchKey == "HEADER")
            {
                string[] headerField_value = (string[])searchKeyValue;
                string   headerFileDValue  = Core.CanonicalDecode(MimeParser.ParseHeaderField(headerField_value[0], msg.Headers));
                if (headerField_value[1].Length == 0)
                {
                    return(true);
                }
                else if (headerFileDValue.IndexOf(headerField_value[1]) > -1)
                {
                    return(true);
                }
            }
            // KEYWORD <flag>
            //	Messages with the specified keyword flag set.
            else if (searchKey == "KEYWORD")
            {
                if ((messageInfo.Flags & IMAP_Utils.ParseMessageFalgs((string)searchKeyValue)) != 0)
                {
                    return(true);
                }
            }
            // LARGER <n>
            //	Messages with an [RFC-2822] size larger than the specified number of octets.
            else if (searchKey == "LARGER")
            {
                if (messageInfo.Size > Convert.ToInt64(searchKeyValue))
                {
                    return(true);
                }
            }
            // ON <date>
            //	Messages whose internal date (disregarding time and timezone)
            //	is within the specified date.
            else if (searchKey == "ON")
            {
                if (messageInfo.Date.Date == (DateTime)searchKeyValue)
                {
                    return(true);
                }
            }
            // SENTBEFORE <date>
            //	Messages whose [RFC-2822] Date: header (disregarding time and
            //	timezone) is earlier than the specified date.
            else if (searchKey == "SENTBEFORE")
            {
                if (msg.MessageDate.Date < (DateTime)searchKeyValue)
                {
                    return(true);
                }
            }
            // SENTON <date>
            //	Messages whose [RFC-2822] Date: header (disregarding time and
            //	timezone) is within the specified date.
            else if (searchKey == "SENTON")
            {
                if (msg.MessageDate.Date == (DateTime)searchKeyValue)
                {
                    return(true);
                }
            }
            // SENTSINCE <date>
            //	Messages whose [RFC-2822] Date: header (disregarding time and
            //	timezone) is within or later than the specified date.
            else if (searchKey == "SENTSINCE")
            {
                if (msg.MessageDate.Date >= (DateTime)searchKeyValue)
                {
                    return(true);
                }
            }
            // SINCE <date>
            //	Messages whose internal date (disregarding time and timezone)
            //	is within or later than the specified date.
            else if (searchKey == "SINCE")
            {
                if (messageInfo.Date.Date >= (DateTime)searchKeyValue)
                {
                    return(true);
                }
            }
            // SMALLER <n>
            //	Messages with an [RFC-2822] size smaller than the specified	number of octets.
            else if (searchKey == "SMALLER")
            {
                if (messageInfo.Size < Convert.ToInt64(searchKeyValue))
                {
                    return(true);
                }
            }
            // TEXT <string>
            //	Messages that contain the specified string in the header or	body of the message.
            else if (searchKey == "TEXT")
            {
                // TODO:
            }
            // UID <sequence set>
            //	Messages with unique identifiers corresponding to the specified
            //	unique identifier set.  Sequence set ranges are permitted.
            else if (searchKey == "UID")
            {
                if (((string)searchKeyValue).IndexOf(":") > -1)
                {
                    string[] start_end = ((string)searchKeyValue).Split(':');
                    if (messageInfo.MessageUID >= Convert.ToInt64(start_end[0]) && messageInfo.MessageUID <= Convert.ToInt64(start_end[1]))
                    {
                        return(true);
                    }
                }
                else
                {
                    if (messageInfo.MessageUID == Convert.ToInt64(searchKeyValue))
                    {
                        return(true);
                    }
                }
            }
            // UNKEYWORD <flag>
            //	Messages that do not have the specified keyword flag set.
            else if (searchKey == "UNKEYWORD")
            {
                if ((messageInfo.Flags & IMAP_Utils.ParseMessageFalgs((string)searchKeyValue)) == 0)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #16
0
		/// <summary>
		/// Removes message from list.
		/// </summary>
		/// <param name="msg">Message which to remove.</param>
		public void RemoveMessage(IMAP_Message msg)
		{
			m_Messages.RemoveAt(msg.MessageNo - 1);
		}
		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="folder">IMAP folder which message is.</param>
		/// <param name="msg"></param>
		public Message_EventArgs(string folder,IMAP_Message msg)
		{				
			m_Folder   = folder;
			m_pMessage = msg;
		}
예제 #18
0
		/// <summary>
		/// Gets messages marked for delete.
		/// </summary>
		/// <returns></returns>
		public IMAP_Message[] GetDeleteMessages()
		{
			ArrayList retVal = new ArrayList();
			foreach(IMAP_Message msg in m_Messages.GetValueList()){
				if(((int)IMAP_MessageFlags.Deleted & (int)msg.Flags) != 0){
					retVal.Add(msg);
				}
			}

			IMAP_Message[] messages = new IMAP_Message[retVal.Count];
			retVal.CopyTo(messages);

			return messages;
		}
		/// <summary>
		/// Copy constructor.
		/// </summary>
		/// <param name="folder">IMAP folder which message is.</param>
		/// <param name="msg"></param>
		/// <param name="copyLocation"></param>
		public Message_EventArgs(string folder,IMAP_Message msg,string copyLocation)
		{				
			m_Folder       = folder;
			m_pMessage     = msg;
			m_CopyLocation = copyLocation;
		}
예제 #20
0
		/// <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>
		/// GetMessage constructor.
		/// </summary>
		/// <param name="folder">IMAP folder which message is.</param>
		/// <param name="msg"></param>
		/// <param name="headersOnly">Specifies if messages headers or full message is needed.</param>
		public Message_EventArgs(string folder,IMAP_Message msg,bool headersOnly)
		{				
			m_Folder      = folder;
			m_pMessage    = msg;
			m_HeadersOnly = headersOnly;
		}
예제 #22
0
		/// <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;
		}
예제 #23
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="folder">IMAP folder which message is.</param>
 /// <param name="msg"></param>
 public Message_EventArgs(string folder, IMAP_Message msg)
 {
     m_Folder   = folder;
     m_pMessage = msg;
 }
예제 #24
0
		/// <summary>
		/// Checks if message matches for specified search key.
		/// </summary>
		/// <param name="searchKey"></param>
		/// <param name="searchKeyValue"></param>
		/// <param name="messageInfo"></param>
		/// <param name="msg"></param>
		/// <returns></returns>
		public static bool MatchSearchKey(string searchKey,object searchKeyValue,IMAP_Message messageInfo,MimeParser msg)
		{						
			// BEFORE <date>
			//	Messages whose internal date (disregarding time and timezone)
			//	is earlier than the specified date.
			if(searchKey == "BEFORE"){
				if(messageInfo.Date.Date < (DateTime)searchKeyValue){
					return true;
				}
			}
			// BODY <string>
			//	Messages that contain the specified string in the body of the message.
			else if(searchKey == "BODY"){
				if(msg.BodyText.IndexOf((string)searchKeyValue) > -1){
					return true;
				}
			}
			// HEADER <field-name> <string>
			//	Messages that have a header with the specified field-name (as
			//	defined in [RFC-2822]) and that contains the specified string
			//	in the text of the header (what comes after the colon).  If the
			//	string to search is zero-length, this matches all messages that
			//	have a header line with the specified field-name regardless of
			//	the contents.
			else if(searchKey == "HEADER"){				
				string[] headerField_value = (string[])searchKeyValue;
				string headerFileDValue = Core.CanonicalDecode(MimeParser.ParseHeaderField(headerField_value[0],msg.Headers));
				if(headerField_value[1].Length == 0){
					return true;					
				}
				else if(headerFileDValue.IndexOf(headerField_value[1]) > -1){
					return true;
				}
			}
			// KEYWORD <flag>
			//	Messages with the specified keyword flag set.
			else if(searchKey == "KEYWORD"){
				if((messageInfo.Flags & IMAP_Utils.ParseMessageFalgs((string)searchKeyValue)) != 0){
					return true;
				}
			}					
			// LARGER <n>
			//	Messages with an [RFC-2822] size larger than the specified number of octets.
			else if(searchKey == "LARGER"){
				if(messageInfo.Size > Convert.ToInt64(searchKeyValue)){
					return true;
				}
			}
			// ON <date>
			//	Messages whose internal date (disregarding time and timezone)
			//	is within the specified date.
			else if(searchKey == "ON"){
				if(messageInfo.Date.Date == (DateTime)searchKeyValue){
					return true;
				}
			}
			// SENTBEFORE <date>
			//	Messages whose [RFC-2822] Date: header (disregarding time and
			//	timezone) is earlier than the specified date.
			else if(searchKey == "SENTBEFORE"){				
				if(msg.MessageDate.Date < (DateTime)searchKeyValue){
					return true;
				}
			}
			// SENTON <date>
			//	Messages whose [RFC-2822] Date: header (disregarding time and
			//	timezone) is within the specified date.
			else if(searchKey == "SENTON"){				
				if(msg.MessageDate.Date == (DateTime)searchKeyValue){
					return true;
				}
			}
			// SENTSINCE <date>
			//	Messages whose [RFC-2822] Date: header (disregarding time and
			//	timezone) is within or later than the specified date.
			else if(searchKey == "SENTSINCE"){
				if(msg.MessageDate.Date >= (DateTime)searchKeyValue){
					return true;
				}
			}
			// SINCE <date>
			//	Messages whose internal date (disregarding time and timezone)
			//	is within or later than the specified date.	
			else if(searchKey == "SINCE"){
				if(messageInfo.Date.Date >= (DateTime)searchKeyValue){
					return true;
				}
			}
			// SMALLER <n>
			//	Messages with an [RFC-2822] size smaller than the specified	number of octets.
			else if(searchKey == "SMALLER"){
				if(messageInfo.Size < Convert.ToInt64(searchKeyValue)){
					return true;
				}
			}
			// TEXT <string>
			//	Messages that contain the specified string in the header or	body of the message.				
			else if(searchKey == "TEXT"){
				// TODO:
			}
			// UID <sequence set>
			//	Messages with unique identifiers corresponding to the specified
			//	unique identifier set.  Sequence set ranges are permitted.
			else if(searchKey == "UID"){				
				if(((string)searchKeyValue).IndexOf(":") > -1){
					string[] start_end = ((string)searchKeyValue).Split(':');
					if(messageInfo.MessageUID >= Convert.ToInt64(start_end[0]) && messageInfo.MessageUID <= Convert.ToInt64(start_end[1])){
						return true;
					}
				}
				else{
					if(messageInfo.MessageUID == Convert.ToInt64(searchKeyValue)){
						return true;
					}
				}
			}
			// UNKEYWORD <flag>
			//	Messages that do not have the specified keyword flag set.
			else if(searchKey == "UNKEYWORD"){
				if((messageInfo.Flags & IMAP_Utils.ParseMessageFalgs((string)searchKeyValue)) == 0){
					return true;
				}
			}

			return false;
		}
예제 #25
0
		/// <summary>
		/// Is called when DATA command is finnished.
		/// </summary>
		/// <param name="result"></param>
		/// <param name="count"></param>
		/// <param name="exception"></param>
		/// <param name="tag"></param>
		private void EndAppendCmd(SocketCallBackResult result,long count,Exception exception,object tag)
		{
			try{
			//	if(m_pServer.LogCommands){
			//		m_pLogWriter.AddEntry("big binary " + count.ToString() + " bytes",this.SessionID,this.RemoteEndPoint.Address.ToString(),"S");
			//	}

				switch(result)
				{
					case SocketCallBackResult.Ok:
						Hashtable         param   = (Hashtable)tag;
						string            cmdTag  = (string)param["cmdTag"];
						string            mailbox = (string)param["mailbox"];
						IMAP_MessageFlags mFlags  = (IMAP_MessageFlags)param["mFlags"];
						DateTime          date    = (DateTime)param["date"];
						MemoryStream      strm    = (MemoryStream)param["strm"];
						
						IMAP_Message msg = new IMAP_Message(null,"",0,mFlags,0,date);
						string errotText = m_pServer.OnStoreMessage(this,mailbox,msg,strm.ToArray());
						if(errotText == null){
							m_pSocket.SendLine(cmdTag + " OK APPEND completed, recieved " + strm.Length + " bytes");
						}
						else{
							m_pSocket.SendLine(cmdTag + " NO " + errotText);
						}												
						break;

					case SocketCallBackResult.LengthExceeded:
					//	SendData("552 Requested mail action aborted: exceeded storage allocation\r\n");

					//	BeginRecieveCmd();
						break;

					case SocketCallBackResult.SocketClosed:
						EndSession();
						return;

					case SocketCallBackResult.Exception:
						OnError(exception);
						return;
				}

				// Command completed ok, get next command
				BeginRecieveCmd();
			}
			catch(Exception x){
				OnError(x);
			}
		}