diff --git a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart index 8831a9a8..1c6bd86d 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -51,6 +51,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { result.add(chunkData); startIndex += chunkSize; } + return result; } @@ -58,11 +59,14 @@ class _SmtpSendBdatCommand extends SmtpCommand { String get command { if (supportUnicode) { print('supportUnicode $supportUnicode'); + // cSpell:ignore SMTPUTF8 + return 'MAIL FROM:<$fromEmail> SMTPUTF8'; } if (use8BitEncoding) { return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } + return 'MAIL FROM:<$fromEmail>'; } @@ -74,13 +78,18 @@ class _SmtpSendBdatCommand extends SmtpCommand { _currentStep = _BdatSequence.rcptTo; _recipientIndex++; return SmtpCommandData( - _getRecipientToCommand(recipientEmails[0]), null); + _getRecipientToCommand(recipientEmails[0]), + null, + ); case _BdatSequence.rcptTo: final index = _recipientIndex; if (index < recipientEmails.length) { _recipientIndex++; + return SmtpCommandData( - _getRecipientToCommand(recipientEmails[index]), null); + _getRecipientToCommand(recipientEmails[index]), + null, + ); } else if (response.type == SmtpResponseType.success) { return _getCurrentChunk(); } else { @@ -99,6 +108,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { if (_chunkIndex >= _chunks.length) { _currentStep = _BdatSequence.done; } + return SmtpCommandData(null, chunk); } @@ -109,6 +119,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { if (_currentStep == _BdatSequence.bdat) { return response.code == 354; } + return (response.type != SmtpResponseType.success) || (_currentStep == _BdatSequence.done); } @@ -147,13 +158,14 @@ class SmtpSendBdatMailDataCommand extends _SmtpSendBdatCommand { required bool use8BitEncoding, required bool supportUnicode, }) : super( - () => data - .toString() - .replaceAll(RegExp('^Bcc:.*\r\n', multiLine: true), ''), - from.email, - recipientEmails, - use8BitEncoding: use8BitEncoding, - supportUnicode: supportUnicode); + () => data + .toString() + .replaceAll(RegExp('^Bcc:.*\r\n', multiLine: true), ''), + from.email, + recipientEmails, + use8BitEncoding: use8BitEncoding, + supportUnicode: supportUnicode, + ); /// The message data to be sent final MimeData data; @@ -168,8 +180,13 @@ class SmtpSendBdatMailTextCommand extends _SmtpSendBdatCommand { List recipientEmails, { required bool use8BitEncoding, required bool supportUnicode, - }) : super(() => data, from.email, recipientEmails, - use8BitEncoding: use8BitEncoding, supportUnicode: supportUnicode); + }) : super( + () => data, + from.email, + recipientEmails, + use8BitEncoding: use8BitEncoding, + supportUnicode: supportUnicode, + ); /// The message text data final String data; diff --git a/test/message_builder_test.dart b/test/message_builder_test.dart index 8c415f61..583e91fd 100644 --- a/test/message_builder_test.dart +++ b/test/message_builder_test.dart @@ -189,29 +189,42 @@ void main() { const from = MailAddress('Personal Name', 'sender@domain.com'); final to = [ const MailAddress('Recipient Personal Name', 'recipient@domain.com'), - const MailAddress('Other Recipient', 'other@domain.com') + const MailAddress('Other Recipient', 'other@domain.com'), ]; const subject = 'Hello from test'; const text = 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.'; - final message = MessageBuilder.buildSimpleTextMessage(from, to, text, - subject: subject, isChat: true, chatGroupId: '1234abc123'); + final message = MessageBuilder.buildSimpleTextMessage( + from, + to, + text, + subject: subject, + isChat: true, + chatGroupId: '1234abc123', + ); expect(message.getHeaderValue('subject'), 'Hello from test'); var id = message.getHeaderValue('message-id') ?? ''; expect(id, isNotNull); expect(id.startsWith(''); expect( - message.getHeaderValue('to'), - '"Recipient Personal Name" , ' - '"Other Recipient" '); - expect(message.getHeaderValue('Content-Type'), - 'text/plain; charset="utf-8"'); - expect(message.getHeaderValue('Content-Transfer-Encoding'), - 'quoted-printable'); + message.getHeaderValue('from'), + '"Personal Name" ', + ); + expect( + message.getHeaderValue('to'), + '"Recipient Personal Name" , ' + '"Other Recipient" ', + ); + expect( + message.getHeaderValue('Content-Type'), + 'text/plain; charset="utf-8"', + ); + expect( + message.getHeaderValue('Content-Transfer-Encoding'), + 'quoted-printable', + ); final buffer = StringBuffer(); message.render(buffer); @@ -225,7 +238,9 @@ void main() { expect(id.startsWith(''); + parsed.getHeaderValue('from'), + '"Personal Name" ', + ); final toRecipients = parsed.decodeHeaderMailAddressValue('to') ?? []; expect(toRecipients, isNotNull); expect(toRecipients.length, 2); @@ -238,13 +253,18 @@ void main() { expect(toRecipients[1].mailboxName, 'other'); expect(toRecipients[1].personalName, 'Other Recipient'); expect( - parsed.getHeaderValue('Content-Type'), 'text/plain; charset="utf-8"'); - expect(parsed.getHeaderValue('Content-Transfer-Encoding'), - 'quoted-printable'); + parsed.getHeaderValue('Content-Type'), + 'text/plain; charset="utf-8"', + ); expect( - parsed.decodeContentText(), - 'Hello World - here\s some text that should spans two lines in the ' - 'end when this sentence is finished.'); + parsed.getHeaderValue('Content-Transfer-Encoding'), + 'quoted-printable', + ); + expect( + parsed.decodeContentText(), + 'Hello World - here\s some text that should spans two lines in the ' + 'end when this sentence is finished.', + ); }); }); @@ -254,7 +274,7 @@ void main() { ..from = [const MailAddress('Personal Name', 'sender@domain.com')] ..to = [ const MailAddress('Recipient Personal Name', 'recipient@domain.com'), - const MailAddress('Other Recipient', 'other@domain.com') + const MailAddress('Other Recipient', 'other@domain.com'), ] ..addTextPlain('Hello world!') ..addTextHtml('

Hello world!

'); @@ -262,15 +282,21 @@ void main() { final rendered = message.renderMessage(); //print(rendered); final parsed = MimeMessage.parseFromText(rendered); - expect(parsed.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartAlternative); + expect( + parsed.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); expect(parsed.parts, isNotNull); expect(parsed.parts?.length, 2); - expect(parsed.parts?[0].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); + expect( + parsed.parts?[0].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); expect(parsed.parts?[0].decodeContentText(), 'Hello world!\r\n'); - expect(parsed.parts?[1].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textHtml); + expect( + parsed.parts?[1].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textHtml, + ); expect(parsed.parts?[1].decodeContentText(), '

Hello world!

\r\n'); }); @@ -279,10 +305,11 @@ void main() { ..from = [const MailAddress('Personal Name', 'sender@domain.com')] ..to = [ const MailAddress('Recipient Personal Name', 'recipient@domain.com'), - const MailAddress('Other Recipient', 'other@domain.com') + const MailAddress('Other Recipient', 'other@domain.com'), ] ..addTextPlain('Hello world!') - ..addText(''' + ..addText( + ''' BEGIN:VCARD\r VERSION:4.0\r UID:urn:uuid:4fbe8971-0bc3-424c-9c26-36c3e1eff6b1\r @@ -297,24 +324,32 @@ CLIENTPIDMAP:1;urn:uuid:53e374d9-337e-4727-8803-a1e9c14e0556\r CLIENTPIDMAP:2;urn:uuid:1f762d2b-03c4-4a83-9a03-75ff658a6eee\r END:VCARD\r ''', - mediaType: MediaSubtype.textVcard.mediaType, - disposition: ContentDispositionHeader.from( - ContentDisposition.attachment, - filename: 'contact.vcard')); + mediaType: MediaSubtype.textVcard.mediaType, + disposition: ContentDispositionHeader.from( + ContentDisposition.attachment, + filename: 'contact.vcard', + ), + ); final message = builder.buildMimeMessage(); final rendered = message.renderMessage(); //print(rendered); final parsed = MimeMessage.parseFromText(rendered); - expect(parsed.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartMixed); + expect( + parsed.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartMixed, + ); expect(parsed.parts, isNotNull); expect(parsed.parts?.length, 2); - expect(parsed.parts?[0].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); + expect( + parsed.parts?[0].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); expect(parsed.parts?[0].decodeContentText(), 'Hello world!\r\n'); - expect(parsed.parts?[1].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textVcard); + expect( + parsed.parts?[1].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textVcard, + ); final disposition = parsed.parts?[1].getHeaderContentDisposition(); expect(disposition, isNotNull); expect(disposition?.disposition, ContentDisposition.attachment); @@ -392,7 +427,7 @@ END:VCARD\r ..from = [const MailAddress('Personal Name', 'sender@domain.com')] ..to = [ const MailAddress('Recipient Personal Name', 'recipient@domain.com'), - const MailAddress('Other Recipient', 'other@domain.com') + const MailAddress('Other Recipient', 'other@domain.com'), ] ..addTextPlain('Hello world!') ..addText( @@ -413,26 +448,35 @@ END:VCARD\r ''', mediaType: MediaSubtype.textVcard.mediaType, disposition: ContentDispositionHeader.from( - ContentDisposition.attachment, - filename: 'contact.vcard'), + ContentDisposition.attachment, + filename: 'contact.vcard', + ), ) - ..addBinary(Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), - MediaSubtype.imageJpeg.mediaType, - filename: 'helloworld.jpg'); + ..addBinary( + Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), + MediaSubtype.imageJpeg.mediaType, + filename: 'helloworld.jpg', + ); final message = builder.buildMimeMessage(); final rendered = message.renderMessage(); //print(rendered); final parsed = MimeMessage.parseFromText(rendered); - expect(parsed.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartMixed); + expect( + parsed.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartMixed, + ); expect(parsed.parts, isNotNull); expect(parsed.parts?.length, 3); - expect(parsed.parts?[0].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); + expect( + parsed.parts?[0].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); expect(parsed.parts?[0].decodeContentText(), 'Hello world!\r\n'); - expect(parsed.parts?[1].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textVcard); + expect( + parsed.parts?[1].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textVcard, + ); var disposition = parsed.parts?[1].getHeaderContentDisposition(); expect(disposition, isNotNull); expect(disposition?.disposition, ContentDisposition.attachment); @@ -453,64 +497,93 @@ CLIENTPIDMAP:2;urn:uuid:1f762d2b-03c4-4a83-9a03-75ff658a6eee\r END:VCARD\r \r '''); - expect(parsed.parts?[2].getHeaderContentType()?.mediaType.sub, - MediaSubtype.imageJpeg); - expect(parsed.parts?[2].getHeaderContentType()?.parameters['name'], - 'helloworld.jpg'); + expect( + parsed.parts?[2].getHeaderContentType()?.mediaType.sub, + MediaSubtype.imageJpeg, + ); + expect( + parsed.parts?[2].getHeaderContentType()?.parameters['name'], + 'helloworld.jpg', + ); disposition = parsed.parts?[2].getHeaderContentDisposition(); expect(disposition, isNotNull); expect(disposition?.disposition, ContentDisposition.attachment); expect(disposition?.filename, 'helloworld.jpg'); - expect(parsed.parts?[2].decodeContentBinary(), - Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])); + expect( + parsed.parts?[2].decodeContentBinary(), + Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), + ); }); test( - 'implicit multipart/mixed with binary attachment and both plain and html text', - () { - final builder = MessageBuilder() - ..from = [const MailAddress('Personal Name', 'sender@domain.com')] - ..to = [ - const MailAddress('Recipient Personal Name', 'recipient@domain.com'), - const MailAddress('Other Recipient', 'other@domain.com') - ] - ..addMultipartAlternative( - plainText: 'Hello world!', - htmlText: '

Hello world!

', - ) - ..addBinary(Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), + 'implicit multipart/mixed with binary attachment and both plain and html text', + () { + final builder = MessageBuilder() + ..from = [const MailAddress('Personal Name', 'sender@domain.com')] + ..to = [ + const MailAddress( + 'Recipient Personal Name', + 'recipient@domain.com', + ), + const MailAddress('Other Recipient', 'other@domain.com'), + ] + ..addMultipartAlternative( + plainText: 'Hello world!', + htmlText: '

Hello world!

', + ) + ..addBinary( + Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), MediaSubtype.imageJpeg.mediaType, - filename: 'helloworld.jpg'); + filename: 'helloworld.jpg', + ); + + final message = builder.buildMimeMessage(); + final rendered = message.renderMessage(); + //print(rendered); + final parsed = MimeMessage.parseFromText(rendered); + expect( + parsed.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartMixed, + ); + expect(parsed.parts, isNotNull); + expect(parsed.parts?.length, 2); + expect( + parsed.parts?[0].getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect(parsed.parts?[0].parts?.length, 2); + expect( + parsed.parts?[0].parts?[0].mediaType.sub, + MediaSubtype.textPlain, + ); + expect( + parsed.parts?[0].parts?[0].decodeContentText(), + 'Hello world!\r\n', + ); + expect(parsed.parts?[0].parts?[1].mediaType.sub, MediaSubtype.textHtml); + expect( + parsed.parts?[0].parts?[1].decodeContentText(), + '

Hello world!

\r\n', + ); - final message = builder.buildMimeMessage(); - final rendered = message.renderMessage(); - //print(rendered); - final parsed = MimeMessage.parseFromText(rendered); - expect(parsed.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartMixed); - expect(parsed.parts, isNotNull); - expect(parsed.parts?.length, 2); - expect(parsed.parts?[0].getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartAlternative); - expect(parsed.parts?[0].parts?.length, 2); - expect(parsed.parts?[0].parts?[0].mediaType.sub, MediaSubtype.textPlain); - expect( - parsed.parts?[0].parts?[0].decodeContentText(), 'Hello world!\r\n'); - expect(parsed.parts?[0].parts?[1].mediaType.sub, MediaSubtype.textHtml); - expect(parsed.parts?[0].parts?[1].decodeContentText(), - '

Hello world!

\r\n'); - - expect(parsed.parts?[1].getHeaderContentType()?.mediaType.sub, - MediaSubtype.imageJpeg); - expect(parsed.parts?[1].getHeaderContentType()?.parameters['name'], - 'helloworld.jpg'); - final disposition = parsed.parts?[1].getHeaderContentDisposition(); - expect(disposition, isNotNull); - expect(disposition?.disposition, ContentDisposition.attachment); - expect(disposition?.filename, 'helloworld.jpg'); - expect(parsed.parts?[1].decodeContentBinary(), - Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])); - }); + expect( + parsed.parts?[1].getHeaderContentType()?.mediaType.sub, + MediaSubtype.imageJpeg, + ); + expect( + parsed.parts?[1].getHeaderContentType()?.parameters['name'], + 'helloworld.jpg', + ); + final disposition = parsed.parts?[1].getHeaderContentDisposition(); + expect(disposition, isNotNull); + expect(disposition?.disposition, ContentDisposition.attachment); + expect(disposition?.filename, 'helloworld.jpg'); + expect( + parsed.parts?[1].decodeContentBinary(), + Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), + ); + }, + ); }); group('reply', () { @@ -518,7 +591,7 @@ END:VCARD\r const from = MailAddress('Personal Name', 'sender@domain.com'); final to = [ const MailAddress('Me', 'recipient@domain.com'), - const MailAddress('Group Member', 'group.member@domain.com') + const MailAddress('Group Member', 'group.member@domain.com'), ]; final cc = [const MailAddress('One möre', 'one.more@domain.com')]; const subject = 'Hello from test'; @@ -526,8 +599,12 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); @@ -542,13 +619,18 @@ END:VCARD\r expect(message.getHeaderValue('date'), isNotNull); expect(message.getHeaderValue('from'), '"Me" '); expect( - message.getHeaderValue('to'), - '"Personal Name" , "Group Member" ' - ''); - expect(message.getHeaderValue('cc'), - '"=?utf8?Q?One_m=C3=B6re?=" '); - expect(message.getHeaderValue('Content-Type'), - 'text/plain; charset="utf-8"'); + message.getHeaderValue('to'), + '"Personal Name" , "Group Member" ' + '', + ); + expect( + message.getHeaderValue('cc'), + '"=?utf8?Q?One_m=C3=B6re?=" ', + ); + expect( + message.getHeaderValue('Content-Type'), + 'text/plain; charset="utf-8"', + ); expect(message.getHeaderValue('Content-Transfer-Encoding'), '7bit'); expect(message.decodeContentText(), 'Here is my reply'); }); @@ -562,15 +644,20 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in ' 'the end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); final replyBuilder = MessageBuilder.prepareReplyToMessage( - originalMessage, to.first, - replyAll: false) - ..text = 'Here is my reply'; + originalMessage, + to.first, + replyAll: false, + )..text = 'Here is my reply'; final message = replyBuilder.buildMimeMessage(); // print('reply:'); // print(message.renderMessage()); @@ -579,7 +666,9 @@ END:VCARD\r expect(message.getHeaderValue('date'), isNotNull); expect(message.getHeaderValue('from'), '"Me" '); expect( - message.getHeaderValue('to'), '"Personal Name" '); + message.getHeaderValue('to'), + '"Personal Name" ', + ); expect(message.getHeaderValue('cc'), null); }); @@ -587,7 +676,7 @@ END:VCARD\r const from = MailAddress('Personal Name', 'sender@domain.com'); final to = [ const MailAddress('Me', 'recipient@domain.com'), - const MailAddress('Group Member', 'group.member@domain.com') + const MailAddress('Group Member', 'group.member@domain.com'), ]; final cc = [const MailAddress('One möre', 'one.more@domain.com')]; const subject = 'Hello from test'; @@ -595,15 +684,20 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in ' 'the end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); final replyBuilder = MessageBuilder.prepareReplyToMessage( - originalMessage, to.first, - replyAll: false) - ..text = 'Here is my reply'; + originalMessage, + to.first, + replyAll: false, + )..text = 'Here is my reply'; final message = replyBuilder.buildMimeMessage(); // print('reply:'); // print(message.renderMessage()); @@ -612,7 +706,9 @@ END:VCARD\r expect(message.getHeaderValue('date'), isNotNull); expect(message.getHeaderValue('from'), '"Me" '); expect( - message.getHeaderValue('to'), '"Personal Name" '); + message.getHeaderValue('to'), + '"Personal Name" ', + ); expect(message.getHeaderValue('cc'), null); }); @@ -625,14 +721,20 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); final replyBuilder = MessageBuilder.prepareReplyToMessage( - originalMessage, to.first, - quoteOriginalText: true); + originalMessage, + to.first, + quoteOriginalText: true, + ); replyBuilder.text = 'Here is my reply\r\n${replyBuilder.text}'; final message = replyBuilder.buildMimeMessage(); // print('reply:'); @@ -642,23 +744,33 @@ END:VCARD\r expect(message.getHeaderValue('date'), isNotNull); expect(message.getHeaderValue('from'), '"Me" '); expect( - message.getHeaderValue('to'), '"Personal Name" '); - expect(message.getHeaderValue('cc'), - '"=?utf8?Q?One_m=C3=B6re?=" '); - expect(message.getHeaderValue('Content-Type'), - 'text/plain; charset="utf-8"'); + message.getHeaderValue('to'), + '"Personal Name" ', + ); + expect( + message.getHeaderValue('cc'), + '"=?utf8?Q?One_m=C3=B6re?=" ', + ); + expect( + message.getHeaderValue('Content-Type'), + 'text/plain; charset="utf-8"', + ); expect( message.getHeaderValue('Content-Transfer-Encoding'), 'quoted-printable', ); const expectedStart = 'Here is my reply\r\n>On '; - expect(message.decodeContentText()?.substring(0, expectedStart.length), - expectedStart); + expect( + message.decodeContentText()?.substring(0, expectedStart.length), + expectedStart, + ); const expectedEnd = 'sentence is finished.\r\n>'; expect( - message.decodeContentText()?.substring( - message.decodeContentText()?.length ?? 0 - expectedEnd.length), - expectedEnd); + message.decodeContentText()?.substring( + (message.decodeContentText()?.length ?? 0) - expectedEnd.length, + ), + expectedEnd, + ); }); test('reply multipart text msg with quote', () { @@ -682,8 +794,10 @@ END:VCARD\r // print(originalMessage.renderMessage()); final replyBuilder = MessageBuilder.prepareReplyToMessage( - originalMessage, to.first, - quoteOriginalText: true); + originalMessage, + to.first, + quoteOriginalText: true, + ); final textPlain = replyBuilder.getTextPlainPart(); expect(textPlain, isNotNull); textPlain?.text = 'Here is my reply.\r\n${textPlain.text}'; @@ -698,18 +812,26 @@ END:VCARD\r expect(message.getHeaderValue('date'), isNotNull); expect(message.getHeaderValue('from'), '"Me" '); expect( - message.getHeaderValue('to'), '"Personal Name" '); - expect(message.getHeaderValue('cc'), - '"=?utf8?Q?One_m=C3=B6re?=" '); - expect(message.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartAlternative); + message.getHeaderValue('to'), + '"Personal Name" ', + ); + expect( + message.getHeaderValue('cc'), + '"=?utf8?Q?One_m=C3=B6re?=" ', + ); + expect( + message.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); //expect(message.getHeaderValue('Content-Transfer-Encoding'), '8bit'); const expectedStart = 'Here is my reply.\r\n>On '; final plainText = message.decodeTextPlainPart(); expect(plainText?.substring(0, expectedStart.length), expectedStart); const expectedEnd = 'sentence is finished.\r\n>'; - expect(plainText?.substring(plainText.length - expectedEnd.length), - expectedEnd); + expect( + plainText?.substring(plainText.length - expectedEnd.length), + expectedEnd, + ); final html = message.decodeTextHtmlPart(); const expectedStart2 = '

Here is my reply.

\r\n

On '; expect(html?.substring(0, expectedStart2.length), expectedStart2); @@ -726,8 +848,12 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); @@ -735,11 +861,15 @@ END:VCARD\r MessageBuilder.prepareReplyToMessage(originalMessage, from) ..text = 'Here is my reply'; final message = replyBuilder.buildMimeMessage(); - expect(message.getHeaderValue('from'), - '"Personal Name" '); + expect( + message.getHeaderValue('from'), + '"Personal Name" ', + ); expect(message.getHeaderValue('to'), '"Me" '); - expect(message.getHeaderValue('cc'), - '"=?utf8?Q?One_m=C3=B6re?=" '); + expect( + message.getHeaderValue('cc'), + '"=?utf8?Q?One_m=C3=B6re?=" ', + ); }); test('reply to myself with alias', () { @@ -751,21 +881,30 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); - final replyBuilder = MessageBuilder.prepareReplyToMessage(originalMessage, - const MailAddress('Personal Name', 'sender@domain.com'), - aliases: [from]) - ..text = 'Here is my reply'; + final replyBuilder = MessageBuilder.prepareReplyToMessage( + originalMessage, + const MailAddress('Personal Name', 'sender@domain.com'), + aliases: [from], + )..text = 'Here is my reply'; final message = replyBuilder.buildMimeMessage(); expect(message.getHeaderValue('to'), '"Me" '); - expect(message.getHeaderValue('cc'), - '"=?utf8?Q?One_m=C3=B6re?=" '); - expect(message.getHeaderValue('from'), - '"Alias Name" '); + expect( + message.getHeaderValue('cc'), + '"=?utf8?Q?One_m=C3=B6re?=" ', + ); + expect( + message.getHeaderValue('from'), + '"Alias Name" ', + ); }); test('reply to myself with plus alias', () { @@ -777,21 +916,30 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); - final replyBuilder = MessageBuilder.prepareReplyToMessage(originalMessage, - const MailAddress('Personal Name', 'sender@domain.com'), - handlePlusAliases: true) - ..text = 'Here is my reply'; + final replyBuilder = MessageBuilder.prepareReplyToMessage( + originalMessage, + const MailAddress('Personal Name', 'sender@domain.com'), + handlePlusAliases: true, + )..text = 'Here is my reply'; final message = replyBuilder.buildMimeMessage(); expect(message.getHeaderValue('to'), '"Me" '); - expect(message.getHeaderValue('cc'), - '"=?utf8?Q?One_m=C3=B6re?=" '); - expect(message.getHeaderValue('from'), - '"Alias Name" '); + expect( + message.getHeaderValue('cc'), + '"=?utf8?Q?One_m=C3=B6re?=" ', + ); + expect( + message.getHeaderValue('from'), + '"Alias Name" ', + ); }); test('reply simple text msg with alias recognition', () { @@ -803,25 +951,36 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); const replyFrom = MailAddress('Me', 'recipient@domain.com'); final replyBuilder = MessageBuilder.prepareReplyToMessage( - originalMessage, replyFrom, - aliases: [const MailAddress('Me Full', 'recipient.full@domain.com')]) - ..text = 'Here is my reply'; + originalMessage, + replyFrom, + aliases: [const MailAddress('Me Full', 'recipient.full@domain.com')], + )..text = 'Here is my reply'; final message = replyBuilder.buildMimeMessage(); // print('reply:'); // print(message.renderMessage()); - expect(message.getHeaderValue('from'), - '"Me Full" '); expect( - message.getHeaderValue('to'), '"Personal Name" '); - expect(message.getHeaderValue('cc'), - '"=?utf8?Q?One_m=C3=B6re?=" '); + message.getHeaderValue('from'), + '"Me Full" ', + ); + expect( + message.getHeaderValue('to'), + '"Personal Name" ', + ); + expect( + message.getHeaderValue('cc'), + '"=?utf8?Q?One_m=C3=B6re?=" ', + ); }); test('reply simple text msg with +alias recognition', () { @@ -833,25 +992,36 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); const replyFrom = MailAddress('Me', 'recipient@domain.com'); final replyBuilder = MessageBuilder.prepareReplyToMessage( - originalMessage, replyFrom, - handlePlusAliases: true) - ..text = 'Here is my reply'; + originalMessage, + replyFrom, + handlePlusAliases: true, + )..text = 'Here is my reply'; final message = replyBuilder.buildMimeMessage(); // print('reply:'); // print(message.renderMessage()); expect( - message.getHeaderValue('from'), '"Me" '); + message.getHeaderValue('from'), + '"Me" ', + ); + expect( + message.getHeaderValue('to'), + '"Personal Name" ', + ); expect( - message.getHeaderValue('to'), '"Personal Name" '); - expect(message.getHeaderValue('cc'), - '"=?utf8?Q?One_m=C3=B6re?=" '); + message.getHeaderValue('cc'), + '"=?utf8?Q?One_m=C3=B6re?=" ', + ); }); }); group('forward', () { @@ -864,8 +1034,12 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; final originalMessage = MessageBuilder.buildSimpleTextMessage( - from, to, text, - cc: cc, subject: subject); + from, + to, + text, + cc: cc, + subject: subject, + ); // print('original:'); // print(originalMessage.renderMessage()); @@ -873,7 +1047,7 @@ END:VCARD\r MessageBuilder.prepareForwardMessage(originalMessage, from: to.first) ..to = [ const MailAddress('First', 'first@domain.com'), - const MailAddress('Second', 'second@domain.com') + const MailAddress('Second', 'second@domain.com'), ]; forwardBuilder.text = 'This should be interesting:\r\n${forwardBuilder.text}'; @@ -884,24 +1058,34 @@ END:VCARD\r expect(message.getHeaderValue('message-id'), isNotNull); expect(message.getHeaderValue('date'), isNotNull); expect(message.getHeaderValue('from'), '"Me" '); - expect(message.getHeaderValue('to'), - '"First" , "Second" '); - expect(message.getHeaderValue('Content-Type'), - 'text/plain; charset="utf-8"'); - expect(message.getHeaderValue('Content-Transfer-Encoding'), - 'quoted-printable'); + expect( + message.getHeaderValue('to'), + '"First" , "Second" ', + ); + expect( + message.getHeaderValue('Content-Type'), + 'text/plain; charset="utf-8"', + ); + expect( + message.getHeaderValue('Content-Transfer-Encoding'), + 'quoted-printable', + ); const expectedStart = 'This should be interesting:\r\n' '>---------- Original Message ----------\r\n' '>From: "Personal Name" \r\n' '>To: "Me" \r\n' '>CC: "One m=C3=B6re" '; - expect(getRawBodyText(message)?.substring(0, expectedStart.length), - expectedStart); + expect( + getRawBodyText(message)?.substring(0, expectedStart.length), + expectedStart, + ); const expectedEnd = 'sentence is finished.\r\n>'; expect( - getRawBodyText(message)?.substring( - getRawBodyText(message)?.length ?? 0 - expectedEnd.length), - expectedEnd); + getRawBodyText(message)?.substring( + (getRawBodyText(message)?.length ?? 0) - expectedEnd.length, + ), + expectedEnd, + ); }); test('forward multipart text msg', () { @@ -928,7 +1112,7 @@ END:VCARD\r MessageBuilder.prepareForwardMessage(originalMessage, from: to.first) ..to = [ const MailAddress('First', 'first@domain.com'), - const MailAddress('Second', 'second@domain.com') + const MailAddress('Second', 'second@domain.com'), ]; final textPlain = forwardBuilder.getTextPlainPart(); textPlain?.text = 'This should be interesting:\r\n${textPlain.text}'; @@ -941,10 +1125,14 @@ END:VCARD\r expect(message.getHeaderValue('message-id'), isNotNull); expect(message.getHeaderValue('date'), isNotNull); expect(message.getHeaderValue('from'), '"Me" '); - expect(message.getHeaderValue('to'), - '"First" , "Second" '); - expect(message.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartAlternative); + expect( + message.getHeaderValue('to'), + '"First" , "Second" ', + ); + expect( + message.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); const expectedStart = 'This should be interesting:\r\n' '>---------- Original Message ----------\r\n' '>From: "Personal Name" \r\n' @@ -954,8 +1142,10 @@ END:VCARD\r expect(plainText, isNotNull); expect(plainText?.substring(0, expectedStart.length), expectedStart); const expectedEnd = 'sentence is finished.\r\n>'; - expect(plainText?.substring(plainText.length - expectedEnd.length), - expectedEnd); + expect( + plainText?.substring(plainText.length - expectedEnd.length), + expectedEnd, + ); //expect(message.getHeaderValue('Content-Transfer-Encoding'), '8bit'); const expectedStart2 = '

This should be interesting:

\r\n' '
---------- Original Message ----------
\r\n' @@ -966,8 +1156,10 @@ END:VCARD\r expect(htmlText, isNotNull); expect(htmlText?.substring(0, expectedStart2.length), expectedStart2); const expectedEnd2 = 'sentence is finished.\r\n

'; - expect(htmlText?.substring(htmlText.length - expectedEnd2.length), - expectedEnd2); + expect( + htmlText?.substring(htmlText.length - expectedEnd2.length), + expectedEnd2, + ); }); test('forward multipart msg with attachments', () async { @@ -996,7 +1188,7 @@ END:VCARD\r MessageBuilder.prepareForwardMessage(originalMessage, from: to.first) ..to = [ const MailAddress('First', 'first@domain.com'), - const MailAddress('Second', 'second@domain.com') + const MailAddress('Second', 'second@domain.com'), ]; final textPlain = forwardBuilder.getTextPlainPart(); expect(textPlain, isNotNull); @@ -1013,10 +1205,14 @@ END:VCARD\r expect(message.getHeaderValue('message-id'), isNotNull); expect(message.getHeaderValue('date'), isNotNull); expect(message.getHeaderValue('from'), '"Me" '); - expect(message.getHeaderValue('to'), - '"First" , "Second" '); - expect(message.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartAlternative); + expect( + message.getHeaderValue('to'), + '"First" , "Second" ', + ); + expect( + message.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); const expectedStart = 'This should be interesting:\r\n' '>---------- Original Message ----------\r\n' '>From: "Personal Name" \r\n' @@ -1025,8 +1221,10 @@ END:VCARD\r final plainText = message.decodeTextPlainPart(); expect(plainText?.substring(0, expectedStart.length), expectedStart); const expectedEnd = 'sentence is finished.\r\n>'; - expect(plainText?.substring(plainText.length - expectedEnd.length), - expectedEnd); + expect( + plainText?.substring(plainText.length - expectedEnd.length), + expectedEnd, + ); //expect(message.getHeaderValue('Content-Transfer-Encoding'), '8bit'); const expectedStart2 = '

This should be interesting:

\r\n' '
---------- Original Message ----------
\r\n' @@ -1036,8 +1234,10 @@ END:VCARD\r final htmlText = message.decodeTextHtmlPart(); expect(htmlText?.substring(0, expectedStart2.length), expectedStart2); const expectedEnd2 = 'sentence is finished.\r\n

'; - expect(htmlText?.substring(htmlText.length - expectedEnd2.length), - expectedEnd2); + expect( + htmlText?.substring(htmlText.length - expectedEnd2.length), + expectedEnd2, + ); expect(message.parts?.length, 3); final filePart = message.parts?[2]; final dispositionHeader = filePart?.getHeaderContentDisposition(); @@ -1061,7 +1261,8 @@ END:VCARD\r 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; final originalBuilder = MessageBuilder.prepareMessageWithMediaType( - MediaSubtype.multipartMixed) + MediaSubtype.multipartMixed, + ) ..from = [from] ..to = to ..cc = cc @@ -1075,12 +1276,12 @@ END:VCARD\r // print('original:'); // print(originalMessage.renderMessage()); final forwardBuilder = MessageBuilder.prepareForwardMessage( - originalMessage, - from: to.first, - quoteMessage: false) - ..to = [ + originalMessage, + from: to.first, + quoteMessage: false, + )..to = [ const MailAddress('First', 'first@domain.com'), - const MailAddress('Second', 'second@domain.com') + const MailAddress('Second', 'second@domain.com'), ]; // ..addTextPlain(text) // ..addTextHtml('

$text

'); @@ -1092,10 +1293,14 @@ END:VCARD\r expect(message.getHeaderValue('message-id'), isNotNull); expect(message.getHeaderValue('date'), isNotNull); expect(message.getHeaderValue('from'), '"Me" '); - expect(message.getHeaderValue('to'), - '"First" , "Second" '); - expect(message.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartMixed); + expect( + message.getHeaderValue('to'), + '"First" , "Second" ', + ); + expect( + message.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartMixed, + ); expect(message.parts?.length, 1); final filePart = message.parts?[0]; @@ -1120,7 +1325,7 @@ END:VCARD\r ..from = [const MailAddress('Personal Name', 'sender@domain.com')] ..to = [ const MailAddress('Recipient Personal Name', 'recipient@domain.com'), - const MailAddress('Other Recipient', 'other@domain.com') + const MailAddress('Other Recipient', 'other@domain.com'), ] ..addTextPlain('Hello world!'); @@ -1130,15 +1335,21 @@ END:VCARD\r final rendered = message.renderMessage(); //print(rendered); final parsed = MimeMessage.parseFromText(rendered); - expect(parsed.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartMixed); + expect( + parsed.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartMixed, + ); expect(parsed.parts, isNotNull); expect(parsed.parts?.length, 2); - expect(parsed.parts?[0].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); + expect( + parsed.parts?[0].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); expect(parsed.parts?[0].decodeContentText(), 'Hello world!\r\n'); - expect(parsed.parts?[1].getHeaderContentType()?.mediaType.sub, - MediaSubtype.imageJpeg); + expect( + parsed.parts?[1].getHeaderContentType()?.mediaType.sub, + MediaSubtype.imageJpeg, + ); final disposition = parsed.parts?[1].getHeaderContentDisposition(); expect(disposition, isNotNull); expect(disposition?.disposition, ContentDisposition.attachment); @@ -1156,7 +1367,7 @@ END:VCARD\r ..from = [const MailAddress('Personal Name', 'sender@domain.com')] ..to = [ const MailAddress('Recipient Personal Name', 'recipient@domain.com'), - const MailAddress('Other Recipient', 'other@domain.com') + const MailAddress('Other Recipient', 'other@domain.com'), ] ..addTextPlain('Hello world!'); @@ -1166,15 +1377,21 @@ END:VCARD\r final rendered = message.renderMessage(); // print(rendered); final parsed = MimeMessage.parseFromText(rendered); - expect(parsed.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartMixed); + expect( + parsed.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartMixed, + ); expect(parsed.parts, isNotNull); expect(parsed.parts?.length, 2); - expect(parsed.parts?[0].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); + expect( + parsed.parts?[0].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); expect(parsed.parts?[0].decodeContentText(), 'Hello world!\r\n'); - expect(parsed.parts?[1].getHeaderContentType()?.mediaType.sub, - MediaSubtype.imageJpeg); + expect( + parsed.parts?[1].getHeaderContentType()?.mediaType.sub, + MediaSubtype.imageJpeg, + ); final disposition = parsed.parts?[1].getHeaderContentDisposition(); expect(disposition, isNotNull); expect(disposition?.disposition, ContentDisposition.attachment); @@ -1194,7 +1411,7 @@ END:VCARD\r ..from = [const MailAddress('Personal Name', 'sender@domain.com')] ..to = [ const MailAddress('Recipient Personal Name', 'recipient@domain.com'), - const MailAddress('Other Recipient', 'other@domain.com') + const MailAddress('Other Recipient', 'other@domain.com'), ] ..addTextPlain('Hello world!'); final data = Uint8List.fromList([127, 32, 64, 128, 255]); @@ -1203,15 +1420,21 @@ END:VCARD\r final rendered = message.renderMessage(); //print(rendered); final parsed = MimeMessage.parseFromText(rendered); - expect(parsed.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartMixed); + expect( + parsed.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartMixed, + ); expect(parsed.parts, isNotNull); expect(parsed.parts?.length, 2); - expect(parsed.parts?[0].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); + expect( + parsed.parts?[0].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); expect(parsed.parts?[0].decodeContentText(), 'Hello world!\r\n'); - expect(parsed.parts?[1].getHeaderContentType()?.mediaType.sub, - MediaSubtype.imageJpeg); + expect( + parsed.parts?[1].getHeaderContentType()?.mediaType.sub, + MediaSubtype.imageJpeg, + ); final disposition = parsed.parts?[1].getHeaderContentDisposition(); expect(disposition, isNotNull); expect(disposition?.disposition, ContentDisposition.attachment); @@ -1225,29 +1448,43 @@ END:VCARD\r test('createReplySubject', () { expect(MessageBuilder.createReplySubject('Hello'), 'Re: Hello'); expect( - MessageBuilder.createReplySubject('Hello', - defaultReplyAbbreviation: 'AW'), - 'AW: Hello'); + MessageBuilder.createReplySubject( + 'Hello', + defaultReplyAbbreviation: 'AW', + ), + 'AW: Hello', + ); expect(MessageBuilder.createReplySubject('Re: Hello'), 'Re: Hello'); expect(MessageBuilder.createReplySubject('AW: Hello'), 'AW: Hello'); - expect(MessageBuilder.createReplySubject('[External] Re: Hello'), - 'Re: Hello'); - expect(MessageBuilder.createReplySubject('[External] AW: Hello'), - 'AW: Hello'); + expect( + MessageBuilder.createReplySubject('[External] Re: Hello'), + 'Re: Hello', + ); + expect( + MessageBuilder.createReplySubject('[External] AW: Hello'), + 'AW: Hello', + ); }); test('createFowardSubject', () { expect(MessageBuilder.createForwardSubject('Hello'), 'Fwd: Hello'); expect( - MessageBuilder.createForwardSubject('Hello', - defaultForwardAbbreviation: 'WG'), - 'WG: Hello'); + MessageBuilder.createForwardSubject( + 'Hello', + defaultForwardAbbreviation: 'WG', + ), + 'WG: Hello', + ); expect(MessageBuilder.createForwardSubject('Fwd: Hello'), 'Fwd: Hello'); expect(MessageBuilder.createForwardSubject('WG: Hello'), 'WG: Hello'); - expect(MessageBuilder.createForwardSubject('[External] FWD: Hello'), - 'FWD: Hello'); - expect(MessageBuilder.createForwardSubject('[External] Fwd: Hello'), - 'Fwd: Hello'); + expect( + MessageBuilder.createForwardSubject('[External] FWD: Hello'), + 'FWD: Hello', + ); + expect( + MessageBuilder.createForwardSubject('[External] Fwd: Hello'), + 'Fwd: Hello', + ); }); test('createRandomId', () { @@ -1265,23 +1502,28 @@ END:VCARD\r test('fillTemplate', () { const from = MailAddress('Personal Name', 'sender@domain.com'); final to = [ - const MailAddress('Recipient Personal Name', 'recipient@domain.com') + const MailAddress('Recipient Personal Name', 'recipient@domain.com'), ]; const subject = 'Hello from test'; const text = 'Hello World - here\s some text that should spans two lines in the ' 'end when this sentence is finished.\r\n'; - final message = MessageBuilder.buildSimpleTextMessage(from, to, text, - subject: subject); + final message = MessageBuilder.buildSimpleTextMessage( + from, + to, + text, + subject: subject, + ); var template = 'On wrote:'; var filled = MessageBuilder.fillTemplate(template, message); //print(template + ' -> ' + filled); expect(filled.substring(0, 3), 'On '); expect(filled.substring(filled.length - ' wrote:'.length), ' wrote:'); expect( - filled.substring(filled.length - - ' "Personal Name" wrote:'.length), - ' "Personal Name" wrote:'); + filled.substring(filled.length - + ' "Personal Name" wrote:'.length), + ' "Personal Name" wrote:', + ); template = '---------- Original Message ----------\r\n' 'From: \r\n' '[[to To: \r\n]]' @@ -1336,8 +1578,10 @@ END:VCARD\r final mailto = Uri.parse('mailto:recpient@domain.com,another@domain.com'); final builder = MessageBuilder.prepareMailtoBasedMessage(mailto, from); final message = builder.buildMimeMessage(); - expect(message.getHeaderValue('to'), - 'recpient@domain.com, another@domain.com'); + expect( + message.getHeaderValue('to'), + 'recpient@domain.com, another@domain.com', + ); }); test('to, subject, body', () { @@ -1358,25 +1602,30 @@ END:VCARD\r final builder = MessageBuilder.prepareMailtoBasedMessage(mailto, from); final message = builder.buildMimeMessage(); expect(message.getHeaderValue('subject'), 'hello'); - expect(message.getHeaderValue('to'), - 'recpient@domain.com, another@domain.com'); + expect( + message.getHeaderValue('to'), + 'recpient@domain.com, another@domain.com', + ); expect(message.decodeContentText(), 'world'); }); test('address, cc, subject, body, in-reply-to', () { const from = MailAddress('Me', 'me@domain.com'); final mailto = Uri.parse( - 'mailto:recpient@domain.com?cc=another@domain.com&subject=hello' - '%20wörld&body=let%20me%20unsubscribe&in-reply-to=%3C3469A91.D10A' - 'F4C@example.com%3E'); + 'mailto:recpient@domain.com?cc=another@domain.com&subject=hello' + '%20wörld&body=let%20me%20unsubscribe&in-reply-to=%3C3469A91.D10A' + 'F4C@example.com%3E', + ); final builder = MessageBuilder.prepareMailtoBasedMessage(mailto, from); final message = builder.buildMimeMessage(); expect(message.getHeaderValue('subject'), 'hello w=?utf8?Q?=C3=B6?=rld'); expect(message.getHeaderValue('to'), 'recpient@domain.com'); expect(message.getHeaderValue('cc'), 'another@domain.com'); expect(message.decodeContentText(), 'let me unsubscribe'); - expect(message.getHeaderValue('in-reply-to'), - '<3469A91.D10AF4C@example.com>'); + expect( + message.getHeaderValue('in-reply-to'), + '<3469A91.D10AF4C@example.com>', + ); }); }); @@ -1384,12 +1633,16 @@ END:VCARD\r test('add text message', () { const from = MailAddress('Me', 'me@domain.com'); final to = [ - const MailAddress('Recipient Personal Name', 'recipient@domain.com') + const MailAddress('Recipient Personal Name', 'recipient@domain.com'), ]; const subject = 'Original Message'; const text = 'Hello World - this is the original message'; - final original = MessageBuilder.buildSimpleTextMessage(from, to, text, - subject: subject); + final original = MessageBuilder.buildSimpleTextMessage( + from, + to, + text, + subject: subject, + ); final builder = MessageBuilder() ..addMessagePart(original) ..subject = 'message with attached message' @@ -1404,19 +1657,25 @@ END:VCARD\r expect(parts[1].decodeFileName(), 'Original Message.eml'); final embeddedMessage = parts[1].decodeContentMessage(); expect(embeddedMessage, isNotNull); - expect(embeddedMessage?.decodeTextPlainPart(), - 'Hello World - this is the original message'); + expect( + embeddedMessage?.decodeTextPlainPart(), + 'Hello World - this is the original message', + ); }); test('add text message with quotes in subject', () { const from = MailAddress('Me', 'me@domain.com'); final to = [ - const MailAddress('Recipient Personal Name', 'recipient@domain.com') + const MailAddress('Recipient Personal Name', 'recipient@domain.com'), ]; const subject = '"Original" Message'; const text = 'Hello World - this is the original message'; - final original = MessageBuilder.buildSimpleTextMessage(from, to, text, - subject: subject); + final original = MessageBuilder.buildSimpleTextMessage( + from, + to, + text, + subject: subject, + ); final builder = MessageBuilder() ..addMessagePart(original) ..subject = 'message with attached message' @@ -1431,14 +1690,16 @@ END:VCARD\r expect(parts[1].decodeFileName(), '"Original" Message.eml'); final embeddedMessage = parts[1].decodeContentMessage(); expect(embeddedMessage, isNotNull); - expect(embeddedMessage?.decodeTextPlainPart(), - 'Hello World - this is the original message'); + expect( + embeddedMessage?.decodeTextPlainPart(), + 'Hello World - this is the original message', + ); }); test('add multipart/alternative message', () { const from = MailAddress('Me', 'me@domain.com'); final to = [ - const MailAddress('Recipient Personal Name', 'recipient@domain.com') + const MailAddress('Recipient Personal Name', 'recipient@domain.com'), ]; final originalBuilder = MessageBuilder.prepareMultipartAlternativeMessage() @@ -1447,8 +1708,9 @@ END:VCARD\r ..subject = 'Original Message' ..addTextPlain('Hello World - this is the original message') ..addTextHtml( - '

Hello World - this is the original message' - '

'); + '

Hello World - this is the original message' + '

', + ); final original = originalBuilder.buildMimeMessage(); final builder = MessageBuilder() ..addMessagePart(original) @@ -1464,14 +1726,16 @@ END:VCARD\r expect(parts[1].decodeFileName(), 'Original Message.eml'); final embeddedMessage = parts[1].decodeContentMessage(); expect(embeddedMessage, isNotNull); - expect(embeddedMessage?.decodeTextPlainPart(), - 'Hello World - this is the original message\r\n'); + expect( + embeddedMessage?.decodeTextPlainPart(), + 'Hello World - this is the original message\r\n', + ); }); test('add multipart/mixed message', () { const from = MailAddress('Me', 'me@domain.com'); final to = [ - const MailAddress('Recipient Personal Name', 'recipient@domain.com') + const MailAddress('Recipient Personal Name', 'recipient@domain.com'), ]; final originalBuilder = MessageBuilder() ..from = [from] @@ -1480,9 +1744,11 @@ END:VCARD\r ..addTextPlain('Hello World - this is the original message') ..addTextHtml('

Hello World - this is the original ' 'message

') - ..addBinary(Uint8List.fromList([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), - MediaSubtype.applicationOctetStream.mediaType, - filename: 'mydata.bin'); + ..addBinary( + Uint8List.fromList([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), + MediaSubtype.applicationOctetStream.mediaType, + filename: 'mydata.bin', + ); final original = originalBuilder.buildMimeMessage(); final builder = MessageBuilder() ..addMessagePart(original) @@ -1500,25 +1766,32 @@ END:VCARD\r expect(embeddedMessage, isNotNull); expect(embeddedMessage?.mediaType.sub, MediaSubtype.multipartMixed); expect(embeddedMessage?.parts?.length, 3); - expect(embeddedMessage?.decodeTextPlainPart(), - 'Hello World - this is the original message\r\n'); + expect( + embeddedMessage?.decodeTextPlainPart(), + 'Hello World - this is the original message\r\n', + ); expect(embeddedMessage?.parts?.length, 3); - expect(embeddedMessage?.parts?[2].decodeContentBinary(), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]); + expect( + embeddedMessage?.parts?[2].decodeContentBinary(), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], + ); }); test('real world test', () { final original = MimeMessage.parseFromText(complexMessageText); expect( - original.decodeSubject(), - 'Ihre Telekom Mobilfunk RechnungOnline Januar 2021 (Adresse: ' - '1234567 89, Kundenkonto: 123)'); + original.decodeSubject(), + 'Ihre Telekom Mobilfunk RechnungOnline Januar 2021 (Adresse: ' + '1234567 89, Kundenkonto: 123)', + ); final builder = MessageBuilder() ..addMessagePart(original) ..subject = 'message with attached message'; builder.getPart(MediaSubtype.multipartAlternative, recursive: false) ?? builder.addPart( - mediaSubtype: MediaSubtype.multipartAlternative, insert: true) + mediaSubtype: MediaSubtype.multipartAlternative, + insert: true, + ) ..addTextPlain('hello world') ..addTextHtml('

hello world

'); final message = builder.buildMimeMessage(); @@ -1530,39 +1803,52 @@ END:VCARD\r expect(parts[0].parts?[0].decodeContentText(), 'hello world'); expect(parts[1].mediaType.sub, MediaSubtype.messageRfc822); expect( - parts[1].decodeFileName(), - 'Ihre Telekom Mobilfunk RechnungOnline Januar 2021 (Adresse: 1234567 ' - '89, Kundenkonto: 123).eml'); + parts[1].decodeFileName(), + 'Ihre Telekom Mobilfunk RechnungOnline Januar 2021 (Adresse: 1234567 ' + '89, Kundenkonto: 123).eml', + ); final embeddedMessage = parts[1].decodeContentMessage(); expect(embeddedMessage, isNotNull); expect(embeddedMessage?.mediaType.sub, MediaSubtype.multipartMixed); expect(embeddedMessage?.parts?.length, 2); - expect(embeddedMessage?.parts?[0].mediaType.sub, - MediaSubtype.multipartAlternative); + expect( + embeddedMessage?.parts?[0].mediaType.sub, + MediaSubtype.multipartAlternative, + ); expect(embeddedMessage?.decodeTextPlainPart()?.startsWith('Guten Tag '), isTrue); - expect(embeddedMessage?.parts?[1].decodeFileName(), - 'Rechnung_2021_01_27317621000841.pdf'); - expect(embeddedMessage?.parts?[1].decodeContentBinary()?.sublist(0, 9), - [37, 80, 68, 70, 45, 49, 46, 53, 10]); + expect( + embeddedMessage?.parts?[1].decodeFileName(), + 'Rechnung_2021_01_27317621000841.pdf', + ); + expect( + embeddedMessage?.parts?[1].decodeContentBinary()?.sublist(0, 9), + [37, 80, 68, 70, 45, 49, 46, 53, 10], + ); final parsedAgain = MimeMessage.parseFromText(message.renderMessage()); final parsedAgainEmbedded = parsedAgain.parts?[1].decodeContentMessage(); expect( - parsedAgainEmbedded?.decodeTextPlainPart()?.startsWith('Guten Tag '), - isTrue); - expect(parsedAgainEmbedded?.parts?[1].decodeFileName(), - 'Rechnung_2021_01_27317621000841.pdf'); + parsedAgainEmbedded?.decodeTextPlainPart()?.startsWith('Guten Tag '), + isTrue, + ); + expect( + parsedAgainEmbedded?.parts?[1].decodeFileName(), + 'Rechnung_2021_01_27317621000841.pdf', + ); expect( - parsedAgainEmbedded?.parts?[1].decodeContentBinary()?.sublist(0, 9), - [37, 80, 68, 70, 45, 49, 46, 53, 10]); + parsedAgainEmbedded?.parts?[1].decodeContentBinary()?.sublist(0, 9), + [37, 80, 68, 70, 45, 49, 46, 53, 10], + ); }); }); group('MDNs', () { test('buildReadReceipt', () { final originalMessage = MimeMessage.parseFromText(complexMessageText); - originalMessage.addHeader(MailConventions.headerDispositionNotificationTo, - originalMessage.fromEmail); + originalMessage.addHeader( + MailConventions.headerDispositionNotificationTo, + originalMessage.fromEmail, + ); const finalRecipient = MailAddress('My Name', 'recipient@domain.com'); final mdn = MessageBuilder.buildReadReceipt(originalMessage, finalRecipient); diff --git a/test/mime_message_test.dart b/test/mime_message_test.dart index d4738351..8cbc6d85 100644 --- a/test/mime_message_test.dart +++ b/test/mime_message_test.dart @@ -133,7 +133,7 @@ MIME-Version: 1.0\r --unique-boundary-1\r Content-Type: text/plain; charset=UTF-8\r \r -hello COI world!\r +hello COI world\r \r \r --unique-boundary-1\r @@ -143,49 +143,57 @@ Content-Type: multipart/mixed;\r --unique-boundary-2\r Content-Type: text/html; charset=UTF-8\r \r -

hello COI world!

\r +

hello COI world

\r \r --unique-boundary-2\r Content-Type: text/html; charset=UTF-8\r Chat-Content: ignore\r \r -

This message is a chat message - consider using my awesome COI app for best experience!

\r +

This message is a chat message - consider using my awesome COI app for best experience

\r \r --unique-boundary-2--\r \r --unique-boundary-1\r Content-Type: text/markdown; charset=UTF-8\r \r -hello **COI** world!\r +hello **COI** world\r \r --unique-boundary-1--\r '''; final message = MimeMessage.parseFromText(body); var contentTypeHeader = message.getHeaderContentType(); expect(contentTypeHeader, isNotNull); - expect(contentTypeHeader!.mediaType, isNotNull); - expect(contentTypeHeader.mediaType.top, MediaToptype.multipart); + expect(contentTypeHeader?.mediaType, isNotNull); + expect(contentTypeHeader?.mediaType.top, MediaToptype.multipart); expect( - contentTypeHeader.mediaType.sub, MediaSubtype.multipartAlternative); - expect(contentTypeHeader.charset, isNull); - expect(contentTypeHeader.boundary, 'unique-boundary-1'); + contentTypeHeader?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect(contentTypeHeader?.charset, isNull); + expect(contentTypeHeader?.boundary, 'unique-boundary-1'); expect(message.headers, isNotNull); expect(message.parts, isNotNull); - expect(message.parts!.length, 3); - expect(message.decodeTextPlainPart()!.trim(), 'hello COI world!'); - contentTypeHeader = message.parts![0].getHeaderContentType()!; + expect(message.parts?.length, 3); + expect(message.decodeTextPlainPart()?.trim(), 'hello COI world'); + contentTypeHeader = message.parts?[0].getHeaderContentType(); expect(contentTypeHeader, isNotNull); - expect(contentTypeHeader.mediaType.top, MediaToptype.text); - expect(contentTypeHeader.mediaType.sub, MediaSubtype.textPlain); - expect(contentTypeHeader.charset, 'utf-8'); - expect(message.parts![1].parts, isNotNull); - expect(message.parts![1].parts!.length, 2); - expect(message.parts![1].parts![0].decodeContentText()!.trim(), - '

hello COI world!

'); - expect(message.parts![1].parts![1].decodeContentText()!.trim(), - '

This message is a chat message - consider using my awesome COI app for best experience!

'); - expect(message.parts![2].decodeContentText()!.trim(), - 'hello **COI** world!'); + expect(contentTypeHeader?.mediaType.top, MediaToptype.text); + expect(contentTypeHeader?.mediaType.sub, MediaSubtype.textPlain); + expect(contentTypeHeader?.charset, 'utf-8'); + expect(message.parts?[1].parts, isNotNull); + expect(message.parts?[1].parts?.length, 2); + expect( + message.parts?[1].parts?[0].decodeContentText()?.trim(), + '

hello COI world

', + ); + expect( + message.parts?[1].parts?[1].decodeContentText()?.trim(), + '

This message is a chat message - consider using my awesome COI app for best experience

', + ); + expect( + message.parts?[2].decodeContentText()?.trim(), + 'hello **COI** world', + ); expect(message.isTextPlainMessage(), isTrue); }); @@ -219,27 +227,30 @@ This is the epilogue. It is also to be ignored.\r final message = MimeMessage.parseFromText(body); expect(message.headers, isNotNull); expect(message.parts, isNotNull); - expect(message.parts!.length, 2); - expect(message.parts![0].headers, isNull); + expect(message.parts?.length, 2); + expect(message.parts?[0].headers, isNull); expect( - message.parts![0].decodeContentText(), - 'This is implicitly typed plain US-ASCII text.\r\n' - 'It does NOT end with a linebreak.\r\n'); + message.parts?[0].decodeContentText(), + 'This is implicitly typed plain US-ASCII text.\r\n' + 'It does NOT end with a linebreak.\r\n', + ); expect( - message.parts![0].decodeContentText(), - 'This is implicitly typed plain US-ASCII text.\r\nIt does NOT end ' - 'with a linebreak.\r\n'); - expect(message.parts![1].headers?.isNotEmpty, isTrue); - expect(message.parts![1].headers!.length, 1); - final contentType = message.parts![1].getHeaderContentType()!; + message.parts?[0].decodeContentText(), + 'This is implicitly typed plain US-ASCII text.\r\nIt does NOT end ' + 'with a linebreak.\r\n', + ); + expect(message.parts?[1].headers?.isNotEmpty, isTrue); + expect(message.parts?[1].headers?.length, 1); + final contentType = message.parts?[1].getHeaderContentType(); expect(contentType, isNotNull); - expect(contentType.mediaType.top, MediaToptype.text); - expect(contentType.mediaType.sub, MediaSubtype.textPlain); - expect(contentType.charset, 'us-ascii'); + expect(contentType?.mediaType.top, MediaToptype.text); + expect(contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(contentType?.charset, 'us-ascii'); expect( - message.parts![1].decodeContentText(), - 'This is explicitly typed plain US-ASCII text.\r\n' - 'It DOES end with a linebreak.\r\n\r\n'); + message.parts?[1].decodeContentText(), + 'This is explicitly typed plain US-ASCII text.\r\n' + 'It DOES end with a linebreak.\r\n\r\n', + ); expect(message.isTextPlainMessage(), isTrue); }); @@ -321,20 +332,24 @@ Content-Transfer-Encoding: Quoted-printable\r final message = MimeMessage.parseFromText(body); expect(message.headers, isNotNull); expect(message.parts, isNotNull); - expect(message.parts!.length, 5); - expect(message.parts![0].headers, isNull); - final decodedContentText = message.parts![0].decodeContentText()!; + expect(message.parts?.length, 5); + expect(message.parts?[0].headers, isNull); + final decodedContentText = message.parts?[0].decodeContentText(); expect(decodedContentText, isNotNull); final firstLine = - decodedContentText.substring(0, decodedContentText.indexOf('\r\n')); + decodedContentText?.substring(0, decodedContentText.indexOf('\r\n')); expect(firstLine, ' ... Some text appears here ...'); - expect(message.parts![1].headers?.isNotEmpty, isTrue); - expect(message.parts![1].getHeaderContentType()?.mediaType.text, - 'text/plain'); - expect(message.parts![2].getHeaderContentType()?.mediaType.text, - 'multipart/parallel'); - expect(message.parts![2].parts, isNotNull); - expect(message.parts![2].parts!.length, 2); + expect(message.parts?[1].headers?.isNotEmpty, isTrue); + expect( + message.parts?[1].getHeaderContentType()?.mediaType.text, + 'text/plain', + ); + expect( + message.parts?[2].getHeaderContentType()?.mediaType.text, + 'multipart/parallel', + ); + expect(message.parts?[2].parts, isNotNull); + expect(message.parts?[2].parts?.length, 2); }); test('realworld maillist-example 1', () { @@ -348,7 +363,7 @@ Received: from localhost (localhost.localdomain [127.0.0.1])\r by mx1.domain.com (Postfix) with ESMTP id 031456A8A0;\r Sat, 21 Mar 2020 12:52:03 +0100 (CET)\r Authentication-Results: domain.com;\r - dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=domain.com header.i=@domain.com header.b="ZWO+bEJO";\r + dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header?.d=domain.com header?.i=@domain.com header?.b="ZWO+bEJO";\r dkim-atps=neutral\r Received: from [127.0.0.1] (helo=localhost)\r by localhost with ESMTP (eXpurgate 4.11.2)\r @@ -364,7 +379,7 @@ Received: from lists.mailman.org (lists.mailman.org [78.47.150.134])\r (Client did not present a certificate)\r by mx1.domain.com (Postfix) with ESMTPS id C0AFF6A84C;\r Sat, 21 Mar 2020 12:51:59 +0100 (CET)\r -Authentication-Results: domain.com; dmarc=fail (p=none dis=none) header.from=domain.com\r +Authentication-Results: domain.com; dmarc=fail (p=none dis=none) header?.from=domain.com\r Authentication-Results: domain.com; spf=fail smtp.mailfrom=maillist-bounces@mailman.org\r Received: from lists.mailman.org (localhost.localdomain [127.0.0.1])\r by lists.mailman.org (Postfix) with ESMTP id A6BB6662F7;\r @@ -468,29 +483,37 @@ To unsubscribe send an email to coi-dev-leave@mailman.org\r final message = MimeMessage.parseFromText(body)..parse(); expect(message.headers, isNotNull); expect(message.parts, isNotNull); - expect(message.parts!.length, 3); - expect(message.parts![0].headers?.isNotEmpty, isTrue); - expect(message.parts![0].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); - var decodedContentText = message.parts![0].decodeContentText()!; + expect(message.parts?.length, 3); + expect(message.parts?[0].headers?.isNotEmpty, isTrue); + expect( + message.parts?[0].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); + var decodedContentText = message.parts?[0].decodeContentText(); expect(decodedContentText, isNotNull); var firstLine = - decodedContentText.substring(0, decodedContentText.indexOf('\r\n')); + decodedContentText?.substring(0, decodedContentText.indexOf('\r\n')); expect(firstLine, 'hello world'); - expect(message.parts![1].headers?.isNotEmpty, isTrue); - expect(message.parts![1].getHeaderContentType()?.mediaType.text, - 'text/plain'); - expect(message.parts![1].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); - decodedContentText = message.parts![1].decodeContentText()!; + expect(message.parts?[1].headers?.isNotEmpty, isTrue); + expect( + message.parts?[1].getHeaderContentType()?.mediaType.text, + 'text/plain', + ); + expect( + message.parts?[1].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); + decodedContentText = message.parts?[1].decodeContentText(); expect(decodedContentText, isNotNull); - expect(message.parts![2].getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); - expect(message.parts![2].parts, isNull); - decodedContentText = message.parts![2].decodeContentText()!; + expect( + message.parts?[2].getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); + expect(message.parts?[2].parts, isNull); + decodedContentText = message.parts?[2].decodeContentText(); expect(decodedContentText, isNotNull); firstLine = - decodedContentText.substring(0, decodedContentText.indexOf('\r\n')); + decodedContentText?.substring(0, decodedContentText.indexOf('\r\n')); expect(firstLine, '_______________________________________________'); }); @@ -505,7 +528,7 @@ Received: from localhost (localhost.localdomain [127.0.0.1])\r by mx1.domain.com (Postfix) with ESMTP id 906166A8D4;\r Sat, 21 Mar 2020 22:15:38 +0100 (CET)\r Authentication-Results: domain.com;\r - dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=previouslyNoEvil.com header.i=@previouslyNoEvil.com header.b="oN0X9Vdd";\r + dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header?.d=previouslyNoEvil.com header?.i=@previouslyNoEvil.com header?.b="oN0X9Vdd";\r dkim-atps=neutral\r Received: from [127.0.0.1] (helo=localhost)\r by localhost with ESMTP (eXpurgate 4.11.2)\r @@ -521,7 +544,7 @@ Received: from lists.mailman.org (lists.mailman.org [78.47.150.134])\r (Client did not present a certificate)\r by mx1.domain.com (Postfix) with ESMTPS id 4E4B06A853;\r Sat, 21 Mar 2020 22:15:33 +0100 (CET)\r -Authentication-Results: domain.com; dmarc=fail (p=none dis=none) header.from=previouslyNoEvil.com\r +Authentication-Results: domain.com; dmarc=fail (p=none dis=none) header?.from=previouslyNoEvil.com\r Authentication-Results: domain.com; spf=fail smtp.mailfrom=maillist-bounces@mailman.org\r Received: from lists.mailman.org (localhost.localdomain [127.0.0.1])\r by lists.mailman.org (Postfix) with ESMTP id C3938666B2;\r @@ -604,12 +627,14 @@ To unsubscribe send an email to coi-dev-leave@mailman.org\r final message = MimeMessage.parseFromText(body); expect(message.headers, isNotNull); expect(message.parts, isNull); - expect(message.getHeaderContentType()?.mediaType.sub, - MediaSubtype.textPlain); - final decodedContentText = message.decodeContentText()!; + expect( + message.getHeaderContentType()?.mediaType.sub, + MediaSubtype.textPlain, + ); + final decodedContentText = message.decodeContentText(); expect(decodedContentText, isNotNull); final firstLine = - decodedContentText.substring(0, decodedContentText.indexOf('\r\n')); + decodedContentText?.substring(0, decodedContentText.indexOf('\r\n')); expect(firstLine, 'This is a reply'); }); @@ -720,8 +745,10 @@ UckHnSueOzINHwA=\r '''; final message = MimeMessage.parseFromText(body); expect(message.headers, isNotNull); - expect(message.getHeaderContentType()?.mediaType.sub, - MediaSubtype.multipartSigned); + expect( + message.getHeaderContentType()?.mediaType.sub, + MediaSubtype.multipartSigned, + ); expect(message.parts, isNotNull); expect(message.allPartsFlat, isNotNull); expect(message.allPartsFlat, isNotEmpty); @@ -729,8 +756,10 @@ UckHnSueOzINHwA=\r part.getHeaderContentType()?.mediaType.sub == MediaSubtype.applicationPgpKeys); expect(keysPart, isNotNull); - expect(message.allPartsFlat.last.getHeaderContentType()?.mediaType.sub, - MediaSubtype.applicationPgpSignature); + expect( + message.allPartsFlat.last.getHeaderContentType()?.mediaType.sub, + MediaSubtype.applicationPgpSignature, + ); }); }); @@ -747,27 +776,28 @@ Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\r '''; final message = MimeMessage.parseFromText(body); expect(message.headers, isNotNull); - var header = message.decodeHeaderMailAddressValue('from')!; + var header = message.decodeHeaderMailAddressValue('from'); expect(header, isNotNull); - expect(header.length, 1); - expect(header[0].personalName, 'Keith Moore'); - expect(header[0].email, 'moore@cs.utk.edu'); - header = message.decodeHeaderMailAddressValue('to')!; + expect(header?.length, 1); + expect(header?[0].personalName, 'Keith Moore'); + expect(header?[0].email, 'moore@cs.utk.edu'); + header = message.decodeHeaderMailAddressValue('to'); expect(header, isNotNull); - expect(header.length, 1); - expect(header[0].personalName, 'Keld Jørn Simonsen'); - expect(header[0].email, 'keld@dkuug.dk'); - header = message.decodeHeaderMailAddressValue('cc')!; + expect(header?.length, 1); + expect(header?[0].personalName, 'Keld Jørn Simonsen'); + expect(header?[0].email, 'keld@dkuug.dk'); + header = message.decodeHeaderMailAddressValue('cc'); expect(header, isNotNull); - expect(header.length, 1); - expect(header[0].personalName, 'André Pirard'); - expect(header[0].email, 'PIRARD@vm1.ulg.ac.be'); + expect(header?.length, 1); + expect(header?[0].personalName, 'André Pirard'); + expect(header?[0].email, 'PIRARD@vm1.ulg.ac.be'); final rawSubject = message.getHeaderValue('subject'); expect( - rawSubject, - '=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=' - '=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?='); + rawSubject, + '=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=' + '=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=', + ); final subject = message.decodeHeaderValue('subject'); expect(subject, 'If you can read this you understand the example.'); @@ -785,45 +815,51 @@ Content-type: text/plain; charset=ISO-8859-1\r '''; final message = MimeMessage.parseFromText(body); expect(message.headers, isNotNull); - var header = message.decodeHeaderMailAddressValue('from')!; + var header = message.decodeHeaderMailAddressValue('from'); expect(header, isNotNull); - expect(header.length, 1); - expect(header[0].personalName, 'Nathaniel Borenstein'); - expect(header[0].email, 'nsb@thumper.bellcore.com'); - header = message.decodeHeaderMailAddressValue('to')!; + expect(header?.length, 1); + expect(header?[0].personalName, 'Nathaniel Borenstein'); + expect(header?[0].email, 'nsb@thumper.bellcore.com'); + header = message.decodeHeaderMailAddressValue('to'); expect(header, isNotNull); - expect(header.length, 3); - expect(header[0].personalName, 'Greg Vaudreuil'); - expect(header[0].email, 'gvaudre@NRI.Reston.VA.US'); - expect(header[1].personalName, 'Ned Freed'); - expect(header[1].email, 'ned@innosoft.com'); - expect(header[2].personalName, 'Keith Moore'); - expect(header[2].email, 'moore@cs.utk.edu'); + expect(header?.length, 3); + expect(header?[0].personalName, 'Greg Vaudreuil'); + expect(header?[0].email, 'gvaudre@NRI.Reston.VA.US'); + expect(header?[1].personalName, 'Ned Freed'); + expect(header?[1].email, 'ned@innosoft.com'); + expect(header?[2].personalName, 'Keith Moore'); + expect(header?[2].email, 'moore@cs.utk.edu'); final subject = message.decodeHeaderValue('subject'); expect(subject, 'Test of new header generator'); final contentType = message.getHeaderContentType(); expect(contentType, isNotNull); - expect(contentType!.mediaType.top, MediaToptype.text); - expect(contentType.mediaType.sub, MediaSubtype.textPlain); - expect(contentType.charset, 'iso-8859-1'); + expect(contentType?.mediaType.top, MediaToptype.text); + expect(contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(contentType?.charset, 'iso-8859-1'); }); }); group('Header tests', () { - test('Header.render() short line', () { + test('header?.render() short line', () { final header = Header( - 'Content-Type', 'text/plain; charset="us-ascii"; format="flowed"'); + 'Content-Type', + 'text/plain; charset="us-ascii"; format="flowed"', + ); final buffer = StringBuffer(); header.render(buffer); final text = buffer.toString().split('\r\n'); expect(text.length, 2); - expect(text[0], - 'Content-Type: text/plain; charset="us-ascii"; format="flowed"'); + expect( + text[0], + 'Content-Type: text/plain; charset="us-ascii"; format="flowed"', + ); expect(text[1], ''); }); - test('Header.render() long line 1', () { - final header = Header('Content-Type', - 'multipart/alternative; boundary="12345678901233456789012345678901234567"'); + test('header?.render() long line 1', () { + final header = Header( + 'Content-Type', + 'multipart/alternative; boundary="12345678901233456789012345678901234567"', + ); final buffer = StringBuffer(); header.render(buffer); final text = buffer.toString().split('\r\n'); @@ -833,9 +869,11 @@ Content-type: text/plain; charset=ISO-8859-1\r expect(text[2], ''); }); - test('Header.render() long line 2', () { - final header = Header('Content-Type', - 'multipart/alternative;boundary="12345678901233456789012345678901234567"'); + test('header?.render() long line 2', () { + final header = Header( + 'Content-Type', + 'multipart/alternative;boundary="12345678901233456789012345678901234567"', + ); final buffer = StringBuffer(); header.render(buffer); final text = buffer.toString().split('\r\n'); @@ -845,37 +883,43 @@ Content-type: text/plain; charset=ISO-8859-1\r expect(text[2], ''); }); - test('Header.render() long line 3', () { - final header = Header('Content-Type', - 'multipart/alternative;boundary="12345678901233456789012345678901234567"; fileName="one_two_three_four_five_six_seven.png";'); + test('header?.render() long line 3', () { + final header = Header( + 'Content-Type', + 'multipart/alternative;boundary="12345678901233456789012345678901234567"; fileName="one_two_three_four_five_six_seven.png";', + ); final buffer = StringBuffer(); header.render(buffer); final text = buffer.toString(); expect( - text, - 'Content-Type: multipart/alternative;\r\n' - '\tboundary="12345678901233456789012345678901234567";\r\n' - '\tfileName="one_two_three_four_five_six_seven.png";\r\n'); + text, + 'Content-Type: multipart/alternative;\r\n' + '\tboundary="12345678901233456789012345678901234567";\r\n' + '\tfileName="one_two_three_four_five_six_seven.png";\r\n', + ); }); - test('Header.render() long line without split pos', () { + test('header?.render() long line without split pos', () { final header = Header( - 'Content-Type', - '1234567890123456789012345678901234567890123456789012345678901234' - '5678901234567890123456789012345678901234567890123456789012345678' - '90123456789012345678901234567890'); + 'Content-Type', + '1234567890123456789012345678901234567890123456789012345678901234' + '5678901234567890123456789012345678901234567890123456789012345678' + '90123456789012345678901234567890', + ); final buffer = StringBuffer(); header.render(buffer); final text = buffer.toString().split('\r\n'); expect(text.length, 4); expect( - text[0], - 'Content-Type: 123456789012345678901234567890123456789012345678901' - '23456789012'); + text[0], + 'Content-Type: 123456789012345678901234567890123456789012345678901' + '23456789012', + ); expect( - text[1], - '\t345678901234567890123456789012345678901234567890123456789012345' - '678901234567'); + text[1], + '\t345678901234567890123456789012345678901234567890123456789012345' + '678901234567', + ); expect(text[2], '\t89012345678901234567890'); expect(text[3], ''); }); @@ -957,22 +1001,34 @@ Content-type: text/plain; charset=ISO-8859-1\r '''; final mimeMessage = MimeMessage.parseFromText(body); expect( - mimeMessage.isFrom(const MailAddress( - 'Nathaniel Borenstein', 'nsb@thumper.bellcore.com')), - isTrue); + mimeMessage.isFrom(const MailAddress( + 'Nathaniel Borenstein', + 'nsb@thumper.bellcore.com', + )), + isTrue, + ); expect( - mimeMessage.isFrom(const MailAddress( - 'Nathaniel Borenstein', 'ns2b@thumper.bellcore.com')), - isFalse); + mimeMessage.isFrom(const MailAddress( + 'Nathaniel Borenstein', + 'ns2b@thumper.bellcore.com', + )), + isFalse, + ); expect( - mimeMessage.isFrom( - const MailAddress( - 'Nathaniel Borenstein', 'other@thumper.bellcore.com'), - aliases: [ - const MailAddress( - 'Nathaniel Borenstein', 'nsb@thumper.bellcore.com') - ]), - isTrue); + mimeMessage.isFrom( + const MailAddress( + 'Nathaniel Borenstein', + 'other@thumper.bellcore.com', + ), + aliases: [ + const MailAddress( + 'Nathaniel Borenstein', + 'nsb@thumper.bellcore.com', + ), + ], + ), + isTrue, + ); }); test('From with + Alias', () { @@ -987,15 +1043,22 @@ Content-type: text/plain; charset=ISO-8859-1\r '''; final mimeMessage = MimeMessage.parseFromText(body); expect( - mimeMessage.isFrom(const MailAddress( - 'Nathaniel Borenstein', 'nsb@thumper.bellcore.com')), - isFalse); + mimeMessage.isFrom(const MailAddress( + 'Nathaniel Borenstein', + 'nsb@thumper.bellcore.com', + )), + isFalse, + ); expect( - mimeMessage.isFrom( - const MailAddress( - 'Nathaniel Borenstein', 'nsb@thumper.bellcore.com'), - allowPlusAliases: true), - isTrue); + mimeMessage.isFrom( + const MailAddress( + 'Nathaniel Borenstein', + 'nsb@thumper.bellcore.com', + ), + allowPlusAliases: true, + ), + isTrue, + ); }); test('Combine Reply-To, Sender and From', () { @@ -1012,28 +1075,42 @@ Content-type: text/plain; charset=ISO-8859-1\r '''; final mimeMessage = MimeMessage.parseFromText(body); expect( - mimeMessage.isFrom(const MailAddress( - 'Nathaniel Borenstein', 'nsb@thumper.bellcore.com')), - isTrue); + mimeMessage.isFrom(const MailAddress( + 'Nathaniel Borenstein', + 'nsb@thumper.bellcore.com', + )), + isTrue, + ); expect( - mimeMessage.isFrom(const MailAddress('Sender', 'sender@domain.com')), - isTrue); + mimeMessage.isFrom(const MailAddress('Sender', 'sender@domain.com')), + isTrue, + ); expect( - mimeMessage.isFrom(const MailAddress('Reply To', 'mail@domain.com')), - isTrue); + mimeMessage.isFrom(const MailAddress('Reply To', 'mail@domain.com')), + isTrue, + ); expect( - mimeMessage.isFrom(const MailAddress( - 'Nathaniel Borenstein', 'ns2b@thumper.bellcore.com')), - isFalse); + mimeMessage.isFrom(const MailAddress( + 'Nathaniel Borenstein', + 'ns2b@thumper.bellcore.com', + )), + isFalse, + ); expect( - mimeMessage.isFrom( - const MailAddress( - 'Nathaniel Borenstein', 'other@thumper.bellcore.com'), - aliases: [ - const MailAddress( - 'Nathaniel Borenstein', 'nsb@thumper.bellcore.com') - ]), - isTrue); + mimeMessage.isFrom( + const MailAddress( + 'Nathaniel Borenstein', + 'other@thumper.bellcore.com', + ), + aliases: [ + const MailAddress( + 'Nathaniel Borenstein', + 'nsb@thumper.bellcore.com', + ), + ], + ), + isTrue, + ); }); }); @@ -1046,18 +1123,22 @@ Content-type: text/plain; charset=ISO-8859-1\r final creation = DateTime.now(); final creationDateText = DateCodec.encodeDate(creation); header.creationDate = creation; - expect(header.render(), - 'inline; filename="image.jpeg"; creation-date="$creationDateText"'); + expect( + header.render(), + 'inline; filename="image.jpeg"; creation-date="$creationDateText"', + ); header.size = 2046; expect( - header.render(), - 'inline; filename="image.jpeg"; creation-date="$creationDateText";' - ' size=2046'); + header.render(), + 'inline; filename="image.jpeg"; creation-date="$creationDateText";' + ' size=2046', + ); header.setParameter('hello', 'world'); expect( - header.render(), - 'inline; filename="image.jpeg"; creation-date="$creationDateText";' - ' size=2046; hello=world'); + header.render(), + 'inline; filename="image.jpeg"; creation-date="$creationDateText";' + ' size=2046; hello=world', + ); }); test('listContentInfo() 1', () { @@ -1071,7 +1152,7 @@ Received: from localhost (localhost.localdomain [127.0.0.1])\r by mx1.domain.com (Postfix) with ESMTP id 031456A8A0;\r Sat, 21 Mar 2020 12:52:03 +0100 (CET)\r Authentication-Results: domain.com;\r - dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=domain.com header.i=@domain.com header.b="ZWO+bEJO";\r + dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header?.d=domain.com header?.i=@domain.com header?.b="ZWO+bEJO";\r dkim-atps=neutral\r Received: from [127.0.0.1] (helo=localhost)\r by localhost with ESMTP (eXpurgate 4.11.2)\r @@ -1087,7 +1168,7 @@ Received: from lists.mailman.org (lists.mailman.org [78.47.150.134])\r (Client did not present a certificate)\r by mx1.domain.com (Postfix) with ESMTPS id C0AFF6A84C;\r Sat, 21 Mar 2020 12:51:59 +0100 (CET)\r -Authentication-Results: domain.com; dmarc=fail (p=none dis=none) header.from=domain.com\r +Authentication-Results: domain.com; dmarc=fail (p=none dis=none) header?.from=domain.com\r Authentication-Results: domain.com; spf=fail smtp.mailfrom=maillist-bounces@mailman.org\r Received: from lists.mailman.org (localhost.localdomain [127.0.0.1])\r by lists.mailman.org (Postfix) with ESMTP id A6BB6662F7;\r @@ -1192,24 +1273,30 @@ To unsubscribe send an email to coi-dev-leave@mailman.org\r var attachments = message.findContentInfo(); expect(attachments, isNotEmpty); expect(attachments.length, 1); - expect(attachments[0].contentDisposition!.filename, - 'report-ffb73289-e5ba-4b13-aa8a-57ef5eede8d9.toml'); - expect(attachments[0].contentType!.mediaType.sub, MediaSubtype.textPlain); + expect( + attachments[0].contentDisposition?.filename, + 'report-ffb73289-e5ba-4b13-aa8a-57ef5eede8d9.toml', + ); + expect(attachments[0].contentType?.mediaType.sub, MediaSubtype.textPlain); attachments = message.findContentInfo(disposition: ContentDisposition.attachment); expect(attachments, isNotEmpty); expect(attachments.length, 1); - expect(attachments[0].contentDisposition!.filename, - 'report-ffb73289-e5ba-4b13-aa8a-57ef5eede8d9.toml'); - expect(attachments[0].contentType!.mediaType.sub, MediaSubtype.textPlain); + expect( + attachments[0].contentDisposition?.filename, + 'report-ffb73289-e5ba-4b13-aa8a-57ef5eede8d9.toml', + ); + expect(attachments[0].contentType?.mediaType.sub, MediaSubtype.textPlain); final inlineAttachments = message.findContentInfo(disposition: ContentDisposition.inline); expect(inlineAttachments, isNotEmpty); expect(inlineAttachments.length, 1); - expect(inlineAttachments[0].contentType!.mediaType.sub, - MediaSubtype.textPlain); + expect( + inlineAttachments[0].contentType?.mediaType.sub, + MediaSubtype.textPlain, + ); }); test('listContentInfo() 2', () { @@ -1269,12 +1356,14 @@ To unsubscribe send an email to coi-dev-leave@mailman.org\r final attachments = message.findContentInfo(); expect(attachments, isNotEmpty); expect(attachments.length, 2); - expect(attachments[0].contentDisposition!.filename, - 'report-ffb73289-e5ba-4b13-aa8a-57ef5eede8d9.toml'); - expect(attachments[0].contentType!.mediaType.sub, MediaSubtype.textPlain); + expect( + attachments[0].contentDisposition?.filename, + 'report-ffb73289-e5ba-4b13-aa8a-57ef5eede8d9.toml', + ); + expect(attachments[0].contentType?.mediaType.sub, MediaSubtype.textPlain); - expect(attachments[1].contentDisposition!.filename, 'hello.jpg'); - expect(attachments[1].contentType!.mediaType.sub, MediaSubtype.imageJpeg); + expect(attachments[1].contentDisposition?.filename, 'hello.jpg'); + expect(attachments[1].contentType?.mediaType.sub, MediaSubtype.imageJpeg); }); test('apple message with image attachment', () { @@ -1439,19 +1528,19 @@ Sent from my iPhone\r '''; final mime = MimeMessage.parseFromText(body); expect(mime.parts, isNotNull); - expect(mime.parts!.length, 2); + expect(mime.parts?.length, 2); expect(mime.mediaType.sub, MediaSubtype.multipartMixed); final inlineInfos = mime.findContentInfo(disposition: ContentDisposition.inline); expect(inlineInfos.length, 1); final info = inlineInfos.first; - expect(info.mediaType!.sub, MediaSubtype.imageJpeg); + expect(info.mediaType?.sub, MediaSubtype.imageJpeg); expect(info.fileName, 'image0.jpeg'); expect(info.fetchId, '1'); final part = mime.getPart(info.fetchId); expect(part, isNotNull); - expect(part!.mediaType.sub, info.mediaType!.sub); + expect(part?.mediaType.sub, info.mediaType?.sub); }); }); @@ -1568,28 +1657,32 @@ Content-Description: S/MIME Cryptographic Signature\r '''; final mime = MimeMessage.parseFromText(body); - final messagePart = mime.getPart('1.2')!; - expect(messagePart.mediaType.sub, MediaSubtype.messageRfc822); - final embedded = messagePart.decodeContentMessage(); + final messagePart = mime.getPart('1.2'); + expect(messagePart?.mediaType.sub, MediaSubtype.messageRfc822); + final embedded = messagePart?.decodeContentMessage(); expect(embedded, isNotNull); expect( - embedded!.decodeSubject(), - MailCodec.decodeHeader('=?UTF-8?Q?Test_email_with_unicode_characters' - '_=C3=A0=C3=A8=C3=B6?=')); - expect(embedded.mediaType.sub, MediaSubtype.multipartAlternative); + embedded?.decodeSubject(), + MailCodec.decodeHeader('=?UTF-8?Q?Test_email_with_unicode_characters' + '_=C3=A0=C3=A8=C3=B6?='), + ); + expect(embedded?.mediaType.sub, MediaSubtype.multipartAlternative); expect( - embedded.decodeTextPlainPart()!.substring( + embedded?.decodeTextPlainPart()?.substring( 0, 'This pårt of the emäįl contains various accéntè characterś' - .length), - 'This pårt of the emäįl contains various accéntè characterś'); + .length, + ), + 'This pårt of the emäįl contains various accéntè characterś', + ); // print(embedded.decodeTextHtmlPart()); expect( - embedded - .decodeTextHtmlPart()! - .contains('This pårt of the emäįl contains various ' - 'accéntè characterś'), - isTrue); + embedded + ?.decodeTextHtmlPart() + ?.contains('This pårt of the emäįl contains various ' + 'accéntè characterś'), + isTrue, + ); }); test('cp-1253 message', () { @@ -1671,7 +1764,7 @@ Content-Description: S/MIME Cryptographic Signature\r ------=_Part_5490272_1539179725.1617090882104--\r '''; final bytes = - const Windows1253Encoder().convert('Χαίρομαι που σας γνωρίζω!'); + const Windows1253Encoder().convert('Χαίρομαι που σας γνωρίζω'); final builder = BytesBuilder() ..add(utf8.encode(body1)) ..add(bytes) @@ -1695,10 +1788,10 @@ Content-Description: S/MIME Cryptographic Signature\r ); expect(embedded?.mediaType.sub, MediaSubtype.multipartAlternative); // print(embedded.decodeTextPlainPart()); - expect(embedded?.decodeTextPlainPart(), 'Χαίρομαι που σας γνωρίζω!\r\n'); + expect(embedded?.decodeTextPlainPart(), 'Χαίρομαι που σας γνωρίζω\r\n'); // print(embedded.decodeTextHtmlPart()); expect( - embedded?.decodeTextHtmlPart()?.contains('Χαίρομαι που σας γνωρίζω!'), + embedded?.decodeTextHtmlPart()?.contains('Χαίρομαι που σας γνωρίζω'), isTrue, ); }); diff --git a/test/mock_socket.dart b/test/mock_socket.dart index 128ee2a6..89b25230 100644 --- a/test/mock_socket.dart +++ b/test/mock_socket.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; - import 'dart:typed_data'; class MockConnection { @@ -27,11 +26,13 @@ class MockSocket implements Socket { @override void add(List data) { - Timer.run(() => _other!._subscription.handleData!(data as Uint8List)); + Timer.run(() => _other?._subscription.handleData?.call(data as Uint8List)); } @override - void addError(Object error, [StackTrace? stackTrace]) {} + void addError(Object error, [StackTrace? stackTrace]) { + print(error); + } @override Future addStream(Stream> stream) { @@ -47,9 +48,10 @@ class MockSocket implements Socket { } @override - Stream asBroadcastStream( - {void Function(StreamSubscription subscription)? onListen, - void Function(StreamSubscription subscription)? onCancel}) { + Stream asBroadcastStream({ + void Function(StreamSubscription subscription)? onListen, + void Function(StreamSubscription subscription)? onCancel, + }) { throw UnimplementedError(); } @@ -65,7 +67,8 @@ class MockSocket implements Socket { @override Future close() { - _subscription.handleDone!(); + _subscription.handleDone?.call(); + return Future.value(); } @@ -75,11 +78,14 @@ class MockSocket implements Socket { } @override - void destroy() {} + void destroy() { + print('mock socket destroyed'); + } @override - Stream distinct( - [bool Function(Uint8List previous, Uint8List next)? equals]) { + Stream distinct([ + bool Function(Uint8List previous, Uint8List next)? equals, + ]) { throw UnimplementedError(); } @@ -110,8 +116,10 @@ class MockSocket implements Socket { Future get first => throw UnimplementedError(); @override - Future firstWhere(bool Function(Uint8List element) test, - {Uint8List Function()? orElse}) { + Future firstWhere( + bool Function(Uint8List element) test, { + Uint8List Function()? orElse, + }) { throw UnimplementedError(); } @@ -120,7 +128,9 @@ class MockSocket implements Socket { @override Future fold( - S initialValue, S Function(S previous, Uint8List element) combine) { + S initialValue, + S Function(S previous, Uint8List element) combine, + ) { throw UnimplementedError(); } @@ -135,8 +145,10 @@ class MockSocket implements Socket { } @override - Stream handleError(Function onError, - {bool Function(dynamic)? test}) { + Stream handleError( + Function onError, { + bool Function(dynamic)? test, + }) { throw UnimplementedError(); } @@ -155,8 +167,10 @@ class MockSocket implements Socket { Future get last => throw UnimplementedError(); @override - Future lastWhere(bool Function(Uint8List element) test, - {Uint8List Function()? orElse}) { + Future lastWhere( + bool Function(Uint8List element) test, { + Uint8List Function()? orElse, + }) { throw UnimplementedError(); } @@ -172,12 +186,17 @@ class MockSocket implements Socket { } @override - StreamSubscription listen(void Function(Uint8List event)? onData, - {Function? onError, void Function()? onDone, bool? cancelOnError}) { + StreamSubscription listen( + void Function(Uint8List event)? onData, { + Function? onError, + void Function()? onDone, + bool? cancelOnError, + }) { onError ??= onErrorImpl; onDone ??= onDoneImpl; final subscription = MockStreamSubscription(onData, onError, onDone); _subscription = subscription; + return subscription; } @@ -196,7 +215,8 @@ class MockSocket implements Socket { @override Future reduce( - Uint8List Function(Uint8List previous, Uint8List element) combine) { + Uint8List Function(Uint8List previous, Uint8List element) combine, + ) { throw UnimplementedError(); } @@ -212,14 +232,18 @@ class MockSocket implements Socket { } @override - void setRawOption(RawSocketOption option) {} + void setRawOption(RawSocketOption option) { + print('setRawOption $option'); + } @override Future get single => throw UnimplementedError(); @override - Future singleWhere(bool Function(Uint8List element) test, - {Uint8List Function()? orElse}) { + Future singleWhere( + bool Function(Uint8List element) test, { + Uint8List Function()? orElse, + }) { throw UnimplementedError(); } @@ -244,8 +268,10 @@ class MockSocket implements Socket { } @override - Stream timeout(Duration timeLimit, - {void Function(EventSink sink)? onTimeout}) { + Stream timeout( + Duration timeLimit, { + void Function(EventSink sink)? onTimeout, + }) { throw UnimplementedError(); } @@ -279,10 +305,14 @@ class MockSocket implements Socket { } @override - void writeAll(Iterable objects, [String separator = '']) {} + void writeAll(Iterable objects, [String separator = '']) { + print('writeAll [$objects]'); + } @override - void writeCharCode(int charCode) {} + void writeCharCode(int charCode) { + print('writeCharCode [$charCode]'); + } @override void writeln([Object? obj = '']) { @@ -329,8 +359,12 @@ class MockStreamSubscription extends StreamSubscription { } @override - void pause([Future? resumeSignal]) {} + void pause([Future? resumeSignal]) { + throw UnimplementedError(); + } @override - void resume() {} + void resume() { + throw UnimplementedError(); + } } diff --git a/test/pop/mock_pop_server.dart b/test/pop/mock_pop_server.dart index 880bbad2..fc013939 100644 --- a/test/pop/mock_pop_server.dart +++ b/test/pop/mock_pop_server.dart @@ -4,13 +4,17 @@ import 'dart:io'; class MockPopServer { // ignore: avoid_unused_constructor_parameters MockPopServer(this._socket) { - _socket.listen((data) { - onRequest(String.fromCharCodes(data)); - }, onDone: () { - print('server connection done'); - }, onError: (error) { - print('server error: $error'); - }); + _socket.listen( + (data) { + onRequest(String.fromCharCodes(data)); + }, + onDone: () { + print('server connection done'); + }, + onError: (error) { + print('server error: $error'); + }, + ); } String? nextResponse; @@ -20,7 +24,7 @@ class MockPopServer { void onRequest(String request) { final response = nextResponse ?? ((nextResponses?.isNotEmpty ?? false) - ? nextResponses!.removeAt(0) + ? nextResponses?.removeAt(0) : '-ERR no reponse defined'); writeln(response); nextResponse = null; diff --git a/test/smtp/mock_smtp_server.dart b/test/smtp/mock_smtp_server.dart index aa0ad943..2823ed01 100644 --- a/test/smtp/mock_smtp_server.dart +++ b/test/smtp/mock_smtp_server.dart @@ -6,13 +6,17 @@ enum _MailSendState { notStarted, rcptTo, data, bdat } class MockSmtpServer { // ignore: avoid_unused_constructor_parameters MockSmtpServer(this._socket, String? userName, String? userPassword) { - _socket.listen((data) { - onRequest(String.fromCharCodes(data)); - }, onDone: () { - print('server connection done'); - }, onError: (error) { - print('server error: $error'); - }); + _socket.listen( + (data) { + onRequest(String.fromCharCodes(data)); + }, + onDone: () { + print('server connection done'); + }, + onError: (error) { + print('server error: $error'); + }, + ); } String? nextResponse; @@ -23,18 +27,20 @@ class MockSmtpServer { void onRequest(String request) { // check for supported request: // print('onMockRequest "$request"'); + final nextResponse = this.nextResponse; if (_sendState != _MailSendState.notStarted || request.startsWith('MAIL FROM:')) { onMailSendRequest(request); + return; } else if (request == 'QUIT\r\n') { writeln('221 2.0.0 Bye'); - } else if (nextResponse == null || nextResponse!.isEmpty) { + } else if (nextResponse == null || nextResponse.isEmpty) { // // no supported request found, answer with the pre-defined response: writeln('500 Invalid state - define nextResponse for MockSmtpServer'); } else { writeln(nextResponse); - nextResponse = null; + this.nextResponse = null; } } diff --git a/test/src/imap/fetch_parser_test.dart b/test/src/imap/fetch_parser_test.dart index 1c574b23..f0fcad9f 100644 --- a/test/src/imap/fetch_parser_test.dart +++ b/test/src/imap/fetch_parser_test.dart @@ -18,26 +18,26 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].sequenceId, 70); - final body = messages[0].body!; + expect(messages?.length, 1); + expect(messages?[0].sequenceId, 70); + final body = messages?[0].body; expect(body, isNotNull); - expect(body.parts, isNotNull); - expect(body.parts!.length, 2); - expect(body.parts![0].contentType, isNotNull); - expect(body.parts![0].contentType!.mediaType, isNotNull); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType!.mediaType.sub, MediaSubtype.textPlain); - expect(body.parts![0].size, 45); - expect(body.parts![0].numberOfLines, 3); - expect(body.parts![0].contentType!.charset, 'utf8'); - expect(body.parts![1].contentType!.mediaType.top, MediaToptype.image); - expect(body.parts![1].contentType!.mediaType.sub, MediaSubtype.imageJpeg); - expect(body.parts![1].contentType!.parameters['name'], 'testimage.jpg'); - expect(body.parts![1].size, 18324); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.parts, isNotNull); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(body?.parts?[0].size, 45); + expect(body?.parts?[0].numberOfLines, 3); + expect(body?.parts?[0].contentType?.charset, 'utf8'); + expect(body?.parts?[1].contentType?.mediaType.top, MediaToptype.image); + expect(body?.parts?[1].contentType?.mediaType.sub, MediaSubtype.imageJpeg); + expect(body?.parts?[1].contentType?.parameters['name'], 'testimage.jpg'); + expect(body?.parts?[1].size, 18324); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); }); test('BODY 2', () { @@ -52,32 +52,32 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; expect(body, isNotNull); - expect(body.parts, isNotNull); - expect(body.parts!.length, 2); - expect(body.parts![0].contentType, isNotNull); - expect(body.parts![0].contentType!.mediaType, isNotNull); - expect(body.parts![0].contentType!.charset, 'us-ascii'); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType!.mediaType.sub, MediaSubtype.textPlain); - expect(body.parts![0].size, 1152); - expect(body.parts![0].numberOfLines, 23); - expect(body.parts![0].encoding, '7bit'); - expect(body.parts![1].description, 'Compiler diff'); - expect(body.parts![1].cid, '<960723163407.20117h@cac.washington.edu>'); - expect(body.parts![1].contentType!.charset, 'us-ascii'); - expect(body.parts![1].contentType!.parameters['name'], 'cc.diff'); + expect(body?.parts, isNotNull); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType, isNotNull); + expect(body?.parts?[0].contentType?.charset, 'us-ascii'); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(body?.parts?[0].size, 1152); + expect(body?.parts?[0].numberOfLines, 23); + expect(body?.parts?[0].encoding, '7bit'); + expect(body?.parts?[1].description, 'Compiler diff'); + expect(body?.parts?[1].cid, '<960723163407.20117h@cac.washington.edu>'); + expect(body?.parts?[1].contentType?.charset, 'us-ascii'); + expect(body?.parts?[1].contentType?.parameters['name'], 'cc.diff'); - expect(body.parts![1].contentType!.mediaType.top, MediaToptype.text); - expect(body.parts![1].contentType!.mediaType.sub, MediaSubtype.textPlain); - expect(body.parts![1].size, 4554); - expect(body.parts![1].numberOfLines, 73); - expect(body.parts![1].encoding, 'base64'); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.parts?[1].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[1].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(body?.parts?[1].size, 4554); + expect(body?.parts?[1].numberOfLines, 73); + expect(body?.parts?[1].encoding, 'base64'); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); }); test('BODY 3', () { @@ -107,39 +107,57 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body.parts, isNotNull); - expect(body.parts!.length, 4); - expect(body.parts![0].contentType, isNotNull); - expect(body.parts![0].contentType!.mediaType, isNotNull); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.multipart); - expect(body.parts![0].contentType!.mediaType.sub, - MediaSubtype.multipartRelated); - expect(body.parts![0].parts, isNotEmpty); - expect(body.parts![0].parts!.length, 7); - expect(body.parts![0].parts![0].contentType!.mediaType.sub, - MediaSubtype.multipartAlternative); - expect(body.parts![0].parts![0].parts, isNotEmpty); - expect(body.parts![0].parts![0].parts![0].contentType!.mediaType.sub, - MediaSubtype.textPlain); - expect(body.parts![0].parts![0].parts![1].contentType!.mediaType.sub, - MediaSubtype.textHtml); - expect(body.parts![0].parts![1].contentType!.mediaType.sub, - MediaSubtype.imagePng); - expect(body.parts![0].parts![6].contentType!.mediaType.sub, - MediaSubtype.imagePng); - expect( - body.parts![1].contentType?.mediaType.sub, MediaSubtype.applicationPdf); - expect( - body.parts![2].contentType?.mediaType.sub, MediaSubtype.applicationPdf); - expect( - body.parts![3].contentType?.mediaType.sub, MediaSubtype.applicationPdf); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.parts, isNotNull); + expect(body?.parts?.length, 4); + expect(body?.parts?[0].contentType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.multipart); + expect( + body?.parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartRelated, + ); + expect(body?.parts?[0].parts, isNotEmpty); + expect(body?.parts?[0].parts?.length, 7); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect(body?.parts?[0].parts?[0].parts, isNotEmpty); + expect( + body?.parts?[0].parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.textPlain, + ); + expect( + body?.parts?[0].parts?[0].parts?[1].contentType?.mediaType.sub, + MediaSubtype.textHtml, + ); + expect( + body?.parts?[0].parts?[1].contentType?.mediaType.sub, + MediaSubtype.imagePng, + ); + expect( + body?.parts?[0].parts?[6].contentType?.mediaType.sub, + MediaSubtype.imagePng, + ); + expect( + body?.parts?[1].contentType?.mediaType.sub, + MediaSubtype.applicationPdf, + ); + expect( + body?.parts?[2].contentType?.mediaType.sub, + MediaSubtype.applicationPdf, + ); + expect( + body?.parts?[3].contentType?.mediaType.sub, + MediaSubtype.applicationPdf, + ); }); test('BODY 4 with encoded filename', () { @@ -150,29 +168,33 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].sequenceId, 70); - final body = messages[0].body!; + expect(messages?.length, 1); + expect(messages?[0].sequenceId, 70); + final body = messages?[0].body; expect(body, isNotNull); - expect(body.parts, isNotNull); - expect(body.parts!.length, 2); - expect(body.parts![0].contentType, isNotNull); - expect(body.parts![0].contentType!.mediaType, isNotNull); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType!.mediaType.sub, MediaSubtype.textPlain); - expect(body.parts![0].size, 45); - expect(body.parts![0].numberOfLines, 3); - expect(body.parts![0].contentType!.charset, 'utf8'); - expect(body.parts![1].contentType!.mediaType.top, MediaToptype.audio); - expect(body.parts![1].contentType!.mediaType.sub, MediaSubtype.audioMp4); - expect(body.parts![1].contentType!.parameters['name'], - '=?iso-8859-1?Q?01_So_beeinflu=DFbar.m4a?='); - expect(body.parts![1].description, - '=?iso-8859-1?Q?01_So_beeinflu=DFbar.m4a?='); - expect(body.parts![1].size, 18324); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.parts, isNotNull); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(body?.parts?[0].size, 45); + expect(body?.parts?[0].numberOfLines, 3); + expect(body?.parts?[0].contentType?.charset, 'utf8'); + expect(body?.parts?[1].contentType?.mediaType.top, MediaToptype.audio); + expect(body?.parts?[1].contentType?.mediaType.sub, MediaSubtype.audioMp4); + expect( + body?.parts?[1].contentType?.parameters['name'], + '=?iso-8859-1?Q?01_So_beeinflu=DFbar.m4a?=', + ); + expect( + body?.parts?[1].description, + '=?iso-8859-1?Q?01_So_beeinflu=DFbar.m4a?=', + ); + expect(body?.parts?[1].size, 18324); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); }); test('BODYSTRUCTURE 1', () { @@ -188,35 +210,37 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; expect(body, isNotNull); - expect(body.parts, isNotNull); - expect(body.parts!.length, 2); - expect(body.parts![0].contentType, isNotNull); - expect(body.parts![0].contentType!.mediaType, isNotNull); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType!.mediaType.sub, MediaSubtype.textPlain); - expect(body.parts![0].contentType!.charset, 'utf8'); - expect(body.parts![0].contentDisposition, isNull); - expect(body.parts![1].contentType!.mediaType.top, MediaToptype.image); - expect(body.parts![1].contentType!.mediaType.sub, MediaSubtype.imageJpeg); - expect(body.parts![1].contentType!.parameters['name'], 'testimage.jpg'); - expect(body.parts![1].encoding, 'base64'); - final contentDisposition = body.parts![1].contentDisposition!; + expect(body?.parts, isNotNull); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(body?.parts?[0].contentType?.charset, 'utf8'); + expect(body?.parts?[0].contentDisposition, isNull); + expect(body?.parts?[1].contentType?.mediaType.top, MediaToptype.image); + expect(body?.parts?[1].contentType?.mediaType.sub, MediaSubtype.imageJpeg); + expect(body?.parts?[1].contentType?.parameters['name'], 'testimage.jpg'); + expect(body?.parts?[1].encoding, 'base64'); + final contentDisposition = body?.parts?[1].contentDisposition; expect(contentDisposition, isNotNull); - expect(contentDisposition.dispositionText, 'attachment'); - expect(contentDisposition.disposition, ContentDisposition.attachment); - expect(contentDisposition.size, 13390); - expect(contentDisposition.modificationDate, - DateCodec.decodeDate('Fri, 27 Jan 2017 16:34:4 +0100')); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body.contentType!.charset, 'utf8'); - expect(body.contentType!.boundary, 'cTOLC7EsqRfMsG'); + expect(contentDisposition?.dispositionText, 'attachment'); + expect(contentDisposition?.disposition, ContentDisposition.attachment); + expect(contentDisposition?.size, 13390); + expect( + contentDisposition?.modificationDate, + DateCodec.decodeDate('Fri, 27 Jan 2017 16:34:4 +0100'), + ); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.contentType?.charset, 'utf8'); + expect(body?.contentType?.boundary, 'cTOLC7EsqRfMsG'); }); test('BODYSTRUCTURE 2', () { @@ -237,45 +261,61 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body.contentType!.boundary, '00000000000005d38005a528d9c5'); - expect(body.parts, isNotNull); - expect(body.parts!.length, 2); - expect(body.parts![0].contentType, isNotNull); - expect(body.parts![0].contentType!.mediaType, isNotNull); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.multipart); - expect(body.parts![0].contentType!.mediaType.sub, - MediaSubtype.multipartAlternative); - expect( - body.parts![0].contentType!.boundary, '00000000000005d37e05a528d9c3'); - expect(body.parts![0].parts, isNotNull); - expect(body.parts![0].parts, isNotEmpty); - expect(body.parts![0].parts!.length, 2); - expect(body.parts![0].parts![0].contentType?.mediaType.sub, - MediaSubtype.textPlain); - expect(body.parts![0].parts![0].encoding, '7bit'); - expect(body.parts![0].parts![1].contentType?.mediaType.sub, - MediaSubtype.textHtml); - expect(body.parts![0].parts![1].encoding, '7bit'); - expect(body.parts![1].contentType, isNotNull); - expect(body.parts![1].contentType!.mediaType, isNotNull); - expect( - body.parts![1].contentType!.mediaType.sub, MediaSubtype.applicationPdf); - expect(body.parts![1].contentType!.parameters['name'], - 'gdpr infomedica informativa clienti.pdf'); - expect(body.parts![1].contentDisposition!.disposition, - ContentDisposition.attachment); - expect(body.parts![1].contentDisposition!.filename, - 'gdpr infomedica informativa clienti.pdf'); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.contentType?.boundary, '00000000000005d38005a528d9c5'); + expect(body?.parts, isNotNull); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.multipart); + expect( + body?.parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect( + body?.parts?[0].contentType?.boundary, + '00000000000005d37e05a528d9c3', + ); + expect(body?.parts?[0].parts, isNotNull); + expect(body?.parts?[0].parts, isNotEmpty); + expect(body?.parts?[0].parts?.length, 2); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.textPlain, + ); + expect(body?.parts?[0].parts?[0].encoding, '7bit'); + expect( + body?.parts?[0].parts?[1].contentType?.mediaType.sub, + MediaSubtype.textHtml, + ); + expect(body?.parts?[0].parts?[1].encoding, '7bit'); + expect(body?.parts?[1].contentType, isNotNull); + expect(body?.parts?[1].contentType?.mediaType, isNotNull); + expect( + body?.parts?[1].contentType?.mediaType.sub, + MediaSubtype.applicationPdf, + ); + expect( + body?.parts?[1].contentType?.parameters['name'], + 'gdpr infomedica informativa clienti.pdf', + ); + expect( + body?.parts?[1].contentDisposition?.disposition, + ContentDisposition.attachment, + ); + expect( + body?.parts?[1].contentDisposition?.filename, + 'gdpr infomedica informativa clienti.pdf', + ); }); test('BODYSTRUCTURE 3', () { @@ -310,93 +350,121 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].uid, 3641); - expect(messages[0].flags, ['\\Seen']); - final body = messages[0].body!; + expect(messages?.length, 1); + expect(messages?[0].uid, 3641); + expect(messages?[0].flags, ['\\Seen']); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartReport); - expect(body.contentType!.boundary, '0000000000002f1f3705a71aaf47'); - expect(body.contentType!.parameters['report-type'], 'delivery-status'); - expect(body.parts, isNotNull); - expect(body.parts!.length, 3); - expect(body.parts![0].fetchId, '1'); - expect(body.parts![0].contentType, isNotNull); - expect(body.parts![0].contentType!.mediaType, isNotNull); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.multipart); - expect(body.parts![0].contentType!.mediaType.sub, - MediaSubtype.multipartRelated); - expect( - body.parts![0].contentType!.boundary, '0000000000002f322205a71aaf68'); - expect(body.parts![0].parts, isNotNull); - expect(body.parts![0].parts, isNotEmpty); - expect(body.parts![0].parts!.length, 2); - expect(body.parts![0].parts![0].contentType?.mediaType.top, - MediaToptype.multipart); - expect(body.parts![0].parts![0].contentType?.mediaType.sub, - MediaSubtype.multipartAlternative); - expect(body.parts![0].parts![0].contentType!.boundary, - '0000000000002f322a05a71aaf69'); - expect(body.parts![0].parts![0].parts!.length, 2); - expect(body.parts![0].parts![0].parts![0].contentType?.mediaType.sub, - MediaSubtype.textPlain); - expect(body.parts![0].parts![0].parts![0].contentType?.charset, 'utf-8'); - expect(body.parts![0].parts![0].parts![0].encoding, 'quoted-printable'); - expect(body.parts![0].parts![0].parts![0].size, 274); - expect(body.parts![0].parts![0].parts![1].contentType?.mediaType.sub, - MediaSubtype.textHtml); - expect(body.parts![0].parts![0].parts![1].contentType?.charset, 'utf-8'); - expect(body.parts![0].parts![0].parts![1].encoding, 'quoted-printable'); - expect(body.parts![0].parts![0].parts![1].size, 1455); - expect(body.parts![1].contentType, isNotNull); - expect(body.parts![1].contentType!.mediaType, isNotNull); - expect(body.parts![1].contentType!.mediaType.top, MediaToptype.message); - expect(body.parts![1].contentType!.mediaType.sub, - MediaSubtype.messageDeliveryStatus); - expect(body.parts![1].size, 488); - expect(body.parts![1].encoding, '7bit'); - expect(body.parts![2].contentType!.mediaType.top, MediaToptype.message); - expect( - body.parts![2].contentType!.mediaType.sub, MediaSubtype.messageRfc822); - expect(body.parts![2].envelope, isNotNull); - expect(body.parts![2].envelope!.subject, 'tested'); - expect(body.parts![2].envelope!.date, - DateCodec.decodeDate('Tue, 2 Jun 2020 16:25:29 +0200')); - expect(body.parts![2].envelope!.from?.length, 1); - expect(body.parts![2].envelope!.from![0].email, 'Rocks@domain.com'); - expect(body.parts![2].envelope!.to?.length, 2); - expect(body.parts![2].envelope!.to![0].email, 'Rocks@domain.com'); - expect(body.parts![2].envelope!.to![1].email, 'akari-haro@domain.com'); - expect(body.parts![2].envelope!.to![1].personalName, 'Akari Haro'); - expect(body.parts![2].parts?.length, 1); - expect(body.parts![2].parts![0].contentType?.mediaType.top, - MediaToptype.multipart); - expect(body.parts![2].parts![0].contentType?.mediaType.sub, - MediaSubtype.multipartAlternative); - expect(body.parts![2].parts![0].contentType?.boundary, 'C6WuYgfyNiVn6u'); - expect(body.parts![2].parts![0].contentType?.charset, 'utf8'); - expect(body.parts![2].parts![0].parts?.length, 2); - expect(body.parts![2].parts![0].parts![0].contentType?.mediaType.sub, - MediaSubtype.textPlain); - expect(body.parts![2].parts![0].parts![0].contentType?.charset, 'utf8'); - expect(body.parts![2].parts![0].parts![0].encoding, '7bit'); - expect(body.parts![2].parts![0].parts![0].size, 0); - expect(body.parts![2].parts![0].parts![1].contentType?.mediaType.sub, - MediaSubtype.textHtml); - expect(body.parts![2].parts![0].parts![1].contentType?.charset, 'utf8'); - expect(body.parts![2].parts![0].parts![1].encoding, '8bit'); - expect(body.parts![2].parts![0].parts![1].size, 1); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartReport); + expect(body?.contentType?.boundary, '0000000000002f1f3705a71aaf47'); + expect(body?.contentType?.parameters['report-type'], 'delivery-status'); + expect(body?.parts, isNotNull); + expect(body?.parts?.length, 3); + expect(body?.parts?[0].fetchId, '1'); + expect(body?.parts?[0].contentType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType, isNotNull); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.multipart); + expect( + body?.parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartRelated, + ); + expect( + body?.parts?[0].contentType?.boundary, + '0000000000002f322205a71aaf68', + ); + expect(body?.parts?[0].parts, isNotNull); + expect(body?.parts?[0].parts, isNotEmpty); + expect(body?.parts?[0].parts?.length, 2); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.top, + MediaToptype.multipart, + ); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect( + body?.parts?[0].parts?[0].contentType?.boundary, + '0000000000002f322a05a71aaf69', + ); + expect(body?.parts?[0].parts?[0].parts?.length, 2); + expect( + body?.parts?[0].parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.textPlain, + ); + expect(body?.parts?[0].parts?[0].parts?[0].contentType?.charset, 'utf-8'); + expect(body?.parts?[0].parts?[0].parts?[0].encoding, 'quoted-printable'); + expect(body?.parts?[0].parts?[0].parts?[0].size, 274); + expect( + body?.parts?[0].parts?[0].parts?[1].contentType?.mediaType.sub, + MediaSubtype.textHtml, + ); + expect(body?.parts?[0].parts?[0].parts?[1].contentType?.charset, 'utf-8'); + expect(body?.parts?[0].parts?[0].parts?[1].encoding, 'quoted-printable'); + expect(body?.parts?[0].parts?[0].parts?[1].size, 1455); + expect(body?.parts?[1].contentType, isNotNull); + expect(body?.parts?[1].contentType?.mediaType, isNotNull); + expect(body?.parts?[1].contentType?.mediaType.top, MediaToptype.message); + expect( + body?.parts?[1].contentType?.mediaType.sub, + MediaSubtype.messageDeliveryStatus, + ); + expect(body?.parts?[1].size, 488); + expect(body?.parts?[1].encoding, '7bit'); + expect(body?.parts?[2].contentType?.mediaType.top, MediaToptype.message); + expect( + body?.parts?[2].contentType?.mediaType.sub, + MediaSubtype.messageRfc822, + ); + expect(body?.parts?[2].envelope, isNotNull); + expect(body?.parts?[2].envelope?.subject, 'tested'); + expect( + body?.parts?[2].envelope?.date, + DateCodec.decodeDate('Tue, 2 Jun 2020 16:25:29 +0200'), + ); + expect(body?.parts?[2].envelope?.from?.length, 1); + expect(body?.parts?[2].envelope?.from?[0].email, 'Rocks@domain.com'); + expect(body?.parts?[2].envelope?.to?.length, 2); + expect(body?.parts?[2].envelope?.to?[0].email, 'Rocks@domain.com'); + expect(body?.parts?[2].envelope?.to?[1].email, 'akari-haro@domain.com'); + expect(body?.parts?[2].envelope?.to?[1].personalName, 'Akari Haro'); + expect(body?.parts?[2].parts?.length, 1); + expect( + body?.parts?[2].parts?[0].contentType?.mediaType.top, + MediaToptype.multipart, + ); + expect( + body?.parts?[2].parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect(body?.parts?[2].parts?[0].contentType?.boundary, 'C6WuYgfyNiVn6u'); + expect(body?.parts?[2].parts?[0].contentType?.charset, 'utf8'); + expect(body?.parts?[2].parts?[0].parts?.length, 2); + expect( + body?.parts?[2].parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.textPlain, + ); + expect(body?.parts?[2].parts?[0].parts?[0].contentType?.charset, 'utf8'); + expect(body?.parts?[2].parts?[0].parts?[0].encoding, '7bit'); + expect(body?.parts?[2].parts?[0].parts?[0].size, 0); + expect( + body?.parts?[2].parts?[0].parts?[1].contentType?.mediaType.sub, + MediaSubtype.textHtml, + ); + expect(body?.parts?[2].parts?[0].parts?[1].contentType?.charset, 'utf8'); + expect(body?.parts?[2].parts?[0].parts?[1].encoding, '8bit'); + expect(body?.parts?[2].parts?[0].parts?[1].size, 1); }); test('BODYSTRUCTURE 4 - single part', () { const responseTexts = [ - '''* 2175 FETCH (BODYSTRUCTURE ("TEXT" "PLAIN" ("CHARSET" "iso-8859-1") NIL NIL "QUOTED-PRINTABLE" 1315 42 NIL NIL NIL NIL))''' + '''* 2175 FETCH (BODYSTRUCTURE ("TEXT" "PLAIN" ("CHARSET" "iso-8859-1") NIL NIL "QUOTED-PRINTABLE" 1315 42 NIL NIL NIL NIL))''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -406,26 +474,26 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.sub, MediaSubtype.textPlain); - expect(body.contentType!.mediaType.top, MediaToptype.text); - expect(body.contentType!.charset, 'iso-8859-1'); - expect(body.encoding, 'quoted-printable'); - expect(body.size, 1315); - expect(body.numberOfLines, 42); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(body?.contentType?.mediaType.top, MediaToptype.text); + expect(body?.contentType?.charset, 'iso-8859-1'); + expect(body?.encoding, 'quoted-printable'); + expect(body?.size, 1315); + expect(body?.numberOfLines, 42); }); // source: http://sgerwk.altervista.org/imapbodystructure.html test('BODYSTRUCTURE 5 - simple alternative', () { const responseTexts = [ - '''* 1 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "iso-8859-1") NIL NIL "QUOTED-PRINTABLE" 2234 63 NIL NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "iso-8859-1") NIL NIL "QUOTED-PRINTABLE" 2987 52 NIL NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "d3438gr7324") NIL NIL NIL))''' + '''* 1 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "iso-8859-1") NIL NIL "QUOTED-PRINTABLE" 2234 63 NIL NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "iso-8859-1") NIL NIL "QUOTED-PRINTABLE" 2987 52 NIL NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "d3438gr7324") NIL NIL NIL))''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -435,34 +503,34 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartAlternative); - expect(body.contentType!.boundary, 'd3438gr7324'); - expect(body.parts?.length, 2); - expect(body.parts![0].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType?.mediaType.sub, MediaSubtype.textPlain); - expect(body.parts![0].contentType?.charset, 'iso-8859-1'); - expect(body.parts![0].encoding, 'quoted-printable'); - expect(body.parts![0].size, 2234); - expect(body.parts![1].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![1].contentType?.mediaType.sub, MediaSubtype.textHtml); - expect(body.parts![1].contentType?.charset, 'iso-8859-1'); - expect(body.parts![1].encoding, 'quoted-printable'); - expect(body.parts![1].size, 2987); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartAlternative); + expect(body?.contentType?.boundary, 'd3438gr7324'); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(body?.parts?[0].contentType?.charset, 'iso-8859-1'); + expect(body?.parts?[0].encoding, 'quoted-printable'); + expect(body?.parts?[0].size, 2234); + expect(body?.parts?[1].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[1].contentType?.mediaType.sub, MediaSubtype.textHtml); + expect(body?.parts?[1].contentType?.charset, 'iso-8859-1'); + expect(body?.parts?[1].encoding, 'quoted-printable'); + expect(body?.parts?[1].size, 2987); }); // source: http://sgerwk.altervista.org/imapbodystructure.html test('BODYSTRUCTURE 6 - simple alternative with image', () { const responseTexts = [ - '''* 335 FETCH (BODYSTRUCTURE (("TEXT" "HTML" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 119 2 NIL ("INLINE" NIL) NIL)("IMAGE" "JPEG" ("NAME" "4356415.jpg") "<0__=rhksjt>" NIL "BASE64" 143804 NIL ("INLINE" ("FILENAME" "4356415.jpg")) NIL) "RELATED" ("BOUNDARY" "0__=5tgd3d") ("INLINE" NIL) NIL))''' + '''* 335 FETCH (BODYSTRUCTURE (("TEXT" "HTML" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 119 2 NIL ("INLINE" NIL) NIL)("IMAGE" "JPEG" ("NAME" "4356415.jpg") "<0__=rhksjt>" NIL "BASE64" 143804 NIL ("INLINE" ("FILENAME" "4356415.jpg")) NIL) "RELATED" ("BOUNDARY" "0__=5tgd3d") ("INLINE" NIL) NIL))''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -472,42 +540,46 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartRelated); - expect(body.contentType!.boundary, '0__=5tgd3d'); - // expect(body.contentDisposition, isNotNull); - // expect(body.contentDisposition?.disposition, ContentDisposition.inline); - expect(body.parts?.length, 2); - expect(body.parts![0].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType?.mediaType.sub, MediaSubtype.textHtml); - expect(body.parts![0].contentType?.charset, 'us-ascii'); - expect(body.parts![0].encoding, '7bit'); - expect(body.parts![0].size, 119); - expect(body.parts![0].contentDisposition?.disposition, - ContentDisposition.inline); - expect(body.parts![1].contentType?.mediaType.top, MediaToptype.image); - expect(body.parts![1].contentType?.mediaType.sub, MediaSubtype.imageJpeg); - expect(body.parts![1].contentType?.parameters['name'], '4356415.jpg'); - expect(body.parts![1].encoding, 'base64'); - expect(body.parts![1].cid, '<0__=rhksjt>'); - expect(body.parts![1].size, 143804); - expect(body.parts![1].contentDisposition?.disposition, - ContentDisposition.inline); - expect(body.parts![1].contentDisposition?.filename, '4356415.jpg'); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartRelated); + expect(body?.contentType?.boundary, '0__=5tgd3d'); + // expect(body?.contentDisposition, isNotNull); + // expect(body?.contentDisposition?.disposition, ContentDisposition.inline); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textHtml); + expect(body?.parts?[0].contentType?.charset, 'us-ascii'); + expect(body?.parts?[0].encoding, '7bit'); + expect(body?.parts?[0].size, 119); + expect( + body?.parts?[0].contentDisposition?.disposition, + ContentDisposition.inline, + ); + expect(body?.parts?[1].contentType?.mediaType.top, MediaToptype.image); + expect(body?.parts?[1].contentType?.mediaType.sub, MediaSubtype.imageJpeg); + expect(body?.parts?[1].contentType?.parameters['name'], '4356415.jpg'); + expect(body?.parts?[1].encoding, 'base64'); + expect(body?.parts?[1].cid, '<0__=rhksjt>'); + expect(body?.parts?[1].size, 143804); + expect( + body?.parts?[1].contentDisposition?.disposition, + ContentDisposition.inline, + ); + expect(body?.parts?[1].contentDisposition?.filename, '4356415.jpg'); }); // source: http://sgerwk.altervista.org/imapbodystructure.html test('BODYSTRUCTURE 7 - text + html with images', () { const responseTexts = [ - '''* 202 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1" "FORMAT" "flowed") NIL NIL "QUOTED-PRINTABLE" 2815 73 NIL NIL NIL NIL)(("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 4171 66 NIL NIL NIL NIL)("IMAGE" "JPEG" ("NAME" "image.jpg") "<3245dsf7435>" NIL "BASE64" 189906 NIL NIL NIL NIL)("IMAGE" "GIF" ("NAME" "other.gif") "<32f6324f>" NIL "BASE64" 1090 NIL NIL NIL NIL) "RELATED" ("BOUNDARY" "--=sdgqgt") NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "--=u5sfrj") NIL NIL NIL))''' + '''* 202 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1" "FORMAT" "flowed") NIL NIL "QUOTED-PRINTABLE" 2815 73 NIL NIL NIL NIL)(("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 4171 66 NIL NIL NIL NIL)("IMAGE" "JPEG" ("NAME" "image.jpg") "<3245dsf7435>" NIL "BASE64" 189906 NIL NIL NIL NIL)("IMAGE" "GIF" ("NAME" "other.gif") "<32f6324f>" NIL "BASE64" 1090 NIL NIL NIL NIL) "RELATED" ("BOUNDARY" "--=sdgqgt") NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "--=u5sfrj") NIL NIL NIL))''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -517,61 +589,79 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartAlternative); - expect(body.contentType!.boundary, '--=u5sfrj'); - expect(body.parts?.length, 2); - expect(body.parts![0].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType?.mediaType.sub, MediaSubtype.textPlain); - expect(body.parts![0].contentType?.charset, 'iso-8859-1'); - expect(body.parts![0].contentType?.isFlowedFormat, true); - expect(body.parts![0].encoding, 'quoted-printable'); - expect(body.parts![0].size, 2815); - // expect(body.parts[0].contentDisposition?.disposition, + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartAlternative); + expect(body?.contentType?.boundary, '--=u5sfrj'); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(body?.parts?[0].contentType?.charset, 'iso-8859-1'); + expect(body?.parts?[0].contentType?.isFlowedFormat, true); + expect(body?.parts?[0].encoding, 'quoted-printable'); + expect(body?.parts?[0].size, 2815); + // expect(body?.parts?[0].contentDisposition?.disposition, // ContentDisposition.inline); - expect(body.parts![1].contentType?.mediaType.top, MediaToptype.multipart); - expect(body.parts![1].contentType?.mediaType.sub, - MediaSubtype.multipartRelated); - expect(body.parts![1].contentType?.boundary, '--=sdgqgt'); - expect(body.parts![1].parts?.length, 3); - expect( - body.parts![1].parts![0].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![1].parts![0].contentType?.mediaType.sub, - MediaSubtype.textHtml); - expect(body.parts![1].parts![0].contentType?.charset, 'iso-8859-1'); - expect(body.parts![1].parts![0].encoding, 'quoted-printable'); - expect(body.parts![1].parts![1].contentType?.mediaType.top, - MediaToptype.image); - expect(body.parts![1].parts![1].contentType?.mediaType.sub, - MediaSubtype.imageJpeg); - expect( - body.parts![1].parts![1].contentType?.parameters['name'], 'image.jpg'); - expect(body.parts![1].parts![1].cid, '<3245dsf7435>'); - expect(body.parts![1].parts![1].encoding, 'base64'); - expect(body.parts![1].parts![1].size, 189906); - expect(body.parts![1].parts![2].contentType?.mediaType.top, - MediaToptype.image); - expect(body.parts![1].parts![2].contentType?.mediaType.sub, - MediaSubtype.imageGif); - expect( - body.parts![1].parts![2].contentType?.parameters['name'], 'other.gif'); - expect(body.parts![1].parts![2].cid, '<32f6324f>'); - expect(body.parts![1].parts![2].encoding, 'base64'); - expect(body.parts![1].parts![2].size, 1090); + expect(body?.parts?[1].contentType?.mediaType.top, MediaToptype.multipart); + expect( + body?.parts?[1].contentType?.mediaType.sub, + MediaSubtype.multipartRelated, + ); + expect(body?.parts?[1].contentType?.boundary, '--=sdgqgt'); + expect(body?.parts?[1].parts?.length, 3); + expect( + body?.parts?[1].parts?[0].contentType?.mediaType.top, + MediaToptype.text, + ); + expect( + body?.parts?[1].parts?[0].contentType?.mediaType.sub, + MediaSubtype.textHtml, + ); + expect(body?.parts?[1].parts?[0].contentType?.charset, 'iso-8859-1'); + expect(body?.parts?[1].parts?[0].encoding, 'quoted-printable'); + expect( + body?.parts?[1].parts?[1].contentType?.mediaType.top, + MediaToptype.image, + ); + expect( + body?.parts?[1].parts?[1].contentType?.mediaType.sub, + MediaSubtype.imageJpeg, + ); + expect( + body?.parts?[1].parts?[1].contentType?.parameters['name'], + 'image.jpg', + ); + expect(body?.parts?[1].parts?[1].cid, '<3245dsf7435>'); + expect(body?.parts?[1].parts?[1].encoding, 'base64'); + expect(body?.parts?[1].parts?[1].size, 189906); + expect( + body?.parts?[1].parts?[2].contentType?.mediaType.top, + MediaToptype.image, + ); + expect( + body?.parts?[1].parts?[2].contentType?.mediaType.sub, + MediaSubtype.imageGif, + ); + expect( + body?.parts?[1].parts?[2].contentType?.parameters['name'], + 'other.gif', + ); + expect(body?.parts?[1].parts?[2].cid, '<32f6324f>'); + expect(body?.parts?[1].parts?[2].encoding, 'base64'); + expect(body?.parts?[1].parts?[2].size, 1090); }); // source: http://sgerwk.altervista.org/imapbodystructure.html test('BODYSTRUCTURE 8 - text + html with images 2', () { const responseTexts = [ - '''* 41 FETCH (BODYSTRUCTURE ((("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 471 28 NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 1417 36 NIL ("INLINE" NIL) NIL) "ALTERNATIVE" ("BOUNDARY" "1__=hqjksdm") NIL NIL)("IMAGE" "GIF" ("NAME" "image.gif") "<1__=cxdf2f>" NIL "BASE64" 50294 NIL ("INLINE" ("FILENAME" "image.gif")) NIL) "RELATED" ("BOUNDARY" "0__=hqjksdm") NIL NIL))''' + '''* 41 FETCH (BODYSTRUCTURE ((("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 471 28 NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 1417 36 NIL ("INLINE" NIL) NIL) "ALTERNATIVE" ("BOUNDARY" "1__=hqjksdm") NIL NIL)("IMAGE" "GIF" ("NAME" "image.gif") "<1__=cxdf2f>" NIL "BASE64" 50294 NIL ("INLINE" ("FILENAME" "image.gif")) NIL) "RELATED" ("BOUNDARY" "0__=hqjksdm") NIL NIL))''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -581,54 +671,68 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartRelated); - expect(body.contentType!.boundary, '0__=hqjksdm'); - expect(body.parts?.length, 2); - expect(body.parts![0].contentType?.mediaType.top, MediaToptype.multipart); - expect(body.parts![0].contentType?.mediaType.sub, - MediaSubtype.multipartAlternative); - expect(body.parts![0].contentType?.boundary, '1__=hqjksdm'); - expect(body.parts![0].parts?.length, 2); - expect( - body.parts![0].parts![0].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![0].parts![0].contentType?.mediaType.sub, - MediaSubtype.textPlain); - expect(body.parts![0].parts![0].contentType?.charset, 'iso-8859-1'); - expect(body.parts![0].parts![0].encoding, 'quoted-printable'); - expect(body.parts![0].parts![0].size, 471); - expect( - body.parts![0].parts![1].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![0].parts![1].contentType?.mediaType.sub, - MediaSubtype.textHtml); - expect(body.parts![0].parts![1].contentType?.charset, 'iso-8859-1'); - expect(body.parts![0].parts![1].encoding, 'quoted-printable'); - expect(body.parts![0].parts![1].size, 1417); - expect(body.parts![0].parts![1].contentDisposition?.disposition, - ContentDisposition.inline); - expect(body.parts![1].contentType?.mediaType.top, MediaToptype.image); - expect(body.parts![1].contentType?.mediaType.sub, MediaSubtype.imageGif); - expect(body.parts![1].contentType?.parameters['name'], 'image.gif'); - expect(body.parts![1].cid, '<1__=cxdf2f>'); - expect(body.parts![1].encoding, 'base64'); - expect(body.parts![1].size, 50294); - expect(body.parts![1].contentDisposition?.disposition, - ContentDisposition.inline); - expect(body.parts![1].contentDisposition?.filename, 'image.gif'); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartRelated); + expect(body?.contentType?.boundary, '0__=hqjksdm'); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.multipart); + expect( + body?.parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect(body?.parts?[0].contentType?.boundary, '1__=hqjksdm'); + expect(body?.parts?[0].parts?.length, 2); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.top, + MediaToptype.text, + ); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.textPlain, + ); + expect(body?.parts?[0].parts?[0].contentType?.charset, 'iso-8859-1'); + expect(body?.parts?[0].parts?[0].encoding, 'quoted-printable'); + expect(body?.parts?[0].parts?[0].size, 471); + expect( + body?.parts?[0].parts?[1].contentType?.mediaType.top, + MediaToptype.text, + ); + expect( + body?.parts?[0].parts?[1].contentType?.mediaType.sub, + MediaSubtype.textHtml, + ); + expect(body?.parts?[0].parts?[1].contentType?.charset, 'iso-8859-1'); + expect(body?.parts?[0].parts?[1].encoding, 'quoted-printable'); + expect(body?.parts?[0].parts?[1].size, 1417); + expect( + body?.parts?[0].parts?[1].contentDisposition?.disposition, + ContentDisposition.inline, + ); + expect(body?.parts?[1].contentType?.mediaType.top, MediaToptype.image); + expect(body?.parts?[1].contentType?.mediaType.sub, MediaSubtype.imageGif); + expect(body?.parts?[1].contentType?.parameters['name'], 'image.gif'); + expect(body?.parts?[1].cid, '<1__=cxdf2f>'); + expect(body?.parts?[1].encoding, 'base64'); + expect(body?.parts?[1].size, 50294); + expect( + body?.parts?[1].contentDisposition?.disposition, + ContentDisposition.inline, + ); + expect(body?.parts?[1].contentDisposition?.filename, 'image.gif'); }); // source: http://sgerwk.altervista.org/imapbodystructure.html test('BODYSTRUCTURE 9 - mail with attachment', () { const responseTexts = [ - '''* 302 FETCH (BODYSTRUCTURE (("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 4692 69 NIL NIL NIL NIL)("APPLICATION" "PDF" ("NAME" "pages.pdf") NIL NIL "BASE64" 38838 NIL ("attachment" ("FILENAME" "pages.pdf")) NIL NIL) "MIXED" ("BOUNDARY" "----=6fgshr") NIL NIL NIL))''' + '''* 302 FETCH (BODYSTRUCTURE (("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 4692 69 NIL NIL NIL NIL)("APPLICATION" "PDF" ("NAME" "pages.pdf") NIL NIL "BASE64" 38838 NIL ("attachment" ("FILENAME" "pages.pdf")) NIL NIL) "MIXED" ("BOUNDARY" "----=6fgshr") NIL NIL NIL))''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -638,38 +742,45 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body.contentType!.boundary, '----=6fgshr'); - expect(body.parts?.length, 2); - expect(body.parts![0].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType?.mediaType.sub, MediaSubtype.textHtml); - expect(body.parts![0].contentType?.charset, 'iso-8859-1'); - expect(body.parts![0].encoding, 'quoted-printable'); - expect(body.parts![0].size, 4692); - expect(body.parts![1].contentType?.mediaType.top, MediaToptype.application); - expect( - body.parts![1].contentType?.mediaType.sub, MediaSubtype.applicationPdf); - expect(body.parts![1].contentType?.parameters['name'], 'pages.pdf'); - expect(body.parts![1].encoding, 'base64'); - expect(body.parts![1].size, 38838); - expect(body.parts![1].contentDisposition?.disposition, - ContentDisposition.attachment); - expect(body.parts![1].contentDisposition?.filename, 'pages.pdf'); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.contentType?.boundary, '----=6fgshr'); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textHtml); + expect(body?.parts?[0].contentType?.charset, 'iso-8859-1'); + expect(body?.parts?[0].encoding, 'quoted-printable'); + expect(body?.parts?[0].size, 4692); + expect( + body?.parts?[1].contentType?.mediaType.top, + MediaToptype.application, + ); + expect( + body?.parts?[1].contentType?.mediaType.sub, + MediaSubtype.applicationPdf, + ); + expect(body?.parts?[1].contentType?.parameters['name'], 'pages.pdf'); + expect(body?.parts?[1].encoding, 'base64'); + expect(body?.parts?[1].size, 38838); + expect( + body?.parts?[1].contentDisposition?.disposition, + ContentDisposition.attachment, + ); + expect(body?.parts?[1].contentDisposition?.filename, 'pages.pdf'); }); // source: http://sgerwk.altervista.org/imapbodystructure.html test('BODYSTRUCTURE 10 - alternative and attachment', () { const responseTexts = [ - '''* 356 FETCH (BODYSTRUCTURE ((("TEXT" "PLAIN" ("CHARSET" "UTF-8") NIL NIL "QUOTED-PRINTABLE" 403 6 NIL NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "UTF-8") NIL NIL "QUOTED-PRINTABLE" 421 6 NIL NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "----=fghgf3") NIL NIL NIL)("APPLICATION" "vnd.openxmlformats-officedocument.wordprocessingml.document" ("NAME" "letter.docx") NIL NIL "BASE64" 110000 NIL ("attachment" ("FILENAME" "letter.docx" "SIZE" "80384")) NIL NIL) "MIXED" ("BOUNDARY" "----=y34fgl") NIL NIL NIL))''' + '''* 356 FETCH (BODYSTRUCTURE ((("TEXT" "PLAIN" ("CHARSET" "UTF-8") NIL NIL "QUOTED-PRINTABLE" 403 6 NIL NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "UTF-8") NIL NIL "QUOTED-PRINTABLE" 421 6 NIL NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "----=fghgf3") NIL NIL NIL)("APPLICATION" "vnd.openxmlformats-officedocument.wordprocessingml.document" ("NAME" "letter.docx") NIL NIL "BASE64" 110000 NIL ("attachment" ("FILENAME" "letter.docx" "SIZE" "80384")) NIL NIL) "MIXED" ("BOUNDARY" "----=y34fgl") NIL NIL NIL))''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -679,57 +790,74 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body.contentType!.boundary, '----=y34fgl'); - expect(body.parts?.length, 2); - expect(body.parts![0].fetchId, '1'); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.multipart); - expect(body.parts![0].contentType!.mediaType.sub, - MediaSubtype.multipartAlternative); - expect(body.parts![0].contentType!.boundary, '----=fghgf3'); - expect(body.parts![0].parts?.length, 2); - expect(body.parts![0].parts![0].fetchId, '1.1'); - expect( - body.parts![0].parts![0].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![0].parts![0].contentType?.mediaType.sub, - MediaSubtype.textPlain); - expect(body.parts![0].parts![0].contentType?.charset, 'utf-8'); - expect(body.parts![0].parts![0].encoding, 'quoted-printable'); - expect(body.parts![0].parts![0].size, 403); - expect(body.parts![0].parts![1].fetchId, '1.2'); - expect( - body.parts![0].parts![1].contentType?.mediaType.top, MediaToptype.text); - expect(body.parts![0].parts![1].contentType?.mediaType.sub, - MediaSubtype.textHtml); - expect(body.parts![0].parts![1].contentType?.charset, 'utf-8'); - expect(body.parts![0].parts![1].encoding, 'quoted-printable'); - expect(body.parts![0].parts![1].size, 421); - expect(body.parts![1].contentType?.mediaType.top, MediaToptype.application); - expect(body.parts![1].fetchId, '2'); - expect(body.parts![1].contentType?.mediaType.sub, - MediaSubtype.applicationOfficeDocumentWordProcessingDocument); - expect(body.parts![1].contentType?.parameters['name'], 'letter.docx'); - expect(body.parts![1].encoding, 'base64'); - expect(body.parts![1].size, 110000); - expect(body.parts![1].contentDisposition?.disposition, - ContentDisposition.attachment); - expect(body.parts![1].contentDisposition?.filename, 'letter.docx'); - expect(body.parts![1].contentDisposition?.size, 80384); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.contentType?.boundary, '----=y34fgl'); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].fetchId, '1'); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.multipart); + expect( + body?.parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect(body?.parts?[0].contentType?.boundary, '----=fghgf3'); + expect(body?.parts?[0].parts?.length, 2); + expect(body?.parts?[0].parts?[0].fetchId, '1.1'); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.top, + MediaToptype.text, + ); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.textPlain, + ); + expect(body?.parts?[0].parts?[0].contentType?.charset, 'utf-8'); + expect(body?.parts?[0].parts?[0].encoding, 'quoted-printable'); + expect(body?.parts?[0].parts?[0].size, 403); + expect(body?.parts?[0].parts?[1].fetchId, '1.2'); + expect( + body?.parts?[0].parts?[1].contentType?.mediaType.top, + MediaToptype.text, + ); + expect( + body?.parts?[0].parts?[1].contentType?.mediaType.sub, + MediaSubtype.textHtml, + ); + expect(body?.parts?[0].parts?[1].contentType?.charset, 'utf-8'); + expect(body?.parts?[0].parts?[1].encoding, 'quoted-printable'); + expect(body?.parts?[0].parts?[1].size, 421); + expect( + body?.parts?[1].contentType?.mediaType.top, + MediaToptype.application, + ); + expect(body?.parts?[1].fetchId, '2'); + expect( + body?.parts?[1].contentType?.mediaType.sub, + MediaSubtype.applicationOfficeDocumentWordProcessingDocument, + ); + expect(body?.parts?[1].contentType?.parameters['name'], 'letter.docx'); + expect(body?.parts?[1].encoding, 'base64'); + expect(body?.parts?[1].size, 110000); + expect( + body?.parts?[1].contentDisposition?.disposition, + ContentDisposition.attachment, + ); + expect(body?.parts?[1].contentDisposition?.filename, 'letter.docx'); + expect(body?.parts?[1].contentDisposition?.size, 80384); }); // source: http://sgerwk.altervista.org/imapbodystructure.html test('BODYSTRUCTURE 11 - all together', () { const responseTexts = [ - '''* 1569 FETCH (BODYSTRUCTURE (((("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 833 30 NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 3412 62 NIL ("INLINE" NIL) NIL) "ALTERNATIVE" ("BOUNDARY" "2__=fgrths") NIL NIL)("IMAGE" "GIF" ("NAME" "485039.gif") "<2__=lgkfjr>" NIL "BASE64" 64 NIL ("INLINE" ("FILENAME" "485039.gif")) NIL) "RELATED" ("BOUNDARY" "1__=fgrths") NIL NIL)("APPLICATION" "PDF" ("NAME" "title.pdf") "<1__=lgkfjr>" NIL "BASE64" 333980 NIL ("ATTACHMENT" ("FILENAME" "title.pdf")) NIL) "MIXED" ("BOUNDARY" "0__=fgrths") NIL NIL))''' + '''* 1569 FETCH (BODYSTRUCTURE (((("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 833 30 NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 3412 62 NIL ("INLINE" NIL) NIL) "ALTERNATIVE" ("BOUNDARY" "2__=fgrths") NIL NIL)("IMAGE" "GIF" ("NAME" "485039.gif") "<2__=lgkfjr>" NIL "BASE64" 64 NIL ("INLINE" ("FILENAME" "485039.gif")) NIL) "RELATED" ("BOUNDARY" "1__=fgrths") NIL NIL)("APPLICATION" "PDF" ("NAME" "title.pdf") "<1__=lgkfjr>" NIL "BASE64" 333980 NIL ("ATTACHMENT" ("FILENAME" "title.pdf")) NIL) "MIXED" ("BOUNDARY" "0__=fgrths") NIL NIL))''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -739,62 +867,89 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body.contentType!.boundary, '0__=fgrths'); - expect(body.parts?.length, 2); - expect(body.parts![0].fetchId, '1'); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.multipart); - expect(body.parts![0].contentType!.mediaType.sub, - MediaSubtype.multipartRelated); - expect(body.parts![0].contentType!.boundary, '1__=fgrths'); - expect(body.parts![0].parts?.length, 2); - expect(body.parts![0].parts![0].contentType!.mediaType.top, - MediaToptype.multipart); - expect(body.parts![0].parts![0].contentType!.mediaType.sub, - MediaSubtype.multipartAlternative); - expect(body.parts![0].parts![0].contentType!.boundary, '2__=fgrths'); - expect(body.parts![0].parts![0].fetchId, '1.1'); - expect(body.parts![0].parts![0].parts?.length, 2); - expect(body.parts![0].parts![0].parts![0].fetchId, '1.1.1'); - expect(body.parts![0].parts![0].parts![0].contentType?.mediaType.top, - MediaToptype.text); - expect(body.parts![0].parts![0].parts![0].contentType?.mediaType.sub, - MediaSubtype.textPlain); - expect( - body.parts![0].parts![0].parts![0].contentType?.charset, 'iso-8859-1'); - expect(body.parts![0].parts![0].parts![0].encoding, 'quoted-printable'); - expect(body.parts![0].parts![0].parts![0].size, 833); - expect(body.parts![0].parts![0].parts![1].fetchId, '1.1.2'); - expect(body.parts![0].parts![0].parts![1].contentType?.mediaType.top, - MediaToptype.text); - expect(body.parts![0].parts![0].parts![1].contentType?.mediaType.sub, - MediaSubtype.textHtml); - expect( - body.parts![0].parts![0].parts![1].contentType?.charset, 'iso-8859-1'); - expect(body.parts![0].parts![0].parts![1].encoding, 'quoted-printable'); - expect(body.parts![0].parts![0].parts![1].size, 3412); - expect(body.parts![0].parts![0].parts![1].contentDisposition?.disposition, - ContentDisposition.inline); - expect(body.parts![1].fetchId, '2'); - expect(body.parts![1].contentType?.mediaType.top, MediaToptype.application); - expect( - body.parts![1].contentType?.mediaType.sub, MediaSubtype.applicationPdf); - expect(body.parts![1].contentType?.parameters['name'], 'title.pdf'); - expect(body.parts![1].encoding, 'base64'); - expect(body.parts![1].cid, '<1__=lgkfjr>'); - expect(body.parts![1].size, 333980); - expect(body.parts![1].contentDisposition?.disposition, - ContentDisposition.attachment); - expect(body.parts![1].contentDisposition?.filename, 'title.pdf'); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.contentType?.boundary, '0__=fgrths'); + expect(body?.parts?.length, 2); + expect(body?.parts?[0].fetchId, '1'); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.multipart); + expect( + body?.parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartRelated, + ); + expect(body?.parts?[0].contentType?.boundary, '1__=fgrths'); + expect(body?.parts?[0].parts?.length, 2); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.top, + MediaToptype.multipart, + ); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect(body?.parts?[0].parts?[0].contentType?.boundary, '2__=fgrths'); + expect(body?.parts?[0].parts?[0].fetchId, '1.1'); + expect(body?.parts?[0].parts?[0].parts?.length, 2); + expect(body?.parts?[0].parts?[0].parts?[0].fetchId, '1.1.1'); + expect( + body?.parts?[0].parts?[0].parts?[0].contentType?.mediaType.top, + MediaToptype.text, + ); + expect( + body?.parts?[0].parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.textPlain, + ); + expect( + body?.parts?[0].parts?[0].parts?[0].contentType?.charset, + 'iso-8859-1', + ); + expect(body?.parts?[0].parts?[0].parts?[0].encoding, 'quoted-printable'); + expect(body?.parts?[0].parts?[0].parts?[0].size, 833); + expect(body?.parts?[0].parts?[0].parts?[1].fetchId, '1.1.2'); + expect( + body?.parts?[0].parts?[0].parts?[1].contentType?.mediaType.top, + MediaToptype.text, + ); + expect( + body?.parts?[0].parts?[0].parts?[1].contentType?.mediaType.sub, + MediaSubtype.textHtml, + ); + expect( + body?.parts?[0].parts?[0].parts?[1].contentType?.charset, + 'iso-8859-1', + ); + expect(body?.parts?[0].parts?[0].parts?[1].encoding, 'quoted-printable'); + expect(body?.parts?[0].parts?[0].parts?[1].size, 3412); + expect( + body?.parts?[0].parts?[0].parts?[1].contentDisposition?.disposition, + ContentDisposition.inline, + ); + expect(body?.parts?[1].fetchId, '2'); + expect( + body?.parts?[1].contentType?.mediaType.top, + MediaToptype.application, + ); + expect( + body?.parts?[1].contentType?.mediaType.sub, + MediaSubtype.applicationPdf, + ); + expect(body?.parts?[1].contentType?.parameters['name'], 'title.pdf'); + expect(body?.parts?[1].encoding, 'base64'); + expect(body?.parts?[1].cid, '<1__=lgkfjr>'); + expect(body?.parts?[1].size, 333980); + expect( + body?.parts?[1].contentDisposition?.disposition, + ContentDisposition.attachment, + ); + expect(body?.parts?[1].contentDisposition?.filename, 'title.pdf'); }); // real world example @@ -833,44 +988,56 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartRelated); - expect(body.contentType!.boundary, - '_007_AM5PR0701MB25139B9E8D23795759E68308E8AD0AM5PR0701MB2513_'); - expect(body.parts?.length, 5); - expect(body.parts![1].cid, ''); - expect(body.parts![2].cid, ''); - expect(body.parts![3].cid, '<63441da1-6a9e-4afc-b13a-6ee3700e7fa7>'); - expect(body.parts![4].cid, '<0756cb18-2a81-4bd1-a3af-b11816caf509>'); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartRelated); + expect( + body?.contentType?.boundary, + '_007_AM5PR0701MB25139B9E8D23795759E68308E8AD0AM5PR0701MB2513_', + ); + expect(body?.parts?.length, 5); + expect(body?.parts?[1].cid, ''); + expect(body?.parts?[2].cid, ''); + expect(body?.parts?[3].cid, '<63441da1-6a9e-4afc-b13a-6ee3700e7fa7>'); + expect(body?.parts?[4].cid, '<0756cb18-2a81-4bd1-a3af-b11816caf509>'); - expect(body.parts![0].fetchId, '1'); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.multipart); - expect(body.parts![0].contentType!.mediaType.sub, - MediaSubtype.multipartAlternative); - expect(body.parts![0].contentType!.boundary, - '_000_AM5PR0701MB25139B9E8D23795759E68308E8AD0AM5PR0701MB2513_'); - expect(body.parts![0].parts?.length, 2); - expect( - body.parts![0].parts![0].contentType!.mediaType.top, MediaToptype.text); - expect(body.parts![0].parts![0].contentType!.mediaType.sub, - MediaSubtype.textPlain); - expect(body.parts![0].parts![1].contentType!.mediaType.sub, - MediaSubtype.textHtml); - expect(body.parts![0].parts![0].contentType!.boundary, null); + expect(body?.parts?[0].fetchId, '1'); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.multipart); + expect( + body?.parts?[0].contentType?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect( + body?.parts?[0].contentType?.boundary, + '_000_AM5PR0701MB25139B9E8D23795759E68308E8AD0AM5PR0701MB2513_', + ); + expect(body?.parts?[0].parts?.length, 2); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.top, + MediaToptype.text, + ); + expect( + body?.parts?[0].parts?[0].contentType?.mediaType.sub, + MediaSubtype.textPlain, + ); + expect( + body?.parts?[0].parts?[1].contentType?.mediaType.sub, + MediaSubtype.textHtml, + ); + expect(body?.parts?[0].parts?[0].contentType?.boundary, null); }); // source: http://sgerwk.altervista.org/imapbodystructure.html test('BODYSTRUCTURE 13 - single-element lists', () { const responseTexts = [ - '''* 2246 FETCH (BODYSTRUCTURE (("TEXT" "HTML" NIL NIL NIL "7BIT" 151 0 NIL NIL NIL) "MIXED" ("BOUNDARY" "----=rfsewr") NIL NIL))''' + '''* 2246 FETCH (BODYSTRUCTURE (("TEXT" "HTML" NIL NIL NIL "7BIT" 151 0 NIL NIL NIL) "MIXED" ("BOUNDARY" "----=rfsewr") NIL NIL))''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -880,23 +1047,23 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body!; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body.contentType!.boundary, '----=rfsewr'); - expect(body.parts?.length, 1); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType!.mediaType.sub, MediaSubtype.textHtml); - expect(body.parts![0].encoding, '7bit'); - expect(body.parts![0].size, 151); - expect(body.parts![0].fetchId, '1'); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.contentType?.boundary, '----=rfsewr'); + expect(body?.parts?.length, 1); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textHtml); + expect(body?.parts?[0].encoding, '7bit'); + expect(body?.parts?[0].size, 151); + expect(body?.parts?[0].fetchId, '1'); }); test('BODYSTRUCTURE 14 - with raw data parameters', () { @@ -936,43 +1103,62 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body; + expect(messages?.length, 1); + final body = messages?[0].body; //print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body!.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body.contentType!.boundary, '--_com.android.email_1204848368992460'); - expect(body.parts?.length, 3); - expect(body.parts![0].contentType!.mediaType.top, MediaToptype.text); - expect(body.parts![0].contentType!.mediaType.sub, MediaSubtype.textHtml); - expect(body.parts![0].encoding, 'base64'); - expect(body.parts![0].size, 5234); - expect( - body.parts![1].contentType!.mediaType.sub, MediaSubtype.applicationPdf); - expect(body.parts![1].contentType!.parameters['name'], - 'Testpflicht an Schulen_09_04_21.pdf'); - expect(body.parts![1].contentDisposition, isNotNull); - expect(body.parts![1].contentDisposition!.disposition, - ContentDisposition.attachment); - expect(body.parts![1].contentDisposition!.filename, - 'Testpflicht an Schulen_09_04_21.pdf'); - expect(body.parts![1].contentDisposition!.size, 466602); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); + expect( + body?.contentType?.boundary, + '--_com.android.email_1204848368992460', + ); + expect(body?.parts?.length, 3); + expect(body?.parts?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?.parts?[0].contentType?.mediaType.sub, MediaSubtype.textHtml); + expect(body?.parts?[0].encoding, 'base64'); + expect(body?.parts?[0].size, 5234); + expect( + body?.parts?[1].contentType?.mediaType.sub, + MediaSubtype.applicationPdf, + ); + expect( + body?.parts?[1].contentType?.parameters['name'], + 'Testpflicht an Schulen_09_04_21.pdf', + ); + expect(body?.parts?[1].contentDisposition, isNotNull); + expect( + body?.parts?[1].contentDisposition?.disposition, + ContentDisposition.attachment, + ); + expect( + body?.parts?[1].contentDisposition?.filename, + 'Testpflicht an Schulen_09_04_21.pdf', + ); + expect(body?.parts?[1].contentDisposition?.size, 466602); expect( - body.parts![2].contentType!.mediaType.sub, MediaSubtype.applicationPdf); - expect(body.parts![2].contentType!.parameters['name'], - 'Schnelltest Einverständniserklärung3.pdf'); - expect(body.parts![2].contentDisposition, isNotNull); - expect(body.parts![2].contentDisposition!.disposition, - ContentDisposition.attachment); - expect(body.parts![2].contentDisposition!.filename, - 'Schnelltest Einverständniserklärung3.pdf'); - expect(body.parts![2].contentDisposition!.size, 174701); + body?.parts?[2].contentType?.mediaType.sub, + MediaSubtype.applicationPdf, + ); + expect( + body?.parts?[2].contentType?.parameters['name'], + 'Schnelltest Einverständniserklärung3.pdf', + ); + expect(body?.parts?[2].contentDisposition, isNotNull); + expect( + body?.parts?[2].contentDisposition?.disposition, + ContentDisposition.attachment, + ); + expect( + body?.parts?[2].contentDisposition?.filename, + 'Schnelltest Einverständniserklärung3.pdf', + ); + expect(body?.parts?[2].contentDisposition?.size, 174701); }); test('BODYSTRUCTURE 15 - complex with nested messages', () { @@ -983,57 +1169,65 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - final body = messages[0].body; + expect(messages?.length, 1); + final body = messages?[0].body; // print('parsed body part: \n$body'); expect(body, isNotNull); - expect(body!.contentType, isNotNull); - expect(body.contentType!.mediaType, isNotNull); - expect(body.contentType!.mediaType.top, MediaToptype.multipart); - expect(body.contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body.contentType!.boundary, '------------511076DDA2208D9767CA39EA'); - expect(body.length, 3); - expect(body[0].contentType!.mediaType.top, MediaToptype.text); - expect(body[0].contentType!.mediaType.sub, MediaSubtype.textPlain); - expect(body[0].encoding, '7bit'); - expect(body[0].size, 18); - expect(body[0].fetchId, '1'); - expect(body[1].fetchId, '2'); - expect(body[1].contentType, isNotNull); - expect(body[1].contentType!.mediaType.sub, MediaSubtype.messageRfc822); - expect(body[1].contentType!.parameters['name'], 'hello.eml'); - expect(body[1].contentDisposition, isNotNull); - expect( - body[1].contentDisposition!.disposition, ContentDisposition.attachment); - expect(body[1].contentDisposition!.filename, 'hello.eml'); - expect(body[1].length, 1); - expect(body[1][0].contentType, isNotNull); - expect(body[1][0].contentType!.mediaType.sub, - MediaSubtype.multipartAlternative); - expect(body[1].fetchId, '2'); - expect(body[1][0].fetchId, '2.TEXT'); - expect(body[1][0].length, 2); - expect(body[1][0][0].fetchId, '2.TEXT.1'); - expect(body[1][0][0].contentType, isNotNull); - expect(body[1][0][0].contentType!.mediaType.sub, MediaSubtype.textPlain); - expect( - body[1][0][1].contentType!.mediaType.sub, MediaSubtype.multipartMixed); - expect(body[2].fetchId, '3'); - expect(body[2][0].fetchId, '3.TEXT'); + expect(body?.contentType, isNotNull); + expect(body?.contentType?.mediaType, isNotNull); + expect(body?.contentType?.mediaType.top, MediaToptype.multipart); + expect(body?.contentType?.mediaType.sub, MediaSubtype.multipartMixed); + expect(body?.contentType?.boundary, '------------511076DDA2208D9767CA39EA'); + expect(body?.length, 3); + expect(body?[0].contentType?.mediaType.top, MediaToptype.text); + expect(body?[0].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(body?[0].encoding, '7bit'); + expect(body?[0].size, 18); + expect(body?[0].fetchId, '1'); + expect(body?[1].fetchId, '2'); + expect(body?[1].contentType, isNotNull); + expect(body?[1].contentType?.mediaType.sub, MediaSubtype.messageRfc822); + expect(body?[1].contentType?.parameters['name'], 'hello.eml'); + expect(body?[1].contentDisposition, isNotNull); + expect( + body?[1].contentDisposition?.disposition, + ContentDisposition.attachment, + ); + expect(body?[1].contentDisposition?.filename, 'hello.eml'); + expect(body?[1].length, 1); + expect(body?[1][0].contentType, isNotNull); + expect( + body?[1][0].contentType?.mediaType.sub, + MediaSubtype.multipartAlternative, + ); + expect(body?[1].fetchId, '2'); + expect(body?[1][0].fetchId, '2.TEXT'); + expect(body?[1][0].length, 2); + expect(body?[1][0][0].fetchId, '2.TEXT.1'); + expect(body?[1][0][0].contentType, isNotNull); + expect(body?[1][0][0].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect( + body?[1][0][1].contentType?.mediaType.sub, + MediaSubtype.multipartMixed, + ); + expect(body?[2].fetchId, '3'); + expect(body?[2][0].fetchId, '3.TEXT'); - final leafParts = body.allLeafParts; - expect(leafParts.length, 8); - expect(leafParts[0].contentType?.mediaType.sub, MediaSubtype.textPlain); - expect(leafParts[1].contentType?.mediaType.sub, MediaSubtype.textPlain); - expect(leafParts[2].contentType?.mediaType.sub, MediaSubtype.textHtml); - expect( - leafParts[3].contentType?.mediaType.sub, MediaSubtype.applicationPdf); - expect(leafParts[4].contentType?.mediaType.sub, MediaSubtype.textHtml); - expect(leafParts[5].contentType?.mediaType.sub, MediaSubtype.textPlain); - expect(leafParts[6].contentType?.mediaType.sub, MediaSubtype.textHtml); - expect(leafParts[7].contentType?.mediaType.sub, MediaSubtype.imageJpeg); + final leafParts = body?.allLeafParts; + expect(leafParts?.length, 8); + expect(leafParts?[0].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(leafParts?[1].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(leafParts?[2].contentType?.mediaType.sub, MediaSubtype.textHtml); + expect( + leafParts?[3].contentType?.mediaType.sub, + MediaSubtype.applicationPdf, + ); + expect(leafParts?[4].contentType?.mediaType.sub, MediaSubtype.textHtml); + expect(leafParts?[5].contentType?.mediaType.sub, MediaSubtype.textPlain); + expect(leafParts?[6].contentType?.mediaType.sub, MediaSubtype.textHtml); + expect(leafParts?[7].contentType?.mediaType.sub, MediaSubtype.imageJpeg); }); test('MODSEQ', () { @@ -1043,11 +1237,11 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].sequenceId, 50); - expect(messages[0].modSequence, 12111230047); + expect(messages?.length, 1); + expect(messages?[0].sequenceId, 50); + expect(messages?[0].modSequence, 12111230047); }); test('HIGHESTMODSEQ', () { @@ -1069,13 +1263,17 @@ void main() { expect(processed, true); expect(parser.lastParsedMessage, isNull); expect(parser.vanishedMessages, isNotNull); - expect(parser.vanishedMessages!.toList(), - [300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 405, 411]); - final result = parser.parse(details, response)!; - expect(result.messages, isEmpty); - expect(result.vanishedMessagesUidSequence, isNotNull); - expect(result.vanishedMessagesUidSequence!.toList(), - [300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 405, 411]); + expect( + parser.vanishedMessages?.toList(), + [300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 405, 411], + ); + final result = parser.parse(details, response); + expect(result?.messages, isEmpty); + expect(result?.vanishedMessagesUidSequence, isNotNull); + expect( + result?.vanishedMessagesUidSequence?.toList(), + [300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 405, 411], + ); }); test('BODY[2.1]', () { @@ -1091,12 +1289,12 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final result = parser.parse(details, response)!; - expect(result.messages, isNotEmpty); - expect(result.messages.length, 1); - final part = result.messages[0].getPart('2.1'); + final result = parser.parse(details, response); + expect(result?.messages, isNotEmpty); + expect(result?.messages.length, 1); + final part = result?.messages[0].getPart('2.1'); expect(part, isNotNull); - expect(part!.decodeContentText(), 'Hello Word\r\n'); + expect(part?.decodeContentText(), 'Hello Word\r\n'); }); test('empty BODY[2.1]', () { @@ -1111,17 +1309,17 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final result = parser.parse(details, response)!; - expect(result.messages, isNotEmpty); - expect(result.messages.length, 1); - final part = result.messages[0].getPart('2.1'); + final result = parser.parse(details, response); + expect(result?.messages, isNotEmpty); + expect(result?.messages.length, 1); + final part = result?.messages[0].getPart('2.1'); expect(part, isNotNull); - expect(part!.decodeContentText(), ''); + expect(part?.decodeContentText(), ''); }); test('ENVELOPE 1', () { const responseTexts = [ - r'* 61792 FETCH (UID 347524 RFC822.SIZE 4579 ENVELOPE ("Sun, 9 Aug 2020 09:03:12 +0200 (CEST)" "Re: Your Query" (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) ((NIL NIL "recipient" "enough.de")) NIL NIL NIL "<9jbzp5olgc9n54qwutoty0pnxunmoyho5ugshxplpvudvurjwh3a921kjdwkpwrf9oe06g95k69t@mail.ebay-kleinanzeigen.de>") FLAGS (\Seen))' + r'* 61792 FETCH (UID 347524 RFC822.SIZE 4579 ENVELOPE ("Sun, 9 Aug 2020 09:03:12 +0200 (CEST)" "Re: Your Query" (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) ((NIL NIL "recipient" "enough.de")) NIL NIL NIL "<9jbzp5olgc9n54qwutoty0pnxunmoyho5ugshxplpvudvurjwh3a921kjdwkpwrf9oe06g95k69t@mail.ebay-kleinanzeigen.de>") FLAGS (\Seen))', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -1131,24 +1329,28 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].uid, 347524); - expect(messages[0].size, 4579); - expect(messages[0].flags, ['\\Seen']); - expect(messages[0].from, isNotNull); - expect(messages[0].from!.length, 1); - expect(messages[0].from![0].email, - 'anbieter-sdkjskjfkd@mail.ebay-kleinanzeigen.de'); - expect( - messages[0].from![0].personalName, 'C. Sender über eBay Kleinanzeigen'); - expect(messages[0].decodeSubject(), 'Re: Your Query'); + expect(messages?.length, 1); + expect(messages?[0].uid, 347524); + expect(messages?[0].size, 4579); + expect(messages?[0].flags, ['\\Seen']); + expect(messages?[0].from, isNotNull); + expect(messages?[0].from?.length, 1); + expect( + messages?[0].from?[0].email, + 'anbieter-sdkjskjfkd@mail.ebay-kleinanzeigen.de', + ); + expect( + messages?[0].from?[0].personalName, + 'C. Sender über eBay Kleinanzeigen', + ); + expect(messages?[0].decodeSubject(), 'Re: Your Query'); }); test('ENVELOPE 2 with escaped quote in subject', () { const responseTexts = [ - r'* 61792 FETCH (UID 347524 RFC822.SIZE 4579 ENVELOPE ("Sun, 9 Aug 2020 09:03:12 +0200 (CEST)" "Re: Your Query about \"Table\"" (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) ((NIL NIL "recipient" "enough.de")) NIL NIL NIL "<9jbzp5olgc9n54qwutoty0pnxunmoyho5ugshxplpvudvurjwh3a921kjdwkpwrf9oe06g95k69t@mail.ebay-kleinanzeigen.de>") FLAGS (\Seen))' + r'* 61792 FETCH (UID 347524 RFC822.SIZE 4579 ENVELOPE ("Sun, 9 Aug 2020 09:03:12 +0200 (CEST)" "Re: Your Query about \"Table\"" (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) ((NIL NIL "recipient" "enough.de")) NIL NIL NIL "<9jbzp5olgc9n54qwutoty0pnxunmoyho5ugshxplpvudvurjwh3a921kjdwkpwrf9oe06g95k69t@mail.ebay-kleinanzeigen.de>") FLAGS (\Seen))', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -1158,24 +1360,28 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].uid, 347524); - expect(messages[0].size, 4579); - expect(messages[0].flags, ['\\Seen']); - expect(messages[0].decodeSubject(), 'Re: Your Query about "Table"'); - expect(messages[0].from, isNotNull); - expect(messages[0].from!.length, 1); - expect(messages[0].from![0].email, - 'anbieter-sdkjskjfkd@mail.ebay-kleinanzeigen.de'); - expect( - messages[0].from![0].personalName, 'C. Sender über eBay Kleinanzeigen'); + expect(messages?.length, 1); + expect(messages?[0].uid, 347524); + expect(messages?[0].size, 4579); + expect(messages?[0].flags, ['\\Seen']); + expect(messages?[0].decodeSubject(), 'Re: Your Query about "Table"'); + expect(messages?[0].from, isNotNull); + expect(messages?[0].from?.length, 1); + expect( + messages?[0].from?[0].email, + 'anbieter-sdkjskjfkd@mail.ebay-kleinanzeigen.de', + ); + expect( + messages?[0].from?[0].personalName, + 'C. Sender über eBay Kleinanzeigen', + ); }); test('ENVELOPE 3 with base64 in subject', () { const responseTexts = [ - '''* 43792 FETCH (UID 146616 RFC822.SIZE 23156 ENVELOPE ("Tue, 12 Jan 2021 00:18:08 +0800" " =?utf-8?B?SWbCoEnCoGhhdmXCoHRoZcKgaG9ub3LCoHRvwqBqb2luwqB5b3VywqB2ZW5kb3LCoGFzwqBhwqB0cmFuc2xhdGlvbsKgY29tcGFueQ==?=" (("Sherry|Company" NIL "company" "domain.com")) (("Sherry|Company" NIL "company" "domain.com")) ((NIL NIL "company" "domain.com")) (("info" NIL "info" "recipientdomain.com")) NIL NIL NIL " ") FLAGS ())''' + '''* 43792 FETCH (UID 146616 RFC822.SIZE 23156 ENVELOPE ("Tue, 12 Jan 2021 00:18:08 +0800" " =?utf-8?B?SWbCoEnCoGhhdmXCoHRoZcKgaG9ub3LCoHRvwqBqb2luwqB5b3VywqB2ZW5kb3LCoGFzwqBhwqB0cmFuc2xhdGlvbsKgY29tcGFueQ==?=" (("Sherry|Company" NIL "company" "domain.com")) (("Sherry|Company" NIL "company" "domain.com")) ((NIL NIL "company" "domain.com")) (("info" NIL "info" "recipientdomain.com")) NIL NIL NIL " ") FLAGS ())''', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -1185,38 +1391,44 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].decodeSubject(), - ' If I have the honor to join your vendor as a translation company'); - expect(messages[0].uid, 146616); - expect(messages[0].size, 23156); - expect(messages[0].flags, []); - expect(messages[0].from, isNotNull); - expect(messages[0].from!.length, 1); - expect(messages[0].from![0].email, 'company@domain.com'); - expect(messages[0].from![0].personalName, 'Sherry|Company'); + expect(messages?.length, 1); + expect( + messages?[0].decodeSubject(), + ' If I have the honor to join your vendor as a translation company', + ); + expect(messages?[0].uid, 146616); + expect(messages?[0].size, 23156); + expect(messages?[0].flags, []); + expect(messages?[0].from, isNotNull); + expect(messages?[0].from?.length, 1); + expect(messages?[0].from?[0].email, 'company@domain.com'); + expect(messages?[0].from?[0].personalName, 'Sherry|Company'); }); test('ENVELOPE 4 with linebreak in subject', () { final details = ImapResponse() ..add(ImapResponseLine( - '''* 65300 FETCH (UID 355372 ENVELOPE ("Sat, 13 Nov 2021 09:01:57 +0100 (CET)" {108}''')) + '''* 65300 FETCH (UID 355372 ENVELOPE ("Sat, 13 Nov 2021 09:01:57 +0100 (CET)" {108}''', + )) ..add(ImapResponseLine.raw(utf8 .encode('''=?UTF-8?Q?Anzeige_"K=C3=BCchenutensilien,_K=C3=A4seme?=\r =?UTF-8?Q?sser"_erfolgreich_ver=C3=B6ffentlicht.?='''))) ..add(ImapResponseLine( - ''' (("eBay Kleinanzeigen" NIL "noreply" "ebay-kleinanzeigen.de")) (("eBay Kleinanzeigen" NIL "noreply" "ebay-kleinanzeigen.de")) (("eBay Kleinanzeigen" NIL "noreply" "ebay-kleinanzeigen.de")) ((NIL NIL "some.one" "domain.com")) NIL NIL NIL "<709648757.77104.1636790517873@tns-consumer-app-7.tns-consumer-app.ebayk.svc.cluster.local>"))''')); + ''' (("eBay Kleinanzeigen" NIL "noreply" "ebay-kleinanzeigen.de")) (("eBay Kleinanzeigen" NIL "noreply" "ebay-kleinanzeigen.de")) (("eBay Kleinanzeigen" NIL "noreply" "ebay-kleinanzeigen.de")) ((NIL NIL "some.one" "domain.com")) NIL NIL NIL "<709648757.77104.1636790517873@tns-consumer-app-7.tns-consumer-app.ebayk.svc.cluster.local>"))''', + )); final parser = FetchParser(isUidFetch: false); final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].decodeSubject(), - 'Anzeige "Küchenutensilien, Käsemesser" erfolgreich veröffentlicht.'); + expect(messages?.length, 1); + expect( + messages?[0].decodeSubject(), + 'Anzeige "Küchenutensilien, Käsemesser" erfolgreich veröffentlicht.', + ); }); test('ENVELOPE 5 with base-encoded personal name in email', () { @@ -1231,26 +1443,28 @@ void main() { final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].decodeSubject(), - 'New Release: Modernize Applications Faster Than Ever'); - expect(messages[0].uid, 366113); - expect(messages[0].size, 67087); - expect(messages[0].flags, ['Seen']); - expect(messages[0].from, isNotNull); - expect(messages[0].from!.length, 1); - expect(messages[0].from![0].email, 'progress@products.progress.com'); - expect( - messages[0].from![0].personalName, + expect(messages?.length, 1); + expect( + messages?[0].decodeSubject(), + 'New Release: Modernize Applications Faster Than Ever', + ); + expect(messages?[0].uid, 366113); + expect(messages?[0].size, 67087); + expect(messages?[0].flags, ['Seen']); + expect(messages?[0].from, isNotNull); + expect(messages?[0].from?.length, 1); + expect(messages?[0].from?[0].email, 'progress@products.progress.com'); + expect( + messages?[0].from?[0].personalName, 'The Telerik & Kendo UI Teams at Progress ', ); }); test('measure performance', () { const responseTexts = [ - r'* 61792 FETCH (UID 347524 RFC822.SIZE 4579 ENVELOPE ("Sun, 9 Aug 2020 09:03:12 +0200 (CEST)" "Re: Your Query about \"Table\"" (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) ((NIL NIL "recipient" "enough.de")) NIL NIL NIL "<9jbzp5olgc9n54qwutoty0pnxunmoyho5ugshxplpvudvurjwh3a921kjdwkpwrf9oe06g95k69t@mail.ebay-kleinanzeigen.de>") FLAGS (\Seen))' + r'* 61792 FETCH (UID 347524 RFC822.SIZE 4579 ENVELOPE ("Sun, 9 Aug 2020 09:03:12 +0200 (CEST)" "Re: Your Query about \"Table\"" (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) (("=?ISO-8859-1?Q?C=2E_Sender_=FCber_eBay_Kleinanzeigen?=" NIL "anbieter-sdkjskjfkd" "mail.ebay-kleinanzeigen.de")) ((NIL NIL "recipient" "enough.de")) NIL NIL NIL "<9jbzp5olgc9n54qwutoty0pnxunmoyho5ugshxplpvudvurjwh3a921kjdwkpwrf9oe06g95k69t@mail.ebay-kleinanzeigen.de>") FLAGS (\Seen))', ]; final details = ImapResponse(); for (final text in responseTexts) { @@ -1259,10 +1473,11 @@ void main() { final parser = FetchParser(isUidFetch: false); final response = Response()..status = ResponseStatus.ok; final stopwatch = Stopwatch()..start(); - for (var i = 10000; --i >= 0;) { + const count = 10000; + for (var i = count; --i >= 0;) { final processed = parser.parseUntagged(details, response); if (!processed) { - fail('unable to parse during performance test at round $i'); + fail('unable to parse during performance test at round ${count - i}'); } } //print('elapsed time: ${stopwatch.elapsedMicroseconds}'); @@ -1277,13 +1492,14 @@ void main() { Content-Type: text/plain; charset=windows-1252; format=flowed\r Content-Transfer-Encoding: 8bit\r \r -Teší ma, že vás spoznávam!\r +Teší ma, že vás spoznávam\r '''; final codecData = codec.encode(messageText); final messageData = Uint8List.fromList(codecData); details ..add(ImapResponseLine( - '* 61792 FETCH (UID 347524 BODY[] {${messageData.length}}')) + '* 61792 FETCH (UID 347524 BODY[] {${messageData.length}}', + )) ..add(ImapResponseLine.raw(messageData)) ..add(ImapResponseLine(')')); @@ -1291,13 +1507,13 @@ Teší ma, že vás spoznávam!\r final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].decodeSubject(), 'Hello world'); - expect(messages[0].uid, 347524); - expect(messages[0].sequenceId, 61792); - expect(messages[0].decodeContentText(), 'Teší ma, že vás spoznávam!\r\n'); + expect(messages?.length, 1); + expect(messages?[0].decodeSubject(), 'Hello world'); + expect(messages?[0].uid, 347524); + expect(messages?[0].sequenceId, 61792); + expect(messages?[0].decodeContentText(), 'Teší ma, že vás spoznávam\r\n'); }); test('Multipart text message - windows-1252', () { @@ -1310,19 +1526,20 @@ Content-Type: multipart/alternative; boundary=abcdefghijkl\r Content-Type: text/plain; charset=windows-1252; format=flowed\r Content-Transfer-Encoding: 8bit\r \r -Teší ma, že vás spoznávam!\r +Teší ma, že vás spoznávam\r --abcdefghijkl\r Content-Type: text/html; charset=windows-1252\r Content-Transfer-Encoding: 8bit\r \r -

