Skip to content

Commit

Permalink
Different email senders for different kind of emails. (dart-lang#7431)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 25, 2024
1 parent fbe468a commit 5dba536
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions app/lib/shared/email.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import 'dart:io';

import 'urls.dart';

const pubDartlangOrgEmail = '[email protected]';
const _invitesAtPubDev = '[email protected]';
const _noreplyAtPubDev = '[email protected]';
final _lenientEmailRegExp = RegExp(r'^\S+@\S+\.\S+$');

/// Strict regular expression used in <input type="email" />
/// https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
final _strictEmailRegExp = RegExp(
r'''[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$''');

final _defaultFrom = EmailAddress(
pubDartlangOrgEmail,
name: 'Dart package site admin',
final _invitesFrom = EmailAddress(
_invitesAtPubDev,
name: 'Dart package site invites',
);

final _notificationsFrom = EmailAddress(
_noreplyAtPubDev,
name: 'Dart package site notifications',
);

String _footer(String action) {
Expand Down Expand Up @@ -178,7 +184,8 @@ For details, go to $url
${_footer('package')}
''';

return EmailMessage(_defaultFrom, authorizedUploaders, subject, bodyText);
return EmailMessage(
_notificationsFrom, authorizedUploaders, subject, bodyText);
}

/// Creates the [EmailMessage] that will be sent to users about new invitations
Expand All @@ -201,7 +208,7 @@ If you don’t want to accept it, simply ignore this email.
${_footer('invitation')}
''';
return EmailMessage(
_defaultFrom, [EmailAddress(invitedEmail)], subject, bodyText);
_invitesFrom, [EmailAddress(invitedEmail)], subject, bodyText);
}

/// Creates the [EmailMessage] that we be sent on package transfer to a new publisher.
Expand Down Expand Up @@ -229,5 +236,5 @@ For details, go to $url
${_footer('transfer')}
''';

return EmailMessage(_defaultFrom, authorizedAdmins, subject, bodyText);
return EmailMessage(_notificationsFrom, authorizedAdmins, subject, bodyText);
}
2 changes: 1 addition & 1 deletion app/test/shared/email_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void main() {
EmailAddress('[email protected]')
],
);
expect(message.from.toString(), contains('<noreply@pub.dev>'));
expect(message.from.toString(), contains('@pub.dev'));
expect(message.recipients.map((e) => e.toString()).toList(), [
'Joe <[email protected]>',
'[email protected]',
Expand Down

0 comments on commit 5dba536

Please sign in to comment.