Add option notification_email_parser_lib
This commit is contained in:
@@ -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.
|
Enable to strip images from e-mails. This option superseeds notification_email_replacement_img.
|
||||||
* **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.
|
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
|
### Actions
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ notification_email_template = templates/notification.template
|
|||||||
|
|
||||||
# Option: notification_email_strip_images
|
# Option: notification_email_strip_images
|
||||||
# Notes: Optionally enable this option to strip img tags from emails.
|
# Notes: Optionally enable this option to strip img tags from emails.
|
||||||
# Values: [ TRUE|ON|YES|FALSE|OFF|NO ]
|
# Values: [ TRUE | ON | YES | FALSE | OFF | NO ]
|
||||||
#
|
#
|
||||||
notification_email_strip_images = False
|
notification_email_strip_images = False
|
||||||
|
|
||||||
@@ -138,6 +138,13 @@ notification_email_replacement_img = templates/removed.png
|
|||||||
#
|
#
|
||||||
notification_email_embedded_imgs = templates/logo.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
|
# Option: whitelist_type
|
||||||
# Notes: Set the whitelist type.
|
# Notes: Set the whitelist type.
|
||||||
# Values: [ db | none ]
|
# Values: [ db | none ]
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ class EMailNotification(BaseNotification):
|
|||||||
# check if optional config options are present in config
|
# check if optional config options are present in config
|
||||||
defaults = {
|
defaults = {
|
||||||
"notification_email_replacement_img": "",
|
"notification_email_replacement_img": "",
|
||||||
"notification_email_strip_images": "false"
|
"notification_email_strip_images": "false",
|
||||||
|
"notification_email_parser_lib": "lxml"
|
||||||
}
|
}
|
||||||
for option in defaults.keys():
|
for option in defaults.keys():
|
||||||
if option not in config.keys() and \
|
if option not in config.keys() and \
|
||||||
@@ -181,6 +182,10 @@ class EMailNotification(BaseNotification):
|
|||||||
else:
|
else:
|
||||||
raise RuntimeError("error parsing notification_email_strip_images: unknown value")
|
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
|
# read email replacement image if specified
|
||||||
replacement_img = self.config["notification_email_replacement_img"].strip()
|
replacement_img = self.config["notification_email_replacement_img"].strip()
|
||||||
if not strip_images and replacement_img:
|
if not strip_images and replacement_img:
|
||||||
@@ -229,8 +234,13 @@ class EMailNotification(BaseNotification):
|
|||||||
"{}: content mimetype is {}".format(
|
"{}: content mimetype is {}".format(
|
||||||
queueid, mimetype))
|
queueid, mimetype))
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
"{}: creating BeatufilSoup object".format(queueid))
|
"{}: trying to create BeatufilSoup object with parser lib {}, "
|
||||||
return BeautifulSoup(text, "lxml")
|
"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):
|
def get_text_multipart(self, queueid, msg, preferred=_html_text):
|
||||||
"Get the mail text of a multipart email in html form."
|
"Get the mail text of a multipart email in html form."
|
||||||
|
|||||||
Reference in New Issue
Block a user