Teší ma, že vás spoznávam!

\r +

Teší ma, že vás spoznávam

\r --abcdefghijkl--\r '''; final codecData = codec.encode(messageText); final messageData = Uint8List.fromList(codecData); details ..add(ImapResponseLine( - '* 61792 FETCH (UID 347524 BODY[] {${messageData.length}}')) + '* 61792 FETCH (UID 347524 BODY[] {${messageData.length}}', + )) ..add(ImapResponseLine.raw(messageData)) ..add(ImapResponseLine(')')); @@ -1330,22 +1547,22 @@ Content-Transfer-Encoding: 8bit\r final response = Response()..status = ResponseStatus.ok; final processed = parser.parseUntagged(details, response); expect(processed, true); - final messages = parser.parse(details, response)!.messages; + final messages = parser.parse(details, response)?.messages; expect(messages, isNotNull); - expect(messages.length, 1); - expect(messages[0].headers, isNotNull); - expect(messages[0].headers?.isNotEmpty, isTrue); - expect(messages[0].headers?.length, 2); - expect(messages[0].decodeSubject(), 'Hello world'); - expect(messages[0].uid, 347524); - expect(messages[0].sequenceId, 61792); + expect(messages?.length, 1); + expect(messages?[0].headers, isNotNull); + expect(messages?[0].headers?.isNotEmpty, isTrue); + expect(messages?[0].headers?.length, 2); + expect(messages?[0].decodeSubject(), 'Hello world'); + expect(messages?[0].uid, 347524); + expect(messages?[0].sequenceId, 61792); expect( - messages[0].decodeTextPlainPart(), - 'Teší ma, že vás spoznávam!\r\n', + messages?[0].decodeTextPlainPart(), + 'Teší ma, že vás spoznávam\r\n', ); expect( - messages[0].decodeTextHtmlPart(), - '

Teší ma, že vás spoznávam!

\r\n', + messages?[0].decodeTextHtmlPart(), + '

Teší ma, že vás spoznávam

\r\n', ); }); }); diff --git a/test/src/imap/id_parser_test.dart b/test/src/imap/id_parser_test.dart index 9518970b..a6006af4 100644 --- a/test/src/imap/id_parser_test.dart +++ b/test/src/imap/id_parser_test.dart @@ -28,12 +28,12 @@ void main() { expect(processed, true); final id = parser.parse(details, response); expect(id, isNotNull); - expect(id!.name, 'Cyrus'); - expect(id.version, '1.5'); - expect(id.os, 'sunos'); - expect(id.osVersion, '5.5'); - expect(id.supportUrl, 'mailto:cyrus-bugs+@andrew.cmu.edu'); - expect(id.nonStandardFields, isEmpty); + expect(id?.name, 'Cyrus'); + expect(id?.version, '1.5'); + expect(id?.os, 'sunos'); + expect(id?.osVersion, '5.5'); + expect(id?.supportUrl, 'mailto:cyrus-bugs+@andrew.cmu.edu'); + expect(id?.nonStandardFields, isEmpty); }); test('Cyrus with Date', () { @@ -46,12 +46,12 @@ void main() { expect(processed, true); final id = parser.parse(details, response); expect(id, isNotNull); - expect(id!.name, 'Cyrus'); - expect(id.version, '1.5'); - expect(id.os, 'sunos'); - expect(id.osVersion, '5.5'); - expect(id.supportUrl, 'mailto:cyrus-bugs+@andrew.cmu.edu'); - expect(id.nonStandardFields, isEmpty); - expect(id.date?.toUtc(), DateTime.utc(2021, 08, 15, 22, 45)); + expect(id?.name, 'Cyrus'); + expect(id?.version, '1.5'); + expect(id?.os, 'sunos'); + expect(id?.osVersion, '5.5'); + expect(id?.supportUrl, 'mailto:cyrus-bugs+@andrew.cmu.edu'); + expect(id?.nonStandardFields, isEmpty); + expect(id?.date?.toUtc(), DateTime.utc(2021, 08, 15, 22, 45)); }); } diff --git a/test/src/imap/imap_response_reader_test.dart b/test/src/imap/imap_response_reader_test.dart index 157a8e4c..ad023db4 100644 --- a/test/src/imap/imap_response_reader_test.dart +++ b/test/src/imap/imap_response_reader_test.dart @@ -38,17 +38,21 @@ void main() { '7496 302) "alternative"))\r\n'; reader.onData(_toUint8List(text)); expect(_lastResponse, isNotNull, reason: 'response expected'); - expect(_lastResponse!.isSimple, false); - expect(_lastResponse!.lines, isNotEmpty); - expect(_lastResponse!.lines.length, 3); - expect(_lastResponse!.lines[0].isWithLiteral, true); - expect(_lastResponse!.lines[0].literal, 61); - expect(_lastResponse!.lines[0].line, - '''1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200" RFC822.SIZE 15320 ENVELOPE ("Fri, 25 Oct 2019 16:35:28 +0200 (CEST)"'''); - expect(_lastResponse!.lines[1].isWithLiteral, false); - expect(_lastResponse!.lines[1].line, - 'New appointment: SoW (x2) for rebranding of App & Mobile Apps'); - expect(_lastResponse!.lines[2].isWithLiteral, false); + expect(_lastResponse?.isSimple, false); + expect(_lastResponse?.lines, isNotEmpty); + expect(_lastResponse?.lines.length, 3); + expect(_lastResponse?.lines[0].isWithLiteral, true); + expect(_lastResponse?.lines[0].literal, 61); + expect( + _lastResponse?.lines[0].line, + '''1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200" RFC822.SIZE 15320 ENVELOPE ("Fri, 25 Oct 2019 16:35:28 +0200 (CEST)"''', + ); + expect(_lastResponse?.lines[1].isWithLiteral, false); + expect( + _lastResponse?.lines[1].line, + 'New appointment: SoW (x2) for rebranding of App & Mobile Apps', + ); + expect(_lastResponse?.lines[2].isWithLiteral, false); _lastResponse = null; }); // test end @@ -58,14 +62,18 @@ void main() { '1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200")\r\n'; reader.onData(_toUint8List(text)); expect(_lastResponse != null, true, reason: 'response expected'); - expect(_lastResponse!.isSimple, true); - expect(_lastResponse!.lines.length, 1); - expect(_lastResponse!.first, _lastResponse!.lines[0]); - expect(_lastResponse!.lines[0].isWithLiteral, false); - expect(_lastResponse!.lines[0].rawLine, - '1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200")'); - expect(_lastResponse!.lines[0].line, - '1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200")'); + expect(_lastResponse?.isSimple, true); + expect(_lastResponse?.lines.length, 1); + expect(_lastResponse?.first, _lastResponse?.lines[0]); + expect(_lastResponse?.lines[0].isWithLiteral, false); + expect( + _lastResponse?.lines[0].rawLine, + '1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200")', + ); + expect( + _lastResponse?.lines[0].line, + '1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200")', + ); _lastResponse = null; }); // test end @@ -77,14 +85,18 @@ void main() { text = ' "25-Oct-2019 16:35:31 +0200")\r\n'; reader.onData(_toUint8List(text)); expect(_lastResponse != null, true, reason: 'response expected'); - expect(_lastResponse!.isSimple, true); - expect(_lastResponse!.lines.length, 1); - expect(_lastResponse!.first, _lastResponse!.lines[0]); - expect(_lastResponse!.lines[0].isWithLiteral, false); - expect(_lastResponse!.lines[0].rawLine, - '1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200")'); - expect(_lastResponse!.lines[0].line, - '1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200")'); + expect(_lastResponse?.isSimple, true); + expect(_lastResponse?.lines.length, 1); + expect(_lastResponse?.first, _lastResponse?.lines[0]); + expect(_lastResponse?.lines[0].isWithLiteral, false); + expect( + _lastResponse?.lines[0].rawLine, + '1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200")', + ); + expect( + _lastResponse?.lines[0].line, + '1232 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200")', + ); _lastResponse = null; }); @@ -99,17 +111,17 @@ void main() { text = 'fat man\r\n'; reader.onData(_toUint8List(text)); expect(_lastResponse != null, true); - expect(_lastResponse!.isSimple, false); - expect(_lastResponse!.lines.length, 3); - expect(_lastResponse!.lines[0].isWithLiteral, true); - expect(_lastResponse!.lines[0].literal, 11); - expect(_lastResponse!.lines[0].rawLine, 'A001 LOGIN {11+}'); - expect(_lastResponse!.lines[0].line, 'A001 LOGIN'); - expect(_lastResponse!.lines[1].isWithLiteral, true); - expect(_lastResponse!.lines[1].line, 'FRED FOOBAR'); - expect(_lastResponse!.lines[1].literal, 7); - expect(_lastResponse!.lines[2].isWithLiteral, false); - expect(_lastResponse!.lines[2].line, 'fat man'); + expect(_lastResponse?.isSimple, false); + expect(_lastResponse?.lines.length, 3); + expect(_lastResponse?.lines[0].isWithLiteral, true); + expect(_lastResponse?.lines[0].literal, 11); + expect(_lastResponse?.lines[0].rawLine, 'A001 LOGIN {11+}'); + expect(_lastResponse?.lines[0].line, 'A001 LOGIN'); + expect(_lastResponse?.lines[1].isWithLiteral, true); + expect(_lastResponse?.lines[1].line, 'FRED FOOBAR'); + expect(_lastResponse?.lines[1].literal, 7); + expect(_lastResponse?.lines[2].isWithLiteral, false); + expect(_lastResponse?.lines[2].line, 'fat man'); _lastResponse = null; }); // test end @@ -134,11 +146,13 @@ void main() { expect(response.isSimple, true); expect(response.lines[0].isWithLiteral, false); expect(response.lines[0].literal, null); - expect(response.first.line!.isNotEmpty, true); + expect(response.first.line?.isNotEmpty, true); } final last = _lastResponses.last; - expect(last.lines[0].line, - 'a4 OK [READ-WRITE] Select completed (0.088 + 0.000 + 0.087 secs).'); + expect( + last.lines[0].line, + 'a4 OK [READ-WRITE] Select completed (0.088 + 0.000 + 0.087 secs).', + ); // expect(_lastResponse.lines[0].line, r'* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $Forwarded $social $promotion $HasAttachment $HasNoAttachment $HasChat $MDNSent)'); // expect(_lastResponse.lines[1] != null, true); // expect(_lastResponse.lines[1].line, r"* OK [PERMANENTFLAGS (\Seen \Flagged)] Flags permitted"); @@ -196,14 +210,20 @@ a3 OK Fetch completed (0.020 + 0.000 + 0.019 secs).\r expect(_lastResponses[0].lines[0].rawLine, '* 3 FETCH (BODY[TEXT] {6}'); expect(_lastResponses[0].lines[1].line, 'Hi\r\n\r\n'); expect( - _lastResponses[0].lines[2].rawLine, ' BODY[HEADER.FIELDS (DATE)] {47}'); - expect(_lastResponses[0].lines[3].line, - 'Date: Tue, 21 Jan 2020 11:59:55 +0100 (CET)\r\n\r\n'); + _lastResponses[0].lines[2].rawLine, + ' BODY[HEADER.FIELDS (DATE)] {47}', + ); + expect( + _lastResponses[0].lines[3].line, + 'Date: Tue, 21 Jan 2020 11:59:55 +0100 (CET)\r\n\r\n', + ); expect(_lastResponses[0].lines[4].rawLine, ')'); expect(_lastResponses[0].lines.length, 5); expect(_lastResponses[1].isSimple, true); - expect(_lastResponses[1].parseText, - 'a3 OK Fetch completed (0.020 + 0.000 + 0.019 secs).'); + expect( + _lastResponses[1].parseText, + 'a3 OK Fetch completed (0.020 + 0.000 + 0.019 secs).', + ); }); test('ImapResponseReader - 2 responses in 1 delivery with 3 literals', () { @@ -225,18 +245,28 @@ a3 OK Fetch completed (0.020 + 0.000 + 0.019 secs).\r expect(_lastResponses[0].lines[0].rawLine, '* 3 FETCH (BODY[TEXT] {6}'); expect(_lastResponses[0].lines[1].line, 'Hi\r\n\r\n'); expect( - _lastResponses[0].lines[2].rawLine, ' BODY[HEADER.FIELDS (DATE)] {47}'); - expect(_lastResponses[0].lines[3].line, - 'Date: Tue, 21 Jan 2020 11:59:55 +0100 (CET)\r\n\r\n'); - expect(_lastResponses[0].lines[4].rawLine, - ' BODY[HEADER.FIELDS (MESSAGE-ID)] {36}'); - expect(_lastResponses[0].lines[5].line, - 'Message-ID: <3049329.2-302-12-2>\r\n\r\n'); + _lastResponses[0].lines[2].rawLine, + ' BODY[HEADER.FIELDS (DATE)] {47}', + ); + expect( + _lastResponses[0].lines[3].line, + 'Date: Tue, 21 Jan 2020 11:59:55 +0100 (CET)\r\n\r\n', + ); + expect( + _lastResponses[0].lines[4].rawLine, + ' BODY[HEADER.FIELDS (MESSAGE-ID)] {36}', + ); + expect( + _lastResponses[0].lines[5].line, + 'Message-ID: <3049329.2-302-12-2>\r\n\r\n', + ); expect(_lastResponses[0].lines[6].rawLine, ')'); expect(_lastResponses[0].lines.length, 7); expect(_lastResponses[1].isSimple, true); - expect(_lastResponses[1].parseText, - 'a3 OK Fetch completed (0.020 + 0.000 + 0.019 secs).'); + expect( + _lastResponses[1].parseText, + 'a3 OK Fetch completed (0.020 + 0.000 + 0.019 secs).', + ); }); test('ImapResponseReader - 3 response lines with break in rn sequence', () { @@ -257,7 +287,9 @@ a3 OK Fetch completed (0.020 + 0.000 + 0.019 secs).\r expect(_lastResponses[1].lines[0].rawLine, '* 4 FETCH (BODY[TEXT] {7}'); expect(_lastResponses[1].lines[1].line, '1234567'); expect(_lastResponses[1].lines[2].rawLine, ')'); - expect(_lastResponses[2].parseText, - 'a3 OK Fetch completed (0.020 + 0.000 + 0.019 secs).'); + expect( + _lastResponses[2].parseText, + 'a3 OK Fetch completed (0.020 + 0.000 + 0.019 secs).', + ); }); } diff --git a/test/src/imap/imap_response_test.dart b/test/src/imap/imap_response_test.dart index b5a1dc3d..9e6207f5 100644 --- a/test/src/imap/imap_response_test.dart +++ b/test/src/imap/imap_response_test.dart @@ -50,9 +50,9 @@ void main() { expect(parsed.values[1].value, 'OK'); expect(parsed.values[2].value, 'FLAGS'); expect(parsed.values[2].children != null, true); - expect(parsed.values[2].children!.length, 2); - expect(parsed.values[2].children![0].value, 'seen'); - expect(parsed.values[2].children![1].value, 'new flag'); + expect(parsed.values[2].children?.length, 2); + expect(parsed.values[2].children?[0].value, 'seen'); + expect(parsed.values[2].children?[1].value, 'new flag'); input = 'A001 OK FLAGS (seen new)'; response = ImapResponse(); @@ -65,9 +65,9 @@ void main() { expect(parsed.values[1].value, 'OK'); expect(parsed.values[2].value, 'FLAGS'); expect(parsed.values[2].children != null, true); - expect(parsed.values[2].children!.length, 2); - expect(parsed.values[2].children![0].value, 'seen'); - expect(parsed.values[2].children![1].value, 'new'); + expect(parsed.values[2].children?.length, 2); + expect(parsed.values[2].children?[0].value, 'seen'); + expect(parsed.values[2].children?[1].value, 'new'); }); // test end test('ImapResponse.iterate() with simple response and empty parentheses', () { @@ -83,7 +83,7 @@ void main() { expect(parsed.values[1].value, 'OK'); expect(parsed.values[2].value, 'FLAGS'); expect(parsed.values[2].children != null, true); - expect(parsed.values[2].children!.length, 0); + expect(parsed.values[2].children?.length, 0); expect(parsed.values[3].value, 'INTERNALDATE'); input = 'A001 OK FLAGS ()'; @@ -98,7 +98,7 @@ void main() { expect(parsed.values[1].value, 'OK'); expect(parsed.values[2].value, 'FLAGS'); expect(parsed.values[2].children != null, true); - expect(parsed.values[2].children!.length, 0); + expect(parsed.values[2].children?.length, 0); }); // test end test('ImapResponse.iterate() with complex response and parentheses', () { @@ -114,92 +114,101 @@ void main() { expect(parsed.values[1].value, 'OK'); expect(parsed.values[2].value, 'FLAGS'); expect(parsed.values[2].children != null, true); - expect(parsed.values[2].children!.length, 2); - expect(parsed.values[2].children![0].valueOrDataText, '1"2 3 \r\n90'); - expect(parsed.values[2].children![1].value, 'seen'); + expect(parsed.values[2].children?.length, 2); + expect(parsed.values[2].children?[0].valueOrDataText, '1"2 3 \r\n90'); + expect(parsed.values[2].children?[1].value, 'seen'); }); - test('ImapResponse.iterate() with simple response and double parentheses [1]', - () { - const input = 'A001 OK FLAGS (("seen" "new flag"))'; - final response = ImapResponse(); - final line = ImapResponseLine(input); - response.add(line); - final parsed = response.iterate(); - - //print(parsed.values); - expect(parsed.values.length, 3); - expect(parsed.values[0].value, 'A001'); - expect(parsed.values[1].value, 'OK'); - expect(parsed.values[2].value, 'FLAGS'); - expect(parsed.values[2].children != null, true); - expect(parsed.values[2].children![0].children!.length, 2); - expect(parsed.values[2].children![0].children![0].value, 'seen'); - expect(parsed.values[2].children![0].children![1].value, 'new flag'); - }); - test('ImapResponse.iterate() with simple response and double parentheses [2]', - () { - const input = 'A001 OK FLAGS ((seen new))'; - final response = ImapResponse(); - final line = ImapResponseLine(input); - response.add(line); - final parsed = response.iterate(); - - //print(parsed.values); - expect(parsed.values.length, 3); - expect(parsed.values[0].value, 'A001'); - expect(parsed.values[1].value, 'OK'); - expect(parsed.values[2].value, 'FLAGS'); - expect(parsed.values[2].children != null, true); - expect(parsed.values[2].children!.length, 1); - expect(parsed.values[2].children![0].children!.length, 2); - expect(parsed.values[2].children![0].children![0].value, 'seen'); - expect(parsed.values[2].children![0].children![1].value, 'new'); - }); // test end - test( - 'ImapResponse.iterate() with simple response and emtpty ' - 'Flags parentheses', () { - const input = 'A001 OK FLAGS () INTERNALDATE'; - final response = ImapResponse(); - final line = ImapResponseLine(input); - response.add(line); - final parsed = response.iterate(); + 'ImapResponse.iterate() with simple response and double parentheses [1]', + () { + const input = 'A001 OK FLAGS (("seen" "new flag"))'; + final response = ImapResponse(); + final line = ImapResponseLine(input); + response.add(line); + final parsed = response.iterate(); + + //print(parsed.values); + expect(parsed.values.length, 3); + expect(parsed.values[0].value, 'A001'); + expect(parsed.values[1].value, 'OK'); + expect(parsed.values[2].value, 'FLAGS'); + expect(parsed.values[2].children != null, true); + expect(parsed.values[2].children?[0].children?.length, 2); + expect(parsed.values[2].children?[0].children?[0].value, 'seen'); + expect(parsed.values[2].children?[0].children?[1].value, 'new flag'); + }, + ); + test( + 'ImapResponse.iterate() with simple response and double parentheses [2]', + () { + const input = 'A001 OK FLAGS ((seen new))'; + final response = ImapResponse(); + final line = ImapResponseLine(input); + response.add(line); + final parsed = response.iterate(); + + //print(parsed.values); + expect(parsed.values.length, 3); + expect(parsed.values[0].value, 'A001'); + expect(parsed.values[1].value, 'OK'); + expect(parsed.values[2].value, 'FLAGS'); + expect(parsed.values[2].children != null, true); + expect(parsed.values[2].children?.length, 1); + expect(parsed.values[2].children?[0].children?.length, 2); + expect(parsed.values[2].children?[0].children?[0].value, 'seen'); + expect(parsed.values[2].children?[0].children?[1].value, 'new'); + }, + ); // test end - //print(parsed.values); - expect(parsed.values.length, 4); - expect(parsed.values[0].value, 'A001'); - expect(parsed.values[1].value, 'OK'); - expect(parsed.values[2].value, 'FLAGS'); - expect(parsed.values[2].children != null, true); - expect(parsed.values[2].children!.length, 0); - expect(parsed.values[3].value, 'INTERNALDATE'); - }); // test end + test( + 'ImapResponse.iterate() with simple response and emtpty ' + 'Flags parentheses', + () { + const input = 'A001 OK FLAGS () INTERNALDATE'; + final response = ImapResponse(); + final line = ImapResponseLine(input); + response.add(line); + final parsed = response.iterate(); + + //print(parsed.values); + expect(parsed.values.length, 4); + expect(parsed.values[0].value, 'A001'); + expect(parsed.values[1].value, 'OK'); + expect(parsed.values[2].value, 'FLAGS'); + expect(parsed.values[2].children != null, true); + expect(parsed.values[2].children?.length, 0); + expect(parsed.values[3].value, 'INTERNALDATE'); + }, + ); // test end test('ImapResponse.iterate() with complex real world response', () { final response = ImapResponse() ..add(ImapResponseLine( - '* 123 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200" ' - 'RFC822.SIZE 15320 ENVELOPE ("Fri, 25 Oct 2019 16:35:28 ' - '+0200 (CEST)" {61}')); + '* 123 FETCH (FLAGS () INTERNALDATE "25-Oct-2019 16:35:31 +0200" ' + 'RFC822.SIZE 15320 ENVELOPE ("Fri, 25 Oct 2019 16:35:28 ' + '+0200 (CEST)" {61}', + )); expect(response.first.literal, 61); response ..add(ImapResponseLine.raw(Uint8List.fromList( - 'New appointment: SoW (x2) for rebranding of App & Mobile Apps' - .codeUnits))) + 'New appointment: SoW (x2) for rebranding of App & Mobile Apps' + .codeUnits, + ))) ..add(ImapResponseLine( - '(("=?UTF-8?Q?Sch=C3=B6n=2C_Rob?=" NIL "rob.schoen" "domain.com")) ' - '(("=?UTF-8?Q?Sch=C3=B6n=2C_' - 'Rob?=" NIL "rob.schoen" "domain.com")) (("=?UTF-8?Q?Sch=C3=B6n=2C_' - 'Rob?=" NIL "rob.schoen" ' - '"domain.com")) (("Alice Dev" NIL "alice.dev" "domain.com")) NIL NIL' - ' "" "<130499090.797.1572014128349@produ' - 'ct-gw2.domain.com>") BODY (("text" "plain" ' - '("charset" "UTF-8") NIL NIL "quoted-printable" 1289 53)("text" ' - '"html"' - ' ("charset" "UTF-8") NIL NIL "quoted-printable" ' - '7496 302) "alternative"))')); + '(("=?UTF-8?Q?Sch=C3=B6n=2C_Rob?=" NIL "rob.schoen" "domain.com")) ' + '(("=?UTF-8?Q?Sch=C3=B6n=2C_' + 'Rob?=" NIL "rob.schoen" "domain.com")) (("=?UTF-8?Q?Sch=C3=B6n=2C_' + 'Rob?=" NIL "rob.schoen" ' + '"domain.com")) (("Alice Dev" NIL "alice.dev" "domain.com")) NIL NIL' + ' "" "<130499090.797.1572014128349@produ' + 'ct-gw2.domain.com>") BODY (("text" "plain" ' + '("charset" "UTF-8") NIL NIL "quoted-printable" 1289 53)("text" ' + '"html"' + ' ("charset" "UTF-8") NIL NIL "quoted-printable" ' + '7496 302) "alternative"))', + )); final parsed = response.iterate(); //print(parsed.values); @@ -207,109 +216,122 @@ void main() { expect(parsed.values[0].value, '*'); expect(parsed.values[1].value, '123'); expect(parsed.values[2].value, 'FETCH'); - var values = parsed.values[2].children!; - - expect(values[0].value, 'FLAGS'); - expect(values[0].children != null, true); - expect(values[0].children!.length, 0); - expect(values[1].value, 'INTERNALDATE'); - expect(values[2].value, '25-Oct-2019 16:35:31 +0200'); - expect(values[3].value, 'RFC822.SIZE'); - expect(values[4].value, '15320'); - expect(values[5].value, 'ENVELOPE'); - values = values[5].children!; - - expect(values[0].value, 'Fri, 25 Oct 2019 16:35:28 +0200 (CEST)'); - expect(values[1].valueOrDataText, - 'New appointment: SoW (x2) for rebranding of App & Mobile Apps'); - expect(values[2].value, null); - expect(values[2].children != null, true); - expect(values[2].children!.length, 1); - expect(values[2].children![0].children!.length, 4); - expect(values[2].children![0].children![0].value, - '=?UTF-8?Q?Sch=C3=B6n=2C_Rob?='); - expect(values[2].children![0].children![1].value, 'NIL'); - expect(values[2].children![0].children![2].value, 'rob.schoen'); - expect(values[2].children![0].children![3].value, 'domain.com'); - - expect(values[3].value, null); - expect(values[3].children != null, true); - expect(values[3].children!.length, 1); - expect(values[3].children![0].children!.length, 4); - expect(values[3].children![0].children![0].value, - '=?UTF-8?Q?Sch=C3=B6n=2C_Rob?='); - expect(values[3].children![0].children![1].value, 'NIL'); - expect(values[3].children![0].children![2].value, 'rob.schoen'); - expect(values[3].children![0].children![3].value, 'domain.com'); - - expect(values[4].value, null); - expect(values[4].children != null, true); - expect(values[4].children!.length, 1); - expect(values[4].children![0].children!.length, 4); - expect(values[4].children![0].children![0].value, - '=?UTF-8?Q?Sch=C3=B6n=2C_Rob?='); - expect(values[4].children![0].children![1].value, 'NIL'); - expect(values[4].children![0].children![2].value, 'rob.schoen'); - expect(values[4].children![0].children![3].value, 'domain.com'); - - expect(values[5].value, null); - expect(values[5].children != null, true); - expect(values[5].children![0].children!.length, 4); - expect(values[5].children![0].children![0].value, 'Alice Dev'); - expect(values[5].children![0].children![1].value, 'NIL'); - expect(values[5].children![0].children![2].value, 'alice.dev'); - expect(values[5].children![0].children![3].value, 'domain.com'); - - expect(values[6].value, 'NIL'); - expect(values[7].value, 'NIL'); - - expect(values[8].value, - ''); - expect(values[9].value, - '<130499090.797.1572014128349@product-gw2.domain.com>'); - - values = parsed.values[2].children!; - expect(values[6].value, 'BODY'); - expect(values[6].children != null, true); - expect(values[6].children!.length, 3); - var value = values[6].children![0]; - expect(value.value, null); - expect(value.children != null, true); - expect(value.children!.length, 8); - expect(value.children![0].value, 'text'); - expect(value.children![1].value, 'plain'); - expect(value.children![2].children != null, true); - expect(value.children![2].children![0].value, 'charset'); - expect(value.children![2].children![1].value, 'UTF-8'); - expect(value.children![3].value, 'NIL'); - expect(value.children![4].value, 'NIL'); - expect(value.children![5].value, 'quoted-printable'); - expect(value.children![6].value, '1289'); - expect(value.children![7].value, '53'); - - value = values[6].children![1]; - expect(value.value, null); - expect(value.children != null, true); - expect(value.children!.length, 8); - expect(value.children![0].value, 'text'); - expect(value.children![1].value, 'html'); - expect(value.children![2].children != null, true); - expect(value.children![2].children![0].value, 'charset'); - expect(value.children![2].children![1].value, 'UTF-8'); - expect(value.children![3].value, 'NIL'); - expect(value.children![4].value, 'NIL'); - expect(value.children![5].value, 'quoted-printable'); - expect(value.children![6].value, '7496'); - expect(value.children![7].value, '302'); - - expect(values[6].children![2].value, 'alternative'); + var values = parsed.values[2].children; + + expect(values?[0].value, 'FLAGS'); + expect(values?[0].children != null, true); + expect(values?[0].children?.length, 0); + expect(values?[1].value, 'INTERNALDATE'); + expect(values?[2].value, '25-Oct-2019 16:35:31 +0200'); + expect(values?[3].value, 'RFC822.SIZE'); + expect(values?[4].value, '15320'); + expect(values?[5].value, 'ENVELOPE'); + values = values?[5].children; + + expect(values?[0].value, 'Fri, 25 Oct 2019 16:35:28 +0200 (CEST)'); + expect( + values?[1].valueOrDataText, + 'New appointment: SoW (x2) for rebranding of App & Mobile Apps', + ); + expect(values?[2].value, null); + expect(values?[2].children != null, true); + expect(values?[2].children?.length, 1); + expect(values?[2].children?[0].children?.length, 4); + expect( + values?[2].children?[0].children?[0].value, + '=?UTF-8?Q?Sch=C3=B6n=2C_Rob?=', + ); + expect(values?[2].children?[0].children?[1].value, 'NIL'); + expect(values?[2].children?[0].children?[2].value, 'rob.schoen'); + expect(values?[2].children?[0].children?[3].value, 'domain.com'); + + expect(values?[3].value, null); + expect(values?[3].children != null, true); + expect(values?[3].children?.length, 1); + expect(values?[3].children?[0].children?.length, 4); + expect( + values?[3].children?[0].children?[0].value, + '=?UTF-8?Q?Sch=C3=B6n=2C_Rob?=', + ); + expect(values?[3].children?[0].children?[1].value, 'NIL'); + expect(values?[3].children?[0].children?[2].value, 'rob.schoen'); + expect(values?[3].children?[0].children?[3].value, 'domain.com'); + + expect(values?[4].value, null); + expect(values?[4].children != null, true); + expect(values?[4].children?.length, 1); + expect(values?[4].children?[0].children?.length, 4); + expect( + values?[4].children?[0].children?[0].value, + '=?UTF-8?Q?Sch=C3=B6n=2C_Rob?=', + ); + expect(values?[4].children?[0].children?[1].value, 'NIL'); + expect(values?[4].children?[0].children?[2].value, 'rob.schoen'); + expect(values?[4].children?[0].children?[3].value, 'domain.com'); + + expect(values?[5].value, null); + expect(values?[5].children != null, true); + expect(values?[5].children?[0].children?.length, 4); + expect(values?[5].children?[0].children?[0].value, 'Alice Dev'); + expect(values?[5].children?[0].children?[1].value, 'NIL'); + expect(values?[5].children?[0].children?[2].value, 'alice.dev'); + expect(values?[5].children?[0].children?[3].value, 'domain.com'); + + expect(values?[6].value, 'NIL'); + expect(values?[7].value, 'NIL'); + + expect( + values?[8].value, + '', + ); + expect( + values?[9].value, + '<130499090.797.1572014128349@product-gw2.domain.com>', + ); + + values = parsed.values[2].children; + expect(values?[6].value, 'BODY'); + expect(values?[6].children != null, true); + expect(values?[6].children?.length, 3); + var value = values?[6].children?[0]; + expect(value?.value, null); + expect(value?.children != null, true); + expect(value?.children?.length, 8); + expect(value?.children?[0].value, 'text'); + expect(value?.children?[1].value, 'plain'); + expect(value?.children?[2].children != null, true); + expect(value?.children?[2].children?[0].value, 'charset'); + expect(value?.children?[2].children?[1].value, 'UTF-8'); + expect(value?.children?[3].value, 'NIL'); + expect(value?.children?[4].value, 'NIL'); + expect(value?.children?[5].value, 'quoted-printable'); + expect(value?.children?[6].value, '1289'); + expect(value?.children?[7].value, '53'); + + value = values?[6].children?[1]; + expect(value?.value, null); + expect(value?.children != null, true); + expect(value?.children?.length, 8); + expect(value?.children?[0].value, 'text'); + expect(value?.children?[1].value, 'html'); + expect(value?.children?[2].children != null, true); + expect(value?.children?[2].children?[0].value, 'charset'); + expect(value?.children?[2].children?[1].value, 'UTF-8'); + expect(value?.children?[3].value, 'NIL'); + expect(value?.children?[4].value, 'NIL'); + expect(value?.children?[5].value, 'quoted-printable'); + expect(value?.children?[6].value, '7496'); + expect(value?.children?[7].value, '302'); + + expect(values?[6].children?[2].value, 'alternative'); }); // test end test('ImapResponse.iterate() with HEADER.FIELDS response', () { final response = ImapResponse() ..add(ImapResponseLine('16 FETCH (BODY[HEADER.FIELDS (REFERENCES)] {50}')) ..add(ImapResponseLine.raw(Uint8List.fromList( - r'References: '.codeUnits))) + r'References: '.codeUnits, + ))) ..add(ImapResponseLine(')')); final parsed = response.iterate(); @@ -318,11 +340,15 @@ void main() { expect(parsed.values[0].value, '16'); expect(parsed.values[1].value, 'FETCH'); expect(parsed.values[1].children != null, true); - expect(parsed.values[1].children!.length, 2); - expect(parsed.values[1].children![0].value, - 'BODY[HEADER.FIELDS (REFERENCES)]'); - expect(parsed.values[1].children![1].valueOrDataText, - r'References: '); + expect(parsed.values[1].children?.length, 2); + expect( + parsed.values[1].children?[0].value, + 'BODY[HEADER.FIELDS (REFERENCES)]', + ); + expect( + parsed.values[1].children?[1].valueOrDataText, + r'References: ', + ); }); // test end test('ImapResponse.iterate() with HEADER.FIELDS empty response', () { @@ -337,18 +363,22 @@ void main() { expect(parsed.values[0].value, '16'); expect(parsed.values[1].value, 'FETCH'); expect(parsed.values[1].children != null, true); - expect(parsed.values[1].children!.length, 2); - expect(parsed.values[1].children![0].value, - 'BODY[HEADER.FIELDS (REFERENCES)]'); - expect(parsed.values[1].children![1].valueOrDataText, '\r\n'); + expect(parsed.values[1].children?.length, 2); + expect( + parsed.values[1].children?[0].value, + 'BODY[HEADER.FIELDS (REFERENCES)]', + ); + expect(parsed.values[1].children?[1].valueOrDataText, '\r\n'); }); // test end test('ImapResponse.iterate() with HEADER.FIELDS.NOT response', () { final response = ImapResponse() ..add(ImapResponseLine( - '16 FETCH (BODY[HEADER.FIELDS.NOT (REFERENCES)] {42}')) + '16 FETCH (BODY[HEADER.FIELDS.NOT (REFERENCES)] {42}', + )) ..add(ImapResponseLine.raw(Uint8List.fromList( - 'From: Shirley '.codeUnits))) + 'From: Shirley '.codeUnits, + ))) ..add(ImapResponseLine(')')); final parsed = response.iterate(); @@ -357,17 +387,22 @@ void main() { expect(parsed.values[0].value, '16'); expect(parsed.values[1].value, 'FETCH'); expect(parsed.values[1].children != null, true); - expect(parsed.values[1].children!.length, 2); - expect(parsed.values[1].children![0].value, - 'BODY[HEADER.FIELDS.NOT (REFERENCES)]'); - expect(parsed.values[1].children![1].valueOrDataText, - 'From: Shirley '); + expect(parsed.values[1].children?.length, 2); + expect( + parsed.values[1].children?[0].value, + 'BODY[HEADER.FIELDS.NOT (REFERENCES)]', + ); + expect( + parsed.values[1].children?[1].valueOrDataText, + 'From: Shirley ', + ); }); // test end test('ImapResponse.iterate() with HEADER.FIELDS.NOT empty response', () { final response = ImapResponse() ..add(ImapResponseLine( - '16 FETCH (BODY[HEADER.FIELDS.NOT (REFERENCES DATE FROM)] {2}')) + '16 FETCH (BODY[HEADER.FIELDS.NOT (REFERENCES DATE FROM)] {2}', + )) ..add(ImapResponseLine.raw(Uint8List.fromList('\r\n'.codeUnits))) ..add(ImapResponseLine(')')); final parsed = response.iterate(); @@ -377,109 +412,151 @@ void main() { expect(parsed.values[0].value, '16'); expect(parsed.values[1].value, 'FETCH'); expect(parsed.values[1].children != null, true); - expect(parsed.values[1].children!.length, 2); - expect(parsed.values[1].children![0].value, - 'BODY[HEADER.FIELDS.NOT (REFERENCES DATE FROM)]'); - expect(parsed.values[1].children![1].valueOrDataText, '\r\n'); + expect(parsed.values[1].children?.length, 2); + expect( + parsed.values[1].children?[0].value, + 'BODY[HEADER.FIELDS.NOT (REFERENCES DATE FROM)]', + ); + expect(parsed.values[1].children?[1].valueOrDataText, '\r\n'); }); // test end test('ImapResponse.iterate() with TO Envelope part', () { final response = ImapResponse() ..add(ImapResponseLine( - 'ENVELOPE ("TEST" (("Jared" NIL "jared" "domain.com")) (("Ina" NIL ' - '"ina" "domain1.com")("Todd" NIL "todd" "domain2.com")("Dom" NIL ' - '"dom"' - ' "domain3.com")) NIL NIL NIL "<1526109049.228971.1564473376037@my.d' - 'omain.com>")')); + 'ENVELOPE ("TEST" (("Jared" NIL "jared" "domain.com")) (("Ina" NIL ' + '"ina" "domain1.com")("Todd" NIL "todd" "domain2.com")("Dom" NIL ' + '"dom"' + ' "domain3.com")) NIL NIL NIL "<1526109049.228971.1564473376037@my.d' + 'omain.com>")', + )); final parsed = response.iterate(); //print(parsed.values); expect(parsed.values.length, 1); expect(parsed.values[0].value, 'ENVELOPE'); expect(parsed.values[0].children != null, true); - expect(parsed.values[0].children!.length, 7); - expect(parsed.values[0].children![0].value, 'TEST'); - expect(parsed.values[0].children![1].value, null); - expect(parsed.values[0].children![1].children != null, true); - expect(parsed.values[0].children![1].children!.length, 1); - expect(parsed.values[0].children![1].children![0].children != null, true); - expect(parsed.values[0].children![1].children![0].children!.length, 4); + expect(parsed.values[0].children?.length, 7); + expect(parsed.values[0].children?[0].value, 'TEST'); + expect(parsed.values[0].children?[1].value, null); + expect(parsed.values[0].children?[1].children != null, true); + expect(parsed.values[0].children?[1].children?.length, 1); + expect(parsed.values[0].children?[1].children?[0].children != null, true); + expect(parsed.values[0].children?[1].children?[0].children?.length, 4); + expect( + parsed.values[0].children?[1].children?[0].children?[0].value, + 'Jared', + ); + expect( + parsed.values[0].children?[1].children?[0].children?[1].value, + 'NIL', + ); expect( - parsed.values[0].children![1].children![0].children![0].value, 'Jared'); + parsed.values[0].children?[1].children?[0].children?[2].value, + 'jared', + ); expect( - parsed.values[0].children![1].children![0].children![1].value, 'NIL'); + parsed.values[0].children?[1].children?[0].children?[3].value, + 'domain.com', + ); + expect(parsed.values[0].children?[2].value, null); + expect(parsed.values[0].children?[2].children != null, true); + expect(parsed.values[0].children?[2].children?.length, 3); + expect(parsed.values[0].children?[2].children?[0].children != null, true); + expect(parsed.values[0].children?[2].children?[0].children?.length, 4); expect( - parsed.values[0].children![1].children![0].children![2].value, 'jared'); - expect(parsed.values[0].children![1].children![0].children![3].value, - 'domain.com'); - expect(parsed.values[0].children![2].value, null); - expect(parsed.values[0].children![2].children != null, true); - expect(parsed.values[0].children![2].children!.length, 3); - expect(parsed.values[0].children![2].children![0].children != null, true); - expect(parsed.values[0].children![2].children![0].children!.length, 4); + parsed.values[0].children?[2].children?[0].children?[0].value, + 'Ina', + ); expect( - parsed.values[0].children![2].children![0].children![0].value, 'Ina'); + parsed.values[0].children?[2].children?[0].children?[1].value, + 'NIL', + ); expect( - parsed.values[0].children![2].children![0].children![1].value, 'NIL'); + parsed.values[0].children?[2].children?[0].children?[2].value, + 'ina', + ); expect( - parsed.values[0].children![2].children![0].children![2].value, 'ina'); - expect(parsed.values[0].children![2].children![0].children![3].value, - 'domain1.com'); - expect(parsed.values[0].children![2].children![1].children != null, true); - expect(parsed.values[0].children![2].children![1].children!.length, 4); + parsed.values[0].children?[2].children?[0].children?[3].value, + 'domain1.com', + ); + expect(parsed.values[0].children?[2].children?[1].children != null, true); + expect(parsed.values[0].children?[2].children?[1].children?.length, 4); expect( - parsed.values[0].children![2].children![1].children![0].value, 'Todd'); + parsed.values[0].children?[2].children?[1].children?[0].value, + 'Todd', + ); expect( - parsed.values[0].children![2].children![1].children![1].value, 'NIL'); + parsed.values[0].children?[2].children?[1].children?[1].value, + 'NIL', + ); expect( - parsed.values[0].children![2].children![1].children![2].value, 'todd'); - expect(parsed.values[0].children![2].children![1].children![3].value, - 'domain2.com'); + parsed.values[0].children?[2].children?[1].children?[2].value, + 'todd', + ); + expect( + parsed.values[0].children?[2].children?[1].children?[3].value, + 'domain2.com', + ); }); // test end test('ImapResponse.iterate() with nested BODY part', () { final response = ImapResponse() ..add(ImapResponseLine( - 'BODY (("TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 1152 23)' - '("TEXT" "PLAIN" ("CHARSET" "US-ASCII" "NAME" "cc.diff") "<9607231634' - '07.20117h@cac.washington.edu>" "Compiler diff" "BASE64" 4554 73) "MI' - 'XED")')); + 'BODY (("TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 1152 23)' + '("TEXT" "PLAIN" ("CHARSET" "US-ASCII" "NAME" "cc.diff") "<9607231634' + '07.20117h@cac.washington.edu>" "Compiler diff" "BASE64" 4554 73) "MI' + 'XED")', + )); final parsed = response.iterate(); expect(parsed.values.length, 1); - expect(parsed.values[0].children!.length, 3); - expect(parsed.values[0].children![0].children!.length, 8); - expect(parsed.values[0].children![0].children![0].value, 'TEXT'); - expect(parsed.values[0].children![0].children![1].value, 'PLAIN'); - expect(parsed.values[0].children![0].children![2].children!.length, 2); - expect(parsed.values[0].children![0].children![2].children![0].value, - 'CHARSET'); - expect(parsed.values[0].children![0].children![2].children![1].value, - 'US-ASCII'); - expect(parsed.values[0].children![0].children![3].value, 'NIL'); - expect(parsed.values[0].children![0].children![4].value, 'NIL'); - expect(parsed.values[0].children![0].children![5].value, '7BIT'); - expect(parsed.values[0].children![0].children![6].value, '1152'); - expect(parsed.values[0].children![0].children![7].value, '23'); - expect(parsed.values[0].children![1].children!.length, 8); - expect(parsed.values[0].children![1].children![0].value, 'TEXT'); - expect(parsed.values[0].children![1].children![1].value, 'PLAIN'); - expect(parsed.values[0].children![1].children![2].children!.length, 4); - expect(parsed.values[0].children![1].children![2].children![0].value, - 'CHARSET'); - expect(parsed.values[0].children![1].children![2].children![1].value, - 'US-ASCII'); + expect(parsed.values[0].children?.length, 3); + expect(parsed.values[0].children?[0].children?.length, 8); + expect(parsed.values[0].children?[0].children?[0].value, 'TEXT'); + expect(parsed.values[0].children?[0].children?[1].value, 'PLAIN'); + expect(parsed.values[0].children?[0].children?[2].children?.length, 2); + expect( + parsed.values[0].children?[0].children?[2].children?[0].value, + 'CHARSET', + ); + expect( + parsed.values[0].children?[0].children?[2].children?[1].value, + 'US-ASCII', + ); + expect(parsed.values[0].children?[0].children?[3].value, 'NIL'); + expect(parsed.values[0].children?[0].children?[4].value, 'NIL'); + expect(parsed.values[0].children?[0].children?[5].value, '7BIT'); + expect(parsed.values[0].children?[0].children?[6].value, '1152'); + expect(parsed.values[0].children?[0].children?[7].value, '23'); + expect(parsed.values[0].children?[1].children?.length, 8); + expect(parsed.values[0].children?[1].children?[0].value, 'TEXT'); + expect(parsed.values[0].children?[1].children?[1].value, 'PLAIN'); + expect(parsed.values[0].children?[1].children?[2].children?.length, 4); + expect( + parsed.values[0].children?[1].children?[2].children?[0].value, + 'CHARSET', + ); + expect( + parsed.values[0].children?[1].children?[2].children?[1].value, + 'US-ASCII', + ); + expect( + parsed.values[0].children?[1].children?[2].children?[2].value, + 'NAME', + ); + expect( + parsed.values[0].children?[1].children?[2].children?[3].value, + 'cc.diff', + ); expect( - parsed.values[0].children![1].children![2].children![2].value, 'NAME'); - expect(parsed.values[0].children![1].children![2].children![3].value, - 'cc.diff'); - expect(parsed.values[0].children![1].children![3].value, - '<960723163407.20117h@cac.washington.edu>'); - expect(parsed.values[0].children![1].children![4].value, 'Compiler diff'); - expect(parsed.values[0].children![1].children![5].value, 'BASE64'); - expect(parsed.values[0].children![1].children![6].value, '4554'); - expect(parsed.values[0].children![1].children![7].value, '73'); - - expect(parsed.values[0].children![2].value, 'MIXED'); + parsed.values[0].children?[1].children?[3].value, + '<960723163407.20117h@cac.washington.edu>', + ); + expect(parsed.values[0].children?[1].children?[4].value, 'Compiler diff'); + expect(parsed.values[0].children?[1].children?[5].value, 'BASE64'); + expect(parsed.values[0].children?[1].children?[6].value, '4554'); + expect(parsed.values[0].children?[1].children?[7].value, '73'); + + expect(parsed.values[0].children?[2].value, 'MIXED'); }); }