示例#1
0
        private SelectResult GetSelectResult(String folderName, String text) //Sudeda visa informacija apie rezultata i SelectResult
        {
            var rs = new ImapCommandResult(this.Tag, text);                  //Laiko informacija apie atsakyma (ar geras ar ne)

            if (rs.Status == ImapCommandResultStatus.Ok)                     //+
            {
                Int32         exists = 0;                                    //+
                Int32         recent = 0;                                    //+
                List <String> l      = new List <string>();                  //+
                Match         m      = null;                                 //+
                m = RegexList.SelectFolderResult.Match(rs.Text);             //+
                if (m.Success)                                               //+
                {
                    Int32.TryParse(m.Groups["exst"].Value, out exists);      //+
                    Int32.TryParse(m.Groups["rcnt"].Value, out recent);      //+
                }
                m = RegexList.SelectFolderResultFlagsLine.Match(rs.Text);
                if (m.Success == true)                             //+
                {
                    String flags = m.Groups["Flags"].Value;        //+
                    foreach (var el in flags.Split(' '))           //+
                    {
                        if (el.StartsWith("\\") == true)           //+
                        {
                            l.Add(el.Substring(1, el.Length - 1)); //+
                        }
                    }
                }
                return(new SelectResult(folderName, exists, recent, l.ToArray())); //Sudeda visa informacija apie rezultata i objekta
            }
            throw new MailClientException();                                       //+
        }
示例#2
0
        /// <summary>
        /// Send copy command to IMAP server.
        /// </summary>
        /// <param name="mailindexstart"></param>
        /// <param name="mailindexend"></param>
        /// <param name="folderName"></param>
        /// <returns></returns>
        public ImapCommandResult ExecuteCopy(Int32 mailindexstart, Int32 mailindexend, String folderName)
        {
            String s = null;

            this.ValidateState(ImapConnectionState.Authenticated);
            StringBuilder sb = new StringBuilder(256);

            sb.Append(this.Tag);
            sb.Append(" Copy ");
            if (!Int32.Equals(mailindexstart, 0))
            {
                sb.Append(mailindexstart);
            }
            if (!Int32.Equals(mailindexend, 0) && !Int32.Equals(mailindexstart, 0))
            {
                sb.Append(":");
                sb.Append(mailindexend);
            }
            else if (!Int32.Equals(mailindexend, 0))
            {
                sb.Append(mailindexend);
            }
            sb.Append(" ");
            sb.Append(folderName);

            s = this.Execute(sb.ToString());
            var rs = new ImapCommandResult(this.Tag, s);

            if (rs.Status == ImapCommandResultStatus.Ok ||
                rs.Status == ImapCommandResultStatus.None)
            {
                return(rs);
            }
            return(rs);
        }
示例#3
0
        private SelectResult GetSelectResult(String folderName, String text)
        {
            var rs = new ImapCommandResult(this.Tag, text);

            if (rs.Status == ImapCommandResultStatus.Ok)
            {
                Int32         exists = 0;
                Int32         recent = 0;
                List <String> l      = new List <string>();
                Match         m      = null;
                m = RegexList.SelectFolderResult.Match(rs.Text);
                if (m.Success)
                {
                    Int32.TryParse(m.Groups["exst"].Value, out exists);
                    Int32.TryParse(m.Groups["rcnt"].Value, out recent);
                }
                m = RegexList.SelectFolderResultFlagsLine.Match(rs.Text);
                if (m.Success == true)
                {
                    String flags = m.Groups["Flags"].Value;
                    foreach (var el in flags.Split(' '))
                    {
                        if (el.StartsWith("\\") == true)
                        {
                            l.Add(el.Substring(1, el.Length - 1));
                        }
                    }
                }
                return(new SelectResult(folderName, exists, recent, l.ToArray()));
            }
            throw new MailClientException();
        }
示例#4
0
        /// <summary>
        /// Send status command to IMAP server.
        /// </summary>
        /// <param name="folderName"></param>
        /// <param name="message"></param>
        /// <param name="recent"></param>
        /// <param name="uidnext"></param>
        /// <param name="uidvalidity"></param>
        /// <param name="unseen"></param>
        /// <returns></returns>
        public ImapCommandResult ExecuteStatus(String folderName, Boolean message, Boolean recent, Boolean uidnext, Boolean uidvalidity, Boolean unseen)
        {
            String s = null;

            this.ValidateState(ImapConnectionState.Authenticated);
            StringBuilder sb = new StringBuilder(256);

            sb.Append(this.Tag);
            sb.Append(" Status");
            sb.Append(" ");
            sb.Append(folderName);
            if (message || recent || uidnext || uidvalidity || unseen)
            {
                sb.Append(" ");
                sb.Append("(");
                if (message)
                {
                    sb.Append("messages");
                }

                if (recent)
                {
                    sb.Append(" recent");
                }

                if (uidnext)
                {
                    sb.Append(" uidnext");
                }

                if (uidvalidity)
                {
                    sb.Append(" uidvalidity");
                }

                if (unseen)
                {
                    sb.Append(" unseen");
                }

                sb.Append(")");
            }

            s = this.Execute(sb.ToString());
            var rs = new ImapCommandResult(this.Tag, s);

            if (rs.Status == ImapCommandResultStatus.Ok ||
                rs.Status == ImapCommandResultStatus.None)
            {
                return(rs);
            }
            return(rs);
        }
