Exemplo n.º 1
0
        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>
        /// <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);
        }