private async void PrepareAsReply(IReadOnlyDictionary <string, string> arguments)
        {
            MailContactContext from;
            MailMessageReader  message;
            var id = Int64.Parse(arguments["id"]);

            using (var database = new DatabaseContext()) {
                var mime = await database.MimeMessages
                           .Where(x => x.MessageId == id)
                           .ToArrayAsync();

                if (!mime.Any())
                {
                    throw new InvalidOperationException(Properties.Resources.MessageNotFoundException);
                }

                message = new MailMessageReader(mime[0].Data);
                from    = new MailContactContext(await database.MailContacts
                                                 .FirstAsync(x => x.Address == message.Headers.From.Address));
            }

            var context = (MailCompositionContext)DataContext;

            context.Subject = string.Format("{0} {1}", Settings.Default.PrefixForAnswering, message.Headers.Subject);
            context.Source  = string.Format("asset://paranoia/message/reply?id={0}", id);

            await from.CheckSecurityStateAsync();

            RecipientsBox.Preset(new[] { from });
        }
        private async void PrepareAsReplyAll(IReadOnlyDictionary <string, string> arguments)
        {
            MailContactContext from;
            var carbonCopies      = new List <MailContactContext>();
            var blindCarbonCopies = new List <MailContactContext>();
            MailMessageReader message;
            var id = Int64.Parse(arguments["id"]);

            using (var database = new DatabaseContext()) {
                var mime = await database.MimeMessages
                           .Where(x => x.MessageId == id)
                           .ToArrayAsync();

                if (!mime.Any())
                {
                    throw new InvalidOperationException(Properties.Resources.MessageNotFoundException);
                }

                message = new MailMessageReader(mime[0].Data);
                from    = new MailContactContext(await database.MailContacts
                                                 .FirstAsync(x => x.Address == message.Headers.From.Address));

                foreach (var cc in message.Headers.Cc.Where(y =>
                                                            !App.Context.Accounts.Any(x => x.Address.EqualsIgnoreCase(y.Address))))
                {
                    var lcc     = cc;
                    var contact = new MailContactContext(await database.MailContacts
                                                         .FirstAsync(x => x.Address == lcc.Address));

                    await contact.CheckSecurityStateAsync();

                    carbonCopies.Add(contact);
                }

                foreach (var bcc in message.Headers.Bcc.Where(y =>
                                                              !App.Context.Accounts.Any(x => x.Address.EqualsIgnoreCase(y.Address))))
                {
                    var lbcc    = bcc;
                    var contact = new MailContactContext(await database.MailContacts
                                                         .FirstAsync(x => x.Address == lbcc.Address));

                    await contact.CheckSecurityStateAsync();

                    blindCarbonCopies.Add(contact);
                }
            }

            var context = (MailCompositionContext)DataContext;

            context.Subject = string.Format("{0} {1}", Settings.Default.PrefixForAnswering, message.Headers.Subject);
            context.Source  = string.Format("asset://paranoia/message/reply?id={0}", id);

            await from.CheckSecurityStateAsync();

            RecipientsBox.Preset(new[] { from });

            CarbonCopyBox.Preset(carbonCopies);
            BlindCarbonCopyBox.Preset(blindCarbonCopies);
        }