mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Merge pull request #632 from JackDandy/feature/ChangeEmailUnicodeAware
Change emails to Unicode aware.
This commit is contained in:
commit
c114cb9f36
2 changed files with 20 additions and 32 deletions
|
@ -20,6 +20,7 @@
|
|||
* Update SimpleJSON library 3.8.0 (a37a9bd) to 3.8.1 (6022794)
|
||||
* Update Six compatibility library 1.9.0 (r400) to 1.10.0 (r405)
|
||||
* Change refactor email notifier
|
||||
* Change emails to Unicode aware
|
||||
|
||||
|
||||
### 0.11.3 (2016-01-16 20:00:00 UTC)
|
||||
|
|
|
@ -54,20 +54,22 @@ class EmailNotifier:
|
|||
if not sickbeard.USE_EMAIL and not force:
|
||||
return
|
||||
|
||||
ep_name = ep_name.encode('utf-8', 'replace')
|
||||
show = self._parse_ep(ep_name)
|
||||
to = self._generate_recipients(show)
|
||||
show = ep_name.split(' - ')[0]
|
||||
to = self._get_recipients(show)
|
||||
if not any(to):
|
||||
logger.log(u'No email recipients to notify, skipping', logger.WARNING)
|
||||
return
|
||||
|
||||
logger.log(u'Email recipients to notify: %s' % to, logger.DEBUG)
|
||||
|
||||
try:
|
||||
msg = MIMEMultipart('alternative')
|
||||
msg.attach(MIMEText(
|
||||
'<body style="font-family:Helvetica, Arial, sans-serif;">' +
|
||||
'<h3>SickGear Notification - %s</h3>\n' % title +
|
||||
'<p>Show: <b>' + re.search('(.+?) -.+', ep_name).group(1) +
|
||||
'</b></p>\n<p>Episode: <b>' + re.search('.+ - (.+?-.+) -.+', ep_name).group(1) +
|
||||
'<p>Show: <b>' + show.encode('ascii', 'xmlcharrefreplace') +
|
||||
'</b></p>\n<p>Episode: <b>' +
|
||||
unicode(re.search('.+ - (.+?-.+) -.+', ep_name).group(1)).encode('ascii', 'xmlcharrefreplace') +
|
||||
extra +
|
||||
'</b></p>\n\n' +
|
||||
'<footer style="margin-top:2.5em;padding:.7em 0;color:#777;border-top:#BBB solid 1px;">' +
|
||||
|
@ -131,30 +133,26 @@ class EmailNotifier:
|
|||
pass
|
||||
|
||||
@staticmethod
|
||||
def _generate_recipients(show):
|
||||
def _get_recipients(show_name=None):
|
||||
|
||||
addrs = []
|
||||
email_list = []
|
||||
|
||||
# Grab the global recipients
|
||||
if sickbeard.EMAIL_LIST:
|
||||
for addr in sickbeard.EMAIL_LIST.split(','):
|
||||
if any(addr.strip()):
|
||||
addrs.append(addr)
|
||||
for email_address in sickbeard.EMAIL_LIST.split(','):
|
||||
if any(email_address.strip()):
|
||||
email_list.append(email_address)
|
||||
|
||||
# Grab the recipients for the show
|
||||
if None is not show:
|
||||
if None is not show_name:
|
||||
my_db = db.DBConnection()
|
||||
for name in show:
|
||||
for subs in my_db.select('SELECT notify_list FROM tv_shows WHERE show_name = ?', (name,)):
|
||||
if subs['notify_list']:
|
||||
for addr in subs['notify_list'].split(','):
|
||||
if any(addr.strip()):
|
||||
addrs.append(addr)
|
||||
for result in my_db.select('SELECT notify_list FROM tv_shows WHERE show_name = ?', (show_name,)):
|
||||
if result['notify_list']:
|
||||
for email_address in result['notify_list'].split(','):
|
||||
if any(email_address.strip()):
|
||||
email_list.append(email_address)
|
||||
|
||||
addrs = set(addrs)
|
||||
logger.log(u'Email recipients to notify: %s' % addrs, logger.DEBUG)
|
||||
|
||||
return addrs
|
||||
return list(set(email_list))
|
||||
|
||||
def _sendmail(self, host, port, smtp_from, use_tls, user, pwd, to, msg, smtp_debug=False):
|
||||
|
||||
|
@ -190,16 +188,5 @@ class EmailNotifier:
|
|||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _parse_ep(ep_name):
|
||||
|
||||
ep_name = ep_name.encode('utf-8', 'replace')
|
||||
sep = ' - '
|
||||
titles = ep_name.split(sep)
|
||||
titles.sort(key=len, reverse=True)
|
||||
logger.log(u'TITLES: %s' % titles, logger.DEBUG)
|
||||
|
||||
return titles
|
||||
|
||||
|
||||
notifier = EmailNotifier
|
||||
|
|
Loading…
Reference in a new issue