Skip to content

Commit

Permalink
chore: improve line breaks / code style
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-virkus committed Oct 26, 2023
1 parent 405539a commit b073b7a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/src/codecs/base64_mail_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class Base64MailCodec extends MailCodec {
}
cleaned = buffer.toString();
}

return base64.decode(cleaned);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/src/codecs/mail_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ abstract class MailCodec {

/// Decodes the given binary [text]
static Uint8List decodeBinary(
final String text, final String? transferEncoding) {
final String text,
final String? transferEncoding,
) {
final tEncoding = transferEncoding ?? contentTransferEncodingNone;
final decoder = _binaryDecodersByName[tEncoding.toLowerCase()];
if (decoder == null) {
Expand Down
1 change: 1 addition & 0 deletions lib/src/mail/mail_authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class OauthToken {
if (json['created'] == null) {
json['created'] = DateTime.now().toUtc().toIso8601String();
}

return OauthToken.fromJson(json);
}

Expand Down
28 changes: 19 additions & 9 deletions lib/src/mime_data.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:collection/collection.dart' show IterableExtension;

import 'codecs/mail_codec.dart';
import 'mime_message.dart';
import 'private/imap/parser_helper.dart';
Expand Down Expand Up @@ -252,7 +254,9 @@ class BinaryMimeData extends MimeData {
}

List<BinaryMimeData> _splitAndParse(
final String boundaryText, final Uint8List bodyData) {
final String boundaryText,
final Uint8List bodyData,
) {
final boundary = '--$boundaryText\r\n'.codeUnits;
final result = <BinaryMimeData>[];
// end is expected to be \r\n for all but the last one, where -- is expected, possibly followed by \r\n
Expand Down Expand Up @@ -300,18 +304,22 @@ class BinaryMimeData extends MimeData {
}
}
}

return result;
}

@override
String decodeText(
ContentTypeHeader? contentTypeHeader, String? contentTransferEncoding) {
if (_bodyStartIndex == null) {
return '';
}
return MailCodec.decodeAsText(
_bodyData, contentTransferEncoding, contentTypeHeader?.charset);
}
ContentTypeHeader? contentTypeHeader,
String? contentTransferEncoding,
) =>
_bodyStartIndex == null
? ''
: MailCodec.decodeAsText(
_bodyData,
contentTransferEncoding,
contentTypeHeader?.charset,
);

@override
Uint8List decodeBinary(String? contentTransferEncoding) {
Expand All @@ -326,7 +334,8 @@ class BinaryMimeData extends MimeData {
// even with a 'binary' content transfer encoding there are \r\n
// characters that need to be handled,
// so translate to text first
final dataText = String.fromCharCodes(_bodyData);
final dataText = utf8.decode(_bodyData);

return MailCodec.decodeBinary(dataText, contentTransferEncodingLC);
}

Expand All @@ -353,6 +362,7 @@ class BinaryMimeData extends MimeData {
}
// the whole data is just headers:
final headerLines = String.fromCharCodes(headerData).split('\r\n');

return ParserHelper.parseHeaderLines(headerLines).headersList;
}

Expand Down

0 comments on commit b073b7a

Please sign in to comment.