mirror of
https://github.com/caronc/apprise.git
synced 2024-11-09 01:34:11 +01:00
title handling and bulletproofing
This commit is contained in:
parent
643dc3f561
commit
268d11f181
@ -74,6 +74,13 @@ class NotifyBase(URLBase):
|
||||
# Default Overflow Mode
|
||||
overflow_mode = OverflowMode.UPSTREAM
|
||||
|
||||
# Default Title HTML Tagging
|
||||
# When a title is specified for a notification service that doesn't accept
|
||||
# titles, by default apprise tries to give a plesant view and convert the
|
||||
# title so that it can be placed into the body. The default is to just
|
||||
# use a <b> tag. The below causes the <b>title</b> to get generated:
|
||||
default_html_tag_id = 'b'
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""
|
||||
Initialize some general configuration that will keep things consistent
|
||||
@ -224,9 +231,23 @@ class NotifyBase(URLBase):
|
||||
# default
|
||||
overflow = self.overflow_mode
|
||||
|
||||
if self.title_maxlen <= 0:
|
||||
# Content is appended to body
|
||||
body = '{}\r\n{}'.format(title, body)
|
||||
if self.title_maxlen <= 0 and len(title) > 0:
|
||||
if self.notify_format == NotifyFormat.MARKDOWN:
|
||||
# Content is appended to body as markdown
|
||||
body = '**{}**\r\n{}'.format(title, body)
|
||||
|
||||
elif self.notify_format == NotifyFormat.HTML:
|
||||
# Content is appended to body as html
|
||||
body = '<{open_tag}>{title}</{close_tag}>' \
|
||||
'<br />\r\n{body}'.format(
|
||||
open_tag=self.default_html_tag_id,
|
||||
title=self.escape_html(title),
|
||||
close_tag=self.default_html_tag_id,
|
||||
body=body)
|
||||
else:
|
||||
# Content is appended to body as text
|
||||
body = '{}\r\n{}'.format(title, body)
|
||||
|
||||
title = ''
|
||||
|
||||
# Enforce the line count first always
|
||||
|
@ -96,7 +96,7 @@ class NotifyGnome(NotifyBase):
|
||||
# content to display
|
||||
body_max_line_count = 10
|
||||
|
||||
# A title can not be used for SMS Messages. Setting this to zero will
|
||||
# A title can not be used for Gnome Messages. Setting this to zero will
|
||||
# cause any title (if defined) to get placed into the message body.
|
||||
title_maxlen = 0
|
||||
|
||||
|
@ -64,6 +64,10 @@ class NotifyPushed(NotifyBase):
|
||||
# Pushed uses the http protocol with JSON requests
|
||||
notify_url = 'https://api.pushed.co/1/push'
|
||||
|
||||
# A title can not be used for Pushed Messages. Setting this to zero will
|
||||
# cause any title (if defined) to get placed into the message body.
|
||||
title_maxlen = 0
|
||||
|
||||
# The maximum allowable characters allowed in the body per message
|
||||
body_maxlen = 140
|
||||
|
||||
|
@ -167,7 +167,7 @@ class NotifyRyver(NotifyBase):
|
||||
|
||||
# prepare JSON Object
|
||||
payload = {
|
||||
"body": body if not title else '**%s**\r\n%s' % (title, body),
|
||||
"body": body if not title else '**{}**\r\n{}'.format(title, body),
|
||||
'createSource': {
|
||||
"displayName": self.user,
|
||||
"avatar": self.image_url(notify_type),
|
||||
|
@ -367,8 +367,10 @@ class NotifyTelegram(NotifyBase):
|
||||
# Tabs become 3 spaces
|
||||
title = re.sub(' ?', ' ', title, re.I)
|
||||
|
||||
# HTML
|
||||
title = NotifyBase.escape_html(title, whitespace=False)
|
||||
|
||||
# HTML
|
||||
title = NotifyBase.escape_html(title, whitespace=False)
|
||||
body = NotifyBase.escape_html(body, whitespace=False)
|
||||
|
||||
# Assign the body
|
||||
|
@ -3128,6 +3128,16 @@ def test_notify_overflow_truncate():
|
||||
|
||||
# Verify that we break the title to a max length of our title_max
|
||||
# and that the body remains untouched
|
||||
|
||||
obj.notify_format = NotifyFormat.HTML
|
||||
chunks = obj._apply_overflow(body=body, title=title)
|
||||
assert len(chunks) == 1
|
||||
|
||||
obj.notify_format = NotifyFormat.MARKDOWN
|
||||
chunks = obj._apply_overflow(body=body, title=title)
|
||||
assert len(chunks) == 1
|
||||
|
||||
obj.notify_format = NotifyFormat.TEXT
|
||||
chunks = obj._apply_overflow(body=body, title=title)
|
||||
assert len(chunks) == 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user