66using MassTransit ;
77using Microsoft . EntityFrameworkCore ;
88using Microsoft . Extensions . Options ;
9- using System . Net ;
109using System . Text . RegularExpressions ;
1110
1211namespace Jordnaer . Consumers ;
@@ -69,7 +68,7 @@ public async Task Consume(ConsumeContext<GroupPostCreated> consumeContext)
6968 var email = new SendEmail
7069 {
7170 Subject = $ "Nyt opslag i { message . GroupName } ",
72- HtmlContent = CreateNewPostEmailContent ( message . AuthorDisplayName , postPreview , groupUrl ) ,
71+ HtmlContent = CreateNewPostEmailContent ( baseUrl , message . AuthorDisplayName , postPreview , groupUrl ) ,
7372 Bcc = emails
7473 } ;
7574
@@ -96,31 +95,8 @@ private static string GetPostPreview(string text)
9695 : plainText . Substring ( 0 , 200 ) + "..." ;
9796 }
9897
99- private static string CreateNewPostEmailContent ( string authorName , string postPreview , string groupUrl )
100- {
101- // HTML-encode to prevent XSS attacks
102- var encodedAuthorName = WebUtility . HtmlEncode ( authorName ) ;
103- var encodedPostPreview = WebUtility . HtmlEncode ( postPreview ) ;
104-
105- // Convert newlines to <br/> tags for proper display after encoding
106- encodedPostPreview = encodedPostPreview . Replace ( "\r \n " , "<br/>" ) . Replace ( "\n " , "<br/>" ) ;
107-
108- var encodedGroupUrl = WebUtility . HtmlEncode ( groupUrl ) ;
109-
110- return $ """
111- <h4>Nyt opslag i din gruppe</h4>
112-
113- <p><b>{ encodedAuthorName } </b> har oprettet et nyt opslag:</p>
114-
115- <blockquote style="border-left: 3px solid #ccc; padding-left: 10px; color: #666;">
116- { encodedPostPreview }
117- </blockquote>
118-
119- <p><a href="{ encodedGroupUrl } ">Klik her for at se opslaget</a></p>
120-
121- { EmailConstants . Signature }
122- """ ;
123- }
98+ private static string CreateNewPostEmailContent ( string baseUrl , string authorName , string postPreview , string groupUrl ) =>
99+ EmailContentBuilder . GroupPostNotification ( baseUrl , authorName , postPreview , groupUrl ) ;
124100
125101 [ GeneratedRegex ( "<.*?>" ) ]
126102 private static partial Regex HtmlTagsRegex ( ) ;
0 commit comments