public void Start() { PrintConfig(); if (_autoConnect) { ProcessResult(ProcessCommand("connect")); } bool quittinTime = false; while (true) { if (quittinTime) { break; } CommandResult result = ProcessCommand(ProcessInput()); quittinTime = ProcessResult(result); } if (_client.IsAlive) { _client.Stop(); } }
private void SyncEvernoteWithIMAP() { Configuration config = Configuration.Create(); enscriptpath = config.ENScriptPath; foreach (SyncPairSettings syncPair in config.SyncPairs) { if (cancelled) { break; } synchronizationContext.Send(new SendOrPostCallback(delegate(object state) { this.infoText0.Text = string.Format("Syncing notebook {0}", syncPair.EvernoteNotebook); }), null); syncStep = SyncStep.Start; SetInfo("Extracting notes from Evernote", "", 0, 0); string exportFile = ExtractNotes(syncPair.EvernoteNotebook); if (exportFile != null) { List <Note> notesEvernote = new List <Note>(); if (exportFile != string.Empty) { SetInfo("Parsing notes from Evernote", "", 0, 0); notesEvernote = ParseNotes(exportFile); } SetInfo("Fetching list of emails", "", 0, 0); List <Note> notesIMAP = GetMailList(syncPair.IMAPServer, syncPair.IMAPUsername, syncPair.IMAPPassword, syncPair.IMAPNotesFolder); SetInfo("Figuring out what needs to be synced", "", 0, 0); DiffNotesAndMails(ref notesEvernote, ref notesIMAP, syncPair.LastSyncTime); SetInfo("Adjusting tags in the GMail account", "", 0, 0); AdjustIMAPTags(syncPair.IMAPNotesFolder, notesIMAP); SetInfo("Downloading emails", "", 0, 0); List <Note> imapnotes = new List <Note>(notesIMAP); DownloadAndImportMailsToEvernote(imapnotes, notesEvernote, syncPair.EvernoteNotebook); if (exportFile != string.Empty) { SetInfo("Figuring out what needs to be synced", "", 0, 0); DiffNotesAndMails(ref notesEvernote, ref notesIMAP, syncPair.LastSyncTime); SetInfo("Uploading emails", "", 0, 0); UploadNotesAsMails(syncPair.IMAPNotesFolder, notesEvernote, exportFile); } syncPair.LastSyncTime = DateTime.Now; if (client != null) { client.Stop(); } } else { MessageBox.Show(string.Format("The notebook \"{0}\" either does not exist or isn't accessible!", syncPair.EvernoteNotebook)); } } if (!cancelled) { config.Save(); } else { SetInfo(null, "Operation cancelled", 0, 0); } synchronizationContext.Send(new SendOrPostCallback(delegate(object state) { startsync.Text = "Start Sync"; this.infoText1.Text = "Finished"; this.progressIndicator.Minimum = 0; this.progressIndicator.Maximum = 100000; this.progressIndicator.Value = 0; }), null); }
static void Main(string[] args) { IMAPConfig config = new IMAPConfig("imap.gmail.com", "atmospherian", "Xr3pr1s3Y", true, true, ""); config.SaveConfig(@"c:\settings.cfg"); //IMAPConfig config = new IMAPConfig(@"c:\test1.cfg"); IMAPAsyncClient client = new IMAPAsyncClient(config, 5); client.MailboxManager.CreateNewMailbox(@"c:\test.mbx"); client.Start(); FolderTreeRequest ftr = new FolderTreeRequest("\"\"", null); client.RequestManager.SubmitAndWait(ftr, false); IBatchRequest batch = new SimpleBatchRequest(); foreach (IFolder folder in client.MailboxManager.GetAllFolders()) { FolderDataRequest fdr = new FolderDataRequest(folder, null); fdr.RequestCompleted += delegate(IRequest req) { FolderDataProcessor fdp = req.GetProcessorAsType <FolderDataProcessor>(); IFolder f = fdp.Request.Command.ParameterObjects[0] as IFolder; Console.WriteLine("Data for {0} loaded. {1} Messages found.", f.Name, f.Exists); }; batch.Requests.Add(fdr); } client.RequestManager.SubmitBatchAndWait(batch, false); batch.Requests.Clear(); foreach (IFolder folder in client.MailboxManager.GetAllFolders()) { MessageListRequest mlr = new MessageListRequest(folder, null); mlr.RequestCompleted += delegate(IRequest req) { MessageListProcessor fdp = req.GetProcessorAsType <MessageListProcessor>(); IFolder f = fdp.Request.Command.ParameterObjects[0] as IFolder; Console.WriteLine("Message List for {0} loaded. {1} Messages found.", f.Name, f.Exists); }; batch.Requests.Add(mlr); } client.RequestManager.SubmitBatchAndWait(batch, false); client.MailboxManager.DownloadEntireAccount(delegate(int messagesCompleted, int totalMessages, IFolder currentFolder) { Console.WriteLine(); Console.WriteLine("Message {0} of {1} downloaded from {2}", messagesCompleted, totalMessages, currentFolder.Name); }, delegate(int totalFolders, int totalMessages, long totalTime) { Console.WriteLine("{0} Messages in {1} folders downloaded in {2} minutes.", totalMessages, totalFolders, new TimeSpan(totalTime).Minutes); }); //config.CacheFi Console.WriteLine("Press any key"); Console.ReadLine(); client.Stop(); }