Example #1
0
        /// <summary>
        /// Copies all messages in this folder to the specified folder
        /// </summary>
        /// <param name="destFolder">The destination folder all the messages should be copied to</param>
        public void CopyAllMessagesToFolder(IMAPFolder destFolder)
        {
            if (_client.OfflineMode)
            {
                _client.Log(IMAPBase.LogTypeEnum.WARN, "Cannot copy messages in offline mode.");
                return;
            }

            if (!this.IsCurrentlySelected)
            {
                this.Select();
            }

            string    cmd      = "UID COPY {0}:{1} \"{2}\"\r\n";
            ArrayList result   = new ArrayList();
            int       firstMsg = _messages[0].Uid;
            int       lastMsg  = _messages[_messages.Count - 1].Uid;

            cmd = String.Format(cmd, firstMsg, lastMsg, destFolder.FolderPath);
            _client._imap.SendAndReceive(cmd, ref result);

            // TODO: Need to find a way to determine what the UIDs of the copies are and instead of having
            // to pull the same messages from the server again, just copy the IMAPMessage objects and update
            // the UID to the new value. This is possible if copying one message at a time, but is not as
            // easy when copying messages in bulk.


            foreach (string s in result)
            {
                if (s.Contains("OK"))
                {
                    destFolder.GetMessageIDs(false);
                    _client.UpdateCache(true);
                    _client.Log(IMAPBase.LogTypeEnum.INFO, String.Format("All Messages from {0} successfully copied to {1}.", this.FolderName, destFolder.FolderName));
                    break;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Synchronizes the local cache with the server
        /// </summary>
        public void SyncCache()
        {
            if (this.OfflineMode)
            {
                return;
            }

            if (!this.UsingCache)
            {
                return;
            }

            // to synchronize the cache without having to download everything all over again,
            // we first get the folder list from the server. We then look at each folder in the server list
            // and see if it already exists in the client list. if it does not, we add it and pull
            // the message UIDs for it.

            // then we check the client list and see if all of those folders are still on the server
            // if not, the folder on the client side is removed, all with all of its messages

            // keep track of newly added folders so their contents can be downloaded.

            // next we iterate through all the existing folders and check for any new messages.
            // this is accomplished by simply calling the GetMessageIDs method on the folder. this will
            // update the folder with any UIDs that dont already exist.
            // the messages content will be loaded automatically when it is serialized.
            Log(IMAPBase.LogTypeEnum.INFO, "Synching Cache...");
            IMAPFolderCollection serverFolderList = _imap.RawFolderList;
            IMAPFolderCollection clientFolderList = FlattenFolderList(_folders);

            IMAPFolderCollection newFolderList = new IMAPFolderCollection();
            IMAPFolderCollection oldFolderList = new IMAPFolderCollection();


            foreach (IMAPFolder f in serverFolderList)
            {
                bool found = false;

                foreach (IMAPFolder cf in clientFolderList)
                {
                    if (cf.FolderPath.Equals(f.FolderPath))
                    {
                        found = true;
                    }
                }

                if (!found)
                {
                    newFolderList.Add(f);
                }
            }

            foreach (IMAPFolder f in clientFolderList)
            {
                bool found = false;

                foreach (IMAPFolder sf in serverFolderList)
                {
                    if (sf.FolderPath.Equals(f.FolderPath))
                    {
                        found = true;
                    }
                }

                if (!found)
                {
                    oldFolderList.Add(f);
                }
            }

            if (oldFolderList.Count > 0)
            {
                Log(IMAPBase.LogTypeEnum.INFO, String.Format("{0} old folders found", newFolderList.Count));
                foreach (IMAPFolder f in oldFolderList)
                {
                    IMAPFolder temp = null;
                    FindFolder(f.FolderPath, ref _folders, ref temp);

                    if (temp != null)
                    {
                        if (temp.ParentFolder == null)
                        {
                            _folders.Remove(temp);
                        }
                        else
                        {
                            temp.ParentFolder.SubFolders.Remove(temp);
                        }
                    }
                }
            }

            if (newFolderList.Count > 0)
            {
                Log(IMAPBase.LogTypeEnum.INFO, String.Format("{0} new folders found", newFolderList.Count));

                // now we need to put these new folders into the proper locations in the tree.
                foreach (IMAPFolder f in newFolderList)
                {
                    f.GetMessageIDs(false);
                    foreach (IMAPFolder sf in serverFolderList)
                    {
                        if (sf.FolderName.Equals(f.ParentFolderName))
                        {
                            f.ParentFolder = sf;
                            break;
                        }
                    }
                    // if the new folder has no parent assigned to it then we just add it to the root folders
                    if (f.ParentFolderName == String.Empty)
                    {
                        _folders.Add(f);
                    }
                    else
                    {
                        // otherwise we just loop through the flat list we created
                        // and find the folder that is the parent of the current new folder
                        // we then add the new folder to the sub folders of its parent
                        foreach (IMAPFolder cf in clientFolderList)
                        {
                            if (cf.FolderPath.Equals(f.ParentFolder.FolderPath))
                            {
                                cf.SubFolders.Add(f);
                                f.ParentFolder = cf;
                                break;
                            }
                        }
                    }
                }
            }

            foreach (IMAPFolder f in clientFolderList)
            {
                // this will get the UIDs of any new messages that have been added to the folder on the server
                f.GetMessageIDs(false);
            }

            UpdateCache(false);
            Log(IMAPBase.LogTypeEnum.INFO, "Cache Synchronization Complete");
        }
Example #3
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 public IMAPSearchResult()
 {
     _query    = null;
     _folder   = null;
     _messages = new IMAPMessageCollection();
 }