#NEWLINE# @ staticmethod #NEWLINE# def parse_email( message ) : #NEWLINE# #INDENT# '\n            Parse Responses\n                - reply to mails from the Monitor service\n                - parse mails directed to the Deploy Module\n\n            @ToDo: Use template for format of field/value encoding\n        ' #NEWLINE# db = current . db #NEWLINE# s3db = current . s3db #NEWLINE# reply = None #NEWLINE# message_id = message . message_id #NEWLINE# table = s3db . msg_email #NEWLINE# record = db ( ( table . message_id == message_id ) ) . select ( table . raw , limitby = ( 0 , 1 ) ) . first ( ) #NEWLINE# if ( not record ) : #NEWLINE# #INDENT# return reply #NEWLINE# #UNINDENT# message_body = record . raw #NEWLINE# if ( not message_body ) : #NEWLINE# #INDENT# return reply #NEWLINE# #UNINDENT# if ( ':run_id:' in message_body ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# run_id = S3Parser . _parse_value ( message_body , 'run_id' ) #NEWLINE# run_id = int ( run_id ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return reply #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# to = S3Parser . _parse_value ( message_body , 'reply_to' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return reply #NEWLINE# #UNINDENT# now = datetime . datetime . utcnow ( ) . isoformat ( ) #NEWLINE# subject = 'MONITOR REPLY: Mail Received and Parsed OK' #NEWLINE# message = ( 'Test message sent to %s from :run_id:%s: arrived fine & was parsed at %s.' % ( current . deployment_settings . get_base_public_url ( ) , run_id , now ) ) #NEWLINE# result = current . msg . send_email ( to , subject , message ) #NEWLINE# return reply #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ':mission_id:' in message_body ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return reply #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# mission_id = S3Parser . _parse_value ( message_body , 'mission_id' ) #NEWLINE# mission_id = int ( mission_id ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return reply #NEWLINE# #UNINDENT# data = dict ( message_id = message_id , mission_id = mission_id ) #NEWLINE# person_id = S3Parsing ( ) . lookup_person ( message . from_address ) #NEWLINE# if person_id : #NEWLINE# #INDENT# atable = s3db . deploy_application #NEWLINE# htable = s3db . hrm_human_resource #NEWLINE# left = atable . on ( ( htable . id == atable . human_resource_id ) ) #NEWLINE# rows = db ( ( ( htable . person_id == person_id ) & ( htable . deleted != True ) ) ) . select ( htable . id , atable . id , atable . active , orderby = ( ~ htable . modified_on ) , left = left ) #NEWLINE# hr_id = None #NEWLINE# if ( len ( rows ) == 1 ) : #NEWLINE# #INDENT# hr_id = rows [ 0 ] [ htable . id ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rows = [ row for row in rows if ( row [ atable . id ] and row [ atable . active ] ) ] #NEWLINE# if ( len ( rows ) == 1 ) : #NEWLINE# #INDENT# hr_id = rows [ 0 ] [ htable . id ] #NEWLINE# #UNINDENT# #UNINDENT# if hr_id : #NEWLINE# #INDENT# data [ 'human_resource_id' ] = hr_id #NEWLINE# #UNINDENT# #UNINDENT# table = s3db . deploy_response #NEWLINE# table . insert ( ** data ) #NEWLINE# atable = s3db . msg_attachment #NEWLINE# atts = db ( ( atable . message_id == message_id ) ) . select ( atable . document_id ) #NEWLINE# if atts : #NEWLINE# #INDENT# dtable = db . doc_document #NEWLINE# ltable = s3db . deploy_mission_document #NEWLINE# if hr_id : #NEWLINE# #INDENT# hrtable = db . hrm_human_resource #NEWLINE# doc_id = db ( ( hrtable . id == hr_id ) ) . select ( hrtable . doc_id , limitby = ( 0 , 1 ) ) . first ( ) . doc_id #NEWLINE# #UNINDENT# for row in atts : #NEWLINE# #INDENT# document_id = row . document_id #NEWLINE# ltable . insert ( mission_id = mission_id , message_id = message_id , document_id = document_id ) #NEWLINE# if hr_id : #NEWLINE# #INDENT# db ( ( dtable . id == document_id ) ) . update ( doc_id = doc_id ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return reply