@@ -862,7 +862,7 @@ def get_author_id(self):
862862 'You are not permitted to access this tracker.' )
863863 self .author = author
864864
865- def check_node_permissions (self ):
865+ def check_permissions (self ):
866866 ''' Check if the author has permission to edit or create this
867867 class of node
868868 '''
@@ -1155,6 +1155,71 @@ def create_node(self):
11551155
11561156 return self .nodeid
11571157
1158+ # XXX Don't enable. This doesn't work yet.
1159+ # "[^A-z.]tracker\+(?P<classname>[^\d\s]+)(?P<nodeid>\d+)\@some.dom.ain[^A-z.]"
1160+ # handle delivery to addresses like:[email protected] 1161+ # use the embedded issue number as our issue
1162+ # issue_re = config['MAILGW_ISSUE_ADDRESS_RE']
1163+ # if issue_re:
1164+ # for header in ['to', 'cc', 'bcc']:
1165+ # addresses = message.getheader(header, '')
1166+ # if addresses:
1167+ # # FIXME, this only finds the first match in the addresses.
1168+ # issue = re.search(issue_re, addresses, 'i')
1169+ # if issue:
1170+ # classname = issue.group('classname')
1171+ # nodeid = issue.group('nodeid')
1172+ # break
1173+
1174+ # Default sequence of methods to be called on message. Use this for
1175+ # easier override of the default message processing
1176+ # list consists of tuples (method, return_if_true), the parsing
1177+ # returns if the return_if_true flag is set for a method *and* the
1178+ # method returns something that evaluates to True.
1179+ method_list = [
1180+ # Filter out messages to ignore
1181+ (handle_ignore , False ),
1182+ # Check for usage/help requests
1183+ (handle_help , False ),
1184+ # Check if the subject line is valid
1185+ (check_subject , False ),
1186+ # get importants parts from subject
1187+ (parse_subject , False ),
1188+ # check for registration OTK
1189+ (rego_confirm , True ),
1190+ # get the classname
1191+ (get_classname , False ),
1192+ # get the optional nodeid:
1193+ (get_nodeid , False ),
1194+ # Determine who the author is:
1195+ (get_author_id , False ),
1196+ # allowed to edit or create this class?
1197+ (check_permissions , False ),
1198+ # author may have been created:
1199+ # commit author to database and re-open as author
1200+ (commit_and_reopen_as_author , False ),
1201+ # Get the recipients list
1202+ (get_recipients , False ),
1203+ # get the new/updated node props
1204+ (get_props , False ),
1205+ # Handle PGP signed or encrypted messages
1206+ (get_pgp_message , False ),
1207+ # extract content and attachments from message body:
1208+ (get_content_and_attachments , False ),
1209+ # put attachments into files linked to the issue:
1210+ (create_files , False ),
1211+ # create the message if there's a message body (content):
1212+ (create_msg , False ),
1213+ ]
1214+
1215+
1216+ def parse (self ):
1217+ for method , flag in self .method_list :
1218+ ret = method (self )
1219+ if flag and ret :
1220+ return
1221+ # perform the node change / create:
1222+ return self .create_node ()
11581223
11591224
11601225class MailGW :
@@ -1370,6 +1435,7 @@ def handle_Message(self, message):
13701435 # in some rare cases, a particularly stuffed-up e-mail will make
13711436 # its way into here... try to handle it gracefully
13721437
1438+ self .parsed_message = None
13731439 sendto = message .getaddrlist ('resent-from' )
13741440 if not sendto :
13751441 sendto = message .getaddrlist ('from' )
@@ -1459,77 +1525,8 @@ def _handle_message(self, message):
14591525 The following code expects an opened database and a try/finally
14601526 that closes the database.
14611527 '''
1462- parsed_message = self .parsed_message_class (self , message )
1463-
1464- # Filter out messages to ignore
1465- parsed_message .handle_ignore ()
1466-
1467- # Check for usage/help requests
1468- parsed_message .handle_help ()
1469-
1470- # Check if the subject line is valid
1471- parsed_message .check_subject ()
1472-
1473- # XXX Don't enable. This doesn't work yet.
1474- # XXX once this works it should be moved to parsedMessage class
1475- # "[^A-z.]tracker\+(?P<classname>[^\d\s]+)(?P<nodeid>\d+)\@some.dom.ain[^A-z.]"
1476- # handle delivery to addresses like:[email protected] 1477- # use the embedded issue number as our issue
1478- # issue_re = config['MAILGW_ISSUE_ADDRESS_RE']
1479- # if issue_re:
1480- # for header in ['to', 'cc', 'bcc']:
1481- # addresses = message.getheader(header, '')
1482- # if addresses:
1483- # # FIXME, this only finds the first match in the addresses.
1484- # issue = re.search(issue_re, addresses, 'i')
1485- # if issue:
1486- # classname = issue.group('classname')
1487- # nodeid = issue.group('nodeid')
1488- # break
1489-
1490- # Parse the subject line to get the importants parts
1491- parsed_message .parse_subject ()
1492-
1493- # check for registration OTK
1494- if parsed_message .rego_confirm ():
1495- return
1496-
1497- # get the classname
1498- parsed_message .get_classname ()
1499-
1500- # get the optional nodeid
1501- parsed_message .get_nodeid ()
1502-
1503- # Determine who the author is
1504- parsed_message .get_author_id ()
1505-
1506- # make sure they're allowed to edit or create this class
1507- parsed_message .check_node_permissions ()
1508-
1509- # author may have been created:
1510- # commit author to database and re-open as author
1511- parsed_message .commit_and_reopen_as_author ()
1512-
1513- # Get the recipients list
1514- parsed_message .get_recipients ()
1515-
1516- # get the new/updated node props
1517- parsed_message .get_props ()
1518-
1519- # Handle PGP signed or encrypted messages
1520- parsed_message .get_pgp_message ()
1521-
1522- # extract content and attachments from message body
1523- parsed_message .get_content_and_attachments ()
1524-
1525- # put attachments into files linked to the issue
1526- parsed_message .create_files ()
1527-
1528- # create the message if there's a message body (content)
1529- parsed_message .create_msg ()
1530-
1531- # perform the node change / create
1532- nodeid = parsed_message .create_node ()
1528+ self .parsed_message = self .parsed_message_class (self , message )
1529+ nodeid = self .parsed_message .parse ()
15331530
15341531 # commit the changes to the DB
15351532 self .db .commit ()
0 commit comments