Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…y is base64 encoded.
  • Loading branch information...
commit 026f8669617a11e92790b8dc2716dd1a543b859a 1 parent ae4b39f
@avleen authored
Showing with 14 additions and 8 deletions.
  1. +14 −8 nagios_email_handler.py
View
22 nagios_email_handler.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.