Header/Meta support added to email plugin (#310)

This commit is contained in:
Chris Caron 2020-10-06 16:32:00 -04:00 committed by GitHub
parent 68adae39d1
commit 53a8d046ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -383,9 +383,17 @@ class NotifyEmail(NotifyBase):
}, },
}) })
# Define any kwargs we're using
template_kwargs = {
'headers': {
'name': _('Email Header'),
'prefix': '+',
},
}
def __init__(self, smtp_host=None, from_name=None, def __init__(self, smtp_host=None, from_name=None,
from_addr=None, secure_mode=None, targets=None, cc=None, from_addr=None, secure_mode=None, targets=None, cc=None,
bcc=None, **kwargs): bcc=None, headers=None, **kwargs):
""" """
Initialize Email Object Initialize Email Object
@ -414,6 +422,11 @@ class NotifyEmail(NotifyBase):
# For tracking our email -> name lookups # For tracking our email -> name lookups
self.names = {} self.names = {}
self.headers = {}
if headers:
# Store our extra headers
self.headers.update(headers)
# Now we want to construct the To and From email # Now we want to construct the To and From email
# addresses from the URL provided # addresses from the URL provided
self.from_addr = from_addr self.from_addr = from_addr
@ -648,6 +661,11 @@ class NotifyEmail(NotifyBase):
content = MIMEText(body, 'plain', 'utf-8') content = MIMEText(body, 'plain', 'utf-8')
base = MIMEMultipart() if attach else content base = MIMEMultipart() if attach else content
# Apply any provided custom headers
for k, v in self.headers.items():
base[k] = Header(v, 'utf-8')
base['Subject'] = Header(title, 'utf-8') base['Subject'] = Header(title, 'utf-8')
try: try:
base['From'] = formataddr( base['From'] = formataddr(
@ -767,6 +785,9 @@ class NotifyEmail(NotifyBase):
'user': self.user, 'user': self.user,
} }
# Append our headers into our parameters
params.update({'+{}'.format(k): v for k, v in self.headers.items()})
# Extend our parameters # Extend our parameters
params.update(self.url_parameters(privacy=privacy, *args, **kwargs)) params.update(self.url_parameters(privacy=privacy, *args, **kwargs))
@ -891,4 +912,9 @@ class NotifyEmail(NotifyBase):
results['from_addr'] = from_addr results['from_addr'] = from_addr
results['smtp_host'] = smtp_host results['smtp_host'] = smtp_host
# Add our Meta Headers that the user can provide with their outbound
# emails
results['headers'] = {NotifyBase.unquote(x): NotifyBase.unquote(y)
for x, y in results['qsd+'].items()}
return results return results

View File

@ -165,6 +165,11 @@ TEST_URLS = (
'instance': plugins.NotifyEmail, 'instance': plugins.NotifyEmail,
}, },
), ),
# headers
('mailto://user:pass@localhost.localdomain'
'?+X-Customer-Campaign-ID=Apprise', {
'instance': plugins.NotifyEmail,
}),
# No Password # No Password
('mailtos://user:@nuxref.com', { ('mailtos://user:@nuxref.com', {
'instance': plugins.NotifyEmail, 'instance': plugins.NotifyEmail,