Permalink
Browse files

added partial support for base64 encoded messages, when the whole bod…

…y is base64 encoded.
  • Loading branch information...
1 parent ae4b39f commit 026f8669617a11e92790b8dc2716dd1a543b859a @avleen committed Feb 26, 2011
Showing with 14 additions and 8 deletions.
  1. +14 −8 nagios_email_handler.py
View
@@ -6,6 +6,7 @@
messages. The messages are then parsed to commands to run against nagios."""
+import base64
import email
import imaplib
import logging
@@ -111,14 +112,19 @@ def get_email_data(msg):
server = server_service
fromaddr = from_p.search(msg['From']).group(1)
- # The command is the first word in the body
- for part in msg.walk():
- if part.get_content_maintype() == 'text' and \
- part.get_content_subtype() == 'plain':
- # Now we have the 'text/plain' part of the message. Find the
- # first word in it, that is our command.
- command = part.get_payload().split()[0].lower()
- break
+ # The command is the first word in the body.
+ # First check if the message is base64 encoded as a whole. If it is,
+ # decode and get the word from there.
+ if msg['Content-Transfer-Encoding'] == 'base64':
+ command = base64.b64decode(msg.get_payload()).split()[0]
+ else:
+ for part in msg.walk():
+ if part.get_content_maintype() == 'text' and \
+ part.get_content_subtype() == 'plain':
+ # Now we have the 'text/plain' part of the message. Find
+ # the first word in it, that is our command.
+ command = part.get_payload().split()[0].lower()
+ break
return alert_class, fromaddr, server, service, command

0 comments on commit 026f866

Please sign in to comment.