示例#5
0
        /// <summary>
        /// Send Logout command to IMAP server.
        /// </summary>
        /// <returns></returns>
        public ImapCommandResult ExecuteLogout()
        {
            this.ValidateState(ImapConnectionState.Authenticated);
            String s  = this.Execute(this.Tag + " Logout");
            var    rs = new ImapCommandResult(this.Tag, s);

            if (rs.Status == ImapCommandResultStatus.Ok)
            {
                this._State = ImapConnectionState.Connected;
            }
            return(rs);
        }
示例#6
0
        /// <summary>
        /// Send rename folder command to IMAP server.
        /// </summary>
        /// <returns></returns>
        public ImapCommandResult ExecuteRename(String oldFolderName, String folderName)
        {
            this.ValidateState(ImapConnectionState.Authenticated);
            String commandText = String.Format(this.Tag + " Rename {0} {1}", NamingConversion.EncodeString(oldFolderName), NamingConversion.EncodeString(folderName));
            String s           = this.Execute(commandText);
            var    rs          = new ImapCommandResult(this.Tag, s);

            if (rs.Status == ImapCommandResultStatus.Ok ||
                rs.Status == ImapCommandResultStatus.None)
            {
                return(rs);
            }
            return(rs);
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="folderName"></param>
        /// <param name="mailData"></param>
        /// <param name="flag"></param>
        /// <param name="datetime"></param>
        /// <returns></returns>
        public ImapCommandResult ExecuteAppend(String folderName, String mailData, String flag, DateTimeOffset datetime)
        {
            String commandText = String.Format(this.Tag + " APPEND \"{0}\" ({1}) \"{2}\" "
                                               , NamingConversion.EncodeString(folderName), flag, MailParser.DateTimeOffsetString(datetime));

            commandText += "{" + mailData.Length + "}";
            String s  = this.Execute(commandText);
            var    rs = new ImapCommandResult(this.Tag, s);

            if (rs.Status == ImapCommandResultStatus.Ok ||
                rs.Status == ImapCommandResultStatus.None)
            {
                var ss = this.Execute(mailData);
                return(new ImapCommandResult(this.Tag, ss));
            }
            return(rs);
        }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ImapCommandResult ExecuteLogin()
        {
            if (this.EnsureOpen() == ImapConnectionState.Disconnected)
            {
                throw new MailClientException();
            }

            String            commandText = String.Format(this.Tag + " LOGIN {0} {1}", this.UserName, this.Password);
            String            s           = this.Execute(commandText);
            ImapCommandResult rs          = new ImapCommandResult(this.Tag, s);

            if (rs.Status == ImapCommandResultStatus.Ok)
            {
                this._State = ImapConnectionState.Authenticated;
            }
            else
            {
                this._State = ImapConnectionState.Connected;
            }
            return(rs);
        }
示例#9
0
        public ImapCommandResult ExecuteLogin()   //Grazina informacija apie atsakyma (ar geras ar ne) ir nustato ImapConnectionState (authenticated / conneceted)
        {
            if (this.EnsureOpen() == ImapConnectionState.Disconnected)
            {
                throw new MailClientException();
            }                                                                                               //Metamas error jei esame disconnected ir negalima prisijungti

            String            commandText = String.Format(this.Tag + " LOGIN {0} {1}", this.UserName, this.Password);
            String            s           = this.Execute(commandText);          //Ivykdo komanda ir grazina atsakyma
            ImapCommandResult rs          = new ImapCommandResult(this.Tag, s); //Laiko informacija apie atsakyma (ar geras ar ne)

            if (rs.Status == ImapCommandResultStatus.Ok)                        //+
            {
                this._State = ImapConnectionState.Authenticated;                //+
            }
            else //+
            {
                this._State = ImapConnectionState.Connected; //+
            }
            return(rs);                                      //+
        }
示例#10
0
 private SelectResult GetSelectResult(String folderName, String text)
 {
     var rs = new ImapCommandResult(this.Tag, text);
     if (rs.Status == ImapCommandResultStatus.Ok)
     {
         Int32 exists = 0;
         Int32 recent = 0;
         List<String> l = new List<string>();
         Match m = null;
         m = RegexList.SelectFolderResult.Match(rs.Text);
         if (m.Success)
         {
             Int32.TryParse(m.Groups["exst"].Value, out exists);
             Int32.TryParse(m.Groups["rcnt"].Value, out recent);
         }
         m = RegexList.SelectFolderResultFlagsLine.Match(rs.Text);
         if (m.Success == true)
         {
             String flags = m.Groups["Flags"].Value;
             foreach (var el in flags.Split(' '))
             {
                 if (el.StartsWith("\\") == true)
                 {
                     l.Add(el.Substring(1, el.Length - 1));
                 }
             }
         }
         return new SelectResult(folderName, exists, recent, l.ToArray());
     }
     throw new MailClientException();
 }
示例#11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public SearchResult Search(SearchCommand command)
 {
     if (command.IsEncodeValue == true)
     {
         this.ValidateState(ImapConnectionState.Authenticated, true);
         var searchText = this.Execute(Encoding.UTF8.GetBytes(this.Tag + " " + command.GetCommandText()), command.GetEncodedValue());
         if (searchText.StartsWith("* Search", StringComparison.OrdinalIgnoreCase) == false)
         {
             throw new MailClientException(searchText);
         }
         var bb = this.GetResponseBytes();
         var rs = new ImapCommandResult(this.Tag, this.ResponseEncoding.GetString(bb));
         if (rs.Status == ImapCommandResultStatus.Ok)
         {
             return new SearchResult(searchText);
         }
         throw new MailClientException(rs.Text);
     }
     else
     {
         var text = this.Tag + " " + command.GetCommandText();
         return this.Search(text);
     }
 }