mirror of https://github.com/caronc/apprise
title handling and bulletproofing
parent
643dc3f561
commit
268d11f181
|
@ -74,6 +74,13 @@ class NotifyBase(URLBase):
|
||||||
# Default Overflow Mode
|
# Default Overflow Mode
|
||||||
overflow_mode = OverflowMode.UPSTREAM
|
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):
|
def __init__(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Initialize some general configuration that will keep things consistent
|
Initialize some general configuration that will keep things consistent
|
||||||
|
@ -224,9 +231,23 @@ class NotifyBase(URLBase):
|
||||||
# default
|
# default
|
||||||
overflow = self.overflow_mode
|
overflow = self.overflow_mode
|
||||||
|
|
||||||
if self.title_maxlen <= 0:
|
if self.title_maxlen <= 0 and len(title) > 0:
|
||||||
# Content is appended to body
|
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)
|
body = '{}\r\n{}'.format(title, body)
|
||||||
|
|
||||||
title = ''
|
title = ''
|
||||||
|
|
||||||
# Enforce the line count first always
|
# Enforce the line count first always
|
||||||
|
|
|
@ -96,7 +96,7 @@ class NotifyGnome(NotifyBase):
|
||||||
# content to display
|
# content to display
|
||||||
body_max_line_count = 10
|
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.
|
# cause any title (if defined) to get placed into the message body.
|
||||||
title_maxlen = 0
|
title_maxlen = 0
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,10 @@ class NotifyPushed(NotifyBase):
|
||||||
# Pushed uses the http protocol with JSON requests
|
# Pushed uses the http protocol with JSON requests
|
||||||
notify_url = 'https://api.pushed.co/1/push'
|
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
|
# The maximum allowable characters allowed in the body per message
|
||||||
body_maxlen = 140
|
body_maxlen = 140
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ class NotifyRyver(NotifyBase):
|
||||||
|
|
||||||
# prepare JSON Object
|
# prepare JSON Object
|
||||||
payload = {
|
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': {
|
'createSource': {
|
||||||
"displayName": self.user,
|
"displayName": self.user,
|
||||||
"avatar": self.image_url(notify_type),
|
"avatar": self.image_url(notify_type),
|
||||||
|
|
|
@ -369,6 +369,8 @@ class NotifyTelegram(NotifyBase):
|
||||||
|
|
||||||
# HTML
|
# HTML
|
||||||
title = NotifyBase.escape_html(title, whitespace=False)
|
title = NotifyBase.escape_html(title, whitespace=False)
|
||||||
|
|
||||||
|
# HTML
|
||||||
body = NotifyBase.escape_html(body, whitespace=False)
|
body = NotifyBase.escape_html(body, whitespace=False)
|
||||||
|
|
||||||
# Assign the body
|
# 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
|
# Verify that we break the title to a max length of our title_max
|
||||||
# and that the body remains untouched
|
# 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)
|
chunks = obj._apply_overflow(body=body, title=title)
|
||||||
assert len(chunks) == 1
|
assert len(chunks) == 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue