private void OnDocumentTextRequested(DocumentTextRequestedEventArgs e)
        {
            var handler = DocumentTextRequested;

            if (handler != null)
            {
                handler(this, e);
            }
        }
        private async Task <IEnumerable <MailMessage> > CreateSmtpMessagesAsync(MailAccountContext account)
        {
            var e = new DocumentTextRequestedEventArgs();

            OnDocumentTextRequested(e);

            var messages = new List <MailMessage>();

            using (var database = new DatabaseContext()) {
                foreach (var recipient in Recipients)
                {
                    if (string.IsNullOrEmpty(recipient))
                    {
                        continue;
                    }

                    var rec     = recipient;
                    var contact = await database.MailContacts.FirstOrDefaultAsync(x => x.Address == rec);

                    if (contact == null)
                    {
                        var message = CreateMailMessage(account, recipient, e.Document);
                        messages.Add(message);
                        continue;
                    }

                    var keys = await database.PublicKeys.Where(x => x.ContactId == contact.Id).ToArrayAsync();

                    if (keys == null || keys.Length == 0)
                    {
                        var message = CreateMailMessage(account, recipient, e.Document);
                        messages.Add(message);
                        continue;
                    }

                    var cryptMessage = await EncryptMessageAsync(account, keys, recipient, e.Document);

                    messages.Add(cryptMessage);
                }

                return(messages);
            }
        }