configure attributes

This commit is contained in:
tekh 2025-09-04 17:46:16 +02:00
parent 9c48b230b4
commit 124523ad88
2 changed files with 31 additions and 22 deletions

View File

@ -34,7 +34,6 @@ public class SendSignedMailHandler : SendMailHandler<DocSignedNotification>
}
/// <summary>
///
/// </summary>
/// <param name="notification"></param>
/// <returns></returns>
@ -42,26 +41,10 @@ public class SendSignedMailHandler : SendMailHandler<DocSignedNotification>
{
var placeHolders = new Dictionary<string, string>()
{
{ "[NAME_RECEIVER]", notification.Name ?? string.Empty },
{ "[DOCUMENT_TITLE]", notification.Envelope?.Title ?? string.Empty },
};
return placeHolders;
}
private static string TextToHtml(string input)
{
if (string.IsNullOrEmpty(input)) return "";
// HTML encoding special characters
string encoded = System.Net.WebUtility.HtmlEncode(input);
// Convert tabs to &nbsp; (4 non-breaking spaces)
encoded = encoded.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
// Convert line breaks to <br />
encoded = encoded.Replace("\r\n", "<br />"); // Windows
encoded = encoded.Replace("\r", "<br />"); // Mac old
encoded = encoded.Replace("\n", "<br />"); // Unix/Linux
return encoded;
}
}

View File

@ -48,7 +48,14 @@ public abstract class SendMailHandler<TNotification> : INotificationHandler<TNot
protected abstract Dictionary<string, string> CreatePlaceHolders(TNotification notification);
/// <summary>
///
///{ "[MESSAGE]", notification.Message },<br/>
///{ "[DOCUMENT_ACCESS_CODE]", notification.ReceiverAccessCode },<br/>
///{ "[REASON]", pReason }<br/>
///{ "[NAME_SENDER]", notification.Envelope.User?.FullName},<br/>
///{ "[NAME_PORTAL]", DispatcherParams. },<br/>
///{ "[SIGNATURE_TYPE]", "signieren" },<br/>
///{ "[LINK_TO_DOCUMENT]", notification.SignatureLink },<br/>
///{ "[LINK_TO_DOCUMENT_TEXT]", $"{notification.SignatureLink.Truncate(40)}.." },
/// </summary>
protected readonly MailParams MailParams;
@ -89,6 +96,7 @@ public abstract class SendMailHandler<TNotification> : INotificationHandler<TNot
public virtual async Task Handle(TNotification notification, CancellationToken cancel)
{
var placeHolders = CreatePlaceHolders(notification);
var temp = await TempRepo
.ReadOnly()
.SingleOrDefaultAsync(x => x.Name == notification.TemplateType.ToString(), cancel)
@ -102,7 +110,7 @@ public abstract class SendMailHandler<TNotification> : INotificationHandler<TNot
var emailOut = new EmailOut
{
EmailAddress = notification.EmailAddress,
EmailBody = temp.Body,
EmailBody = TextToHtml(temp.Body),
EmailSubj = temp.Subject,
AddedWhen = DateTime.UtcNow,
AddedWho = DispatcherParams.AddedWho,
@ -123,4 +131,22 @@ public abstract class SendMailHandler<TNotification> : INotificationHandler<TNot
text = text.Replace(ph.Key, ph.Value);
return text;
}
private static string TextToHtml(string input)
{
if (string.IsNullOrEmpty(input)) return "";
// HTML encoding special characters
string encoded = System.Net.WebUtility.HtmlEncode(input);
// Convert tabs to &nbsp; (4 non-breaking spaces)
encoded = encoded.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
// Convert line breaks to <br />
encoded = encoded.Replace("\r\n", "<br />"); // Windows
encoded = encoded.Replace("\r", "<br />"); // Mac old
encoded = encoded.Replace("\n", "<br />"); // Unix/Linux
return encoded;
}
}