Skip to content

Commit

Permalink
improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-virkus committed Jun 27, 2022
1 parent 39c0222 commit 0d4b83a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
4 changes: 3 additions & 1 deletion lib/src/imap/imap_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ class ImapClient extends ClientBase {

@override
FutureOr<void> onConnectionEstablished(
ConnectionInfo connectionInfo, String serverGreeting) async {
ConnectionInfo connectionInfo,
String serverGreeting,
) async {
_isInIdleMode = false;
_serverInfo = ImapServerInfo(connectionInfo);
final startIndex = serverGreeting.indexOf('[CAPABILITY ');
Expand Down
11 changes: 5 additions & 6 deletions lib/src/mail/mail_authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,17 @@ class OauthAuthentication extends UserNameBasedAuthentication {
@override
Future<void> authenticate(ServerConfig serverConfig,
{ImapClient? imap, PopClient? pop, SmtpClient? smtp}) async {
final name = userName;
final tkn = token;
final accessToken = tkn.accessToken;
final userName = this.userName;
final accessToken = token.accessToken;
switch (serverConfig.type) {
case ServerType.imap:
await imap!.authenticateWithOAuth2(name, accessToken);
await imap!.authenticateWithOAuth2(userName, accessToken);
break;
case ServerType.pop:
await pop!.login(name, accessToken);
await pop!.login(userName, accessToken);
break;
case ServerType.smtp:
await smtp!.authenticate(name, accessToken, AuthMechanism.xoauth2);
await smtp!.authenticate(userName, accessToken, AuthMechanism.xoauth2);
break;
default:
throw InvalidArgumentException(
Expand Down
23 changes: 13 additions & 10 deletions lib/src/mail/mail_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class MailClient {
_isConnected = true;
}

Future _prepareConnect() async {
Future<void> _prepareConnect() async {
final refresh = _refreshOAuthToken;
if (refresh != null) {
final auth = account.incoming?.authentication;
Expand Down Expand Up @@ -313,14 +313,14 @@ class MailClient {
/// Disconnects from the mail service.
///
/// Also compare [connect].
Future disconnect() async {
Future<void> disconnect() async {
final futures = <Future>[
stopPollingIfNeeded(),
_incomingMailClient.disconnect(),
_outgoingMailClient.disconnect(),
];
_isConnected = false;
return Future.wait(futures);
await Future.wait(futures);
}

/// Enforces to reconnect with the service.
Expand Down Expand Up @@ -1415,7 +1415,7 @@ abstract class _IncomingMailClient {

Future<void> connect();

Future disconnect();
Future<void> disconnect();

Future<List<Mailbox>> listMailboxes();

Expand Down Expand Up @@ -1820,14 +1820,14 @@ class _IncomingImapClient extends _IncomingMailClient {
} catch (e, s) {
throw MailException(mailClient, e.toString(), stackTrace: s, details: e);
}
if (_imapClient.serverInfo.capabilities?.isEmpty ?? true) {
final serverInfo = _imapClient.serverInfo;
if (serverInfo.capabilities?.isEmpty ?? true) {
await _imapClient.capability();
}
if (_imapClient.serverInfo.supportsId) {
if (serverInfo.supportsId) {
_serverId = await _imapClient.id(clientId: mailClient.clientId);
}
_config.serverCapabilities = _imapClient.serverInfo.capabilities;
final serverInfo = _imapClient.serverInfo;
_config.serverCapabilities = serverInfo.capabilities;
final enableCaps = <String>[];
if (serverInfo.supportsQresync) {
enableCaps.add(ImapServerInfo.capabilityQresync);
Expand All @@ -1844,7 +1844,10 @@ class _IncomingImapClient extends _IncomingMailClient {
}

@override
Future disconnect() => _imapClient.disconnect();
Future<void> disconnect() {
_reconnectCounter++; // this aborts the reconnect cycle
return _imapClient.disconnect();
}

@override
Future<List<Mailbox>> listMailboxes() async {
Expand Down Expand Up @@ -2847,7 +2850,7 @@ class _IncomingPopClient extends _IncomingMailClient {
}

@override
Future disconnect() => _popClient.disconnect();
Future<void> disconnect() => _popClient.disconnect();

@override
Future<List<Mailbox>> listMailboxes() {
Expand Down
9 changes: 6 additions & 3 deletions lib/src/private/util/client_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ abstract class ClientBase {
/// Connects to the specified server.
///
/// Specify [isSecure] if you do not want to connect to a secure service.
Future<ConnectionInfo> connectToServer(String host, int port,
{bool isSecure = true,
Duration timeout = const Duration(seconds: 10)}) async {
Future<ConnectionInfo> connectToServer(
String host,
int port, {
bool isSecure = true,
Duration timeout = const Duration(seconds: 10),
}) async {
logApp('connecting to server $host:$port - '
'secure: $isSecure, timeout: $timeout');
connectionInfo = ConnectionInfo(host, port, isSecure: isSecure);
Expand Down

0 comments on commit 0d4b83a

Please sign in to comment.