Esempio n. 1
0
        /// <summary>
        /// Sets the client field for this folder and all the sub folders
        /// </summary>
        /// <param name="c"></param>
        internal void SetClient(IMAPClient c)
        {
            this._client = c;
            foreach (IMAPFolder f in _subFolders)
            {
                f.SetClient(c);
            }

            foreach (IMAPMessage m in _messages)
            {
                if (m != null)
                {
                    m._client = c;
                    m.Folder  = this;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the specified local cache into the object model
        /// </summary>
        public void LoadCache()
        {
            Log(IMAPBase.LogTypeEnum.INFO, "Loading Local Cache...");

            //try
            //{
            Stream     s = File.Open(_config.CacheFile, FileMode.Open);
            IMAPClient c = new IMAPClient();

            switch (_config.Format)
            {
            case CacheFormat.XML:
            {
                XmlSerializer xml = new XmlSerializer(typeof(IMAPClient));
                c = (IMAPClient)xml.Deserialize(s);
                break;
            }

            case CacheFormat.Binary:
            {
                BinaryFormatter b = new BinaryFormatter();
                c = (IMAPClient)b.Deserialize(s);
                break;
            }
            }

            this._folders = c.Folders;
            foreach (IMAPFolder f in _folders)
            {
                f.SetClient(this);
                f.SetParent(null);
            }

            s.Close();
            //}
            //catch (Exception e)
            //{
            //    throw e;
            //}

            Log(IMAPBase.LogTypeEnum.INFO, String.Format("Cache loaded ({0} messages found, in {1} folders)", this.TotalMessages, this.FolderCount));
        }
        /// <summary>
        /// Loads the specified local cache into the object model
        /// </summary>
        public void LoadCache()
        {
            Log(IMAPBase.LogTypeEnum.INFO, "Loading Local Cache...");

            //try
            //{
                Stream s = File.Open(_config.CacheFile, FileMode.Open);
                IMAPClient c = new IMAPClient();
                switch (_config.Format)
                {
                    case CacheFormat.XML:
                        {
                            XmlSerializer xml = new XmlSerializer(typeof(IMAPClient));
                            c = (IMAPClient)xml.Deserialize(s);
                            break;
                        }
                    case CacheFormat.Binary:
                        {
                            BinaryFormatter b = new BinaryFormatter();
                            c = (IMAPClient)b.Deserialize(s);
                            break;
                        }
                }

                this._folders = c.Folders;
                foreach (IMAPFolder f in _folders)
                {
                    f.SetClient(this);
                    f.SetParent(null);
                }

                s.Close();
            //}
            //catch (Exception e)
            //{
            //    throw e;
            //}

            Log(IMAPBase.LogTypeEnum.INFO, String.Format("Cache loaded ({0} messages found, in {1} folders)", this.TotalMessages, this.FolderCount));
        }
Esempio n. 4
0
        /// <summary>
        /// Sets the client field for this folder and all the sub folders
        /// </summary>
        /// <param name="c"></param>
        internal void SetClient(IMAPClient c)
        {
            this._client = c;
            foreach (IMAPFolder f in _subFolders)
            {
                f.SetClient(c);
            }

            foreach (IMAPMessage m in _messages)
            {
                if (m != null)
                {
                    m._client = c;
                    m.Folder = this;
                }
            }
        }
Esempio n. 5
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());
        }