⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleemailclient.cs

📁 Source for web based email in Csharp
💻 CS
📖 第 1 页 / 共 2 页
字号:
			error = (error)?error:!this.header ( mindex, 0, stream );
			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="data"></param>
		/// <returns></returns>
		protected abstract System.IO.MemoryStream getStreamDataPortion ( System.IO.MemoryStream data );
		/// <summary>
		/// 
		/// </summary>
		/// <param name="mindex"></param>
		/// <param name="nlines"></param>
		/// <param name="response"></param>
		/// <returns></returns>
		protected virtual bool header ( int mindex, ulong nlines, System.IO.MemoryStream response ) {
			bool error = false;

			System.String cmd = this.buildcommand(anmar.SharpWebMail.EmailClientCommand.Header, mindex, nlines);
			bool SLResponse = this.commandResponseTypeIsSL(anmar.SharpWebMail.EmailClientCommand.Header, mindex, nlines);
			error = ( cmd.Equals(System.String.Empty) )?true:!this.sendCommand( anmar.SharpWebMail.EmailClientCommand.Header, cmd, response, SLResponse );

			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="user"></param>
		/// <param name="pass"></param>
		/// <returns></returns>
		protected virtual bool login ( System.String user, System.String pass ) {
			bool error = false;

			System.String cmd = this.buildcommand(anmar.SharpWebMail.EmailClientCommand.Login, user, pass);
			error = ( cmd.Equals(System.String.Empty) )?true:!this.sendCommand( anmar.SharpWebMail.EmailClientCommand.Login, cmd );

			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="list"></param>
		/// <returns></returns>
		protected virtual bool list ( System.Int32[] list ) {
			bool error = false;
			System.IO.MemoryStream response = new System.IO.MemoryStream();

			// Send LIST and parse response
			System.String cmd = this.buildcommand(anmar.SharpWebMail.EmailClientCommand.ListSize);
			bool SLResponse = this.commandResponseTypeIsSL(anmar.SharpWebMail.EmailClientCommand.ListSize);

			error = ( cmd.Equals(System.String.Empty) )?true:!this.sendCommand( anmar.SharpWebMail.EmailClientCommand.ListSize, cmd, response, SLResponse );

			//Parse the result
			error = (error)?true:!this.parseListSize(list, response);

			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="response"></param>
		/// <param name="SLReponse"></param>
		protected virtual void parseLastResponse ( System.IO.MemoryStream response, bool SLReponse ) {
			System.Byte[] readBytes = new System.Byte[3];
			response.Seek(0,0);
			response.Read (readBytes,  0, 3);
			this.lastResponse = System.Text.Encoding.ASCII.GetString(readBytes, 0, 3);
			response.Seek(0,0);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="list"></param>
		/// <param name="response"></param>
		/// <returns></returns>
		protected abstract bool parseListSize ( System.Int32[] list, System.IO.MemoryStream response );
		/// <summary>
		/// 
		/// </summary>
		/// <param name="list"></param>
		/// <param name="response"></param>
		/// <returns></returns>
		protected abstract bool parseListUID ( System.String[] list, System.IO.MemoryStream response, int mindex );
		/// <summary>
		/// 
		/// </summary>
		/// <param name="num"></param>
		/// <param name="numbytes"></param>
		/// <param name="response"></param>
		/// <returns></returns>
		protected abstract bool parseStatus ( ref int num, ref int numbytes, System.IO.MemoryStream response );
		/// <summary>
		/// 
		/// </summary>
		/// <param name="inbox"></param>
		/// <param name="all"></param>
		/// <returns></returns>
		public bool PurgeInbox ( anmar.SharpWebMail.CTNInbox inbox, bool all ) {
			bool error = false;
			System.String filter;
			if ( all )
				filter = System.String.Empty;
			else
				filter = "delete=true";
			System.Data.DataView result = inbox.Inbox;
			result.RowFilter = filter;
			if ( result.Count>0 ) {
				int total = 0, totalbytes = 0;
				error = !this.connect();
				error = (error)?error:!this.login ( this.username, this.password );
				error = (error)?error:!this.status ( ref total, ref totalbytes );
				error = (error)?error:!this.getListToIndex ( null, total, inbox, 0, 0 );
				result.RowFilter = filter;
				error = (error)?error:!this.deletemessages(result);
				error = (error)?error:!this.getListToIndex ( null, total, inbox, 0, 0 );
				this.quit();
			}
			result.RowFilter = System.String.Empty;
			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="mindex"></param>
		/// <param name="response"></param>
		/// <returns></returns>
		protected virtual bool retrieve ( int mindex, System.IO.MemoryStream response ) {
			bool error = false;

			System.String cmd = this.buildcommand(anmar.SharpWebMail.EmailClientCommand.Message, mindex);
			bool SLResponse = this.commandResponseTypeIsSL(anmar.SharpWebMail.EmailClientCommand.Message, mindex);
			error = ( cmd.Equals(System.String.Empty) )?true:!this.sendCommand( anmar.SharpWebMail.EmailClientCommand.Message, cmd, response, SLResponse );

			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="cmd"></param>
		/// <returns></returns>
		protected virtual bool sendCommand ( anmar.SharpWebMail.EmailClientCommand command, System.String cmd ) {
			bool error = false;
			System.String response = null;

			//Send cmd and evaluate response
			if (connected) {
				// Send cmd
				error = !client.sendCommand( cmd, commandEnd );
				// Read Response
				error = (error)?true:!client.readResponse(ref response, responseEndSL, true);
				// Evaluate the result
				error = (error)?true:!this.evaluateresponse(response);
				if ( error || !command.Equals(anmar.SharpWebMail.EmailClientCommand.Logout) ) {
					this.lastResponse = response;
				}
			} else {
				error = true;
			}

			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="cmd"></param>
		/// <param name="response"></param>
		/// <param name="SLReponse"></param>
		/// <returns></returns>
		protected virtual bool sendCommand ( anmar.SharpWebMail.EmailClientCommand command, System.String cmd, System.IO.MemoryStream response, bool SLReponse ) {
			bool error = false;

			//Send cmd and evaluate response
			if (connected) {
				// Send cmd
				error = !client.sendCommand( cmd, commandEnd );
				// Read Response
				error = (error)?true:!client.readResponse( response, ((SLReponse)?responseEndSL:responseEnd), (SLReponse||this.responseEndOnEnd));
				// Get the last response string from a multiline response
				this.parseLastResponse( response, SLReponse);
				// Evaluate the result
				error = (error)?true:!this.evaluateresponse( this.lastResponse );
				response.Seek(0, System.IO.SeekOrigin.Begin);
			} else {
				error = true;
			}

			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="num"></param>
		/// <param name="numbytes"></param>
		/// <returns></returns>
		protected virtual bool status ( ref int num, ref int numbytes ) {
			bool error = false;
			System.IO.MemoryStream response = new System.IO.MemoryStream();
			// Get status command
			System.String cmd = this.buildcommand(anmar.SharpWebMail.EmailClientCommand.Status);
			bool SLResponse = this.commandResponseTypeIsSL(anmar.SharpWebMail.EmailClientCommand.Status);
			error = ( cmd.Equals(System.String.Empty) )?true:!this.sendCommand( anmar.SharpWebMail.EmailClientCommand.Status, cmd, response, SLResponse );

			//Parse the result
			error = (error)?true:!this.parseStatus(ref num, ref numbytes, response);

			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="list"></param>
		/// <param name="mindex"></param>
		/// <returns></returns>
		protected virtual bool uidl ( System.String[] list, int mindex ) {
			bool error = false;
			System.IO.MemoryStream response = new System.IO.MemoryStream();

			// Send ListUID command
			System.String cmd = this.buildcommand(anmar.SharpWebMail.EmailClientCommand.ListUID, ((mindex>0)?mindex.ToString():System.String.Empty));
			bool SLResponse = this.commandResponseTypeIsSL(anmar.SharpWebMail.EmailClientCommand.ListUID, ((mindex>0)?mindex.ToString():System.String.Empty));
			error = ( cmd.Equals(System.String.Empty) )?true:!this.sendCommand( anmar.SharpWebMail.EmailClientCommand.ListUID, cmd, response, SLResponse );

			//Parse the result
			error = (error)?true:!this.parseListUID(list, response, mindex);

			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		protected virtual bool quit () {
			bool error = false;

			// Send Quit and disconnect
			System.String cmd = this.buildcommand(anmar.SharpWebMail.EmailClientCommand.Logout);
			error = ( cmd.Equals(System.String.Empty) )?true:!this.sendCommand( anmar.SharpWebMail.EmailClientCommand.Logout, cmd );

			this.disconnect();

			return !error;
		}
		/// <summary>
		/// 
		/// </summary>
		public System.String errormessage {
			get {
				return client.errormessage;
			}
		}
		/// <summary>
		/// 
		/// </summary>
		public System.String lastMessage {
			get {
				return this.lastResponse;
			}
		}
		public System.String Password {
			get {
				return this.password;
			}
		}
		public System.String UserName {
			get {
				return this.username;
			}
		}
	}
	internal enum EmailClientCommand {
		Delete,
		Header,
		Login,
		Logout,
		ListSize,
		ListUID,
		Message,
		Other,
		Status
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -