Example #1
0
        /// <summary>
        /// Gets the UIDs for each message in this folder, and populates the Messages collection with IMAPMessage objects
        /// </summary>
        internal int[] GetMessageIDs(bool newOnly)
        {
            List <int> newMsgIDs = new List <int>();

            if (this._client == null)
            {
                return(null);
            }

            if (this._client.OfflineMode)
            {
                return(null);
            }

            IMAPClient c = this._client;

            if (!String.IsNullOrEmpty(_folderPath) || !_folderPath.Equals("\"\""))
            {
                string path = "";
                if (_folderPath.Contains(" "))
                {
                    path = "\"" + _folderPath + "\"";
                }
                else
                {
                    path = _folderPath;
                }

                //if (!this.IsCurrentlyExamined)
                c._imap.ExamineFolder(this);
                List <int> ids = c._imap.GetSelectedFolderMessageIDs(newOnly);
                //_messages.Clear();
                foreach (int id in ids)
                {
                    bool found = false;
                    foreach (IMAPMessage m in _messages)
                    {
                        if (m.Uid == id)
                        {
                            found = true;
                        }
                    }

                    if (!found)
                    {
                        IMAPMessage msg = new IMAPMessage();
                        msg.Uid     = id;
                        msg.Folder  = this;
                        msg._client = c;
                        _messages.Add(msg);
                        newMsgIDs.Add(id);
                        c.Log(IMAPBase.LogTypeEnum.INFO, String.Format("Added message UID {0} to folder {1}", id, this.FolderPath));
                    }
                }
            }

            if (_client.Config.AutoGetMsgID)
            {
                foreach (IMAPFolder f in _subFolders)
                {
                    f.GetMessageIDs(newOnly);
                }
            }

            //_client._messageCount += _messages.Count;
            //foreach (IMAPMessage msg in _messages)
            //{
            //    //ArrayList headerResults = new ArrayList();
            //    //c._imap.FetchPartHeader(msg.Uid.ToString(), "0", headerResults);
            //    c._imap.FetchMessageObject(msg, false);
            //}

            return(newMsgIDs.ToArray());
        }