Add option notification_email_parser_lib

This commit is contained in:
2019-10-26 13:04:19 +02:00
parent 7509629b44
commit 7020c53b28
3 changed files with 23 additions and 4 deletions

View File

@@ -114,6 +114,8 @@ The following configuration options are optional in each quarantine section:
Enable to strip images from e-mails. This option superseeds notification_email_replacement_img.
* **notification_email_replacement_img**
Path to an image to replace images in e-mails. It is hold in memory during runtime.
* **notification_email_parser_lib**
HTML parser library used to parse text part of emails.
### Actions

View File

@@ -138,6 +138,13 @@ notification_email_replacement_img = templates/removed.png
#
notification_email_embedded_imgs = templates/logo.png
# Option: notification_email_parser_lib
# Notes: Optionally set the parser library used to parse
# the text part of emails.
# Values: [ lxml | html.parser ]
#
notification_email_parser_lib = lxml
# Option: whitelist_type
# Notes: Set the whitelist type.
# Values: [ db | none ]

View File

@@ -132,7 +132,8 @@ class EMailNotification(BaseNotification):
# check if optional config options are present in config
defaults = {
"notification_email_replacement_img": "",
"notification_email_strip_images": "false"
"notification_email_strip_images": "false",
"notification_email_parser_lib": "lxml"
}
for option in defaults.keys():
if option not in config.keys() and \
@@ -181,6 +182,10 @@ class EMailNotification(BaseNotification):
else:
raise RuntimeError("error parsing notification_email_strip_images: unknown value")
self.parser_lib = self.config["notification_email_parser_lib"].strip()
if self.parser_lib not in ["lxml", "html.parser"]:
raise RuntimeError("error parsing notification_email_parser_lib: unknown value")
# read email replacement image if specified
replacement_img = self.config["notification_email_replacement_img"].strip()
if not strip_images and replacement_img:
@@ -229,8 +234,13 @@ class EMailNotification(BaseNotification):
"{}: content mimetype is {}".format(
queueid, mimetype))
self.logger.debug(
"{}: creating BeatufilSoup object".format(queueid))
return BeautifulSoup(text, "lxml")
"{}: trying to create BeatufilSoup object with parser lib {}, "
"text length is {} bytes".format(
queueid, self.parser_lib, len(text)))
soup = BeautifulSoup(text, self.parser_lib)
self.logger.debug(
"{}: sucessfully created BeautifulSoup object".format(queueid))
return soup
def get_text_multipart(self, queueid, msg, preferred=_html_text):
"Get the mail text of a multipart email in html form."