fix: Outlook email UTF-8 charset for umlauts - add meta charset to HTML body
All checks were successful
Deploy Plattform-Core / test (push) Successful in 44s
Deploy Plattform-Core (Int) / test (push) Successful in 1m11s
Deploy Plattform-Core / deploy (push) Successful in 5s
Deploy Plattform-Core (Int) / deploy (push) Successful in 9s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
ValueOn AG 2026-06-01 00:04:36 +02:00
parent a7b5192e25
commit 33dd694ba1
2 changed files with 20 additions and 6 deletions

View file

@ -62,7 +62,7 @@ async def _makeGraphCall(
) -> Dict[str, Any]:
"""Execute a single Microsoft Graph API call."""
url = f"{_GRAPH_BASE}/{endpoint.lstrip('/')}"
contentType = "application/json"
contentType = "application/json; charset=utf-8"
if method == "PUT" and isinstance(data, bytes):
contentType = "application/octet-stream"
headers = {
@ -271,6 +271,17 @@ class SharepointAdapter(_GraphApiMixin, ServiceAdapter):
# Outlook Adapter
# ---------------------------------------------------------------------------
_CHARSET_META = '<meta charset="utf-8">'
def _ensureHtmlCharset(html: str) -> str:
"""Ensure HTML body has a charset meta tag so Outlook renders UTF-8 correctly."""
if "charset" in html.lower():
return html
if html.strip().lower().startswith("<html"):
return html.replace("<html>", f"<html><head>{_CHARSET_META}</head>", 1)
return f"<html><head>{_CHARSET_META}</head><body>{html}</body></html>"
class OutlookAdapter(_GraphApiMixin, ServiceAdapter):
"""ServiceAdapter for Outlook (mail, calendar) via Microsoft Graph."""
@ -433,9 +444,12 @@ class OutlookAdapter(_GraphApiMixin, ServiceAdapter):
attachments: list of {"name": str, "contentBytes": str (base64), "contentType": str}
"""
content = body
if bodyType.upper() == "HTML":
content = _ensureHtmlCharset(body)
message: Dict[str, Any] = {
"subject": subject,
"body": {"contentType": bodyType, "content": body},
"body": {"contentType": bodyType, "content": content},
"toRecipients": [{"emailAddress": {"address": addr}} for addr in to],
}
if cc:

View file

@ -261,16 +261,16 @@ Return JSON:
"Content-Type": "application/json"
}
# Clean and format body content
cleaned_body = body.strip()
_CHARSET_META = '<meta charset="utf-8">'
# Check if body is already HTML
if cleaned_body.startswith('<html>') or cleaned_body.startswith('<body>') or '<br>' in cleaned_body:
html_body = cleaned_body
if "charset" not in html_body.lower():
html_body = html_body.replace("<html>", f"<html><head>{_CHARSET_META}</head>", 1) if "<html>" in html_body else f"<html><head>{_CHARSET_META}</head><body>{html_body}</body></html>"
else:
# Convert plain text to proper HTML formatting
html_body = cleaned_body.replace('\n', '<br>')
html_body = f"<html><body>{html_body}</body></html>"
html_body = f"<html><head>{_CHARSET_META}</head><body>{html_body}</body></html>"
# Build the email message
message = {