#!/usr/bin/env python
+"""This script is used to send mail due to job's finishing state"""
+
import os
import re
import base64
+import sys
-from common.send_mail import sendmail, makemail
-from common.envparas import export
+from common.send_mail import sendmail
-envparas = ['FROM',
- 'TO',
- 'MESSAGE',
- 'SMTP_SERVER']
-export(envparas, locals())
-
def is_base64str(string):
- ''' return Ture or False '''
+ ''' If a string is base64 coded, return True; otherwise False'''
try:
if (len(string) % 4) == 0:
if re.match("[A-Za-z0-9/+=]*$", string):
return False
return False
-if is_base64str(MESSAGE):
- sendmail(FROM, TO.split(','), base64.b64decode(MESSAGE), SMTP_SERVER)
-else:
- print "Invalid mail message, job abort!"
+def main():
+ """The main body"""
+
+ message = os.getenv('MESSAGE')
+
+ if is_base64str(message):
+ sendmail(os.getenv('FROM'), os.getenv('TO').split(','),
+ base64.b64decode(message), os.getenv('SMTP_SERVER'))
+ else:
+ print "Invalid mail message, job abort!"
+if __name__ == '__main__':
+ sys.exit(main())