Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/src/private/smtp/commands/smtp_sendmail_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class _SmtpSendCommand extends SmtpCommand {
}
}

/// The `Bcc` header line and every folded continuation line under it.
///
/// `Header.render` folds a value longer than
/// `MailConventions.textLineMaxLength` onto `\r\n\t`-prefixed lines, which
/// three or four addresses already do. Matching only the first physical line
/// left the rest of the list in the DATA that every To/Cc recipient received.
final _bccHeader = RegExp(r'^Bcc:.*\r\n(?:[ \t].*\r\n)*', multiLine: true);

/// Sends a MIME message
class SmtpSendMailCommand extends _SmtpSendCommand {
/// Creates a new DATA command
Expand All @@ -82,10 +90,7 @@ class SmtpSendMailCommand extends _SmtpSendCommand {
List<String> recipientEmails, {
required bool use8BitEncoding,
}) : super(
() => message.renderMessage().replaceAll(
RegExp('^Bcc:.*\r\n', multiLine: true),
'',
),
() => message.renderMessage().replaceAll(_bccHeader, ''),
from?.email ?? message.fromEmail,
recipientEmails,
use8BitEncoding: use8BitEncoding,
Expand All @@ -104,10 +109,7 @@ class SmtpSendMailDataCommand extends _SmtpSendCommand {
List<String> recipientEmails, {
required bool use8BitEncoding,
}) : super(
() => data.toString().replaceAll(
RegExp('^Bcc:.*\r\n', multiLine: true),
'',
),
() => data.toString().replaceAll(_bccHeader, ''),
from.email,
recipientEmails,
use8BitEncoding: use8BitEncoding,
Expand Down
63 changes: 63 additions & 0 deletions test/smtp/smtp_sendmail_command_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:enough_mail/enough_mail.dart';
import 'package:enough_mail/src/private/smtp/commands/smtp_sendmail_command.dart';
import 'package:test/test.dart';

void main() {
group('SmtpSendMailCommand', () {
test('strips a Bcc header that was folded onto continuation lines', () {
final message =
(MessageBuilder()
..from = const [MailAddress('Me', 'me@example.com')]
..to = const [MailAddress('You', 'you@example.com')]
..cc = const [MailAddress('Carol', 'carol@example.com')]
..bcc = [
for (var i = 0; i < 6; i++)
MailAddress(
'Hidden Recipient Number $i',
'hidden.recipient.$i@example.com',
),
]
..subject = 'Hello'
..addTextPlain('Body'))
.buildMimeMessage();
final rendered = message.renderMessage();
expect(
rendered,
contains('\r\n\t'),
reason: 'the fixture must actually fold the Bcc header',
);

final command = SmtpSendMailCommand(
message,
null,
message.recipientAddresses,
use8BitEncoding: false,
);
final data = command.getData();

expect(data, isNot(contains('Bcc')));
expect(data, isNot(contains('hidden.recipient')));
expect(data, isNot(contains('\r\n\t')));
expect(data, contains('To: "You" <you@example.com>\r\n'));
expect(data, contains('Cc: "Carol" <carol@example.com>\r\n'));
expect(data, contains('Subject: Hello\r\n'));
expect(data, contains('Body'));
});

test('keeps every recipient in the envelope', () {
final message =
(MessageBuilder()
..from = const [MailAddress('Me', 'me@example.com')]
..to = const [MailAddress('You', 'you@example.com')]
..bcc = const [MailAddress('Hidden', 'hidden@example.com')]
..subject = 'Hello'
..addTextPlain('Body'))
.buildMimeMessage();

expect(message.recipientAddresses, [
'you@example.com',
'hidden@example.com',
]);
});
});
}
Loading