From b0937227616b532dfa76f809c97454533809d4d6 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sat, 4 Mar 2023 04:02:08 +0200 Subject: [PATCH 01/17] log to check --- lib/src/mail/mail_client.dart | 1 + lib/src/private/smtp/commands/smtp_sendmail_command.dart | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/src/mail/mail_client.dart b/lib/src/mail/mail_client.dart index 97243779..5c269d10 100644 --- a/lib/src/mail/mail_client.dart +++ b/lib/src/mail/mail_client.dart @@ -830,6 +830,7 @@ class MailClient { /// /// Optionally specify the [sentMailbox] when the mail system does not /// support mailbox flags. + /// first Future sendMessage( MimeMessage message, { MailAddress? from, diff --git a/lib/src/private/smtp/commands/smtp_sendmail_command.dart b/lib/src/private/smtp/commands/smtp_sendmail_command.dart index e523342d..4b70d545 100644 --- a/lib/src/private/smtp/commands/smtp_sendmail_command.dart +++ b/lib/src/private/smtp/commands/smtp_sendmail_command.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import '../../../../enough_mail.dart'; import '../smtp_command.dart'; @@ -21,8 +23,10 @@ class _SmtpSendCommand extends SmtpCommand { @override String get command { if (use8BitEncoding) { + log('use8BitEncoding'); return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } + log(' Not use8BitEncoding'); return 'MAIL FROM:<$fromEmail>'; } From f9c04593865d144040d7698c560c8efd1d000105 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sat, 4 Mar 2023 18:59:31 +0200 Subject: [PATCH 02/17] print to check --- lib/src/private/smtp/commands/smtp_sendmail_command.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/private/smtp/commands/smtp_sendmail_command.dart b/lib/src/private/smtp/commands/smtp_sendmail_command.dart index 4b70d545..cb6481aa 100644 --- a/lib/src/private/smtp/commands/smtp_sendmail_command.dart +++ b/lib/src/private/smtp/commands/smtp_sendmail_command.dart @@ -23,10 +23,14 @@ class _SmtpSendCommand extends SmtpCommand { @override String get command { if (use8BitEncoding) { - log('use8BitEncoding'); + print('use8BitEncoding: '); + log('use8BitEncoding: '); + //logApp('use8BitEncoding'); return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } + print(' Not use8BitEncoding'); log(' Not use8BitEncoding'); +// logApp(' Not use8BitEncoding'); return 'MAIL FROM:<$fromEmail>'; } From 76c29e3c9ab45e8dd607e075443e7e51d1da5888 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sat, 4 Mar 2023 19:23:43 +0200 Subject: [PATCH 03/17] print to check --- lib/src/private/util/client_base.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/private/util/client_base.dart b/lib/src/private/util/client_base.dart index a5495f84..dcbcff49 100644 --- a/lib/src/private/util/client_base.dart +++ b/lib/src/private/util/client_base.dart @@ -204,7 +204,7 @@ abstract class ClientBase { /// Disconnects from the service Future disconnect() async { if (_isConnected) { - logApp('disconnecting'); + logApp('dola disconnecting'); isLoggedIn = false; _isConnected = false; isSocketClosingExpected = true; From 6276ab976f9682ca0ea796d21230bcded1eaab05 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sat, 4 Mar 2023 19:29:58 +0200 Subject: [PATCH 04/17] not support print --- lib/src/mail/mail_client.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/mail/mail_client.dart b/lib/src/mail/mail_client.dart index 5c269d10..da2d6418 100644 --- a/lib/src/mail/mail_client.dart +++ b/lib/src/mail/mail_client.dart @@ -3147,6 +3147,7 @@ class _OutgoingSmtpClient extends _OutgoingMailClient { await _connectOutgoingIfRequired(); try { if (_smtpClient.serverInfo.supportsChunking) { + print("dola supportsChunking"); await _smtpClient.sendChunkedMessage( message, from: from, @@ -3154,6 +3155,7 @@ class _OutgoingSmtpClient extends _OutgoingMailClient { recipients: recipients, ); } else { + print("dola not supportsChunking"); await _smtpClient.sendMessage( message, from: from, From c129d02a1a848430ad50cf2bd25dbc49a1f7bf27 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sat, 4 Mar 2023 19:36:45 +0200 Subject: [PATCH 05/17] not support print --- lib/src/mail/mail_client.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/mail/mail_client.dart b/lib/src/mail/mail_client.dart index da2d6418..5556506e 100644 --- a/lib/src/mail/mail_client.dart +++ b/lib/src/mail/mail_client.dart @@ -849,6 +849,7 @@ class MailClient { .log('Error: unable to append sent message: no no mailbox with ' 'flag sent found in $mailboxes'); } else { + print("dola"); futures.add( appendMessage(message, sentMailbox, flags: [MessageFlags.seen])); } From f311b7a5b90c4af70fc74d6df3302f475a3fcbd6 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sat, 4 Mar 2023 20:02:45 +0200 Subject: [PATCH 06/17] not support print --- lib/src/private/smtp/commands/smtp_send_bdat_command.dart | 7 ++++++- lib/src/smtp/smtp_client.dart | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 13c7125c..698f70d1 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -31,6 +31,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { static const Utf8Codec _codec = Utf8Codec(allowMalformed: true); static List chunkData(List binaryData) { + print("dola chunkData"); const chunkSize = 512 * 1024; final result = []; var startIndex = 0; @@ -55,8 +56,10 @@ class _SmtpSendBdatCommand extends SmtpCommand { @override String get command { if (use8BitEncoding) { + print("dola use8BitEncoding"); return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } + print("dola not use8BitEncoding"); return 'MAIL FROM:<$fromEmail>'; } @@ -123,7 +126,9 @@ class SmtpSendBdatMailCommand extends _SmtpSendBdatCommand { from?.email ?? message.fromEmail, recipientEmails, use8BitEncoding: use8BitEncoding, - ); + ){ + print("dola SmtpSendBdatMailCommand"); + } /// The message to be sent final MimeMessage message; diff --git a/lib/src/smtp/smtp_client.dart b/lib/src/smtp/smtp_client.dart index c2e10c60..32ca7fd3 100644 --- a/lib/src/smtp/smtp_client.dart +++ b/lib/src/smtp/smtp_client.dart @@ -311,6 +311,7 @@ class SmtpClient extends ClientBase { if (recipientEmails.isEmpty) { throw SmtpException(this, SmtpResponse(['500 no recipients'])); } + print("dola sendChunkedMessage"); return sendCommand(SmtpSendBdatMailCommand(message, from, recipientEmails, use8BitEncoding: use8BitEncoding)); } @@ -399,6 +400,7 @@ class SmtpClient extends ClientBase { /// Sends the command to the server Future sendCommand(SmtpCommand command) { + print("dola sendCommand"); _currentCommand = command; writeText(command.command, command); return command.completer.future; From 9c8027aee53d8d3431b68cf38f63015d42e64bf8 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sun, 5 Mar 2023 02:54:47 +0200 Subject: [PATCH 07/17] support unicode --- lib/src/mail/mail_client.dart | 21 +++++++++++++++---- .../smtp/commands/smtp_send_bdat_command.dart | 17 +++++++++++++-- .../smtp/commands/smtp_sendmail_command.dart | 9 ++++---- lib/src/smtp/smtp_client.dart | 11 ++++++---- test/smtp/smtp_client_test.dart | 2 +- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/lib/src/mail/mail_client.dart b/lib/src/mail/mail_client.dart index 5556506e..ea029c0a 100644 --- a/lib/src/mail/mail_client.dart +++ b/lib/src/mail/mail_client.dart @@ -793,7 +793,7 @@ class MailClient { final use8Bit = builderEncoding == TransferEncoding.eightBit; final futures = [ - _sendMessageViaOutgoing(message, from, use8Bit, recipients), + _sendMessageViaOutgoing(message, from, use8Bit, recipients,), ]; if (appendToSent && _incomingMailClient.supportsAppendingMessages) { sentMailbox ??= getMailbox(MailboxFlag.sent); @@ -858,8 +858,8 @@ class MailClient { } Future _sendMessageViaOutgoing(MimeMessage message, MailAddress? from, - bool use8BitEncoding, List? recipients) async { - await _outgoingMailClient.sendMessage(message, + bool use8BitEncoding, List? recipients,{bool isUnicode = false}) async { + await _outgoingMailClient.sendMessage(message,isUnicode: isUnicode, from: from, use8BitEncoding: use8BitEncoding, recipients: recipients); await _outgoingMailClient.disconnect(); } @@ -1416,9 +1416,13 @@ enum ThreadPreference { abstract class _IncomingMailClient { _IncomingMailClient(this.downloadSizeLimit, this._config, this.mailClient); + final MailClient mailClient; + ClientBase get client; + ServerType get clientType; + int? downloadSizeLimit; MailServerConfig _config; Mailbox? _selectedMailbox; @@ -1572,6 +1576,7 @@ class _IncomingImapClient extends _IncomingMailClient { @override ClientBase get client => _imapClient; + @override ServerType get clientType => ServerType.imap; final ImapClient _imapClient; @@ -1584,9 +1589,11 @@ class _IncomingImapClient extends _IncomingMailClient { int _reconnectCounter = 0; bool _isIdlePaused = false; ThreadDataResult? _threadData; + @override bool get supportsMailboxes => true; Id? _serverId; + @override Id? get serverId => _serverId; @@ -2803,6 +2810,7 @@ class _IncomingPopClient extends _IncomingMailClient { @override ClientBase get client => _popClient; + @override ServerType get clientType => ServerType.pop; @@ -3066,6 +3074,7 @@ class _IncomingPopClient extends _IncomingMailClient { abstract class _OutgoingMailClient { ClientBase get client; + ServerType get clientType; /// Checks if the incoming mail client supports 8 bit encoded messages. @@ -3074,7 +3083,8 @@ abstract class _OutgoingMailClient { Future supports8BitEncoding(); Future sendMessage(MimeMessage message, - {MailAddress? from, + { required bool isUnicode, + MailAddress? from, bool use8BitEncoding = false, List? recipients}); @@ -3102,6 +3112,7 @@ class _OutgoingSmtpClient extends _OutgoingMailClient { @override ClientBase get client => _smtpClient; + @override ServerType get clientType => ServerType.smtp; final MailClient mailClient; @@ -3141,6 +3152,7 @@ class _OutgoingSmtpClient extends _OutgoingMailClient { @override Future sendMessage( MimeMessage message, { + required bool isUnicode, MailAddress? from, bool use8BitEncoding = false, List? recipients, @@ -3152,6 +3164,7 @@ class _OutgoingSmtpClient extends _OutgoingMailClient { await _smtpClient.sendChunkedMessage( message, from: from, + isUnicode: isUnicode, use8BitEncoding: use8BitEncoding, recipients: recipients, ); 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 698f70d1..6d619711 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -15,6 +15,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { this.fromEmail, this.recipientEmails, { required this.use8BitEncoding, + required this.isUnicode, }) : super('MAIL FROM') { final binaryData = _codec.encode(getData()); _chunks = chunkData(binaryData); @@ -24,6 +25,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { final String? fromEmail; final List recipientEmails; final bool use8BitEncoding; + final bool isUnicode; _BdatSequence _currentStep = _BdatSequence.mailFrom; int _recipientIndex = 0; late List _chunks; @@ -55,11 +57,15 @@ class _SmtpSendBdatCommand extends SmtpCommand { @override String get command { + print("dola dola isUnicode $isUnicode"); + if(isUnicode){ + print("isUnicode $isUnicode"); + } if (use8BitEncoding) { - print("dola use8BitEncoding"); + print("dola use8BitEncoding2 chunkData"); return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } - print("dola not use8BitEncoding"); + print("dola not use8BitEncoding2 chunkData"); return 'MAIL FROM:<$fromEmail>'; } @@ -119,6 +125,8 @@ class SmtpSendBdatMailCommand extends _SmtpSendBdatCommand { MailAddress? from, List recipientEmails, { required bool use8BitEncoding, + + required bool isUnicode, }) : super( () => message .renderMessage() @@ -126,6 +134,7 @@ class SmtpSendBdatMailCommand extends _SmtpSendBdatCommand { from?.email ?? message.fromEmail, recipientEmails, use8BitEncoding: use8BitEncoding, + isUnicode: isUnicode, ){ print("dola SmtpSendBdatMailCommand"); } @@ -142,6 +151,7 @@ class SmtpSendBdatMailDataCommand extends _SmtpSendBdatCommand { MailAddress from, List recipientEmails, { required bool use8BitEncoding, + required bool isUnicode, }) : super( () => data .toString() @@ -149,6 +159,7 @@ class SmtpSendBdatMailDataCommand extends _SmtpSendBdatCommand { from.email, recipientEmails, use8BitEncoding: use8BitEncoding, + isUnicode: isUnicode ); /// The message data to be sent @@ -163,11 +174,13 @@ class SmtpSendBdatMailTextCommand extends _SmtpSendBdatCommand { MailAddress from, List recipientEmails, { required bool use8BitEncoding, + required bool isUnicode, }) : super( () => data, from.email, recipientEmails, use8BitEncoding: use8BitEncoding, + isUnicode: isUnicode ); /// The message text data diff --git a/lib/src/private/smtp/commands/smtp_sendmail_command.dart b/lib/src/private/smtp/commands/smtp_sendmail_command.dart index cb6481aa..83896a6e 100644 --- a/lib/src/private/smtp/commands/smtp_sendmail_command.dart +++ b/lib/src/private/smtp/commands/smtp_sendmail_command.dart @@ -23,14 +23,13 @@ class _SmtpSendCommand extends SmtpCommand { @override String get command { if (use8BitEncoding) { - print('use8BitEncoding: '); - log('use8BitEncoding: '); + print('dola use8BitEncoding:1 SmtpCommand'); + log('dola use8BitEncoding:1 SmtpCommand'); //logApp('use8BitEncoding'); return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } - print(' Not use8BitEncoding'); - log(' Not use8BitEncoding'); -// logApp(' Not use8BitEncoding'); + print(' dola Not use8BitEncoding1 SmtpCommand'); + log(' dola Not use8BitEncoding1 SmtpCommand'); return 'MAIL FROM:<$fromEmail>'; } diff --git a/lib/src/smtp/smtp_client.dart b/lib/src/smtp/smtp_client.dart index 32ca7fd3..6155abd2 100644 --- a/lib/src/smtp/smtp_client.dart +++ b/lib/src/smtp/smtp_client.dart @@ -301,6 +301,7 @@ class SmtpClient extends ClientBase { /// defined in the message are ignored. Future sendChunkedMessage( MimeMessage message, { + required bool isUnicode, bool use8BitEncoding = false, MailAddress? from, List? recipients, @@ -311,9 +312,9 @@ class SmtpClient extends ClientBase { if (recipientEmails.isEmpty) { throw SmtpException(this, SmtpResponse(['500 no recipients'])); } - print("dola sendChunkedMessage"); + print('dola sendChunkedMessage $isUnicode'); return sendCommand(SmtpSendBdatMailCommand(message, from, recipientEmails, - use8BitEncoding: use8BitEncoding)); + use8BitEncoding: use8BitEncoding, isUnicode: isUnicode)); } /// Sends the specified message [data] [from] to the [recipients] @@ -326,7 +327,7 @@ class SmtpClient extends ClientBase { /// Set [use8BitEncoding] to `true` for sending a UTF-8 encoded message body. Future sendChunkedMessageData( MimeData data, MailAddress from, List recipients, - {bool use8BitEncoding = false}) { + { required bool isUnicode,bool use8BitEncoding = false}) { if (recipients.isEmpty) { throw SmtpException(this, SmtpResponse(['500 no recipients'])); } @@ -335,6 +336,7 @@ class SmtpClient extends ClientBase { data, from, recipients.map((r) => r.email).toList(), + isUnicode: isUnicode, use8BitEncoding: use8BitEncoding, ), ); @@ -353,7 +355,7 @@ class SmtpClient extends ClientBase { /// Set [use8BitEncoding] to `true` for sending a UTF-8 encoded message body. Future sendChunkedMessageText( String text, MailAddress from, List recipients, - {bool use8BitEncoding = false}) { + {required bool isUnicode,bool use8BitEncoding = false}) { if (recipients.isEmpty) { throw SmtpException(this, SmtpResponse(['500 no recipients'])); } @@ -362,6 +364,7 @@ class SmtpClient extends ClientBase { text, from, recipients.map((r) => r.email).toList(), + isUnicode: isUnicode, use8BitEncoding: use8BitEncoding, ), ); diff --git a/test/smtp/smtp_client_test.dart b/test/smtp/smtp_client_test.dart index 791ecde4..bd6ffd87 100644 --- a/test/smtp/smtp_client_test.dart +++ b/test/smtp/smtp_client_test.dart @@ -93,7 +93,7 @@ void main() { final message = MessageBuilder.buildSimpleTextMessage( from, to, 'Today as well.\r\nOne more time:\r\nHello from enough_mail!', subject: 'enough_mail hello'); - final response = await client.sendChunkedMessage(message); + final response = await client.sendChunkedMessage(message,isUnicode: false); expect(response.type, SmtpResponseType.success); expect(response.code, 250); }); From 233f11abe307dc4d353a11ee311201be8c0b6752 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sun, 5 Mar 2023 03:00:01 +0200 Subject: [PATCH 08/17] support unicode --- lib/src/mail/mail_client.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/mail/mail_client.dart b/lib/src/mail/mail_client.dart index ea029c0a..c075ccc4 100644 --- a/lib/src/mail/mail_client.dart +++ b/lib/src/mail/mail_client.dart @@ -839,21 +839,24 @@ class MailClient { bool use8BitEncoding = false, List? recipients, }) { + print("dola d"); final futures = [ _sendMessageViaOutgoing(message, from, use8BitEncoding, recipients), ]; if (appendToSent && _incomingMailClient.supportsAppendingMessages) { + print("dola dd"); sentMailbox ??= getMailbox(MailboxFlag.sent); if (sentMailbox == null) { _incomingMailClient .log('Error: unable to append sent message: no no mailbox with ' 'flag sent found in $mailboxes'); } else { - print("dola"); + print("dola ddd"); futures.add( appendMessage(message, sentMailbox, flags: [MessageFlags.seen])); } } + print("dola dddd"); return Future.wait(futures); } From 80a7e9d92eb5f86fcf355c61f893d10ea9c07e3e Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sun, 5 Mar 2023 03:09:32 +0200 Subject: [PATCH 09/17] support unicode --- lib/src/mail/mail_client.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/mail/mail_client.dart b/lib/src/mail/mail_client.dart index c075ccc4..298f386b 100644 --- a/lib/src/mail/mail_client.dart +++ b/lib/src/mail/mail_client.dart @@ -835,13 +835,14 @@ class MailClient { MimeMessage message, { MailAddress? from, bool appendToSent = true, + bool isUnicode = true, Mailbox? sentMailbox, bool use8BitEncoding = false, List? recipients, }) { print("dola d"); final futures = [ - _sendMessageViaOutgoing(message, from, use8BitEncoding, recipients), + _sendMessageViaOutgoing(message, from, use8BitEncoding, recipients,isUnicode:isUnicode ), ]; if (appendToSent && _incomingMailClient.supportsAppendingMessages) { print("dola dd"); From f67fea2e4769043f683f4738d52930e1c1c7e6bb Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sun, 5 Mar 2023 10:02:15 +0200 Subject: [PATCH 10/17] test add UTF-8 --- lib/src/mail/mail_client.dart | 18 ++++++++++++------ .../smtp/commands/smtp_send_bdat_command.dart | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/src/mail/mail_client.dart b/lib/src/mail/mail_client.dart index 298f386b..d11add35 100644 --- a/lib/src/mail/mail_client.dart +++ b/lib/src/mail/mail_client.dart @@ -835,14 +835,15 @@ class MailClient { MimeMessage message, { MailAddress? from, bool appendToSent = true, - bool isUnicode = true, + bool isUnicode = false, Mailbox? sentMailbox, bool use8BitEncoding = false, List? recipients, }) { print("dola d"); final futures = [ - _sendMessageViaOutgoing(message, from, use8BitEncoding, recipients,isUnicode:isUnicode ), + _sendMessageViaOutgoing(message, from, use8BitEncoding, recipients, + isUnicode: isUnicode), ]; if (appendToSent && _incomingMailClient.supportsAppendingMessages) { print("dola dd"); @@ -862,9 +863,14 @@ class MailClient { } Future _sendMessageViaOutgoing(MimeMessage message, MailAddress? from, - bool use8BitEncoding, List? recipients,{bool isUnicode = false}) async { - await _outgoingMailClient.sendMessage(message,isUnicode: isUnicode, - from: from, use8BitEncoding: use8BitEncoding, recipients: recipients); + bool use8BitEncoding, List? recipients, + {bool isUnicode = false}) async { + print("dola _sendMessageViaOutgoing isUnicode $isUnicode"); + await _outgoingMailClient.sendMessage(message, + isUnicode: isUnicode, + from: from, + use8BitEncoding: use8BitEncoding, + recipients: recipients); await _outgoingMailClient.disconnect(); } @@ -3087,7 +3093,7 @@ abstract class _OutgoingMailClient { Future supports8BitEncoding(); Future sendMessage(MimeMessage message, - { required bool isUnicode, + {required bool isUnicode, MailAddress? from, bool use8BitEncoding = false, List? recipients}); 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 6d619711..b1b06eef 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -59,6 +59,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { String get command { print("dola dola isUnicode $isUnicode"); if(isUnicode){ + return 'MAIL FROM:<$fromEmail> BODY=UTF-8'; print("isUnicode $isUnicode"); } if (use8BitEncoding) { From 2986ab7bb99eb5f7dec83afbe31daf99495b6750 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sun, 5 Mar 2023 10:07:09 +0200 Subject: [PATCH 11/17] test add UTF-8 --- lib/src/private/smtp/commands/smtp_send_bdat_command.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b1b06eef..d530cbe4 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -59,7 +59,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { String get command { print("dola dola isUnicode $isUnicode"); if(isUnicode){ - return 'MAIL FROM:<$fromEmail> BODY=UTF-8'; + return 'MAIL FROM:<$fromEmail> charset=UTF-8'; print("isUnicode $isUnicode"); } if (use8BitEncoding) { From e4f3c39c07af8d61af06cce0ae2f4f008d621b84 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sun, 5 Mar 2023 10:32:03 +0200 Subject: [PATCH 12/17] test add UTF-8 --- .../smtp/commands/smtp_send_bdat_command.dart | 46 ++++++++----------- 1 file changed, 19 insertions(+), 27 deletions(-) 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 d530cbe4..239e12b9 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -57,16 +57,15 @@ class _SmtpSendBdatCommand extends SmtpCommand { @override String get command { - print("dola dola isUnicode $isUnicode"); - if(isUnicode){ - return 'MAIL FROM:<$fromEmail> charset=UTF-8'; - print("isUnicode $isUnicode"); + if (isUnicode) { + print('dola dola isUnicode $isUnicode'); + return 'MAIL FROM:<$fromEmail> charset=utf-8'; } if (use8BitEncoding) { - print("dola use8BitEncoding2 chunkData"); + print('dola use8BitEncoding chunkData'); return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } - print("dola not use8BitEncoding2 chunkData"); + print('dola not use8BitEncoding chunkData'); return 'MAIL FROM:<$fromEmail>'; } @@ -126,8 +125,7 @@ class SmtpSendBdatMailCommand extends _SmtpSendBdatCommand { MailAddress? from, List recipientEmails, { required bool use8BitEncoding, - - required bool isUnicode, + required bool isUnicode, }) : super( () => message .renderMessage() @@ -135,8 +133,8 @@ class SmtpSendBdatMailCommand extends _SmtpSendBdatCommand { from?.email ?? message.fromEmail, recipientEmails, use8BitEncoding: use8BitEncoding, - isUnicode: isUnicode, - ){ + isUnicode: isUnicode, + ) { print("dola SmtpSendBdatMailCommand"); } @@ -152,16 +150,15 @@ class SmtpSendBdatMailDataCommand extends _SmtpSendBdatCommand { MailAddress from, List recipientEmails, { required bool use8BitEncoding, - required bool isUnicode, + required bool isUnicode, }) : super( - () => data - .toString() - .replaceAll(RegExp('^Bcc:.*\r\n', multiLine: true), ''), - from.email, - recipientEmails, - use8BitEncoding: use8BitEncoding, - isUnicode: isUnicode - ); + () => data + .toString() + .replaceAll(RegExp('^Bcc:.*\r\n', multiLine: true), ''), + from.email, + recipientEmails, + use8BitEncoding: use8BitEncoding, + isUnicode: isUnicode); /// The message data to be sent final MimeData data; @@ -175,14 +172,9 @@ class SmtpSendBdatMailTextCommand extends _SmtpSendBdatCommand { MailAddress from, List recipientEmails, { required bool use8BitEncoding, - required bool isUnicode, - }) : super( - () => data, - from.email, - recipientEmails, - use8BitEncoding: use8BitEncoding, - isUnicode: isUnicode - ); + required bool isUnicode, + }) : super(() => data, from.email, recipientEmails, + use8BitEncoding: use8BitEncoding, isUnicode: isUnicode); /// The message text data final String data; From 496616698bfdf95b56ba899e9222e8163d33ad41 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sun, 5 Mar 2023 10:39:09 +0200 Subject: [PATCH 13/17] test add UTF-8 --- lib/src/private/smtp/commands/smtp_send_bdat_command.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 239e12b9..10b38a40 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -59,7 +59,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { String get command { if (isUnicode) { print('dola dola isUnicode $isUnicode'); - return 'MAIL FROM:<$fromEmail> charset=utf-8'; + return 'MAIL FROM:<$fromEmail> BODY=utf-8'; } if (use8BitEncoding) { print('dola use8BitEncoding chunkData'); From 634c4e0c831e4bc05d4d39d6f91863a3e219d230 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sun, 5 Mar 2023 10:51:10 +0200 Subject: [PATCH 14/17] test add UTF-8 --- lib/src/smtp/smtp_client.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/smtp/smtp_client.dart b/lib/src/smtp/smtp_client.dart index 6155abd2..63c5be50 100644 --- a/lib/src/smtp/smtp_client.dart +++ b/lib/src/smtp/smtp_client.dart @@ -427,6 +427,7 @@ class SmtpClient extends ClientBase { writeData(next!.data!); } else if (cmd.isCommandDone(response)) { if (response.isFailedStatus) { + log('dola Error isFailedStatus proceeding to nextCommand'); cmd.completer.completeError(SmtpException(this, response)); } else { cmd.completer.complete(response); From fce3dd6971be57ea04b646be7233a1146ef37284 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Sun, 5 Mar 2023 19:32:19 +0200 Subject: [PATCH 15/17] test add UTF-8 --- lib/src/private/smtp/commands/smtp_send_bdat_command.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 10b38a40..df023292 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -59,7 +59,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { String get command { if (isUnicode) { print('dola dola isUnicode $isUnicode'); - return 'MAIL FROM:<$fromEmail> BODY=utf-8'; + return 'MAIL FROM:<$fromEmail> BODY=SMTPUTF8'; } if (use8BitEncoding) { print('dola use8BitEncoding chunkData'); From 1a156cd7f73738715b713756403755a2f03ea992 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Mon, 6 Mar 2023 00:01:26 +0200 Subject: [PATCH 16/17] test add UTF-8 --- lib/src/private/smtp/commands/smtp_send_bdat_command.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 df023292..2c57a9dd 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -62,11 +62,9 @@ class _SmtpSendBdatCommand extends SmtpCommand { return 'MAIL FROM:<$fromEmail> BODY=SMTPUTF8'; } if (use8BitEncoding) { - print('dola use8BitEncoding chunkData'); return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } - print('dola not use8BitEncoding chunkData'); - return 'MAIL FROM:<$fromEmail>'; + return 'MAIL FROM:<$fromEmail> SMTPUTF8'; } @override From 9268ccb666145a0832d4039cf41b2270219c82e8 Mon Sep 17 00:00:00 2001 From: Mohamed adel tawfiq Date: Mon, 6 Mar 2023 03:14:12 +0200 Subject: [PATCH 17/17] support unicode --- lib/src/mail/mail_client.dart | 29 +++++++++---------- .../smtp/commands/smtp_send_bdat_command.dart | 29 +++++++++---------- .../smtp/commands/smtp_sendmail_command.dart | 5 ---- lib/src/private/util/client_base.dart | 1 - lib/src/smtp/smtp_client.dart | 15 ++++------ test/smtp/smtp_client_test.dart | 2 +- 6 files changed, 34 insertions(+), 47 deletions(-) diff --git a/lib/src/mail/mail_client.dart b/lib/src/mail/mail_client.dart index d11add35..2759ed86 100644 --- a/lib/src/mail/mail_client.dart +++ b/lib/src/mail/mail_client.dart @@ -793,7 +793,12 @@ class MailClient { final use8Bit = builderEncoding == TransferEncoding.eightBit; final futures = [ - _sendMessageViaOutgoing(message, from, use8Bit, recipients,), + _sendMessageViaOutgoing( + message, + from, + use8Bit, + recipients, + ), ]; if (appendToSent && _incomingMailClient.supportsAppendingMessages) { sentMailbox ??= getMailbox(MailboxFlag.sent); @@ -835,39 +840,35 @@ class MailClient { MimeMessage message, { MailAddress? from, bool appendToSent = true, - bool isUnicode = false, + bool supportUnicode = false, Mailbox? sentMailbox, bool use8BitEncoding = false, List? recipients, }) { - print("dola d"); final futures = [ _sendMessageViaOutgoing(message, from, use8BitEncoding, recipients, - isUnicode: isUnicode), + supportUnicode: supportUnicode), ]; if (appendToSent && _incomingMailClient.supportsAppendingMessages) { - print("dola dd"); sentMailbox ??= getMailbox(MailboxFlag.sent); if (sentMailbox == null) { _incomingMailClient .log('Error: unable to append sent message: no no mailbox with ' 'flag sent found in $mailboxes'); } else { - print("dola ddd"); futures.add( appendMessage(message, sentMailbox, flags: [MessageFlags.seen])); } } - print("dola dddd"); + return Future.wait(futures); } Future _sendMessageViaOutgoing(MimeMessage message, MailAddress? from, bool use8BitEncoding, List? recipients, - {bool isUnicode = false}) async { - print("dola _sendMessageViaOutgoing isUnicode $isUnicode"); + {bool supportUnicode = false}) async { await _outgoingMailClient.sendMessage(message, - isUnicode: isUnicode, + supportUnicode: supportUnicode, from: from, use8BitEncoding: use8BitEncoding, recipients: recipients); @@ -3093,7 +3094,7 @@ abstract class _OutgoingMailClient { Future supports8BitEncoding(); Future sendMessage(MimeMessage message, - {required bool isUnicode, + {required bool supportUnicode, MailAddress? from, bool use8BitEncoding = false, List? recipients}); @@ -3162,7 +3163,7 @@ class _OutgoingSmtpClient extends _OutgoingMailClient { @override Future sendMessage( MimeMessage message, { - required bool isUnicode, + required bool supportUnicode, MailAddress? from, bool use8BitEncoding = false, List? recipients, @@ -3170,16 +3171,14 @@ class _OutgoingSmtpClient extends _OutgoingMailClient { await _connectOutgoingIfRequired(); try { if (_smtpClient.serverInfo.supportsChunking) { - print("dola supportsChunking"); await _smtpClient.sendChunkedMessage( message, from: from, - isUnicode: isUnicode, + supportUnicode: supportUnicode, use8BitEncoding: use8BitEncoding, recipients: recipients, ); } else { - print("dola not supportsChunking"); await _smtpClient.sendMessage( message, from: from, 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 2c57a9dd..f2333b4c 100644 --- a/lib/src/private/smtp/commands/smtp_send_bdat_command.dart +++ b/lib/src/private/smtp/commands/smtp_send_bdat_command.dart @@ -15,7 +15,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { this.fromEmail, this.recipientEmails, { required this.use8BitEncoding, - required this.isUnicode, + required this.supportUnicode, }) : super('MAIL FROM') { final binaryData = _codec.encode(getData()); _chunks = chunkData(binaryData); @@ -25,7 +25,7 @@ class _SmtpSendBdatCommand extends SmtpCommand { final String? fromEmail; final List recipientEmails; final bool use8BitEncoding; - final bool isUnicode; + final bool supportUnicode; _BdatSequence _currentStep = _BdatSequence.mailFrom; int _recipientIndex = 0; late List _chunks; @@ -33,7 +33,6 @@ class _SmtpSendBdatCommand extends SmtpCommand { static const Utf8Codec _codec = Utf8Codec(allowMalformed: true); static List chunkData(List binaryData) { - print("dola chunkData"); const chunkSize = 512 * 1024; final result = []; var startIndex = 0; @@ -57,14 +56,14 @@ class _SmtpSendBdatCommand extends SmtpCommand { @override String get command { - if (isUnicode) { - print('dola dola isUnicode $isUnicode'); - return 'MAIL FROM:<$fromEmail> BODY=SMTPUTF8'; + if (supportUnicode) { + print('supportUnicode $supportUnicode'); + return 'MAIL FROM:<$fromEmail> SMTPUTF8'; } if (use8BitEncoding) { return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } - return 'MAIL FROM:<$fromEmail> SMTPUTF8'; + return 'MAIL FROM:<$fromEmail>'; } @override @@ -123,7 +122,7 @@ class SmtpSendBdatMailCommand extends _SmtpSendBdatCommand { MailAddress? from, List recipientEmails, { required bool use8BitEncoding, - required bool isUnicode, + required bool supportUnicode, }) : super( () => message .renderMessage() @@ -131,10 +130,8 @@ class SmtpSendBdatMailCommand extends _SmtpSendBdatCommand { from?.email ?? message.fromEmail, recipientEmails, use8BitEncoding: use8BitEncoding, - isUnicode: isUnicode, - ) { - print("dola SmtpSendBdatMailCommand"); - } + supportUnicode: supportUnicode, + ); /// The message to be sent final MimeMessage message; @@ -148,7 +145,7 @@ class SmtpSendBdatMailDataCommand extends _SmtpSendBdatCommand { MailAddress from, List recipientEmails, { required bool use8BitEncoding, - required bool isUnicode, + required bool supportUnicode, }) : super( () => data .toString() @@ -156,7 +153,7 @@ class SmtpSendBdatMailDataCommand extends _SmtpSendBdatCommand { from.email, recipientEmails, use8BitEncoding: use8BitEncoding, - isUnicode: isUnicode); + supportUnicode: supportUnicode); /// The message data to be sent final MimeData data; @@ -170,9 +167,9 @@ class SmtpSendBdatMailTextCommand extends _SmtpSendBdatCommand { MailAddress from, List recipientEmails, { required bool use8BitEncoding, - required bool isUnicode, + required bool supportUnicode, }) : super(() => data, from.email, recipientEmails, - use8BitEncoding: use8BitEncoding, isUnicode: isUnicode); + use8BitEncoding: use8BitEncoding, supportUnicode: supportUnicode); /// The message text data final String data; diff --git a/lib/src/private/smtp/commands/smtp_sendmail_command.dart b/lib/src/private/smtp/commands/smtp_sendmail_command.dart index 83896a6e..ae669932 100644 --- a/lib/src/private/smtp/commands/smtp_sendmail_command.dart +++ b/lib/src/private/smtp/commands/smtp_sendmail_command.dart @@ -23,13 +23,8 @@ class _SmtpSendCommand extends SmtpCommand { @override String get command { if (use8BitEncoding) { - print('dola use8BitEncoding:1 SmtpCommand'); - log('dola use8BitEncoding:1 SmtpCommand'); - //logApp('use8BitEncoding'); return 'MAIL FROM:<$fromEmail> BODY=8BITMIME'; } - print(' dola Not use8BitEncoding1 SmtpCommand'); - log(' dola Not use8BitEncoding1 SmtpCommand'); return 'MAIL FROM:<$fromEmail>'; } diff --git a/lib/src/private/util/client_base.dart b/lib/src/private/util/client_base.dart index dcbcff49..20e9b33a 100644 --- a/lib/src/private/util/client_base.dart +++ b/lib/src/private/util/client_base.dart @@ -204,7 +204,6 @@ abstract class ClientBase { /// Disconnects from the service Future disconnect() async { if (_isConnected) { - logApp('dola disconnecting'); isLoggedIn = false; _isConnected = false; isSocketClosingExpected = true; diff --git a/lib/src/smtp/smtp_client.dart b/lib/src/smtp/smtp_client.dart index 63c5be50..6920fc52 100644 --- a/lib/src/smtp/smtp_client.dart +++ b/lib/src/smtp/smtp_client.dart @@ -301,7 +301,7 @@ class SmtpClient extends ClientBase { /// defined in the message are ignored. Future sendChunkedMessage( MimeMessage message, { - required bool isUnicode, + required bool supportUnicode, bool use8BitEncoding = false, MailAddress? from, List? recipients, @@ -312,9 +312,8 @@ class SmtpClient extends ClientBase { if (recipientEmails.isEmpty) { throw SmtpException(this, SmtpResponse(['500 no recipients'])); } - print('dola sendChunkedMessage $isUnicode'); return sendCommand(SmtpSendBdatMailCommand(message, from, recipientEmails, - use8BitEncoding: use8BitEncoding, isUnicode: isUnicode)); + use8BitEncoding: use8BitEncoding, supportUnicode: supportUnicode)); } /// Sends the specified message [data] [from] to the [recipients] @@ -327,7 +326,7 @@ class SmtpClient extends ClientBase { /// Set [use8BitEncoding] to `true` for sending a UTF-8 encoded message body. Future sendChunkedMessageData( MimeData data, MailAddress from, List recipients, - { required bool isUnicode,bool use8BitEncoding = false}) { + { required bool supportUnicode,bool use8BitEncoding = false}) { if (recipients.isEmpty) { throw SmtpException(this, SmtpResponse(['500 no recipients'])); } @@ -336,7 +335,7 @@ class SmtpClient extends ClientBase { data, from, recipients.map((r) => r.email).toList(), - isUnicode: isUnicode, + supportUnicode: supportUnicode, use8BitEncoding: use8BitEncoding, ), ); @@ -355,7 +354,7 @@ class SmtpClient extends ClientBase { /// Set [use8BitEncoding] to `true` for sending a UTF-8 encoded message body. Future sendChunkedMessageText( String text, MailAddress from, List recipients, - {required bool isUnicode,bool use8BitEncoding = false}) { + {required bool supportUnicode,bool use8BitEncoding = false}) { if (recipients.isEmpty) { throw SmtpException(this, SmtpResponse(['500 no recipients'])); } @@ -364,7 +363,7 @@ class SmtpClient extends ClientBase { text, from, recipients.map((r) => r.email).toList(), - isUnicode: isUnicode, + supportUnicode: supportUnicode, use8BitEncoding: use8BitEncoding, ), ); @@ -403,7 +402,6 @@ class SmtpClient extends ClientBase { /// Sends the command to the server Future sendCommand(SmtpCommand command) { - print("dola sendCommand"); _currentCommand = command; writeText(command.command, command); return command.completer.future; @@ -427,7 +425,6 @@ class SmtpClient extends ClientBase { writeData(next!.data!); } else if (cmd.isCommandDone(response)) { if (response.isFailedStatus) { - log('dola Error isFailedStatus proceeding to nextCommand'); cmd.completer.completeError(SmtpException(this, response)); } else { cmd.completer.complete(response); diff --git a/test/smtp/smtp_client_test.dart b/test/smtp/smtp_client_test.dart index bd6ffd87..2c37ce37 100644 --- a/test/smtp/smtp_client_test.dart +++ b/test/smtp/smtp_client_test.dart @@ -93,7 +93,7 @@ void main() { final message = MessageBuilder.buildSimpleTextMessage( from, to, 'Today as well.\r\nOne more time:\r\nHello from enough_mail!', subject: 'enough_mail hello'); - final response = await client.sendChunkedMessage(message,isUnicode: false); + final response = await client.sendChunkedMessage(message,supportUnicode: false); expect(response.type, SmtpResponseType.success); expect(response.code, 250); });