Last active
August 29, 2015 14:10
-
-
Save exit99/60644089facbd82e2fd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
support: "|/var/scripts/my_script.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import email | |
import sys | |
def walk(stdin_data): | |
"""Prepend alert to all parts of the message.""" | |
root_message = email.message_from_string(stdin_data) | |
f = open('/tmp/ids_logs.txt', 'a') | |
if root_message.is_multipart(): | |
for payload in root_message.get_payload(): | |
# if payload.is_multipart(): ... | |
f.write(str(payload.get_payload())) | |
f.write('\nif\n') | |
else: | |
f.write(str(root_message.get_payload())) | |
f.write('\nelse\n') | |
email_header = root_message.walk().next() | |
f.write(str(email_header['Subject'])) | |
f.write(str(email_header['From'])) | |
f.close() | |
def main(): | |
stdin_data = sys.stdin.read() | |
walk(stdin_data) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment