aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpush.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/push.py b/push.py
index 27e44a6..4b92aa0 100755
--- a/push.py
+++ b/push.py
@@ -42,10 +42,11 @@ for s in sender_map:
if re.match(s['re'], sender):
try:
api_token = s['key']
- break
except KeyError:
print >>sys.stderr, "Found no key for sender."
sys.exit(1)
+ else:
+ break
except KeyError:
next
else:
@@ -58,10 +59,11 @@ for r in recipient_map:
if re.match(r['re'], recipient):
try:
user_tokens = r['keys']
- break
except KeyError:
print >>sys.stderr, "Found no key(s) for recipient."
sys.exit(1)
+ else:
+ break
except KeyError:
next
else:
@@ -74,8 +76,10 @@ mail = parser.parse(sys.stdin)
# Try to get the subject from the email and recode to utf-8 if possible
title, encoding = email.header.decode_header(mail.get('subject'))[0]
-if title is not None and encoding is not None:
+try:
title = title.decode(encoding).encode('utf-8')
+except NameError:
+ pass
# Lets at least try to handle mime multipart
if mail.is_multipart():
@@ -94,8 +98,10 @@ else:
# Recode payload to utf-8 if possible
encoding = payload.get_charsets()[0]
-if payload is not None and encoding is not None:
+try:
payload = payload.decode(encoding).encode('utf-8')
+except NameError:
+ pass
msg = payload.strip()