コード例 #1
0
        /// <summary>
        /// Copies the specified message to the specified folder
        /// </summary>
        /// <param name="msg">The message to copy</param>
        /// <param name="destFolder">The folder to copy the message to</param>
        public void CopyMessageToFolder(IMAPMessage msg, IMAPFolder destFolder)
        {
            if (_client.OfflineMode)
            {
                _client.Log(IMAPBase.LogTypeEnum.WARN, "Cannot copy messages in offline mode.");
                return;
            }

            string    cmd    = "UID COPY {0} \"{1}\"\r\n";
            ArrayList result = new ArrayList();

            _client._imap.SendAndReceive(String.Format(cmd, msg.Uid, destFolder.FolderPath), ref result);
            foreach (string s in result)
            {
                if (s.Contains("OK"))
                {
                    // if the copy was successful, tell the destination folder to refresh its message UID list.
                    destFolder.GetMessageIDs(false);
                    int msgCount = destFolder.Messages.Count;
                    // the copy function puts the new message at the end of the folder so lets automatically
                    // load the data for the copy. If for some reason during the folder refresh another new message
                    // was found and added making the copied message not the last one in the folder, thats ok
                    // because as soon as the content is accessed the data will be loaded automatically
                    if (msgCount > 0)
                    {
                        destFolder.Messages[msgCount - 1].RefreshData(msg.ContentLoaded, true);
                    }
                    _client.UpdateCache(true);
                    _client.Log(IMAPBase.LogTypeEnum.INFO, String.Format("Message with UID {0} successfully copied to folder \"{1}\"", msg.Uid, destFolder.FolderName));
                    break;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Moves the specified message to the specified folder
        /// </summary>
        /// <param name="msg">The message to move</param>
        /// <param name="destFolder">The folder to move the message to</param>
        public void MoveMessageToFolder(IMAPMessage msg, IMAPFolder destFolder)
        {
            if (_client.OfflineMode)
            {
                _client.Log(IMAPBase.LogTypeEnum.WARN, "Cannot move messages in offline mode.");
                return;
            }

            CopyMessageToFolder(msg, destFolder);
            DeleteMessage(msg);
        }
コード例 #3
0
        /// <summary>
        /// Appends new message to end of this folder
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="content">The content of the message</param>
        public void AppendMessage(IMAPMessage msg, string content)
        {
            this.Select();

            // first lets determine what the UID of the new message should be
            int uid = _messages.Count > 0 ? _messages[_messages.Count - 1].Uid : 0;

            uid++;

            msg.Uid = uid;

            //string cmd = "APPEND \"{0}\" (\\Seen) {0}\r\n";
            ArrayList result = new ArrayList();

            _client._imap.SendRaw("APPEND \"" + FolderPath + "\" (\\Seen) {" + uid + "}\r\n", true);
            //if (!result[0].ToString().StartsWith("+"))
            //{
            //    _client.Log(IMAPBase.LogTypeEnum.ERROR, "Invalid response from server");
            //    return;
            //}
            //_client._imap.ReadLine();

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Date: {0}{1}", "Mon, 7 Feb 1994 21:52:25 -0800 (PST)", Environment.NewLine);
            sb.AppendFormat("From: {0}{1}", msg.From[0], Environment.NewLine);
            sb.AppendFormat("Subject: {0}{1}", msg.Subject, Environment.NewLine);
            sb.Append("To: ");
            foreach (IMAPMailAddress addr in msg.To)
            {
                sb.AppendFormat("{0}, ", addr);
            }

            sb.Remove(sb.Length - 2, 1);
            sb.Append(Environment.NewLine);
            sb.AppendFormat("Message-Id: <{0}@{1}>{2}", msg.Date.Ticks, msg.From[0].ToString().Substring(msg.From[0].ToString().IndexOf("@") + 1).Replace(">", ""), Environment.NewLine);
            sb.AppendLine("MIME-Version: 1.0");
            sb.AppendLine("Content-Type: TEXT/PLAIN; CHARSET=US-ASCII");
            sb.AppendLine();
            sb.AppendLine(content);
            sb.AppendLine("\r\n");

            result.Clear();
            _client.Log(IMAPBase.LogTypeEnum.INFO, sb.ToString());
            _client._imap.SendRaw(sb.ToString(), false);
        }
コード例 #4
0
        /// <summary>
        /// Deletes the specified message
        /// </summary>
        /// <param name="msg">The message to delete</param>
        public void DeleteMessage(IMAPMessage msg)
        {
            if (_client.OfflineMode)
            {
                _client.Log(IMAPBase.LogTypeEnum.WARN, "Cannot delete messages in offline mode.");
                return;
            }

            string    cmd    = "UID STORE {0} +FLAGS (\\Deleted)\r\n";
            ArrayList result = new ArrayList();

            // first we need to put the folder in read/write mode by SELECTing it
            this.Select();
            // mark the specified message as deleted
            _client._imap.SendAndReceive(String.Format(cmd, msg.Uid), ref result);
            // EXPUNGE the \Deleted messages
            _client._imap.SendAndReceive("EXPUNGE\r\n", ref result);
            // remove the message object from the collection
            _messages.Remove(msg);
            // set the folder back to read-only mode
            this.Examine();
            _client.UpdateCache(true);
            _client.Log(IMAPBase.LogTypeEnum.INFO, String.Format("Message wih UID {0} in folder \"{1}\" successfully deleted.", msg.Uid, this.FolderName));
        }
コード例 #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());
        }