public Connect ( Socket socket, string host, int port, SecureSocketOptions options = SecureSocketOptions.Auto, |
||
socket | Socket | The socket to use for the connection. |
host | string | The host name to connect to. |
port | int | The port to connect to. If the specified port is |
options | SecureSocketOptions | The secure socket options to when connecting. |
cancellationToken | The cancellation token. | |
return | void |
public ActionResult Index(int currentPageNumber, int nextPageNumber) { int startSerialNumber = ((nextPageNumber - 1) * 30) + 1; int endSerialNumber = ((nextPageNumber) * 30); List<Email> emails = new List<Email>(); try { userGmailConfig = FetchUserGmailProfile(); using (ImapClient client = new ImapClient()) { client.Connect(userGmailConfig.IncomingServerAddress, userGmailConfig.IncomingServerPort, true); client.Authenticate(new NetworkCredential(userGmailConfig.GmailUsername, userGmailConfig.GmailPassword)); var inbox = client.Inbox; inbox.Open(FolderAccess.ReadOnly); if (inbox.Count > 0) { int pageEndIndex = Math.Max(inbox.Count - startSerialNumber, 0); int pageStartIndex = Math.Max(inbox.Count - endSerialNumber, 0); var messages = inbox.Fetch(pageStartIndex, pageEndIndex, MessageSummaryItems.Envelope); messages = messages.OrderByDescending(message => message.Envelope.Date.Value.DateTime).ToList(); foreach (var message in messages) { if (startSerialNumber <= endSerialNumber) { Email tempEmail = new Email() { SerialNo = startSerialNumber, Uid = message.UniqueId, FromDisplayName = message.Envelope.From.First().Name, FromEmail = message.Envelope.From.First().ToString(), To = message.Envelope.To.ToString(), Subject = message.NormalizedSubject, TimeReceived = message.Envelope.Date.Value.DateTime, HasAttachment = message.Attachments.Count() > 0 ? true : false }; emails.Add(tempEmail); startSerialNumber++; } } } } ViewBag.EmailId = userGmailConfig.GmailUsername; ViewBag.NoOfEmails = endSerialNumber; if (currentPageNumber > nextPageNumber) { ViewBag.PageNumber = currentPageNumber - 1; } else { ViewBag.PageNumber = currentPageNumber + 1; } } catch (Exception ex) { ViewBag.ErrorMessage = "There was an error in processing your request. Exception: " + ex.Message; } return View(emails); }
public static void DownloadMessages () { using (var client = new ImapClient (new ProtocolLogger ("imap.log"))) { client.Connect ("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect); client.Authenticate ("username", "password"); client.Inbox.Open (FolderAccess.ReadOnly); var uids = client.Inbox.Search (SearchQuery.All); foreach (var uid in uids) { var message = client.Inbox.GetMessage (uid); // write the message to a file message.WriteTo (string.Format ("{0}.msg", uid)); } client.Disconnect (true); } }
public void login() { result.credential = GoogleWebAuthorizationBroker.AuthorizeAsync( new ClientSecrets { ClientId = "316924129116-efm2iopj3strkrpbjkf7oeqmptn8ph27.apps.googleusercontent.com", ClientSecret = "MAxnno9YGxGTdtNiEqItt8-n" }, new[] { "https://mail.google.com/ email" }, "Tiramisu", CancellationToken.None, new FileDataStore("Analytics.Auth.Store")).Result; if (result.credential != null) { result.service = new PlusService(new BaseClientService.Initializer() { HttpClientInitializer = result.credential, ApplicationName = "Google mail", }); Google.Apis.Plus.v1.Data.Person me = result.service.People.Get("me").Execute(); Google.Apis.Plus.v1.Data.Person.EmailsData myAccountEmail = me.Emails.Where(a => a.Type == "account").FirstOrDefault(); imapClient = new MailKit.Net.Imap.ImapClient(); var credentials = new NetworkCredential(myAccountEmail.Value, result.credential.Token.AccessToken); imapClient.Connect("imap.gmail.com", 993, true, CancellationToken.None); imapClient.Authenticate(credentials, CancellationToken.None); } }
public static void Capabilities () { using (var client = new ImapClient ()) { client.Connect ("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect); var mechanisms = string.Join (", ", client.AuthenticationMechanisms); Console.WriteLine ("The IMAP server supports the following SASL authentication mechanisms: {0}", mechanisms); client.Authenticate ("username", "password"); if (client.Capabilities.HasFlag (ImapCapabilities.Id)) { var clientImplementation = new ImapImplementation { Name = "MailKit", Version = "1.0" }; var serverImplementation = client.Identify (clientImplementation); Console.WriteLine ("Server implementation details:"); foreach (var property in serverImplementation.Properties) Console.WriteLine (" {0} = {1}", property.Key, property.Value); } if (client.Capabilities.HasFlag (ImapCapabilities.Acl)) { Console.WriteLine ("The IMAP server supports Access Control Lists."); Console.WriteLine ("The IMAP server supports the following access rights: {0}", client.Rights); Console.WriteLine ("The Inbox has the following access controls:"); var acl = client.Inbox.GetAccessControlList (); foreach (var ac in acl) Console.WriteLine (" {0} = {1}", ac.Name, ac.Rights); var myRights = client.Inbox.GetMyAccessRights (); Console.WriteLine ("Your current rights for the Inbox folder are: {0}", myRights); } if (client.Capabilities.HasFlag (ImapCapabilities.Quota)) { Console.WriteLine ("The IMAP server supports quotas."); Console.WriteLine ("The current quota for the Inbox is:"); var quota = client.Inbox.GetQuota (); if (quota.StorageLimit.HasValue && quota.StorageLimit.Value) Console.WriteLine (" Limited by storage space. Using {0} out of {1} bytes.", quota.CurrentStorageSize.Value, quota.StorageLimit.Value); if (quota.MessageLimit.HasValue && quota.MessageLimit.Value) Console.WriteLine (" Limited by the number of messages. Using {0} out of {1} bytes.", quota.CurrentMessageCount.Value, quota.MessageLimit.Value); Console.WriteLine ("The quota root is: {0}", quota.QuotaRoot); } if (client.Capabilities.HasFlag (ImapCapabilities.Thread)) { if (client.ThreadingAlgorithms.Contains (ThreadingAlgorithm.OrderedSubject)) Console.WriteLine ("The IMAP server supports threading by subject."); if (client.ThreadingAlgorithms.Contains (ThreadingAlgorithm.References)) Console.WriteLine ("The IMAP server supports threading by references."); } client.Disconnect (true); } }
public ImapClient Init() { if (BindingInfo == null) { throw new MissingFieldException("BindingInfo is missing"); } Client = new ImapClient(); Client.Timeout = 10000; Client.Connect(host: BindingInfo.Server, port: BindingInfo.Port, useSsl: BindingInfo.EnableSSL); Client.AuthenticationMechanisms.Remove("XOAUTH2"); Client.Authenticate(userName: BindingInfo.Mail, password: BindingInfo.Token); return Client; }
public static void Main(string[] args) { var logger = new ProtocolLogger (Console.OpenStandardError ()); using (var client = new ImapClient (logger)) { var credentials = new NetworkCredential ("*****@*****.**", "password"); var uri = new Uri ("imaps://imap.gmail.com"); client.Connect (uri); // Remove the XOAUTH2 authentication mechanism since we don't have an OAuth2 token. client.AuthenticationMechanisms.Remove ("XOAUTH2"); client.Authenticate (credentials); client.Inbox.Open (FolderAccess.ReadOnly); // keep track of the messages var messages = client.Inbox.Fetch (0, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId).ToList (); // connect to some events... client.Inbox.MessagesArrived += (sender, e) => { // Note: the CountChanged event will fire when new messages arrive in the folder. var folder = (ImapFolder) sender; // New messages have arrived in the folder. Console.WriteLine ("{0}: {1} new messages have arrived.", folder, e.Count); // Note: your first instict may be to fetch these new messages now, but you cannot do // that in an event handler (the ImapFolder is not re-entrant). }; client.Inbox.MessageExpunged += (sender, e) => { var folder = (ImapFolder) sender; if (e.Index < messages.Count) { var message = messages[e.Index]; Console.WriteLine ("{0}: expunged message {1}: Subject: {2}", folder, e.Index, message.Envelope.Subject); // Note: If you are keeping a local cache of message information // (e.g. MessageSummary data) for the folder, then you'll need // to remove the message at e.Index. messages.RemoveAt (e.Index); } else { Console.WriteLine ("{0}: expunged message {1}: Unknown message.", folder, e.Index); } }; client.Inbox.MessageFlagsChanged += (sender, e) => { var folder = (ImapFolder) sender; Console.WriteLine ("{0}: flags for message {1} have changed to: {2}.", folder, e.Index, e.Flags); }; Console.WriteLine ("Hit any key to end the IDLE loop."); using (var done = new CancellationTokenSource ()) { var thread = new Thread (IdleLoop); thread.Start (new IdleState (client, done.Token)); Console.ReadKey (); done.Cancel (); thread.Join (); } if (client.Inbox.Count > messages.Count) { Console.WriteLine ("The new messages that arrived during IDLE are:"); foreach (var message in client.Inbox.Fetch (messages.Count, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId)) Console.WriteLine ("Subject: {0}", message.Envelope.Subject); } client.Disconnect (true); } }
public JsonResult Read(uint emailUid) { JsonResult email = new JsonResult(); var outputMessage = ""; try { userGmailConfig = FetchUserGmailProfile(); using (ImapClient client = new ImapClient()) { client.Connect(userGmailConfig.IncomingServerAddress, userGmailConfig.IncomingServerPort, true); client.Authenticate(new NetworkCredential(userGmailConfig.GmailUsername, userGmailConfig.GmailPassword)); var inbox = client.Inbox; inbox.Open(FolderAccess.ReadOnly); MimeMessage message = inbox.GetMessage(new UniqueId(emailUid)); email.Data = new { FromDisplayName = message.From.FirstOrDefault().Name, FromEmail = message.From.FirstOrDefault().ToString(), To = message.To.FirstOrDefault().ToString(), Subject = message.Subject, Body = message.HtmlBody, message = "Email fetched successfully" }; } } catch (Exception ex) { outputMessage = "There was an error in processing your request. Exception: " + ex.Message; } email.Data = new { message = outputMessage, }; return email; }
public ActionResult Index() { long noOfEmails = 1; UniqueId lastUid = new UniqueId(); List<Email> emails = new List<Email>(); try { userGmailConfig = FetchUserGmailProfile(); using (ImapClient client = new ImapClient()) { client.Connect(userGmailConfig.IncomingServerAddress, userGmailConfig.IncomingServerPort, true); client.Authenticate(new NetworkCredential(userGmailConfig.GmailUsername, userGmailConfig.GmailPassword)); var inbox = client.Inbox; inbox.Open(FolderAccess.ReadOnly); if (inbox.Count > 0) { int index = Math.Max(inbox.Count - 30, 0); var uids = (from c in inbox.Fetch(index, -1, MessageSummaryItems.UniqueId) select c.UniqueId).ToList(); var messages = inbox.Fetch(uids, MessageSummaryItems.Envelope); messages = messages.OrderByDescending(message => message.Envelope.Date.Value.DateTime).ToList(); foreach (var message in messages) { Email tempEmail = new Email() { SerialNo = noOfEmails, Uid = message.UniqueId, FromDisplayName = message.Envelope.From.First().Name, FromEmail = message.Envelope.From.First().ToString(), To = message.Envelope.To.ToString(), Subject = message.NormalizedSubject, TimeReceived = message.Envelope.Date.Value.DateTime, HasAttachment = message.Attachments.Count() > 0 ? true : false }; lastUid = tempEmail.Uid; emails.Add(tempEmail); noOfEmails++; } } } ViewBag.EmailId = userGmailConfig.GmailUsername; } catch (Exception ex) { ViewBag.ErrorMessage = "There was an error in processing your request. Exception: " + ex.Message; } ViewBag.NoOfEmails = 30; ViewBag.PageNumber = 1; return View(emails); }
public JsonResult Delete(string csEmailUids) { JsonResult jsonResult = new JsonResult(); var outputMessage = ""; try { userGmailConfig = FetchUserGmailProfile(); using (ImapClient client = new ImapClient()) { client.Connect(userGmailConfig.IncomingServerAddress, userGmailConfig.IncomingServerPort, true); client.Authenticate(new NetworkCredential(userGmailConfig.GmailUsername, userGmailConfig.GmailPassword)); var inbox = client.Inbox; inbox.Open(FolderAccess.ReadWrite); var uids = new List<UniqueId>(); if (csEmailUids.Contains(',')) { foreach (var item in csEmailUids.Split(',')) { uids.Add(new UniqueId(Convert.ToUInt32(item))); } } else { uids.Add(new UniqueId(Convert.ToUInt32(csEmailUids))); } client.Inbox.AddFlags(uids, MessageFlags.Deleted, true); if (client.Capabilities.HasFlag(ImapCapabilities.UidPlus)) { client.Inbox.Expunge(uids); } else { client.Inbox.Expunge(); } outputMessage = "Email(s) deleted successfully!"; } } catch (Exception ex) { outputMessage = "There was an error in processing your request. Exception: " + ex.Message; } jsonResult.Data = new { message = outputMessage, }; return jsonResult; }
private void CheckImapMail() { try { using (ImapClient imapClient = new ImapClient()) { imapClient.Connect(_configuration.ServerName, _configuration.Port, _configuration.SSL); imapClient.AuthenticationMechanisms.Remove("XOAUTH2"); imapClient.Authenticate(_configuration.UserName, _configuration.Password); IMailFolder inbox = imapClient.Inbox; inbox.Open(FolderAccess.ReadWrite); foreach (UniqueId msgUid in inbox.Search(SearchQuery.NotSeen)) { MimeMessage msg = inbox.GetMessage(msgUid); ProcessMail(msg); inbox.SetFlags(msgUid, MessageFlags.Seen, true); } } } catch (Exception ex) { // Sometimes an error occures, e.g. if the network was disconected or a timeout occured. Logger.Instance.LogException(this, ex); } }
private static IMailFolder AuthenticateAndgetInbox(MailReceiverSettings settings, ImapClient client) { client.Connect(settings.Server, port: settings.Port, useSsl: settings.UseSsl); client.AuthenticationMechanisms.Remove(item: "XOAUTH2"); client.Authenticate(settings.User, settings.Password); IMailFolder inbox = client.Inbox; inbox.Open(FolderAccess.ReadOnly); return inbox; }
public void TestArgumentExceptions () { using (var client = new ImapClient ()) { // Connect Assert.Throws<ArgumentNullException> (() => client.Connect ((Uri) null)); Assert.Throws<ArgumentNullException> (async () => await client.ConnectAsync ((Uri) null)); Assert.Throws<ArgumentNullException> (() => client.Connect (null, 143, false)); Assert.Throws<ArgumentNullException> (async () => await client.ConnectAsync (null, 143, false)); Assert.Throws<ArgumentException> (() => client.Connect (string.Empty, 143, false)); Assert.Throws<ArgumentException> (async () => await client.ConnectAsync (string.Empty, 143, false)); Assert.Throws<ArgumentOutOfRangeException> (() => client.Connect ("host", -1, false)); Assert.Throws<ArgumentOutOfRangeException> (async () => await client.ConnectAsync ("host", -1, false)); Assert.Throws<ArgumentNullException> (() => client.Connect (null, 143, SecureSocketOptions.None)); Assert.Throws<ArgumentNullException> (async () => await client.ConnectAsync (null, 143, SecureSocketOptions.None)); Assert.Throws<ArgumentException> (() => client.Connect (string.Empty, 143, SecureSocketOptions.None)); Assert.Throws<ArgumentException> (async () => await client.ConnectAsync (string.Empty, 143, SecureSocketOptions.None)); Assert.Throws<ArgumentOutOfRangeException> (() => client.Connect ("host", -1, SecureSocketOptions.None)); Assert.Throws<ArgumentOutOfRangeException> (async () => await client.ConnectAsync ("host", -1, SecureSocketOptions.None)); // Authenticate Assert.Throws<ArgumentNullException> (() => client.Authenticate (null)); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync (null)); Assert.Throws<ArgumentNullException> (() => client.Authenticate (null, "password")); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync (null, "password")); Assert.Throws<ArgumentNullException> (() => client.Authenticate ("username", null)); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync ("username", null)); } }
public bool CheckAndSend(string user, string pwd, string imapUri, string smtpUri) { using (var client = new ImapClient()) { var credentials = new NetworkCredential(user, pwd); var uriObj = new Uri(imapUri); using (var cancel = new CancellationTokenSource()) { client.Connect(uriObj, cancel.Token); // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.AuthenticationMechanisms.Remove("XOAUTH"); client.Authenticate(credentials, cancel.Token); // The Inbox folder is always available on all IMAP servers... var draftBox = client.GetFolder(SpecialFolder.Drafts); if (draftBox == null) draftBox = client.GetFolder("Drafts"); draftBox.Open(FolderAccess.ReadWrite, cancel.Token); Console.WriteLine("Total messages: {0}", draftBox.Count); Console.WriteLine("Recent messages: {0}", draftBox.Recent); SearchQuery query = SearchQuery.All; //query = SearchQuery.ToContains("*****@*****.**"); UniqueId[] uids = draftBox.Search(query); int count = 0; for (int i = uids.Length - 1; i >= 0; i--) { UniqueId uid = uids[i]; var message = draftBox.GetMessage(uid, cancel.Token); DateTimeOffset dto1 = DateTimeOffset.UtcNow; if (dto1.AddHours(-12) >= message.Date) break; Console.WriteLine("Subject: {0}", message.Subject); Console.WriteLine("Date: {0}", message.Date); if (message.Bcc.Count > 0) { foreach (InternetAddress addr in message.Bcc) { string addrString = addr.Name; if (string.IsNullOrEmpty(addrString)) { addrString = addr.ToString(); if (addrString.Contains("<")) addrString = addrString.Substring(addrString.LastIndexOf("<") + 1, addrString.LastIndexOf(">") - addrString.LastIndexOf("<") -1); } //if (addr.Name.Contains("send@")) if (addrString.Contains("send@")) { //string time = addr.Name.Replace("send@", ""); string time = addrString.Replace("send@", ""); Console.WriteLine("Scheduled mail is found. Scheduled time: {0}", time); count++; string[] parts = time.Split(new char[] { '.' }); if (parts.Length != 2) continue; int hour = 0; int minute = 0; DateTimeOffset dt2 = message.Date; DateTimeOffset offset2; if (int.TryParse(parts[0], out hour)) { if (int.TryParse(parts[1], out minute)) { dt2 = dt2.AddHours(hour - dt2.Hour); dt2 = dt2.AddMinutes(minute - dt2.Minute); dt2 = dt2.AddSeconds(0 - dt2.Second); if (dt2 <= DateTimeOffset.UtcNow && dt2 >= DateTimeOffset.UtcNow.AddHours(-1)) { message.Bcc.Remove(addr); this.Send(message, user, pwd, smtpUri); for (int retry = 1, maxRetry = 10; retry <= maxRetry; i++) { Thread.Sleep(20 * 1000); try { Console.WriteLine("{0} in {1} trys to delete draft", retry, maxRetry); draftBox.SetFlags(new UniqueId[] { uid }, MessageFlags.Deleted, true); draftBox.Expunge(); } catch (IOException e) { retry++; continue; } break; } Console.WriteLine("Scheduled mail is sent. Subject: {0}", message.Subject); break; } else Console.WriteLine("Scheduled time is not satisfied. Mail is not sent. Subject: {0}", message.Subject); } } } } } } Console.WriteLine("Total count for scheduled mails: {0}", count); client.Disconnect(true, cancel.Token); } } return false; }
public RC getMessages(bool bUsePop3 = false, int iPortToUse = 0) { try { if (bUsePop3) { using (var client = new Pop3Client ()) { if (iPortToUse == 0) { client.Connect (m_EmailServiceDescription.Pop3Url, 110, true); } else { client.Connect (m_EmailServiceDescription.Pop3Url, iPortToUse, true); } // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.AuthenticationMechanisms.Remove ("XOAUTH2"); client.Authenticate (m_AuthInfo.m_sId, m_AuthInfo.m_sPassword); for (int i = 0; i < client.Count; i++) { var message = client.GetMessage (i); string sPlainBody = m_OpenPgpCrypter.DecryptPgpString(message.GetTextBody(MimeKit.Text.TextFormat.Text)); m_ConversationManager.addMessage (m_sProtocol, message.Subject + " " + sPlainBody, message.Sender.Address, m_AuthInfo.m_sId); } client.Disconnect(true); return RC.RC_OK; } } else //use IMAP { using (var client = new ImapClient ()) { if (iPortToUse == 0) { client.Connect (m_EmailServiceDescription.ImapUrl, 993, true); } else { client.Connect (m_EmailServiceDescription.ImapUrl, iPortToUse, true); } // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.AuthenticationMechanisms.Remove ("XOAUTH2"); client.Authenticate (m_AuthInfo.m_sId, m_AuthInfo.m_sPassword); // The Inbox folder is always available on all IMAP servers... var inbox = client.Inbox; inbox.Open (FolderAccess.ReadOnly); //TODO: delete writeline Console.WriteLine ("Total messages: {0}", inbox.Count); Console.WriteLine ("Recent messages: {0}", inbox.Recent); for (int i = 0; i < inbox.Count; i++) { var message = inbox.GetMessage (i); m_ConversationManager.addMessage (m_sProtocol, message.Subject + message.Body, message.Sender.Address, m_AuthInfo.m_sId); } client.Disconnect (true); return RC.RC_OK; } } } catch(Exception e) { m_Logger.log (ELogLevel.LVL_WARNING, e.Message, m_sModuleName); return RC.RC_INBOX_NOT_AVAILABLE; } }
public static void Main (string[] args) { using (var client = new ImapClient (new ProtocolLogger (Console.OpenStandardError ()))) { client.Connect ("imap.gmail.com", 993, true); // Remove the XOAUTH2 authentication mechanism since we don't have an OAuth2 token. client.AuthenticationMechanisms.Remove ("XOAUTH2"); client.Authenticate ("*****@*****.**", "password"); client.Inbox.Open (FolderAccess.ReadOnly); // Get the summary information of all of the messages (suitable for displaying in a message list). var messages = client.Inbox.Fetch (0, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId).ToList (); // Keep track of messages being expunged so that when the CountChanged event fires, we can tell if it's // because new messages have arrived vs messages being removed (or some combination of the two). client.Inbox.MessageExpunged += (sender, e) => { var folder = (ImapFolder) sender; if (e.Index < messages.Count) { var message = messages[e.Index]; Console.WriteLine ("{0}: expunged message {1}: Subject: {2}", folder, e.Index, message.Envelope.Subject); // Note: If you are keeping a local cache of message information // (e.g. MessageSummary data) for the folder, then you'll need // to remove the message at e.Index. messages.RemoveAt (e.Index); } else { Console.WriteLine ("{0}: expunged message {1}: Unknown message.", folder, e.Index); } }; // Keep track of changes to the number of messages in the folder (this is how we'll tell if new messages have arrived). client.Inbox.CountChanged += (sender, e) => { // Note: the CountChanged event will fire when new messages arrive in the folder and/or when messages are expunged. var folder = (ImapFolder) sender; Console.WriteLine ("The number of messages in {0} has changed.", folder); // Note: because we are keeping track of the MessageExpunged event and updating our // 'messages' list, we know that if we get a CountChanged event and folder.Count is // larger than messages.Count, then it means that new messages have arrived. if (folder.Count > messages.Count) { Console.WriteLine ("{0} new messages have arrived.", folder.Count - messages.Count); // Note: your first instict may be to fetch these new messages now, but you cannot do // that in this event handler (the ImapFolder is not re-entrant). // // If this code had access to the 'done' CancellationTokenSource (see below), it could // cancel that to cause the IDLE loop to end. } }; // Keep track of flag changes. client.Inbox.MessageFlagsChanged += (sender, e) => { var folder = (ImapFolder) sender; Console.WriteLine ("{0}: flags for message {1} have changed to: {2}.", folder, e.Index, e.Flags); }; Console.WriteLine ("Hit any key to end the IDLE loop."); using (var done = new CancellationTokenSource ()) { // Note: when the 'done' CancellationTokenSource is cancelled, it ends to IDLE loop. var thread = new Thread (IdleLoop); thread.Start (new IdleState (client, done.Token)); Console.ReadKey (); done.Cancel (); thread.Join (); } if (client.Inbox.Count > messages.Count) { Console.WriteLine ("The new messages that arrived during IDLE are:"); foreach (var message in client.Inbox.Fetch (messages.Count, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId)) Console.WriteLine ("Subject: {0}", message.Envelope.Subject); } client.Disconnect (true); } }
private List<string> checkMail() { var users = settings.accountsDict.Keys.ToArray(); var clientkeys = clients.Keys; var intersect = users.Intersect(clientkeys); List<string> mails = new List<string>(users.Count()); foreach (var item in clientkeys) { if (!intersect.Contains(item)) { ImapClient c = clients[item]; c.Disconnect(true, token); c.Dispose(); clients.Remove(item); } if (token.IsCancellationRequested) { break; } } if (token.IsCancellationRequested) { return null; } foreach (var user in users) { if (!clients.ContainsKey(user)) { //create client ImapClient c = new ImapClient(); if (settings.accountsDict[user] != null) { var credentials = new NetworkCredential(user, settings.accountsDict[user].Token.AccessToken); var uri = new Uri("imaps://imap.gmail.com"); c.Connect(uri, token); c.Authenticate(credentials, token); c.Inbox.Open(FolderAccess.ReadOnly, token); clients[user] = c; } else { logging.TraceEvent(TraceEventType.Error, 1, "User credentials is null for: " + user); } } if (token.IsCancellationRequested) { break; } if (clients.ContainsKey(user)) { ImapClient client = clients[user]; int unread; try { unread = client.Inbox.Search(SearchQuery.NotSeen, token).Length; } catch (ImapProtocolException) { logging.TraceEvent(TraceEventType.Error, 1, "IMAP not enabled for: " + user); continue; } //inbox.Open(FolderAccess.ReadOnly, token); if (unread != 0) { mails.Add(user + "(" + unread + ")"); } } else { logging.TraceEvent(TraceEventType.Error, 1, "No client for user: " + user); } if (token.IsCancellationRequested) { break; } } if (mails.Count == 0) return null; else return mails; }
public void TestArgumentExceptions () { var commands = new List<ImapReplayCommand> (); commands.Add (new ImapReplayCommand ("", "dovecot.greeting.txt")); commands.Add (new ImapReplayCommand ("A00000000 LOGIN username password\r\n", "dovecot.authenticate.txt")); commands.Add (new ImapReplayCommand ("A00000001 NAMESPACE\r\n", "dovecot.namespace.txt")); commands.Add (new ImapReplayCommand ("A00000002 LIST \"\" \"INBOX\"\r\n", "dovecot.list-inbox.txt")); commands.Add (new ImapReplayCommand ("A00000003 LIST (SPECIAL-USE) \"\" \"*\"\r\n", "dovecot.list-special-use.txt")); commands.Add (new ImapReplayCommand ("A00000004 SELECT INBOX (CONDSTORE)\r\n", "common.select-inbox.txt")); using (var client = new ImapClient ()) { var credentials = new NetworkCredential ("username", "password"); // Connect Assert.Throws<ArgumentNullException> (() => client.Connect ((Uri) null)); Assert.Throws<ArgumentNullException> (async () => await client.ConnectAsync ((Uri) null)); Assert.Throws<ArgumentNullException> (() => client.Connect (null, 143, false)); Assert.Throws<ArgumentNullException> (async () => await client.ConnectAsync (null, 143, false)); Assert.Throws<ArgumentException> (() => client.Connect (string.Empty, 143, false)); Assert.Throws<ArgumentException> (async () => await client.ConnectAsync (string.Empty, 143, false)); Assert.Throws<ArgumentOutOfRangeException> (() => client.Connect ("host", -1, false)); Assert.Throws<ArgumentOutOfRangeException> (async () => await client.ConnectAsync ("host", -1, false)); Assert.Throws<ArgumentNullException> (() => client.Connect (null, 143, SecureSocketOptions.None)); Assert.Throws<ArgumentNullException> (async () => await client.ConnectAsync (null, 143, SecureSocketOptions.None)); Assert.Throws<ArgumentException> (() => client.Connect (string.Empty, 143, SecureSocketOptions.None)); Assert.Throws<ArgumentException> (async () => await client.ConnectAsync (string.Empty, 143, SecureSocketOptions.None)); Assert.Throws<ArgumentOutOfRangeException> (() => client.Connect ("host", -1, SecureSocketOptions.None)); Assert.Throws<ArgumentOutOfRangeException> (async () => await client.ConnectAsync ("host", -1, SecureSocketOptions.None)); try { client.ReplayConnect ("localhost", new ImapReplayStream (commands, false)); } catch (Exception ex) { Assert.Fail ("Did not expect an exception in Connect: {0}", ex); } // Authenticate Assert.Throws<ArgumentNullException> (() => client.Authenticate (null)); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync (null)); Assert.Throws<ArgumentNullException> (() => client.Authenticate (null, "password")); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync (null, "password")); Assert.Throws<ArgumentNullException> (() => client.Authenticate ("username", null)); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync ("username", null)); Assert.Throws<ArgumentNullException> (() => client.Authenticate (null, credentials)); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync (null, credentials)); Assert.Throws<ArgumentNullException> (() => client.Authenticate (Encoding.UTF8, null)); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync (Encoding.UTF8, null)); Assert.Throws<ArgumentNullException> (() => client.Authenticate (null, "username", "password")); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync (null, "username", "password")); Assert.Throws<ArgumentNullException> (() => client.Authenticate (Encoding.UTF8, null, "password")); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync (Encoding.UTF8, null, "password")); Assert.Throws<ArgumentNullException> (() => client.Authenticate (Encoding.UTF8, "username", null)); Assert.Throws<ArgumentNullException> (async () => await client.AuthenticateAsync (Encoding.UTF8, "username", null)); // Note: we do not want to use SASL at all... client.AuthenticationMechanisms.Clear (); try { client.Authenticate (credentials); } catch (Exception ex) { Assert.Fail ("Did not expect an exception in Authenticate: {0}", ex); } Assert.Throws<ArgumentNullException> (() => client.GetFolder ((string) null)); Assert.Throws<ArgumentNullException> (() => client.GetFolder ((FolderNamespace) null)); Assert.Throws<ArgumentNullException> (() => client.GetFolders (null)); Assert.Throws<ArgumentNullException> (() => client.GetFolders (null, false)); Assert.Throws<ArgumentNullException> (async () => await client.GetFoldersAsync (null)); Assert.Throws<ArgumentNullException> (async () => await client.GetFoldersAsync (null, false)); var personal = client.GetFolder (client.PersonalNamespaces[0]); var dates = new List<DateTimeOffset> (); var messages = new List<MimeMessage> (); var flags = new List<MessageFlags> (); var now = DateTimeOffset.Now; messages.Add (CreateThreadableMessage ("A", "<*****@*****.**>", null, now.AddMinutes (-7))); messages.Add (CreateThreadableMessage ("B", "<*****@*****.**>", "<*****@*****.**>", now.AddMinutes (-6))); messages.Add (CreateThreadableMessage ("C", "<*****@*****.**>", "<*****@*****.**> <*****@*****.**>", now.AddMinutes (-5))); messages.Add (CreateThreadableMessage ("D", "<*****@*****.**>", "<*****@*****.**>", now.AddMinutes (-4))); messages.Add (CreateThreadableMessage ("E", "<*****@*****.**>", "<*****@*****.**> <*****@*****.**> <*****@*****.**> <*****@*****.**>", now.AddMinutes (-3))); messages.Add (CreateThreadableMessage ("F", "<*****@*****.**>", "<*****@*****.**>", now.AddMinutes (-2))); messages.Add (CreateThreadableMessage ("G", "<*****@*****.**>", null, now.AddMinutes (-1))); messages.Add (CreateThreadableMessage ("H", "<*****@*****.**>", null, now)); for (int i = 0; i < messages.Count; i++) { dates.Add (DateTimeOffset.Now); flags.Add (MessageFlags.Seen); } var inbox = (ImapFolder) client.Inbox; inbox.Open (FolderAccess.ReadWrite); // ImapFolder .ctor Assert.Throws<ArgumentNullException> (() => new ImapFolder (null)); // Open Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Open ((FolderAccess) 500)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Open ((FolderAccess) 500, 0, 0, UniqueIdRange.All)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.OpenAsync ((FolderAccess) 500)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.OpenAsync ((FolderAccess) 500, 0, 0, UniqueIdRange.All)); // Create Assert.Throws<ArgumentNullException> (() => inbox.Create (null, true)); Assert.Throws<ArgumentException> (() => inbox.Create (string.Empty, true)); Assert.Throws<ArgumentException> (() => inbox.Create ("Folder./Name", true)); Assert.Throws<ArgumentNullException> (() => inbox.Create (null, SpecialFolder.All)); Assert.Throws<ArgumentException> (() => inbox.Create (string.Empty, SpecialFolder.All)); Assert.Throws<ArgumentException> (() => inbox.Create ("Folder./Name", SpecialFolder.All)); Assert.Throws<ArgumentNullException> (() => inbox.Create (null, new SpecialFolder[] { SpecialFolder.All })); Assert.Throws<ArgumentException> (() => inbox.Create (string.Empty, new SpecialFolder[] { SpecialFolder.All })); Assert.Throws<ArgumentException> (() => inbox.Create ("Folder./Name", new SpecialFolder[] { SpecialFolder.All })); Assert.Throws<ArgumentNullException> (() => inbox.Create ("ValidName", null)); Assert.Throws<NotSupportedException> (() => inbox.Create ("ValidName", SpecialFolder.All)); Assert.Throws<ArgumentNullException> (async () => await inbox.CreateAsync (null, true)); Assert.Throws<ArgumentException> (async () => await inbox.CreateAsync (string.Empty, true)); Assert.Throws<ArgumentException> (async () => await inbox.CreateAsync ("Folder./Name", true)); Assert.Throws<ArgumentNullException> (async () => await inbox.CreateAsync (null, SpecialFolder.All)); Assert.Throws<ArgumentException> (async () => await inbox.CreateAsync (string.Empty, SpecialFolder.All)); Assert.Throws<ArgumentException> (async () => await inbox.CreateAsync ("Folder./Name", SpecialFolder.All)); Assert.Throws<ArgumentNullException> (async () => await inbox.CreateAsync (null, new SpecialFolder[] { SpecialFolder.All })); Assert.Throws<ArgumentException> (async () => await inbox.CreateAsync (string.Empty, new SpecialFolder[] { SpecialFolder.All })); Assert.Throws<ArgumentException> (async () => await inbox.CreateAsync ("Folder./Name", new SpecialFolder[] { SpecialFolder.All })); Assert.Throws<ArgumentNullException> (async () => await inbox.CreateAsync ("ValidName", null)); Assert.Throws<NotSupportedException> (async () => await inbox.CreateAsync ("ValidName", SpecialFolder.All)); // Rename Assert.Throws<ArgumentNullException> (() => inbox.Rename (null, "NewName")); Assert.Throws<ArgumentNullException> (() => inbox.Rename (personal, null)); Assert.Throws<ArgumentException> (() => inbox.Rename (personal, string.Empty)); Assert.Throws<ArgumentNullException> (async () => await inbox.RenameAsync (null, "NewName")); Assert.Throws<ArgumentNullException> (async () => await inbox.RenameAsync (personal, null)); Assert.Throws<ArgumentException> (async () => await inbox.RenameAsync (personal, string.Empty)); // GetSubfolder Assert.Throws<ArgumentNullException> (() => inbox.GetSubfolder (null)); Assert.Throws<ArgumentException> (() => inbox.GetSubfolder (string.Empty)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetSubfolderAsync (null)); Assert.Throws<ArgumentException> (async () => await inbox.GetSubfolderAsync (string.Empty)); // GetMetadata Assert.Throws<ArgumentNullException> (() => client.GetMetadata (null, new MetadataTag[] { MetadataTag.PrivateComment })); Assert.Throws<ArgumentNullException> (() => client.GetMetadata (new MetadataOptions (), null)); Assert.Throws<ArgumentNullException> (async () => await client.GetMetadataAsync (null, new MetadataTag[] { MetadataTag.PrivateComment })); Assert.Throws<ArgumentNullException> (async () => await client.GetMetadataAsync (new MetadataOptions (), null)); Assert.Throws<ArgumentNullException> (() => inbox.GetMetadata (null, new MetadataTag[] { MetadataTag.PrivateComment })); Assert.Throws<ArgumentNullException> (() => inbox.GetMetadata (new MetadataOptions (), null)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetMetadataAsync (null, new MetadataTag[] { MetadataTag.PrivateComment })); Assert.Throws<ArgumentNullException> (async () => await inbox.GetMetadataAsync (new MetadataOptions (), null)); // SetMetadata Assert.Throws<ArgumentNullException> (() => client.SetMetadata (null)); Assert.Throws<ArgumentNullException> (async () => await client.SetMetadataAsync (null)); Assert.Throws<ArgumentNullException> (() => inbox.SetMetadata (null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetMetadataAsync (null)); // Expunge Assert.Throws<ArgumentNullException> (() => inbox.Expunge (null)); Assert.Throws<ArgumentNullException> (async () => await inbox.ExpungeAsync (null)); // Append Assert.Throws<ArgumentNullException> (() => inbox.Append (null)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (null)); Assert.Throws<ArgumentNullException> (() => inbox.Append (null, messages[0])); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (null, messages[0])); Assert.Throws<ArgumentNullException> (() => inbox.Append (FormatOptions.Default, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (FormatOptions.Default, null)); Assert.Throws<ArgumentNullException> (() => inbox.Append (null, MessageFlags.None, DateTimeOffset.Now)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (null, MessageFlags.None, DateTimeOffset.Now)); Assert.Throws<ArgumentNullException> (() => inbox.Append (null, messages[0], MessageFlags.None, DateTimeOffset.Now)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (null, messages[0], MessageFlags.None, DateTimeOffset.Now)); Assert.Throws<ArgumentNullException> (() => inbox.Append (FormatOptions.Default, null, MessageFlags.None, DateTimeOffset.Now)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (FormatOptions.Default, null, MessageFlags.None, DateTimeOffset.Now)); // MultiAppend Assert.Throws<ArgumentNullException> (() => inbox.Append (null, flags)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (null, flags)); Assert.Throws<ArgumentNullException> (() => inbox.Append (messages, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (messages, null)); Assert.Throws<ArgumentNullException> (() => inbox.Append (null, messages, flags)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (null, messages, flags)); Assert.Throws<ArgumentNullException> (() => inbox.Append (FormatOptions.Default, null, flags)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (FormatOptions.Default, null, flags)); Assert.Throws<ArgumentNullException> (() => inbox.Append (FormatOptions.Default, messages, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (FormatOptions.Default, messages, null)); Assert.Throws<ArgumentNullException> (() => inbox.Append (null, flags, dates)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (null, flags, dates)); Assert.Throws<ArgumentNullException> (() => inbox.Append (messages, null, dates)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (messages, null, dates)); Assert.Throws<ArgumentNullException> (() => inbox.Append (messages, flags, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (messages, flags, null)); Assert.Throws<ArgumentNullException> (() => inbox.Append (null, messages, flags, dates)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (null, messages, flags, dates)); Assert.Throws<ArgumentNullException> (() => inbox.Append (FormatOptions.Default, null, flags, dates)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (FormatOptions.Default, null, flags, dates)); Assert.Throws<ArgumentNullException> (() => inbox.Append (FormatOptions.Default, messages, null, dates)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (FormatOptions.Default, messages, null, dates)); Assert.Throws<ArgumentNullException> (() => inbox.Append (FormatOptions.Default, messages, flags, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.AppendAsync (FormatOptions.Default, messages, flags, null)); // CopyTo Assert.Throws<ArgumentNullException> (() => inbox.CopyTo ((IList<UniqueId>) null, inbox)); Assert.Throws<ArgumentNullException> (async () => await inbox.CopyToAsync ((IList<UniqueId>) null, inbox)); Assert.Throws<ArgumentNullException> (() => inbox.CopyTo (UniqueIdRange.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.CopyToAsync (UniqueIdRange.All, null)); Assert.Throws<ArgumentNullException> (() => inbox.CopyTo ((IList<int>) null, inbox)); Assert.Throws<ArgumentNullException> (async () => await inbox.CopyToAsync ((IList<int>) null, inbox)); Assert.Throws<ArgumentNullException> (() => inbox.CopyTo (new int[] { 0 }, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.CopyToAsync (new int[] { 0 }, null)); // MoveTo Assert.Throws<ArgumentNullException> (() => inbox.MoveTo ((IList<UniqueId>) null, inbox)); Assert.Throws<ArgumentNullException> (async () => await inbox.MoveToAsync ((IList<UniqueId>) null, inbox)); Assert.Throws<ArgumentNullException> (() => inbox.MoveTo (UniqueIdRange.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.MoveToAsync (UniqueIdRange.All, null)); Assert.Throws<ArgumentNullException> (() => inbox.MoveTo ((IList<int>) null, inbox)); Assert.Throws<ArgumentNullException> (async () => await inbox.MoveToAsync ((IList<int>) null, inbox)); Assert.Throws<ArgumentNullException> (() => inbox.MoveTo (new int[] { 0 }, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.MoveToAsync (new int[] { 0 }, null)); // Fetch var headers = new HashSet<HeaderId> (new HeaderId[] { HeaderId.Subject }); var fields = new HashSet<string> (new string[] { "SUBJECT" }); var uids = new UniqueId[] { UniqueId.MinValue }; var emptyHeaders = new HashSet<HeaderId> (); var emptyFields = new HashSet<string> (); var indexes = new int[] { 0 }; Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (-1, -1, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (-1, -1, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (5, 1, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (5, 1, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (0, 5, MessageSummaryItems.None)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (0, 5, MessageSummaryItems.None)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<UniqueId>) null, MessageSummaryItems.All)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<UniqueId>) null, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (uids, MessageSummaryItems.None)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (uids, MessageSummaryItems.None)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<int>) null, MessageSummaryItems.All)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<int>) null, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (indexes, MessageSummaryItems.None)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (indexes, MessageSummaryItems.None)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (-1, -1, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (-1, -1, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (5, 1, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (5, 1, MessageSummaryItems.All, headers)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (0, 5, MessageSummaryItems.None, headers)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (0, 5, MessageSummaryItems.None, headers)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (0, 5, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (0, 5, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (0, 5, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (0, 5, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<UniqueId>) null, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<UniqueId>) null, MessageSummaryItems.All, headers)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (uids, MessageSummaryItems.None, headers)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (uids, MessageSummaryItems.None, headers)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (uids, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (uids, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (uids, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (uids, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<int>) null, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<int>) null, MessageSummaryItems.All, headers)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (indexes, MessageSummaryItems.None, headers)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (indexes, MessageSummaryItems.None, headers)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (indexes, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (indexes, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (indexes, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (indexes, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (-1, -1, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (-1, -1, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (5, 1, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (5, 1, MessageSummaryItems.All, fields)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (0, 5, MessageSummaryItems.None, fields)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (0, 5, MessageSummaryItems.None, fields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (0, 5, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (0, 5, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (0, 5, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (0, 5, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<UniqueId>) null, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<UniqueId>) null, MessageSummaryItems.All, fields)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (uids, MessageSummaryItems.None, fields)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (uids, MessageSummaryItems.None, fields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (uids, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (uids, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (uids, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (uids, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<int>) null, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<int>) null, MessageSummaryItems.All, fields)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (indexes, MessageSummaryItems.None, fields)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (indexes, MessageSummaryItems.None, fields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (indexes, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (indexes, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (indexes, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (indexes, MessageSummaryItems.All, emptyFields)); // Fetch + modseq Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (-1, -1, 31337, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (-1, -1, 31337, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (5, 1, 31337, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (5, 1, 31337, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (0, 5, 31337, MessageSummaryItems.None)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (0, 5, 31337, MessageSummaryItems.None)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<UniqueId>) null, 31337, MessageSummaryItems.All)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<UniqueId>) null, 31337, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (uids, 31337, MessageSummaryItems.None)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (uids, 31337, MessageSummaryItems.None)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<int>) null, 31337, MessageSummaryItems.All)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<int>) null, 31337, MessageSummaryItems.All)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (indexes, 31337, MessageSummaryItems.None)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (indexes, 31337, MessageSummaryItems.None)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (-1, -1, 31337, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (-1, -1, 31337, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (5, 1, 31337, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (5, 1, MessageSummaryItems.All, headers)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (0, 5, 31337, MessageSummaryItems.None, headers)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (0, 5, 31337, MessageSummaryItems.None, headers)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (0, 5, 31337, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (0, 5, 31337, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (0, 5, 31337, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (0, 5, 31337, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<UniqueId>) null, 31337, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<UniqueId>) null, 31337, MessageSummaryItems.All, headers)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (uids, 31337, MessageSummaryItems.None, headers)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (uids, 31337, MessageSummaryItems.None, headers)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (uids, 31337, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (uids, 31337, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (uids, 31337, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (uids, 31337, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<int>) null, 31337, MessageSummaryItems.All, headers)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<int>) null, 31337, MessageSummaryItems.All, headers)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (indexes, 31337, MessageSummaryItems.None, headers)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (indexes, 31337, MessageSummaryItems.None, headers)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (indexes, 31337, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (indexes, 31337, MessageSummaryItems.All, (HashSet<HeaderId>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (indexes, 31337, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (indexes, 31337, MessageSummaryItems.All, emptyHeaders)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (-1, -1, 31337, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (-1, -1, 31337, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (5, 1, 31337, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (5, 1, 31337, MessageSummaryItems.All, fields)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (0, 5, 31337, MessageSummaryItems.None, fields)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (0, 5, 31337, MessageSummaryItems.None, fields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (0, 5, 31337, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (0, 5, 31337, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (0, 5, 31337, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (0, 5, 31337, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<UniqueId>) null, 31337, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<UniqueId>) null, 31337, MessageSummaryItems.All, fields)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (uids, 31337, MessageSummaryItems.None, fields)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (uids, 31337, MessageSummaryItems.None, fields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (uids, 31337, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (uids, 31337, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (uids, 31337, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (uids, 31337, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch ((IList<int>) null, 31337, MessageSummaryItems.All, fields)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync ((IList<int>) null, 31337, MessageSummaryItems.All, fields)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Fetch (indexes, 31337, MessageSummaryItems.None, fields)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.FetchAsync (indexes, 31337, MessageSummaryItems.None, fields)); Assert.Throws<ArgumentNullException> (() => inbox.Fetch (indexes, 31337, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.FetchAsync (indexes, 31337, MessageSummaryItems.All, (HashSet<string>) null)); Assert.Throws<ArgumentException> (() => inbox.Fetch (indexes, 31337, MessageSummaryItems.All, emptyFields)); Assert.Throws<ArgumentException> (async () => await inbox.FetchAsync (indexes, 31337, MessageSummaryItems.All, emptyFields)); // GetMessage Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetMessage (-1)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetMessageAsync (-1)); Assert.Throws<ArgumentException> (() => inbox.GetMessage (UniqueId.Invalid)); Assert.Throws<ArgumentException> (async () => await inbox.GetMessageAsync (UniqueId.Invalid)); // GetBodyPart var bodyPart = new BodyPartText (); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetBodyPart (-1, bodyPart)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetBodyPartAsync (-1, bodyPart)); Assert.Throws<ArgumentNullException> (() => inbox.GetBodyPart (0, (BodyPart) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetBodyPartAsync (0, (BodyPart) null)); Assert.Throws<ArgumentException> (() => inbox.GetBodyPart (UniqueId.Invalid, bodyPart)); Assert.Throws<ArgumentException> (async () => await inbox.GetBodyPartAsync (UniqueId.Invalid, bodyPart)); Assert.Throws<ArgumentNullException> (() => inbox.GetBodyPart (UniqueId.MinValue, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetBodyPartAsync (UniqueId.MinValue, null)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetBodyPart (-1, "1.2")); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetBodyPartAsync (-1, "1.2")); Assert.Throws<ArgumentNullException> (() => inbox.GetBodyPart (0, (string) null)); //Assert.Throws<ArgumentNullException> (async () => await inbox.GetBodyPartAsync (0, (string) null)); Assert.Throws<ArgumentException> (() => inbox.GetBodyPart (UniqueId.Invalid, "1.2")); //Assert.Throws<ArgumentException> (async () => await inbox.GetBodyPartAsync (UniqueId.Invalid, "1.2")); Assert.Throws<ArgumentNullException> (() => inbox.GetBodyPart (UniqueId.MinValue, (string) null)); //Assert.Throws<ArgumentNullException> (async () => await inbox.GetBodyPartAsync (UniqueId.MinValue, (string) null)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetBodyPart (-1, bodyPart, true)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetBodyPartAsync (-1, bodyPart, true)); Assert.Throws<ArgumentNullException> (() => inbox.GetBodyPart (0, (BodyPart) null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetBodyPartAsync (0, (BodyPart) null, true)); Assert.Throws<ArgumentException> (() => inbox.GetBodyPart (UniqueId.Invalid, bodyPart, true)); Assert.Throws<ArgumentException> (async () => await inbox.GetBodyPartAsync (UniqueId.Invalid, bodyPart, true)); Assert.Throws<ArgumentNullException> (() => inbox.GetBodyPart (UniqueId.MinValue, (BodyPart) null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetBodyPartAsync (UniqueId.MinValue, (BodyPart) null, true)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetBodyPart (-1, "1.2", true)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetBodyPartAsync (-1, "1.2", true)); Assert.Throws<ArgumentNullException> (() => inbox.GetBodyPart (0, (string) null, true)); //Assert.Throws<ArgumentNullException> (async () => await inbox.GetBodyPartAsync (0, (string) null, true)); Assert.Throws<ArgumentException> (() => inbox.GetBodyPart (UniqueId.Invalid, "1.2", true)); //Assert.Throws<ArgumentException> (async () => await inbox.GetBodyPartAsync (UniqueId.Invalid, "1.2", true)); Assert.Throws<ArgumentNullException> (() => inbox.GetBodyPart (UniqueId.MinValue, (string) null, true)); //Assert.Throws<ArgumentNullException> (async () => await inbox.GetBodyPartAsync (UniqueId.MinValue, (string) null, true)); // GetStream Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (-1, "1.2")); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (-1, "1.2")); Assert.Throws<ArgumentNullException> (() => inbox.GetStream (0, (string) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetStreamAsync (0, (string) null)); Assert.Throws<ArgumentException> (() => inbox.GetStream (UniqueId.Invalid, "1.2")); Assert.Throws<ArgumentException> (async () => await inbox.GetStreamAsync (UniqueId.Invalid, "1.2")); Assert.Throws<ArgumentNullException> (() => inbox.GetStream (UniqueId.MinValue, (string) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, (string) null)); //Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (-1, bodyPart)); //Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (-1, bodyPart)); //Assert.Throws<ArgumentNullException> (() => inbox.GetStream (0, (BodyPart) null)); //Assert.Throws<ArgumentNullException> (async () => await inbox.GetStreamAsync (0, (BodyPart) null)); //Assert.Throws<ArgumentException> (() => inbox.GetStream (UniqueId.Invalid, bodyPart)); //Assert.Throws<ArgumentException> (async () => await inbox.GetStreamAsync (UniqueId.Invalid, bodyPart)); //Assert.Throws<ArgumentNullException> (() => inbox.GetStream (UniqueId.MinValue, (BodyPart) null)); //Assert.Throws<ArgumentNullException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, (BodyPart) null)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (-1, 0, 1024)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (-1, 0, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (0, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (0, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (0, 0, -1)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (0, 0, -1)); Assert.Throws<ArgumentException> (() => inbox.GetStream (UniqueId.Invalid, 0, 1024)); Assert.Throws<ArgumentException> (async () => await inbox.GetStreamAsync (UniqueId.Invalid, 0, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (UniqueId.MinValue, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (UniqueId.MinValue, 0, -1)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, 0, -1)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (-1, "1.2", 0, 1024)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (-1, "1.2", 0, 1024)); Assert.Throws<ArgumentNullException> (() => inbox.GetStream (0, (string) null, 0, 1024)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetStreamAsync (0, (string) null, 0, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (0, "1.2", -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (0, "1.2", -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (0, "1.2", 0, -1)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (0, "1.2", 0, -1)); Assert.Throws<ArgumentException> (() => inbox.GetStream (UniqueId.Invalid, "1.2", 0, 1024)); Assert.Throws<ArgumentException> (async () => await inbox.GetStreamAsync (UniqueId.Invalid, "1.2", 0, 1024)); Assert.Throws<ArgumentNullException> (() => inbox.GetStream (UniqueId.MinValue, (string) null, 0, 1024)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, (string) null, 0, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (UniqueId.MinValue, "1.2", -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, "1.2", -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (UniqueId.MinValue, "1.2", 0, -1)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, "1.2", 0, -1)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (-1, bodyPart, 0, 1024)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (-1, bodyPart, 0, 1024)); Assert.Throws<ArgumentNullException> (() => inbox.GetStream (0, (BodyPart) null, -1, 1024)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetStreamAsync (0, (BodyPart) null, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (0, bodyPart, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (0, bodyPart, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (0, bodyPart, 0, -1)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (0, bodyPart, 0, -1)); Assert.Throws<ArgumentException> (() => inbox.GetStream (UniqueId.Invalid, bodyPart, 0, 1024)); Assert.Throws<ArgumentException> (async () => await inbox.GetStreamAsync (UniqueId.Invalid, bodyPart, 0, 1024)); Assert.Throws<ArgumentNullException> (() => inbox.GetStream (UniqueId.MinValue, (BodyPart) null, -1, 1024)); Assert.Throws<ArgumentNullException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, (BodyPart) null, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (UniqueId.MinValue, bodyPart, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, bodyPart, -1, 1024)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.GetStream (UniqueId.MinValue, bodyPart, 0, -1)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.GetStreamAsync (UniqueId.MinValue, bodyPart, 0, -1)); // AddFlags Assert.Throws<ArgumentException> (() => inbox.AddFlags (-1, MessageFlags.Seen, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddFlagsAsync (-1, MessageFlags.Seen, true)); Assert.Throws<ArgumentException> (() => inbox.AddFlags (0, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddFlagsAsync (0, MessageFlags.None, true)); Assert.Throws<ArgumentException> (() => inbox.AddFlags (UniqueId.MinValue, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddFlagsAsync (UniqueId.MinValue, MessageFlags.None, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddFlags ((IList<int>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddFlagsAsync ((IList<int>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddFlags ((IList<UniqueId>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddFlagsAsync ((IList<UniqueId>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentException> (() => inbox.AddFlags (new int[] { 0 }, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddFlagsAsync (new int[] { 0 }, MessageFlags.None, true)); Assert.Throws<ArgumentException> (() => inbox.AddFlags (UniqueIdRange.All, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddFlagsAsync (UniqueIdRange.All, MessageFlags.None, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddFlags ((IList<int>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddFlagsAsync ((IList<int>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddFlags ((IList<UniqueId>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddFlagsAsync ((IList<UniqueId>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentException> (() => inbox.AddFlags (new int[] { 0 }, 1, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddFlagsAsync (new int[] { 0 }, 1, MessageFlags.None, true)); Assert.Throws<ArgumentException> (() => inbox.AddFlags (UniqueIdRange.All, 1, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddFlagsAsync (UniqueIdRange.All, 1, MessageFlags.None, true)); // RemoveFlags Assert.Throws<ArgumentException> (() => inbox.RemoveFlags (-1, MessageFlags.Seen, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveFlagsAsync (-1, MessageFlags.Seen, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveFlags (0, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveFlagsAsync (0, MessageFlags.None, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveFlags (UniqueId.MinValue, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveFlagsAsync (UniqueId.MinValue, MessageFlags.None, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveFlags ((IList<int>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveFlagsAsync ((IList<int>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveFlags ((IList<UniqueId>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveFlagsAsync ((IList<UniqueId>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveFlags (new int[] { 0 }, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveFlagsAsync (new int[] { 0 }, MessageFlags.None, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveFlags (UniqueIdRange.All, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveFlagsAsync (UniqueIdRange.All, MessageFlags.None, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveFlags ((IList<int>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveFlagsAsync ((IList<int>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveFlags ((IList<UniqueId>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveFlagsAsync ((IList<UniqueId>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveFlags (new int[] { 0 }, 1, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveFlagsAsync (new int[] { 0 }, 1, MessageFlags.None, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveFlags (UniqueIdRange.All, 1, MessageFlags.None, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveFlagsAsync (UniqueIdRange.All, 1, MessageFlags.None, true)); // SetFlags Assert.Throws<ArgumentException> (() => inbox.SetFlags (-1, MessageFlags.Seen, true)); Assert.Throws<ArgumentException> (async () => await inbox.SetFlagsAsync (-1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetFlags ((IList<int>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetFlagsAsync ((IList<int>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetFlags ((IList<UniqueId>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetFlagsAsync ((IList<UniqueId>) null, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetFlags ((IList<int>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetFlagsAsync ((IList<int>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetFlags ((IList<UniqueId>) null, 1, MessageFlags.Seen, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetFlagsAsync ((IList<UniqueId>) null, 1, MessageFlags.Seen, true)); var labels = new string[] { "Label1", "Label2" }; var emptyLabels = new string[0]; // AddLabels Assert.Throws<ArgumentException> (() => inbox.AddLabels (-1, labels, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddLabelsAsync (-1, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels (0, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync (0, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels (UniqueId.MinValue, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync (UniqueId.MinValue, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels ((IList<int>) null, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync ((IList<int>) null, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels ((IList<UniqueId>) null, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync ((IList<UniqueId>) null, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels (new int[] { 0 }, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync (new int[] { 0 }, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels (UniqueIdRange.All, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync (UniqueIdRange.All, null, true)); Assert.Throws<ArgumentException> (() => inbox.AddLabels (new int[] { 0 }, emptyLabels, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddLabelsAsync (new int[] { 0 }, emptyLabels, true)); Assert.Throws<ArgumentException> (() => inbox.AddLabels (UniqueIdRange.All, emptyLabels, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddLabelsAsync (UniqueIdRange.All, emptyLabels, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels ((IList<int>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync ((IList<int>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels ((IList<UniqueId>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync ((IList<UniqueId>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels (new int[] { 0 }, 1, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync (new int[] { 0 }, 1, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.AddLabels (UniqueIdRange.All, 1, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.AddLabelsAsync (UniqueIdRange.All, 1, null, true)); Assert.Throws<ArgumentException> (() => inbox.AddLabels (new int[] { 0 }, 1, emptyLabels, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddLabelsAsync (new int[] { 0 }, 1, emptyLabels, true)); Assert.Throws<ArgumentException> (() => inbox.AddLabels (UniqueIdRange.All, 1, emptyLabels, true)); Assert.Throws<ArgumentException> (async () => await inbox.AddLabelsAsync (UniqueIdRange.All, 1, emptyLabels, true)); // RemoveLabels Assert.Throws<ArgumentException> (() => inbox.RemoveLabels (-1, labels, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveLabelsAsync (-1, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels (0, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync (0, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels (UniqueId.MinValue, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync (UniqueId.MinValue, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels ((IList<int>) null, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync ((IList<int>) null, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels ((IList<UniqueId>) null, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync ((IList<UniqueId>) null, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels (new int[] { 0 }, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync (new int[] { 0 }, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels (UniqueIdRange.All, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync (UniqueIdRange.All, null, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveLabels (new int[] { 0 }, emptyLabels, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveLabelsAsync (new int[] { 0 }, emptyLabels, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveLabels (UniqueIdRange.All, emptyLabels, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveLabelsAsync (UniqueIdRange.All, emptyLabels, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels ((IList<int>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync ((IList<int>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels ((IList<UniqueId>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync ((IList<UniqueId>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels (new int[] { 0 }, 1, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync (new int[] { 0 }, 1, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.RemoveLabels (UniqueIdRange.All, 1, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.RemoveLabelsAsync (UniqueIdRange.All, 1, null, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveLabels (new int[] { 0 }, 1, emptyLabels, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveLabelsAsync (new int[] { 0 }, 1, emptyLabels, true)); Assert.Throws<ArgumentException> (() => inbox.RemoveLabels (UniqueIdRange.All, 1, emptyLabels, true)); Assert.Throws<ArgumentException> (async () => await inbox.RemoveLabelsAsync (UniqueIdRange.All, 1, emptyLabels, true)); // SetLabels Assert.Throws<ArgumentException> (() => inbox.SetLabels (-1, labels, true)); Assert.Throws<ArgumentException> (async () => await inbox.SetLabelsAsync (-1, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels (0, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync (0, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels (UniqueId.MinValue, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync (UniqueId.MinValue, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels ((IList<int>) null, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync ((IList<int>) null, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels ((IList<UniqueId>) null, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync ((IList<UniqueId>) null, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels (new int[] { 0 }, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync (new int[] { 0 }, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels (UniqueIdRange.All, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync (UniqueIdRange.All, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels ((IList<int>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync ((IList<int>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels ((IList<UniqueId>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync ((IList<UniqueId>) null, 1, labels, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels (new int[] { 0 }, 1, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync (new int[] { 0 }, 1, null, true)); Assert.Throws<ArgumentNullException> (() => inbox.SetLabels (UniqueIdRange.All, 1, null, true)); Assert.Throws<ArgumentNullException> (async () => await inbox.SetLabelsAsync (UniqueIdRange.All, 1, null, true)); // Search var searchOptions = SearchOptions.All | SearchOptions.Min | SearchOptions.Max | SearchOptions.Count; var orderBy = new OrderBy[] { OrderBy.Arrival }; var emptyOrderBy = new OrderBy[0]; Assert.Throws<ArgumentNullException> (() => inbox.Search ((SearchQuery) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync ((SearchQuery) null)); Assert.Throws<ArgumentNullException> (() => inbox.Search ((SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync ((SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search (SearchQuery.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (SearchQuery.All, null)); Assert.Throws<ArgumentException> (() => inbox.Search (SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentException> (async () => await inbox.SearchAsync (SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search ((IList<UniqueId>) null, SearchQuery.All)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync ((IList<UniqueId>) null, SearchQuery.All)); Assert.Throws<ArgumentNullException> (() => inbox.Search (UniqueIdRange.All, (SearchQuery) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (UniqueIdRange.All, (SearchQuery) null)); Assert.Throws<ArgumentNullException> (() => inbox.Search ((IList<UniqueId>) null, SearchQuery.All, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync ((IList<UniqueId>) null, SearchQuery.All, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search (UniqueIdRange.All, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (UniqueIdRange.All, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search (UniqueIdRange.All, SearchQuery.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (UniqueIdRange.All, SearchQuery.All, null)); Assert.Throws<ArgumentException> (() => inbox.Search (UniqueIdRange.All, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentException> (async () => await inbox.SearchAsync (UniqueIdRange.All, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search (searchOptions, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (searchOptions, null)); Assert.Throws<ArgumentNullException> (() => inbox.Search (searchOptions, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (searchOptions, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search (searchOptions, SearchQuery.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (searchOptions, SearchQuery.All, null)); Assert.Throws<ArgumentException> (() => inbox.Search (searchOptions, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentException> (async () => await inbox.SearchAsync (searchOptions, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search (searchOptions, (IList<UniqueId>) null, SearchQuery.All)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (searchOptions, (IList<UniqueId>) null, SearchQuery.All)); Assert.Throws<ArgumentNullException> (() => inbox.Search (searchOptions, UniqueIdRange.All, (SearchQuery) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (searchOptions, UniqueIdRange.All, (SearchQuery) null)); Assert.Throws<ArgumentNullException> (() => inbox.Search (searchOptions, (IList<UniqueId>) null, SearchQuery.All, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (searchOptions, (IList<UniqueId>) null, SearchQuery.All, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search (searchOptions, UniqueIdRange.All, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (searchOptions, UniqueIdRange.All, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search (searchOptions, UniqueIdRange.All, SearchQuery.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync (searchOptions, UniqueIdRange.All, SearchQuery.All, null)); Assert.Throws<ArgumentException> (() => inbox.Search (searchOptions, UniqueIdRange.All, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentException> (async () => await inbox.SearchAsync (searchOptions, UniqueIdRange.All, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Search ((string) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SearchAsync ((string) null)); // Sort Assert.Throws<ArgumentNullException> (() => inbox.Sort ((SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync ((SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort (SearchQuery.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync (SearchQuery.All, null)); Assert.Throws<ArgumentException> (() => inbox.Sort (SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentException> (async () => await inbox.SortAsync (SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort ((IList<UniqueId>) null, SearchQuery.All, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync ((IList<UniqueId>) null, SearchQuery.All, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort (UniqueIdRange.All, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync (UniqueIdRange.All, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort (UniqueIdRange.All, SearchQuery.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync (UniqueIdRange.All, SearchQuery.All, null)); Assert.Throws<ArgumentException> (() => inbox.Sort (UniqueIdRange.All, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentException> (async () => await inbox.SortAsync (UniqueIdRange.All, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort (searchOptions, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync (searchOptions, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort (searchOptions, SearchQuery.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync (searchOptions, SearchQuery.All, null)); Assert.Throws<ArgumentException> (() => inbox.Sort (searchOptions, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentException> (async () => await inbox.SortAsync (searchOptions, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort (searchOptions, (IList<UniqueId>) null, SearchQuery.All, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync (searchOptions, (IList<UniqueId>) null, SearchQuery.All, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort (searchOptions, UniqueIdRange.All, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync (searchOptions, UniqueIdRange.All, (SearchQuery) null, orderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort (searchOptions, UniqueIdRange.All, SearchQuery.All, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync (searchOptions, UniqueIdRange.All, SearchQuery.All, null)); Assert.Throws<ArgumentException> (() => inbox.Sort (searchOptions, UniqueIdRange.All, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentException> (async () => await inbox.SortAsync (searchOptions, UniqueIdRange.All, SearchQuery.All, emptyOrderBy)); Assert.Throws<ArgumentNullException> (() => inbox.Sort ((string) null)); Assert.Throws<ArgumentNullException> (async () => await inbox.SortAsync ((string) null)); // Thread Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Thread ((ThreadingAlgorithm) 500, SearchQuery.All)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.ThreadAsync ((ThreadingAlgorithm) 500, SearchQuery.All)); Assert.Throws<ArgumentNullException> (() => inbox.Thread (ThreadingAlgorithm.References, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.ThreadAsync (ThreadingAlgorithm.References, null)); Assert.Throws<ArgumentNullException> (() => inbox.Thread ((IList<UniqueId>) null, ThreadingAlgorithm.References, SearchQuery.All)); Assert.Throws<ArgumentNullException> (async () => await inbox.ThreadAsync ((IList<UniqueId>) null, ThreadingAlgorithm.References, SearchQuery.All)); Assert.Throws<ArgumentOutOfRangeException> (() => inbox.Thread (UniqueIdRange.All, (ThreadingAlgorithm) 500, SearchQuery.All)); Assert.Throws<ArgumentOutOfRangeException> (async () => await inbox.ThreadAsync (UniqueIdRange.All, (ThreadingAlgorithm) 500, SearchQuery.All)); Assert.Throws<ArgumentNullException> (() => inbox.Thread (UniqueIdRange.All, ThreadingAlgorithm.References, null)); Assert.Throws<ArgumentNullException> (async () => await inbox.ThreadAsync (UniqueIdRange.All, ThreadingAlgorithm.References, null)); client.Disconnect (false); } }