private static void ProcessMailbox(dynamic mailbox) { ConsoleUtils.WriteWarning(mailbox["login"]); // For demo-purposes, accept all SSL certificates var client = new ImapClient { ServerCertificateValidationCallback = (s, c, h, e) => true }; client.Connect(mailbox["host"], mailbox["port"], true); client.Authenticate(mailbox["login"], mailbox["password"]); // The Inbox folder is always available on all IMAP servers... IMailFolder inbox = client.Inbox; inbox.Open(FolderAccess.ReadWrite); // convert filters: from JsonArray to List of strings var filters = new List <string>(); foreach (dynamic filter in mailbox["applicable_filters"]) { filters.Add(filter.ToString().Trim('"')); } for (var i = 0; i < inbox.Count; i++) { var wrappedMessage = new WrappedMessage(client, inbox, i, filters); ProcessMessage(wrappedMessage); } client.Disconnect(true); }
private static void ProcessMessage(WrappedMessage wMsg) { Console.WriteLine( "Subject: '{0}' from '{1}' to '{2}'", wMsg.Message.Subject, !wMsg.Message.From.Mailboxes.Any() ? null : wMsg.Message.From.Mailboxes.First(), !wMsg.Message.To.Mailboxes.Any() ? null : wMsg.Message.To.Mailboxes.First() ); foreach (var filter in wMsg.Filters) { object[] parametersArray = { wMsg }; Type.GetType("MailFilter.Filters." + filter) .GetMethod("Filter") .Invoke(null, parametersArray); } }