/// <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; } } }
/// <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)); }
static void Main(string[] args) { //IMAPConfig config = new IMAPConfig("<host>", "<username>", "<password>", false, true, ""); //config.SaveConfig("settings.cfg"); IMAPConfig config = new IMAPConfig(@"c:\test1.cfg"); config.CacheFile = ""; IMAPClient client = null; try { client = new IMAPClient(config, null, 5); } catch (IMAPException e) { Console.WriteLine(e.Message); return; } //IMAPFolder drafts = client.Folders["Drafts"]; //IMAPMessage newMessage = new IMAPMessage(); //newMessage.From.Add(new IMAPMailAddress("Jason Miesionczek", "*****@*****.**")); //newMessage.To.Add(new IMAPMailAddress("Jason Miesionczek", "*****@*****.**")); //newMessage.Date = DateTime.Now; //newMessage.Subject = "this is a new message"; //drafts.AppendMessage(newMessage, "this is the content of the new message"); //IMAPFolder f = client.Folders["INBOX"]; //Console.WriteLine(f.Messages.Count); //IMAPMessage msg = f.GetMessageByID(21967); //Console.WriteLine(msg.TextData.Data); //foreach (IMAPFileAttachment attachment in msg.Attachments) //{ // attachment.SaveFile("C:\\"); //} //Console.ReadLine(); IMAPFolder f = client.Folders["INBOX"]; int[] msgCount = null; while (msgCount.Length == 0) { msgCount = f.CheckForNewMessages(); Thread.Sleep(1000); } foreach (int id in msgCount) { IMAPMessage msg = f.GetMessageByID(id); // do some logic here msg.MarkAsRead(); } //IMAPFolder f = client.Folders["Deleted Items"]; //IMAPMessage m = f.GetMessageByID(707); //IMAPFolder d = client.Folders["Deleted Items"]; //IMAPMessage m = d.Messages[0]; //IMAPMessage m = f.GetMessageByID(375); //IMAPMessage m = f.Messages[0]; //m.RefreshData(true, true); //client._imap.ProcessMessageHeader(m, 0); // 2893 //client._imap.ProcessBodyStructure(m); //client._imap.ProcessMessageHeader(m, 0); //client._imap.ProcessBodyStructure(m); //client._imap.ProcessBodyParts(m); //client._imap.ProcessAttachments(m); //IMAPSearchQuery query = new IMAPSearchQuery(); //query.Range = new DateRange(DateTime.Now.AddDays(-6), DateTime.Now); //IMAPSearchResult sResult = f.Search(query); //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchDateRange(DateTime.Now.AddDays(-6), DateTime.Now)); //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchFrom("Christine Fade", "*****@*****.**")); //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchNew()); //IMAPFolder test = f.SubFolders["Test"]; //IMAPFolder del = client.Folders["Deleted Items"]; //f.CopyMessageToFolder(f.Messages[0], test); //test.DeleteMessage(test.Messages[0]); //f.MoveMessageToFolder(f.Messages[0], test); //test.EmptyFolder(); //Console.WriteLine("{0} - {1}", sResult.Query.Range.StartDate, sResult.Query.Range.EndDate); //foreach (IMAPMessage msg in sResult.Messages) //{ // msg.RefreshData(true, true, false); // Console.WriteLine("{0}: {1}", msg.Date, msg.Subject); // Console.WriteLine(msg.TextData.Data); //} //m.Attachments[1].SaveFile("C:\\"); Console.ReadLine(); foreach (IMAPMessage msg in client.Folders["INBOX"].Messages) { if (msg.BodyParts.Count == 0) Console.WriteLine(msg.Uid); } client.Logoff(); }
public InterIMAPGmailHelper() : base() { _client = new IMAPClient(); }
/// <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()); }