/// <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="args"></param> /// <returns></returns> protected override System.String buildcommand(anmar.SharpWebMail.EmailClientCommand cmd, params System.Object[] args) { System.String command = System.String.Empty; switch (cmd) { case anmar.SharpWebMail.EmailClientCommand.Delete: if (args.Length == 1) { command = System.String.Format("DELE {0}", args[0]); } break; case anmar.SharpWebMail.EmailClientCommand.Header: if (args.Length == 2) { command = System.String.Format("TOP {0} {1}", args[0], args[1]); } break; case anmar.SharpWebMail.EmailClientCommand.ListSize: command = "LIST"; break; case anmar.SharpWebMail.EmailClientCommand.ListUID: if (args.Length == 1) { if (args[0] == null || args[0].Equals(System.String.Empty)) { command = "UIDL"; } else { command = System.String.Concat("UIDL ", args[0]); } } break; case anmar.SharpWebMail.EmailClientCommand.Logout: command = "QUIT"; break; case anmar.SharpWebMail.EmailClientCommand.Message: if (args.Length == 1) { command = System.String.Format("RETR {0}", args[0]); } break; case anmar.SharpWebMail.EmailClientCommand.Status: command = "STAT"; break; } return(command); }
protected override bool commandResponseTypeIsSL(anmar.SharpWebMail.EmailClientCommand cmd, params System.Object[] args) { bool responseSL = true; switch (cmd) { case anmar.SharpWebMail.EmailClientCommand.Delete: break; case anmar.SharpWebMail.EmailClientCommand.Header: responseSL = false; break; case anmar.SharpWebMail.EmailClientCommand.ListSize: responseSL = false; break; case anmar.SharpWebMail.EmailClientCommand.ListUID: if (args.Length == 1) { if (args[0].ToString().Equals(System.String.Empty)) { responseSL = false; } } break; case anmar.SharpWebMail.EmailClientCommand.Logout: break; case anmar.SharpWebMail.EmailClientCommand.Message: responseSL = false; break; case anmar.SharpWebMail.EmailClientCommand.Status: break; } return(responseSL); }
/// <summary> /// /// </summary> /// <param name="cmd"></param> /// <param name="args"></param> /// <returns></returns> protected override bool commandResponseTypeIsSL(anmar.SharpWebMail.EmailClientCommand cmd, params System.Object[] args) { bool responseSL = true; switch (cmd) { case anmar.SharpWebMail.EmailClientCommand.Delete: break; case anmar.SharpWebMail.EmailClientCommand.Header: responseSL = false; break; case anmar.SharpWebMail.EmailClientCommand.ListSize: responseSL = false; break; case anmar.SharpWebMail.EmailClientCommand.ListUID: responseSL = false; break; case anmar.SharpWebMail.EmailClientCommand.Login: break; case anmar.SharpWebMail.EmailClientCommand.Logout: responseSL = false; break; case anmar.SharpWebMail.EmailClientCommand.Message: responseSL = false; break; case anmar.SharpWebMail.EmailClientCommand.Status: responseSL = false; break; } return(responseSL); }
/// <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="cmd"></param> /// <param name="args"></param> /// <returns></returns> protected override System.String buildcommand(anmar.SharpWebMail.EmailClientCommand cmd, params System.Object[] args) { System.String command = System.String.Empty; this.randomTag(); switch (cmd) { case anmar.SharpWebMail.EmailClientCommand.Delete: if (args.Length == 1) { command = System.String.Format("{0} STORE {1}:{1} +FLAGS.SILENT (\\Deleted)", this.tag, args[0]); } break; case anmar.SharpWebMail.EmailClientCommand.Header: if (args.Length == 2) { command = System.String.Format("{0} FETCH {1}:{1} (RFC822.HEADER)", this.tag, args[0], args[1]); } break; case anmar.SharpWebMail.EmailClientCommand.ListSize: command = System.String.Format("{0} FETCH 1:* (RFC822.SIZE)", this.tag); break; case anmar.SharpWebMail.EmailClientCommand.ListUID: if (args.Length == 1) { if (args[0].ToString().Equals(System.String.Empty)) { command = System.String.Format("{0} FETCH 1:* (UID)", this.tag); } else { command = System.String.Format("{0} FETCH {1}:{1} (UID)", this.tag, args[0]); } } break; case anmar.SharpWebMail.EmailClientCommand.Login: if (args.Length == 2) { command = System.String.Format("{0} LOGIN {1} {2}", this.tag, args[0], args[1]); } break; case anmar.SharpWebMail.EmailClientCommand.Logout: command = System.String.Concat(this.tag, " LOGOUT"); break; case anmar.SharpWebMail.EmailClientCommand.Message: if (args.Length == 1) { command = System.String.Format("{0} FETCH {1}:{1} (BODY.PEEK[])", this.tag, args[0]); } break; case anmar.SharpWebMail.EmailClientCommand.Status: command = System.String.Format("{0} EXAMINE {1}", this.tag, this.folder); break; } return(command); }
private bool parseUntaggedResponse(System.IO.MemoryStream response, System.Object[] list, System.String token, anmar.SharpWebMail.EmailClientCommand cmd) { bool error = false; int msgnum = -1; System.Object value = -1; System.IO.StreamReader resp = new System.IO.StreamReader(response); for (System.String line = resp.ReadLine(); line != null; line = resp.ReadLine(), msgnum = -1, value = -1) { if (line.StartsWith("*") && line.IndexOf(token) > 0) { String[] values = line.Split(new char[] { ' ', '(', ')' }); for (int i = 0; i < values.Length; i++) { if (values[i].Equals("*")) { msgnum = this.parseInteger(values[++i]); } else if (values[i].Equals(token)) { if (cmd.Equals(anmar.SharpWebMail.EmailClientCommand.ListSize)) { value = this.parseInteger(values[++i]); } else { value = values[++i]; } } } if ((cmd.Equals(anmar.SharpWebMail.EmailClientCommand.ListUID) || cmd.Equals(anmar.SharpWebMail.EmailClientCommand.ListSize)) && msgnum > 0 && list.Length >= msgnum) { list[msgnum - 1] = value; } else if (cmd.Equals(anmar.SharpWebMail.EmailClientCommand.Status) && msgnum >= 0) { list[0] = msgnum; } else if (log.IsErrorEnabled) { log.Error("Error while parsing response line:" + line); error = true; } } } return(!error); }
/// <summary> /// /// </summary> /// <param name="cmd"></param> /// <param name="args"></param> /// <returns></returns> protected abstract bool commandResponseTypeIsSL(anmar.SharpWebMail.EmailClientCommand cmd, params System.Object[] args);
/// <summary> /// /// </summary> /// <param name="cmd"></param> /// <param name="args"></param> /// <returns></returns> protected abstract System.String buildcommand(anmar.SharpWebMail.EmailClientCommand cmd, params System.Object[] args);