/// <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); }
/// <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()); }