You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "smisch (via GitHub)" <gi...@apache.org> on 2024/04/11 12:19:23 UTC
Re: [I] EMAIL_HEADER_MUTATOR not applying changes to MimeMultipart `msg` [superset]
smisch commented on issue #23247:
URL: https://github.com/apache/superset/issues/23247#issuecomment-2049571431
Thanks for the code. I had to make some slight adjustments in 2024 to make it work:
```
import re
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from typing import Any
def EMAIL_HEADER_MUTATOR(msg: MIMEMultipart, **kwargs: Any) -> MIMEMultipart:
disclaimer = "<i>Please do not reply, this is an automatically generated email.</i>"
mime_text = MIMEText(disclaimer, "html")
msg.attach(mime_text)
# Remove all anchor tags from message payload
for part in msg.walk():
if part.get_content_type() == 'text/html':
payload = part.get_payload(decode=True).decode() # Extract text content
payload = re.sub('<a.*?>|</a>', '', payload) # Apply regular expression
part.set_payload(payload) # Set the modified payload back to the part
return msg
```
It was complaining about `'expected string or bytes-like object'` with the original code due to `part` not being `string or bytes-like object`.
For those of us using the superset helm charts, just add this to `configOverrides.foobar` via `values.yaml` to the `superset_config.py`.
Btw. the disclaimer didn't show up in the mail, but the link removal stuff works great.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org