private void CreateGroups() { // Go through all the mailboxes and organise into groups based on grouping information _groups = new Dictionary <string, GroupInfo>(); // Clear any existing groups string autodiscoverUrl = ""; if (radioButtonOffice365.Checked) { autodiscoverUrl = "https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc"; } _mailboxes.GroupMailboxes = !radioButtonSpecificUri.Checked; _mailboxes.CredentialHandler = CredentialHandler(); //Auth.CredentialHandler credentialHandler = CredentialHandler(); foreach (string sMailbox in checkedListBoxMailboxes.CheckedItems) { _mailboxes.AddMailbox(sMailbox, autodiscoverUrl); MailboxInfo mailboxInfo = _mailboxes.Mailbox(sMailbox); if (mailboxInfo != null) { GroupInfo groupInfo = null; if (_groups.ContainsKey(mailboxInfo.GroupName)) { groupInfo = _groups[mailboxInfo.GroupName]; } else { groupInfo = new GroupInfo(mailboxInfo.GroupName, mailboxInfo.SMTPAddress, mailboxInfo.EwsUrl, _credentialHandler, _traceListener); _groups.Add(mailboxInfo.GroupName, groupInfo); } if (groupInfo.Mailboxes.Count > 199) { // We already have enough mailboxes in this group, so we rename it and create a new one // Renaming it means that we can still put new mailboxes into the correct group based on GroupingInformation int i = 1; while (_groups.ContainsKey(String.Format("{0}{1}", groupInfo.Name, i))) { i++; } _groups.Remove(groupInfo.Name); _groups.Add(String.Format("{0}{1}", groupInfo.Name, i), groupInfo); groupInfo = new GroupInfo(mailboxInfo.GroupName, mailboxInfo.SMTPAddress, mailboxInfo.EwsUrl, _credentialHandler, _traceListener); _groups.Add(mailboxInfo.GroupName, groupInfo); } groupInfo.Mailboxes.Add(sMailbox); } } }
private void CreateGroups() { // Go through all the mailboxes and organise into groups based on grouping information _groups = new Dictionary <string, GroupInfo>(); // Clear any existing groups _mailboxes.Credentials = new WebCredentials(textBoxUsername.Text, textBoxPassword.Text); foreach (string sMailbox in checkedListBoxMailboxes.CheckedItems) { _mailboxes.AddMailbox(sMailbox); MailboxInfo mailboxInfo = _mailboxes.Mailbox(sMailbox); if (mailboxInfo != null) { GroupInfo groupInfo = null; if (_groups.ContainsKey(mailboxInfo.GroupName)) { groupInfo = _groups[mailboxInfo.GroupName]; } else { groupInfo = new GroupInfo(mailboxInfo.GroupName, mailboxInfo.SMTPAddress, mailboxInfo.EwsUrl, _traceListener); _groups.Add(mailboxInfo.GroupName, groupInfo); } if (groupInfo.Mailboxes.Count > 199) { // We already have enough mailboxes in this group, so we rename it and create a new one // Renaming it means that we can still put new mailboxes into the correct group based on GroupingInformation int i = 1; while (_groups.ContainsKey(String.Format("{0}{1}", groupInfo.Name, i))) { i++; } _groups.Remove(groupInfo.Name); _groups.Add(String.Format("{0}{1}", groupInfo.Name, i), groupInfo); groupInfo = new GroupInfo(mailboxInfo.GroupName, mailboxInfo.SMTPAddress, mailboxInfo.EwsUrl, _traceListener); _groups.Add(mailboxInfo.GroupName, groupInfo); } groupInfo.Mailboxes.Add(sMailbox); } } }