Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Adjust client login flow to new core handling #549
Browse files Browse the repository at this point in the history
  • Loading branch information
florianhaar authored and Boehrsi committed May 5, 2020
1 parent d5b8ea4 commit e5c1f88
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 73 deletions.
16 changes: 8 additions & 8 deletions assets/json/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"id": "yahoo",
"name": "Yahoo",
"preset": {
"incoming_security": "ssltls",
"incoming_security": "ssl",
"incoming_server": "imap.mail.yahoo.com",
"incoming_protocol": "imap",
"incoming_port": 993,
"outgoing_security": "ssltls",
"outgoing_security": "ssl",
"outgoing_server": "smtp.mail.yahoo.com",
"outgoing_port": 465
}
Expand All @@ -25,7 +25,7 @@
"id": "outlook",
"name": "Outlook",
"preset": {
"incoming_security": "ssltls",
"incoming_security": "ssl",
"incoming_server": "outlook.office365.com",
"incoming_protocol": "imap",
"incoming_port": 993,
Expand All @@ -38,7 +38,7 @@
"id": "gmx",
"name": "GMX",
"preset": {
"incoming_security": "ssltls",
"incoming_security": "ssl",
"incoming_server": "imap.gmx.net",
"incoming_protocol": "imap",
"incoming_port": 993,
Expand All @@ -52,11 +52,11 @@
"name": "Mailbox.org",
"register_link": "https://register.mailbox.org/",
"preset": {
"incoming_security": "ssltls",
"incoming_security": "ssl",
"incoming_server": "imap.mailbox.org",
"incoming_protocol": "imap",
"incoming_port": 993,
"outgoing_security": "ssltls",
"outgoing_security": "ssl",
"outgoing_server": "smtp.mailbox.org",
"outgoing_port": 465
}
Expand All @@ -65,7 +65,7 @@
"id": "mail_com",
"name": "Mail.com",
"preset": {
"incoming_security": "ssltls",
"incoming_security": "ssl",
"incoming_server": "imap.mail.com",
"incoming_protocol": "imap",
"incoming_port": 993,
Expand Down Expand Up @@ -124,7 +124,7 @@
"incoming_server": "dovecot.qa.open-xchange.com",
"incoming_protocol": "",
"incoming_port": 143,
"outgoing_security": "plain",
"outgoing_security": "plain_socket",
"outgoing_server": "dovecot.qa.open-xchange.com",
"outgoing_port": 25
}
Expand Down
23 changes: 4 additions & 19 deletions lib/src/data/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ class Config {
String imapLogin;
String imapServer;
String imapPort;
int imapSecurity;
String imapSecurity;
String smtpLogin;
String smtpServer;
String smtpPort;
int smtpSecurity;
String smtpSecurity;
int showEmails;
int mdnsEnabled;
int rfc724MsgIdPrefix;
Expand Down Expand Up @@ -89,9 +89,8 @@ class Config {
smtpLogin = await _context.getConfigValue(Context.configSendUser);
smtpServer = await _context.getConfigValue(Context.configSendServer);
smtpPort = await _context.getConfigValue(Context.configSendPort);
int serverFlags = await _context.getConfigValue(Context.configServerFlags, ObjectType.int);
imapSecurity = getSavedImapSecurityOption(serverFlags);
smtpSecurity = getSavedSmtpSecurityOption(serverFlags);
imapSecurity = await _context.getConfigValue(Context.configImapSecurity);
smtpSecurity = await _context.getConfigValue(Context.configSmtpSecurity);
showEmails = await _context.getConfigValue(Context.configShowEmails, ObjectType.int);
mdnsEnabled = await _context.getConfigValue(Context.configMdnsEnabled, ObjectType.int);
rfc724MsgIdPrefix = await _context.getConfigValue(Context.configRfc724MsgIdPrefix, ObjectType.int);
Expand Down Expand Up @@ -135,19 +134,6 @@ class Config {
case Context.configSendPort:
smtpPort = value;
break;
case Context.configServerFlags:
int sel = 0;
if ((value & Context.serverFlagsImapSsl) != 0) sel = 1;
if ((value & Context.serverFlagsImapStartTls) != 0) sel = 2;
if ((value & Context.serverFlagsImapPlain) != 0) sel = 3;
imapSecurity = sel;

sel = 0;
if ((value & Context.serverFlagsSmtpSsl) != 0) sel = 1;
if ((value & Context.serverFlagsSmtpStartTls) != 0) sel = 2;
if ((value & Context.serverFlagsSmtpPlain) != 0) sel = 3;
smtpSecurity = sel;
break;
case Context.configShowEmails:
showEmails = value;
break;
Expand All @@ -165,7 +151,6 @@ class Config {
}

bool isTypeInt(String key) =>
key == Context.configServerFlags ||
key == Context.configShowEmails ||
key == Context.configMdnsEnabled ||
key == Context.configRfc724MsgIdPrefix ||
Expand Down
1 change: 1 addition & 0 deletions lib/src/l10n/l.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import 'package:logging/logging.dart';
import 'package:ox_coi/src/extensions/string_apis.dart';

// Non-translatable strings
const plain = "Plain";
const sslTls = "SSL/TLS";
const startTLS = "StartTLS";
const gif = "GIF";
Expand Down
13 changes: 4 additions & 9 deletions lib/src/login/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,8 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
await config.setValue(Context.configSendPassword, event.smtpPassword);
await config.setValue(Context.configSendServer, event.smtpServer);
await config.setValue(Context.configSendPort, event.smtpPort);
int imapSecurity = event.imapSecurity;
int smtpSecurity = event.smtpSecurity;
int serverFlags = createServerFlagInteger(imapSecurity, smtpSecurity);

await config.setValue(Context.configServerFlags, serverFlags);
await config.setValue(Context.configSmtpSecurity, event.smtpSecurity);
await config.setValue(Context.configImapSecurity, event.imapSecurity);
}

void _updateConfig() {
Expand Down Expand Up @@ -226,10 +223,8 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
await config.setValue(Context.configSendPassword, event.smtpPassword);
await config.setValue(Context.configSendServer, preset.outgoingServer);
await config.setValue(Context.configSendPort, preset.outgoingPort.toString());
int imapSecurity = getSecurityId(preset.incomingSecurity);
int smtpSecurity = getSecurityId(preset.outgoingSecurity);
int serverFlags = createServerFlagInteger(imapSecurity, smtpSecurity);
await config.setValue(Context.configServerFlags, serverFlags);
await config.setValue(Context.configImapSecurity, preset.incomingSecurity.toString());
await config.setValue(Context.configSmtpSecurity, preset.outgoingSecurity.toString());
await setPreference(preferenceNotificationsPushServiceUrl, provider.pushServiceUrl);
await setPreference(preferenceInviteServiceUrl, provider.inviteServiceUrl);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/login/login_events_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ class LoginButtonPressed extends LoginEvent {
final String imapLogin;
final String imapServer;
final String imapPort;
final int imapSecurity;
final String imapSecurity;
final String smtpLogin;
final String smtpPassword;
final String smtpServer;
final String smtpPort;
final int smtpSecurity;
final String smtpSecurity;

LoginButtonPressed(
{@required this.email,
Expand Down
14 changes: 7 additions & 7 deletions lib/src/settings/settings_manual_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ class _SettingsManualFormState extends State<SettingsManualForm> {
smtpServerField.controller.text = state.smtpServer;
smtpPortField.controller.text = state.smtpPort;
setState(() {
selectedImapSecurity = convertProtocolIntToString(context, state.imapSecurity);
selectedSmtpSecurity = convertProtocolIntToString(context, state.smtpSecurity);
selectedImapSecurity = convertProtocolDccStringToString(state.imapSecurity);
selectedSmtpSecurity = convertProtocolDccStringToString(state.smtpSecurity);
});
} else if (state is SettingsManualFormStateValidation) {
var success = formKey.currentState.validate();
Expand All @@ -151,12 +151,12 @@ class _SettingsManualFormState extends State<SettingsManualForm> {
imapLogin: imapLoginNameField.controller.text,
imapServer: imapServerField.controller.text,
imapPort: imapPortField.controller.text,
imapSecurity: convertProtocolStringToInt(context, selectedImapSecurity),
imapSecurity: convertProtocolStringToDccString(selectedImapSecurity),
smtpLogin: smtpLoginNameField.controller.text,
smtpPassword: smtpPasswordField.controller.text,
smtpServer: smtpServerField.controller.text,
smtpPort: smtpPortField.controller.text,
smtpSecurity: convertProtocolStringToInt(context, selectedSmtpSecurity),
smtpSecurity: convertProtocolStringToDccString(selectedSmtpSecurity),
));
}
}
Expand Down Expand Up @@ -213,7 +213,7 @@ class _SettingsManualFormState extends State<SettingsManualForm> {
Padding(padding: const EdgeInsets.all(loginVerticalFormPadding)),
Text(L10n.get(L.settingIMAPSecurity)),
DropdownButton(
value: selectedImapSecurity == null ? L10n.get(L.automatic) : selectedImapSecurity,
value: selectedImapSecurity,
items: getSecurityOptions(context),
onChanged: (String newValue) {
setState(() {
Expand All @@ -232,7 +232,7 @@ class _SettingsManualFormState extends State<SettingsManualForm> {
Padding(padding: const EdgeInsets.all(loginVerticalFormPadding)),
Text(L10n.get(L.settingSMTPSecurity)),
DropdownButton(
value: selectedSmtpSecurity == null ? L10n.get(L.automatic) : selectedSmtpSecurity,
value: selectedSmtpSecurity,
items: getSecurityOptions(context),
onChanged: (String newValue) {
setState(() {
Expand All @@ -254,9 +254,9 @@ class _SettingsManualFormState extends State<SettingsManualForm> {
List<DropdownMenuItem<String>> getSecurityOptions(BuildContext context) {
return [
L10n.get(L.automatic),
plain,
sslTls,
startTLS,
L10n.get(L.off),
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(value: value, child: Text(value));
}).toList();
Expand Down
16 changes: 8 additions & 8 deletions lib/src/settings/settings_manual_form_event_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class SettingsPrefilled extends SettingsManualFormEvent {
final String smtpLogin;
final String smtpServer;
final String smtpPort;
final int imapSecurity;
final int smtpSecurity;
final String imapSecurity;
final String smtpSecurity;
final String password;

SettingsPrefilled({
Expand Down Expand Up @@ -92,8 +92,8 @@ class ValidationDone extends SettingsManualFormEvent {
final String smtpPassword;
final String smtpServer;
final String smtpPort;
final int imapSecurity;
final int smtpSecurity;
final String imapSecurity;
final String smtpSecurity;
final String password;

ValidationDone({
Expand Down Expand Up @@ -125,8 +125,8 @@ class SettingsManualFormStateReady extends SettingsManualFormState {
final String smtpLogin;
final String smtpServer;
final String smtpPort;
final int imapSecurity;
final int smtpSecurity;
final String imapSecurity;
final String smtpSecurity;

SettingsManualFormStateReady({
this.email,
Expand Down Expand Up @@ -154,8 +154,8 @@ class SettingsManualFormStateValidationSuccess extends SettingsManualFormState {
final String smtpPassword;
final String smtpServer;
final String smtpPort;
final int imapSecurity;
final int smtpSecurity;
final String imapSecurity;
final String smtpSecurity;

SettingsManualFormStateValidationSuccess({
this.email,
Expand Down
6 changes: 2 additions & 4 deletions lib/src/user/user_change_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,13 @@ class UserChangeBloc extends Bloc<UserChangeEvent, UserChangeState> {
await config.setValue(Context.configMailPassword, event.imapPassword);
await config.setValue(Context.configMailServer, event.imapServer);
await config.setValue(Context.configMailPort, event.imapPort);
await config.setValue(Context.configImapSecurity, event.imapSecurity);
await config.setValue(Context.configSendUser, event.smtpLogin.isNotEmpty ? event.smtpLogin : null);
await config.setValue(Context.configSendPassword, event.smtpPassword);
await config.setValue(Context.configSendServer, event.smtpServer);
await config.setValue(Context.configSendPort, event.smtpPort);
int imapSecurity = event.imapSecurity;
int smtpSecurity = event.smtpSecurity;
int serverFlags = createServerFlagInteger(imapSecurity, smtpSecurity);
await config.setValue(Context.configSmtpSecurity, event.smtpSecurity);

await config.setValue(Context.configServerFlags, serverFlags);
add(ChangesApplied());
}
}
4 changes: 2 additions & 2 deletions lib/src/user/user_change_event_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class UserAccountDataChanged extends UserChangeEvent {
final String imapPassword;
final String imapServer;
final String imapPort;
final int imapSecurity;
final String imapSecurity;
final String smtpLogin;
final String smtpPassword;
final String smtpServer;
final String smtpPort;
final int smtpSecurity;
final String smtpSecurity;

UserAccountDataChanged({
@required this.imapLogin,
Expand Down
27 changes: 13 additions & 14 deletions lib/src/utils/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,25 @@ import 'package:ox_coi/src/l10n/l10n.dart';

enum ProtocolType { imap, smtp }

int convertProtocolStringToInt(BuildContext context, String value) {
int newValue = 0;
if (value == sslTls)
newValue = 1;
String convertProtocolStringToDccString(String value) {
String newValue = "";
if (value == plain)
newValue = "plain_socket";
else if (value == sslTls)
newValue = "ssl";
else if (value == startTLS)
newValue = 2;
else if (value == L10n.get(L.off)) newValue = 3;
newValue = "starttls";
return newValue;
}

String convertProtocolIntToString(BuildContext context, int value) {
String newValue;
if (value == 1)
String convertProtocolDccStringToString(String value) {
String newValue = L10n.get(L.automatic);
if (value == "plain_socket")
newValue = plain;
else if (value == "ssl")
newValue = sslTls;
else if (value == 2)
else if (value == "starttls")
newValue = startTLS;
else if (value == 3)
newValue = L10n.get(L.off);
else
newValue = L10n.get(L.automatic);
return newValue;
}

Expand Down

0 comments on commit e5c1f88

Please sign in to comment.