Merge pull request #632 from JackDandy/feature/ChangeEmailUnicodeAware

Change emails to Unicode aware.
This commit is contained in:
JackDandy 2016-01-24 23:41:37 +00:00
commit c114cb9f36
2 changed files with 20 additions and 32 deletions

View file

@ -20,6 +20,7 @@
* Update SimpleJSON library 3.8.0 (a37a9bd) to 3.8.1 (6022794) * 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) * Update Six compatibility library 1.9.0 (r400) to 1.10.0 (r405)
* Change refactor email notifier * Change refactor email notifier
* Change emails to Unicode aware
### 0.11.3 (2016-01-16 20:00:00 UTC) ### 0.11.3 (2016-01-16 20:00:00 UTC)

View file

@ -54,20 +54,22 @@ class EmailNotifier:
if not sickbeard.USE_EMAIL and not force: if not sickbeard.USE_EMAIL and not force:
return return
ep_name = ep_name.encode('utf-8', 'replace') show = ep_name.split(' - ')[0]
show = self._parse_ep(ep_name) to = self._get_recipients(show)
to = self._generate_recipients(show)
if not any(to): if not any(to):
logger.log(u'No email recipients to notify, skipping', logger.WARNING) logger.log(u'No email recipients to notify, skipping', logger.WARNING)
return return
logger.log(u'Email recipients to notify: %s' % to, logger.DEBUG)
try: try:
msg = MIMEMultipart('alternative') msg = MIMEMultipart('alternative')
msg.attach(MIMEText( msg.attach(MIMEText(
'<body style="font-family:Helvetica, Arial, sans-serif;">' + '<body style="font-family:Helvetica, Arial, sans-serif;">' +
'<h3>SickGear Notification - %s</h3>\n' % title + '<h3>SickGear Notification - %s</h3>\n' % title +
'<p>Show: <b>' + re.search('(.+?) -.+', ep_name).group(1) + '<p>Show: <b>' + show.encode('ascii', 'xmlcharrefreplace') +
'</b></p>\n<p>Episode: <b>' + re.search('.+ - (.+?-.+) -.+', ep_name).group(1) + '</b></p>\n<p>Episode: <b>' +
unicode(re.search('.+ - (.+?-.+) -.+', ep_name).group(1)).encode('ascii', 'xmlcharrefreplace') +
extra + extra +
'</b></p>\n\n' + '</b></p>\n\n' +
'<footer style="margin-top:2.5em;padding:.7em 0;color:#777;border-top:#BBB solid 1px;">' + '<footer style="margin-top:2.5em;padding:.7em 0;color:#777;border-top:#BBB solid 1px;">' +
@ -131,30 +133,26 @@ class EmailNotifier:
pass pass
@staticmethod @staticmethod
def _generate_recipients(show): def _get_recipients(show_name=None):
addrs = [] email_list = []
# Grab the global recipients # Grab the global recipients
if sickbeard.EMAIL_LIST: if sickbeard.EMAIL_LIST:
for addr in sickbeard.EMAIL_LIST.split(','): for email_address in sickbeard.EMAIL_LIST.split(','):
if any(addr.strip()): if any(email_address.strip()):
addrs.append(addr) email_list.append(email_address)
# Grab the recipients for the show # Grab the recipients for the show
if None is not show: if None is not show_name:
my_db = db.DBConnection() my_db = db.DBConnection()
for name in show: for result in my_db.select('SELECT notify_list FROM tv_shows WHERE show_name = ?', (show_name,)):
for subs in my_db.select('SELECT notify_list FROM tv_shows WHERE show_name = ?', (name,)): if result['notify_list']:
if subs['notify_list']: for email_address in result['notify_list'].split(','):
for addr in subs['notify_list'].split(','): if any(email_address.strip()):
if any(addr.strip()): email_list.append(email_address)
addrs.append(addr)
addrs = set(addrs) return list(set(email_list))
logger.log(u'Email recipients to notify: %s' % addrs, logger.DEBUG)
return addrs
def _sendmail(self, host, port, smtp_from, use_tls, user, pwd, to, msg, smtp_debug=False): def _sendmail(self, host, port, smtp_from, use_tls, user, pwd, to, msg, smtp_debug=False):
@ -190,16 +188,5 @@ class EmailNotifier:
return True 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 notifier = EmailNotifier