Skip to content

Commit

Permalink
chore: improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-virkus committed Jan 21, 2024
1 parent 70a0e36 commit cec51a5
Show file tree
Hide file tree
Showing 59 changed files with 977 additions and 643 deletions.
1 change: 1 addition & 0 deletions lib/src/imap/imap_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,7 @@ class ImapClient extends ClientBase {
responseTimeout: defaultResponseTimeout,
);
final result = await sendCommand<Mailbox?>(cmd, NoopParser(this, box));

return result ?? box;
}

Expand Down
37 changes: 27 additions & 10 deletions lib/src/mail/mail_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,37 @@ class MailException implements Exception {
MailException(this.mailClient, this.message, {this.stackTrace, this.details});

/// Creates a new exception from the low level one
MailException.fromImap(MailClient mailClient, ImapException e,
[StackTrace? s])
: this(mailClient, '${e.imapClient.logName}: ${e.message}',
stackTrace: s ?? e.stackTrace, details: e.details);
MailException.fromImap(
MailClient mailClient,
ImapException e, [
StackTrace? s,
]) : this(
mailClient,
'${e.imapClient.logName}: ${e.message}',
stackTrace: s ?? e.stackTrace,
details: e.details,
);

/// Creates a new exception from the low level one
MailException.fromPop(MailClient mailClient, PopException e, [StackTrace? s])
: this(mailClient, '${e.popClient.logName}: ${e.message}',
stackTrace: s ?? e.stackTrace, details: e.response);
: this(
mailClient,
'${e.popClient.logName}: ${e.message}',
stackTrace: s ?? e.stackTrace,
details: e.response,
);

/// Creates a new exception from the low level one
MailException.fromSmtp(MailClient mailClient, SmtpException e,
[StackTrace? s])
: this(mailClient, '${e.smtpClient.logName}: ${e.message}',
stackTrace: s ?? e.stackTrace, details: e.response);
MailException.fromSmtp(
MailClient mailClient,
SmtpException e, [
StackTrace? s,
]) : this(
mailClient,
'${e.smtpClient.logName}: ${e.message}',
stackTrace: s ?? e.stackTrace,
details: e.response,
);

/// The originating mail client
final MailClient mailClient;
Expand Down Expand Up @@ -49,6 +65,7 @@ class MailException implements Exception {
..write('\n')
..write(stackTrace);
}

return buffer.toString();
}
}
4 changes: 2 additions & 2 deletions lib/src/mail_conventions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ This is no guarantee that the message has been read or understood.''';
'RES', // Portuguese
'Odp', // Polnish
'YNT', // Turkish
'ATB' // Welsh
'ATB', // Welsh
];

/// Common abbreviations in subject header for forwarded messages,
Expand Down Expand Up @@ -97,7 +97,7 @@ This is no guarantee that the message has been read or understood.''';
'ENC', // Portuguese
'PD', // Polnish
'İLT', // Turkish
'YML' // Welsh
'YML', // Welsh
];
// cSpell:enable

Expand Down
9 changes: 8 additions & 1 deletion lib/src/media_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,11 @@ class MediaType {
final topText = lcText.substring(0, splitPos);
final top = _topLevelByMimeName[topText] ?? MediaToptype.other;
final sub = _subtypesByMimeType[lcText] ?? MediaSubtype.other;

return MediaType(lcText, top, sub);
} else {
final top = _topLevelByMimeName[lcText] ?? MediaToptype.other;

return MediaType(lcText, top, MediaSubtype.other);
}
}
Expand All @@ -317,12 +319,14 @@ class MediaType {
if (splitPos != -1) {
final topText = key.substring(0, splitPos);
final top = _topLevelByMimeName[topText] ?? MediaToptype.other;

return MediaType(key, top, subtype);
}
break;
}
}
print('Error: unable to resolve media subtype $subtype');

return MediaType('example/example', MediaToptype.other, subtype);
}

Expand All @@ -336,8 +340,10 @@ class MediaType {
final lastDotIndex = fileNameOrPath.lastIndexOf('.');
if (lastDotIndex != -1 && lastDotIndex < fileNameOrPath.length - 1) {
final ext = fileNameOrPath.substring(lastDotIndex + 1).toLowerCase();

return MediaType.guessFromFileExtension(ext);
}

return MediaSubtype.applicationOctetStream.mediaType;
}

Expand Down Expand Up @@ -382,6 +388,7 @@ class MediaType {
case 'zip':
return MediaSubtype.applicationZip.mediaType;
}

return MediaSubtype.applicationOctetStream.mediaType;
}
// cSpell:enable
Expand Down Expand Up @@ -492,7 +499,7 @@ class MediaType {
'font/ttf': MediaSubtype.fontTtf,
'font/woff': MediaSubtype.fontWoff,
'font/woff2': MediaSubtype.fontWoff2,
'font/collection': MediaSubtype.fontCollection
'font/collection': MediaSubtype.fontCollection,
};
// cSpell:enable

