Files
Wino-Mail/Wino.Mail/Views/ImapSetup/AdvancedImapSetupPage.xaml.cs

216 lines
9.4 KiB
C#
Raw Normal View History

2024-04-18 01:44:37 +02:00
using System;
using System.Collections.Generic;
using CommunityToolkit.Mvvm.Messaging;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities.Shared;
2024-04-18 01:44:37 +02:00
using Wino.Core.Domain.Models.Accounts;
using Wino.Core.Domain.Models.AutoDiscovery;
Full trust Wino Server implementation. (#295) * Separation of messages. Introducing Wino.Messages library. * Wino.Server and Wino.Packaging projects. Enabling full trust for UWP and app service connection manager basics. * Remove debug code. * Enable generating assembly info to deal with unsupported os platform warnings. * Fix server-client connection. * UIMessage communication. Single instancing for server and re-connection mechanism on suspension. * Removed IWinoSynchronizerFactory from UWP project. * Removal of background task service from core. * Delegating changes to UI and triggering new background synchronization. * Fix build error. * Moved core lib messages to Messaging project. * Better client-server communication. Handling of requests in the server. New synchronizer factory in the server. * WAM broker and MSAL token caching for OutlookAuthenticator. Handling account creation for Outlook. * WinoServerResponse basics. * Delegating protocol activation for Gmail authenticator. * Adding margin to searchbox to match action bar width. * Move libraries into lib folder. * Storing base64 encoded mime on draft creation instead of MimeMessage object. Fixes serialization/deserialization issue with S.T.Json * Scrollbar adjustments * WınoExpander for thread expander layout ıssue. * Handling synchronizer state changes. * Double init on background activation. * FIxing packaging issues and new Wino Mail launcher protocol for activation from full thrust process. * Remove debug deserialization. * Remove debug code. * Making sure the server connection is established when the app is launched. * Thrust -> Trust string replacement... * Rename package to Wino Mail * Enable translated values in the server. * Fixed an issue where toast activation can't find the clicked mail after the folder is initialized. * Revert debug code. * Change server background sync to every 3 minute and Inbox only synchronization. * Revert google auth changes. * App preferences page. * Changing tray icon visibility on preference change. * Start the server with invisible tray icon if set to invisible. * Reconnect button on the title bar. * Handling of toast actions. * Enable x86 build for server during packaging. * Get rid of old background tasks and v180 migration. * Terminate client when Exit clicked in server. * Introducing SynchronizationSource to prevent notifying UI after server tick synchronization. * Remove confirmAppClose restricted capability and unused debug code in manifest. * Closing the reconnect info popup when reconnect is clicked. * Custom RetryHandler for OutlookSynchronizer and separating client/server logs. * Running server on Windows startup. * Fix startup exe. * Fix for expander list view item paddings. * Force full sync on app launch instead of Inbox. * Fix draft creation. * Fix an issue with custom folder sync logic. * Reporting back account sync progress from server. * Fix sending drafts and missing notifications for imap. * Changing imap folder sync requirements. * Retain file count is set to 3. * Disabled swipe gestures temporarily due to native crash with SwipeControl * Save all attachments implementation. * Localization for save all attachments button. * Fix logging dates for logs. * Fixing ARM64 build. * Add ARM64 build config to packaging project. * Comment out OutOfProcPDB for ARM64. * Hnadling GONE response for Outlook folder synchronization.
2024-08-05 00:36:26 +02:00
using Wino.Messaging.Client.Mails;
2024-04-18 01:44:37 +02:00
namespace Wino.Views.ImapSetup
{
public sealed partial class AdvancedImapSetupPage : Page
{
public List<ImapAuthenticationMethodModel> AvailableAuthenticationMethods { get; } = new List<ImapAuthenticationMethodModel>()
{
new ImapAuthenticationMethodModel(Core.Domain.Enums.ImapAuthenticationMethod.Auto, Translator.ImapAuthenticationMethod_Auto),
new ImapAuthenticationMethodModel(Core.Domain.Enums.ImapAuthenticationMethod.None, Translator.ImapAuthenticationMethod_None),
new ImapAuthenticationMethodModel(Core.Domain.Enums.ImapAuthenticationMethod.NormalPassword, Translator.ImapAuthenticationMethod_Plain),
new ImapAuthenticationMethodModel(Core.Domain.Enums.ImapAuthenticationMethod.EncryptedPassword, Translator.ImapAuthenticationMethod_EncryptedPassword),
new ImapAuthenticationMethodModel(Core.Domain.Enums.ImapAuthenticationMethod.Ntlm, Translator.ImapAuthenticationMethod_Ntlm),
new ImapAuthenticationMethodModel(Core.Domain.Enums.ImapAuthenticationMethod.CramMd5, Translator.ImapAuthenticationMethod_CramMD5),
new ImapAuthenticationMethodModel(Core.Domain.Enums.ImapAuthenticationMethod.DigestMd5, Translator.ImapAuthenticationMethod_DigestMD5)
};
public List<ImapConnectionSecurityModel> AvailableConnectionSecurities { get; set; } = new List<ImapConnectionSecurityModel>()
{
new ImapConnectionSecurityModel(Core.Domain.Enums.ImapConnectionSecurity.Auto, Translator.ImapConnectionSecurity_Auto),
new ImapConnectionSecurityModel(Core.Domain.Enums.ImapConnectionSecurity.SslTls, Translator.ImapConnectionSecurity_SslTls),
new ImapConnectionSecurityModel(Core.Domain.Enums.ImapConnectionSecurity.StartTls, Translator.ImapConnectionSecurity_StartTls),
new ImapConnectionSecurityModel(Core.Domain.Enums.ImapConnectionSecurity.None, Translator.ImapConnectionSecurity_None)
};
public bool UseSameCredentialsForSending
{
get { return (bool)GetValue(UseSameCredentialsForSendingProperty); }
set { SetValue(UseSameCredentialsForSendingProperty, value); }
}
public static readonly DependencyProperty UseSameCredentialsForSendingProperty = DependencyProperty.Register(nameof(UseSameCredentialsForSending), typeof(bool), typeof(AdvancedImapSetupPage), new PropertyMetadata(true, OnUseSameCredentialsForSendingChanged));
public AdvancedImapSetupPage()
{
InitializeComponent();
NavigationCacheMode = NavigationCacheMode.Enabled;
}
private static void OnUseSameCredentialsForSendingChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is AdvancedImapSetupPage page)
{
page.UpdateOutgoingAuthenticationPanel();
}
}
private void UpdateOutgoingAuthenticationPanel()
{
if (UseSameCredentialsForSending)
{
OutgoingUsernameBox.Text = UsernameBox.Text;
OutgoingPasswordBox.Password = PasswordBox.Password;
}
else
{
OutgoingUsernameBox.Text = string.Empty;
OutgoingPasswordBox.Password = string.Empty;
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
// Don't override settings on back scenarios.
// User is trying to try again the same configuration.
if (e.NavigationMode == NavigationMode.Back) return;
2024-04-18 01:44:37 +02:00
// Connection is succesfull but error occurred.
// Imap and Smptp settings exists here at this point.
if (e.Parameter is AutoDiscoverySettings preDefinedSettings && preDefinedSettings.UserMinimalSettings != null)
{
// TODO: Auto discovery settings adjustments.
UsernameBox.Text = preDefinedSettings.UserMinimalSettings.Email;
AddressBox.Text = preDefinedSettings.UserMinimalSettings.Email;
2024-04-18 01:44:37 +02:00
DisplayNameBox.Text = preDefinedSettings.UserMinimalSettings.DisplayName;
PasswordBox.Password = preDefinedSettings.UserMinimalSettings.Password;
var serverInfo = preDefinedSettings.ToServerInformation();
IncomingServerBox.Text = serverInfo.IncomingServer;
IncomingServerPortBox.Text = serverInfo.IncomingServerPort;
OutgoingPasswordBox.Password = serverInfo.OutgoingServerPassword;
OutgoingServerPort.Text = serverInfo.OutgoingServerPort;
OutgoingUsernameBox.Text = serverInfo.OutgoingServerUsername;
UseSameCredentialsForSending = OutgoingUsernameBox.Text == UsernameBox.Text;
}
else if (e.Parameter is AutoDiscoveryMinimalSettings autoDiscoveryMinimalSettings)
{
// Auto discovery failed. Only minimal settings are passed.
UsernameBox.Text = autoDiscoveryMinimalSettings.Email;
AddressBox.Text = autoDiscoveryMinimalSettings.Email;
2024-04-18 01:44:37 +02:00
DisplayNameBox.Text = autoDiscoveryMinimalSettings.DisplayName;
PasswordBox.Password = autoDiscoveryMinimalSettings.Password;
}
}
private void CancelClicked(object sender, RoutedEventArgs e) => WeakReferenceMessenger.Default.Send(new ImapSetupDismissRequested(null));
private string GetServerWithoutPort(string server)
{
var splitted = server.Split(':');
if (splitted.Length > 1)
{
return splitted[0];
}
return server;
}
private void SignInClicked(object sender, RoutedEventArgs e)
{
var info = new CustomServerInformation()
{
IncomingServer = GetServerWithoutPort(IncomingServerBox.Text),
Id = Guid.NewGuid(),
IncomingServerPassword = PasswordBox.Password,
IncomingServerType = Core.Domain.Enums.CustomIncomingServerType.IMAP4,
IncomingServerUsername = UsernameBox.Text,
IncomingAuthenticationMethod = (IncomingAuthenticationMethod.SelectedItem as ImapAuthenticationMethodModel).ImapAuthenticationMethod,
IncomingServerSocketOption = (IncomingConnectionSecurity.SelectedItem as ImapConnectionSecurityModel).ImapConnectionSecurity,
IncomingServerPort = IncomingServerPortBox.Text,
OutgoingServer = GetServerWithoutPort(OutgoingServerBox.Text),
OutgoingServerPort = OutgoingServerPort.Text,
OutgoingServerPassword = OutgoingPasswordBox.Password,
OutgoingAuthenticationMethod = (OutgoingAuthenticationMethod.SelectedItem as ImapAuthenticationMethodModel).ImapAuthenticationMethod,
OutgoingServerSocketOption = (OutgoingConnectionSecurity.SelectedItem as ImapConnectionSecurityModel).ImapConnectionSecurity,
OutgoingServerUsername = OutgoingUsernameBox.Text,
ProxyServer = ProxyServerBox.Text,
ProxyServerPort = ProxyServerPortBox.Text,
Address = AddressBox.Text,
DisplayName = DisplayNameBox.Text,
MaxConcurrentClients = 5
2024-04-18 01:44:37 +02:00
};
if (UseSameCredentialsForSending)
{
info.OutgoingServerUsername = info.IncomingServerUsername;
info.OutgoingServerPassword = info.IncomingServerPassword;
}
else
{
info.OutgoingServerUsername = OutgoingUsernameBox.Text;
info.OutgoingServerPassword = OutgoingPasswordBox.Password;
}
WeakReferenceMessenger.Default.Send(new ImapSetupNavigationRequested(typeof(TestingImapConnectionPage), info));
}
private void IncomingServerChanged(object sender, TextChangedEventArgs e)
{
if (sender is TextBox senderTextBox)
{
var splitted = senderTextBox.Text.Split(':');
if (splitted.Length > 1)
{
IncomingServerPortBox.Text = splitted[splitted.Length - 1];
}
}
}
private void OutgoingServerChanged(object sender, TextChangedEventArgs e)
{
if (sender is TextBox senderTextBox)
{
var splitted = senderTextBox.Text.Split(':');
if (splitted.Length > 1)
{
OutgoingServerPort.Text = splitted[splitted.Length - 1];
}
}
}
private void IncomingUsernameChanged(object sender, TextChangedEventArgs e)
{
if (UseSameCredentialsForSending)
{
OutgoingUsernameBox.Text = UsernameBox.Text;
}
}
private void IncomingPasswordChanged(object sender, RoutedEventArgs e)
{
if (UseSameCredentialsForSending)
{
OutgoingPasswordBox.Password = PasswordBox.Password;
}
}
}
}