@@ -19,6 +19,8 @@ public class InviteService(IOptions<Startup.Settings> options, IInviteRepository
1919 private readonly IEmailService _emailService = emailService ;
2020 private readonly IPermissionService _permissionService = permissionService ;
2121
22+ private const int MaxInviteMessageLength = 1000 ;
23+
2224 internal static string CreateLink ( ProjectInvite invite )
2325 {
2426 // Matches the Path.ProjInvite route in src\router\appRoutes.tsx
@@ -32,27 +34,38 @@ internal async Task<ProjectInvite> CreateProjectInvite(string projectId, Role ro
3234 return invite ;
3335 }
3436
35- private MimeMessage CreateEmail ( string emailAddress , string emailMessage , string link , string projectName )
37+ private MimeMessage CreateEmail (
38+ string emailAddress , string emailMessage , string inviter , string link , string projectName )
3639 {
40+ // Trim user-provided emailMessage
41+ var trimmedMessage = emailMessage . Trim ( ) ;
42+ if ( trimmedMessage . Length > MaxInviteMessageLength )
43+ {
44+ trimmedMessage = trimmedMessage . Substring ( 0 , MaxInviteMessageLength ) ;
45+ }
46+
3747 var message = new MimeMessage ( ) ;
3848 message . To . Add ( new MailboxAddress ( "FutureCombineUser" , emailAddress ) ) ;
39- message . Subject = "The Combine Project Invite " ;
40- message . Body = new TextPart ( "plain" )
49+ message . Subject = "The Combine project invitation " ;
50+ message . Body = new TextPart ( "plain" ) // With "plain", we don't need to sanitize emailMessage.
4151 {
42- Text = $ "You have been invited project '{ projectName } ' on The Combine.\n " +
43- $ "To become a member of this project, go to { link } .\n " +
44- $ "Use this email address during registration: { emailAddress } .\n \n " +
45- $ "Message from Project Admin: { emailMessage } \n \n " +
46- $ "(This link will expire in { _expireTime . TotalDays } days.)\n \n " +
47- "If you did not expect an invite please ignore this email."
52+ Text = $ "You have been invited to project '{ projectName } ' on The Combine.\n \n " +
53+ $ "Follow this link to become a member of the project: { link } \n \n " +
54+ $ "(Link will expire in { _expireTime . TotalDays } days.)\n \n " +
55+ $ "Use this email address during registration: { emailAddress } \n \n " +
56+ "If you did not expect an invite, please ignore this email.\n \n " +
57+ $ "Message from project administrator ({ inviter } ):\n \n " +
58+ trimmedMessage
4859 } ;
4960 return message ;
5061 }
5162
52- public async Task < string > EmailLink ( Project project , Role role , string emailAddress , string message )
63+ public async Task < string > EmailLink (
64+ Project project , Role role , string emailAddress , string inviterId , string message )
5365 {
5466 var link = CreateLink ( await CreateProjectInvite ( project . Id , role , emailAddress ) ) ;
55- await _emailService . SendEmail ( CreateEmail ( emailAddress , message , link , project . Name ) ) ;
67+ var inviter = await _userRepo . GetUser ( inviterId ) ?? throw new InviteException ( "Inviting user not found." ) ;
68+ await _emailService . SendEmail ( CreateEmail ( emailAddress , message , inviter . Name , link , project . Name ) ) ;
5669 return link ;
5770 }
5871
0 commit comments