internal MailAccountContext(MailAccountModel account) { _account = account; _appContext = App.Context; _takeOnlineHint = true; _outbox = new OutboxContext(this); _registerCommand = new RelayCommand(OnRegister); _listMailboxesCommand = new RelayCommand(OnListMailboxes); _testSettingsCommand = new RelayCommand(OnTestSettings); _configAccountCommand = new RelayCommand(OnConfigAccount); _deleteAccountCommand = new RelayCommand(OnDeleteAccount); _showUnsubscribedMailboxesCommand = new RelayCommand(OnShowUnsubscribedMailboxes); _hideUnsubscribedMailboxesCommand = new RelayCommand(OnHideUnsubscribedMailboxes); _isAutoDetectPreferred = true; _mailboxes = new ObservableCollection <MailboxContext>(); _mailboxes.CollectionChanged += (sender, e) => { RaisePropertyChanged(() => HasMailboxes); RaisePropertyChanged(() => Children); RaisePropertyChanged(() => MailboxRoots); }; }
internal async Task <bool> TryDeleteAccountAsync() { using (var context = new DatabaseContext()) { await context.Database.Connection.OpenAsync(); using (var transaction = context.Database.Connection.BeginTransaction()) { try { var mailboxes = await context.Mailboxes .Where(x => x.AccountId == Id) .ToArrayAsync(); foreach (var mailbox in mailboxes) { var lMailbox = mailbox; var messages = await context.MailMessages .Where(x => x.MailboxId == lMailbox.Id) .ToArrayAsync(); foreach (var message in messages) { var lMessage = message; var mimeMessages = await context.MimeMessages .Where(x => x.MessageId == lMessage.Id) .ToArrayAsync(); if (mimeMessages == null) { continue; } foreach (var mimeMessage in mimeMessages) { context.MimeMessages.Remove(mimeMessage); } await context.SaveChangesAsync(); } context.MailMessages.RemoveRange(messages); await context.SaveChangesAsync(); } context.Mailboxes.RemoveRange(mailboxes); await context.SaveChangesAsync(); var acc = new MailAccountModel { Id = Id }; context.MailAccounts.Attach(acc); context.MailAccounts.Remove(acc); await context.SaveChangesAsync(); transaction.Commit(); return(true); } catch (Exception ex) { Logger.Error(ex); transaction.Rollback(); return(false); } } } }
protected override void OnStartup(StartupEventArgs e) { #endif base.OnStartup(e); #if DEBUG var commands = Environment.CommandLine; var message = string.Format("Arguments: {0}{1}{1}Pid: {2}{1}{1}Continue?", commands, Environment.NewLine, Process.GetCurrentProcess().Id); var result = MessageBox.Show(message, "Command Line Arguments", MessageBoxButton.YesNo); if (result.HasFlag(MessageBoxResult.No)) { ShutdownMode = ShutdownMode.OnExplicitShutdown; Shutdown(1); } #endif var success = TryCallingLiveProcess(); if (success) { ShutdownMode = ShutdownMode.OnExplicitShutdown; Shutdown(0); } if (Settings.Default.IsFirstStart) { RunFirstStartProcedure(); } InitEnvironment(); InitSodium(); InitAwesomium(); Compose(); InitTheme(); StartComServer(); ProcessCommandLine(); #if DEBUG using (var database = new DatabaseContext()) { var accounts = await database.MailAccounts.ToArrayAsync(); if (accounts.Length != 0) { return; } var account = new MailAccountModel { Name = "Paranoia Test Account", Address = "*****@*****.**", ImapUsername = "******", ImapPassword = "******", ImapHost = "imap.gmail.com", ImapPort = 993, ImapSecurity = SecurityProtocol.Implicit, SmtpHost = "smtp.gmail.com", SmtpPort = 465, SmtpUsername = "******", SmtpPassword = "******", SmtpSecurity = SecurityProtocol.Implicit, UseImapCredentialsForSmtp = true, SmtpRequiresAuthentication = true, }; database.MailAccounts.Add(account); account = new MailAccountModel { Name = "So much Spam!", Address = "*****@*****.**", ImapUsername = "******", ImapPassword = "******", ImapHost = "mail.organice.de", ImapPort = 993, ImapSecurity = SecurityProtocol.Implicit, SmtpHost = "mail.organice.de", SmtpPort = 25, SmtpUsername = "******", SmtpPassword = "******", SmtpSecurity = SecurityProtocol.Explicit, UseImapCredentialsForSmtp = true, SmtpRequiresAuthentication = true, }; Settings.Default.AcceptUntrustedCertificates = true; database.MailAccounts.Add(account); await database.SaveChangesAsync(); } #endif }