1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- """
- This library implements all of the email parsing features needed for gettor.
- """
- import sys
- import email
- import dkim
- import re
- def getMessage():
- """ Read the message into a buffer and return it """
- rawMessage = sys.stdin.read()
- return rawMessage
- def verifySignature(rawMessage):
- """ Attempt to verify the DKIM signature of a message and return a positive or negative status """
- signature = False
-
-
-
- if dkim.verify(rawMessage):
- signature = True
- return signature
- else:
- return signature
- def parseMessage(message):
- """ parse an email message and return a parsed email object """
- return email.message_from_string(message)
- def parseReply(parsedMessage):
- """ Return an email address that we want to email """
-
-
- address = parsedMessage["from"]
- return address
- def parseRequest(parsedMessage, packages):
- """ This parses the request and returns the first specific package name for
- sending. If we do not understand the request, we return None as the package
- name."""
-
-
-
- for line in email.Iterators.body_line_iterator(parsedMessage):
- for package in packages.keys():
- print "Line is: " + line
- print "Package is " + package
- match = re.match(package, line)
- if match:
- return package
-
- return None
- if __name__ == "__main__" :
- """ Give us an email to understand what we think of it. """
- packageList = {
- "windows-bundle": "/tmp/windows-bundle.z",
- "macosx-bundle": "/tmp/macosx-bundle.z",
- "linux-bundle": "/tmp/linux-bundle.z",
- "source-bundle": "/tmp/source-bundle.z"
- }
- print "Fetching raw message."
- rawMessage = getMessage()
-
- print "Verifying signature of message."
- signature = verifySignature(rawMessage)
- print "Parsing Message."
- parsedMessage = parseMessage(rawMessage)
- print "Parsing reply."
- parsedReply = parseReply(parsedMessage)
- print "Parsing package request."
- package = parseRequest(parsedMessage, packageList)
- if package == None:
- package = "help"
- else:
- package = packageList[package]
- print "The signature status of the email is: " + str(signature)
- print "The email requested the following reply address: " + parsedReply
- print "It looks like the email requested the following package: " + package
- print "We would select the following package file: " + package
|