internal async Task StoreMail(MailModel mail, InternetAddressList to) { if (mail is null) { throw new ArgumentNullException(nameof(mail)); } if (to?.Any() != true) { throw new ArgumentException($"{nameof(mail)}.{nameof(to)} cannot be empty."); } List <MailboxModel> mailboxes = await this.mailRepository.GetMailboxes(to.OfType <MailboxAddress>().Select(x => x.Address).ToList()); foreach (var recipient in to.OfType <MailboxAddress>().Select(x => x.Address)) { var mailbox = mailboxes.SingleOrDefault(x => x.Address == recipient); if (mailbox != null) { var encryptedMail = this.emailCryptoService.EncryptWithNewPassword(mail, mailbox.PublicKey); encryptedMail.MailboxId = mailbox.Id; await this.mailRepository.Insert(encryptedMail); } else { this.logger.LogInformation($"disposing received mail with no corresponding mailbox. From={mail.FromAddress}; To={recipient}"); } this.NotifyMail(mail, recipient); } }