protected override bool commandResponseTypeIsSL( EmailClientCommand cmd, params Object[] args ) { bool responseSL = true; switch ( cmd ) { case EmailClientCommand.Delete: break; case EmailClientCommand.Header: responseSL = false; break; case EmailClientCommand.ListSize: responseSL = false; break; case EmailClientCommand.ListUID: if ( args.Length==1 ) if ( args[0].ToString().Equals(String.Empty) ) responseSL = false; break; case EmailClientCommand.Logout: break; case EmailClientCommand.Message: responseSL = false; break; case EmailClientCommand.Status: break; } return responseSL; }
protected override System.String buildcommand( EmailClientCommand cmd, params Object[] args ) { String command = String.Empty; switch ( cmd ) { case EmailClientCommand.Delete: if ( args.Length==1 ) command = String.Format("DELE {0}", args[0]); break; case EmailClientCommand.Header: if ( args.Length==2 ) command = String.Format("TOP {0} {1}", args[0], args[1]); break; case EmailClientCommand.ListSize: command = "LIST"; break; case EmailClientCommand.ListUID: if ( args.Length==1 ) { if ( args[0]==null || args[0].Equals(String.Empty) ) command = "UIDL"; else command = String.Concat("UIDL ", args[0]); } break; case EmailClientCommand.Logout: command = "QUIT"; break; case EmailClientCommand.Message: if ( args.Length==1 ) command = String.Format("RETR {0}", args[0]); break; case EmailClientCommand.Status: command = "STAT"; break; } return command; }
protected virtual bool sendCommand( EmailClientCommand command, String cmd, 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, SeekOrigin.Begin); } else { error = true; } return !error; }
protected virtual bool sendCommand( EmailClientCommand command, 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(EmailClientCommand.Logout) ) { this.lastResponse = response; } } else { error = true; } return !error; }
protected abstract bool commandResponseTypeIsSL( EmailClientCommand cmd, params Object[] args );
protected abstract String buildcommand( EmailClientCommand cmd, params Object[] args );
protected override bool commandResponseTypeIsSL(EmailClientCommand cmd, params Object[] args ) { bool responseSL = true; switch ( cmd ) { case EmailClientCommand.Delete: break; case EmailClientCommand.Header: responseSL = false; break; case EmailClientCommand.ListSize: responseSL = false; break; case EmailClientCommand.ListUID: responseSL = false; break; case EmailClientCommand.Login: break; case EmailClientCommand.Logout: responseSL = false; break; case EmailClientCommand.Message: responseSL = false; break; case EmailClientCommand.Status: responseSL = false; break; } return responseSL; }
private bool parseUntaggedResponse(MemoryStream response, Object[] list, String token, EmailClientCommand cmd ) { bool error = false; int msgnum=-1; Object value=-1; StreamReader resp = new 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; }