Expand Down
6 changes: 5 additions & 1 deletion lib/src/pop/pop_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class PopClient extends ClientBase {

@override
FutureOr<void> onConnectionEstablished(
ConnectionInfo connectionInfo, String serverGreeting) {
ConnectionInfo connectionInfo,
String serverGreeting,
) {
if (serverGreeting.startsWith('+OK')) {
final chunks = serverGreeting.split(' ');
serverInfo = PopServerInfo(chunks.last.trimRight());
Expand All @@ -91,6 +93,7 @@ class PopClient extends ClientBase {
final currentLine = _currentFirstResponseLine;
if (currentLine != null && currentLine.startsWith('-ERR')) {
onServerResponse([currentLine]);

return;
}
if (_currentCommand?.isMultiLine ?? false) {
Expand Down Expand Up @@ -179,6 +182,7 @@ class PopClient extends ClientBase {
_currentCommand = command;
_currentFirstResponseLine = null;
writeText(command.command, command);

return command.completer.future;
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/pop/pop_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class PopException implements Exception {
..write('\n')
..write(stackTrace);
}

return buffer.toString();
}
}
1 change: 1 addition & 0 deletions lib/src/private/imap/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Command {
}
final nextPart = parts[_currentPartIndex];
_currentPartIndex++;

return nextPart;
}
}
Expand Down
11 changes: 9 additions & 2 deletions lib/src/private/imap/enable_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,28 @@ class EnableParser extends ResponseParser<List<Capability>> {

@override
List<Capability>? parse(
ImapResponse imapResponse, Response<List<Capability>> response) {
ImapResponse imapResponse,
Response<List<Capability>> response,
) {
if (response.isOkStatus) {
return info.enabledCapabilities;
}

return null;
}

@override
bool parseUntagged(
ImapResponse imapResponse, Response<List<Capability>>? response) {
ImapResponse imapResponse,
Response<List<Capability>>? response,
) {
final line = imapResponse.parseText;
if (line.startsWith('ENABLED ')) {
parseCapabilities(line, 'ENABLED '.length);

return true;
}

return super.parseUntagged(imapResponse, response);
}

Expand Down
11 changes: 10 additions & 1 deletion lib/src/private/imap/generic_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class GenericParser extends ResponseParser<GenericImapResult> {
final GenericImapResult _result = GenericImapResult();
@override
GenericImapResult parse(
ImapResponse imapResponse, Response<GenericImapResult> response) {
ImapResponse imapResponse,
Response<GenericImapResult> response,
) {
final text = imapResponse.parseText;
final startIndex = text.indexOf('[');
if (startIndex != -1 && startIndex < text.length - 2) {
Expand All @@ -35,6 +37,7 @@ class GenericParser extends ResponseParser<GenericImapResult> {
}
}
_result.details ??= text;

return _result;
}

Expand All @@ -46,15 +49,18 @@ class GenericParser extends ResponseParser<GenericImapResult> {
final text = imapResponse.parseText;
if (text.startsWith('NO ')) {
_result.warnings.add(ImapWarning('NO', text.substring('NO '.length)));

return true;
} else if (text.startsWith('BAD ')) {
_result.warnings.add(ImapWarning('BAD', text.substring('BAD '.length)));

return true;
} else if (text.startsWith('OK [COPYUID')) {
final endIndex = text.lastIndexOf(']');
if (endIndex != -1) {
_result.responseCode = text.substring('OK ['.length, endIndex);
}

return true;
} else if (text.endsWith('EXPUNGE')) {
// this is the expunge response for a MOVE operation, ignore
Expand All @@ -78,6 +84,7 @@ class GenericParser extends ResponseParser<GenericImapResult> {
),
);
}

return true;
} else if (text.endsWith('RECENT')) {
// a message has been added to the current mailbox,
Expand All @@ -93,8 +100,10 @@ class GenericParser extends ResponseParser<GenericImapResult> {
),
);
}

return true;
}

return super.parseUntagged(imapResponse, response);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/src/private/imap/id_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class IdParser extends ResponseParser<Id?> {
if (response.isOkStatus) {
return _id;
}

return null;
}

Expand All @@ -20,9 +21,11 @@ class IdParser extends ResponseParser<Id?> {
final text = imapResponse.parseText;
if (text.startsWith('ID ')) {
_id = Id.fromText(text.substring('ID '.length));

return true;
} else if (text.startsWith('* ID ')) {
_id = Id.fromText(text.substring('* ID '.length));

return true;
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/private/imap/imap_response_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ImapResponseLine {
/// Does this line have a [literal] data indicator?
bool get isWithLiteral {
final literal = this.literal;

return literal != null && literal >= 0;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/src/private/imap/logout_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class LogoutParser extends ResponseParser<String> {
bool parseUntagged(ImapResponse imapResponse, Response<String>? response) {
if (imapResponse.parseText.startsWith('BYE')) {
_bye = imapResponse.parseText;

return true;
}

return super.parseUntagged(imapResponse, response);
}
}
12 changes: 10 additions & 2 deletions lib/src/private/imap/noop_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ class NoopParser extends ResponseParser<Mailbox?> {
final highestModSequenceIndex =
imapResponse.parseText.indexOf('[HIGHESTMODSEQ ');
if (highestModSequenceIndex != -1) {
box.highestModSequence = ParserHelper.parseInt(imapResponse.parseText,
highestModSequenceIndex + '[HIGHESTMODSEQ '.length, ']');
box.highestModSequence = ParserHelper.parseInt(
imapResponse.parseText,
highestModSequenceIndex + '[HIGHESTMODSEQ '.length,
']',
);
}
}

return response.isOkStatus ? box : null;
}

Expand Down Expand Up @@ -78,6 +82,7 @@ class NoopParser extends ResponseParser<Mailbox?> {
),
);
}

return true;
} else {
if (_fetchParser.parseUntagged(imapResponse, _fetchResponse)) {
Expand All @@ -93,6 +98,7 @@ class NoopParser extends ResponseParser<Mailbox?> {
),
);
}

return true;
}
}
Expand All @@ -101,8 +107,10 @@ class NoopParser extends ResponseParser<Mailbox?> {
// a common response in IDLE mode can be "* OK still here" or similar
handled = true;
}

return handled;
}

return true;
}

Expand Down
Loading

0 comments on commit cec51a5

Please sign in to comment.