def __init__(self, commands): super(BugCommandGroups, self).__init__(command=None) self._groups = [] this_bug = BugCommandGroup() this_bugtask = BugTaskCommandGroup() for command in commands: if IBugEmailCommand.providedBy(command) and command.RANK == 0: # Multiple bugs are being edited. this_bug.add(this_bugtask) self.add(this_bug) this_bug = BugCommandGroup(command) this_bugtask = BugTaskCommandGroup() elif IBugEditEmailCommand.providedBy(command): this_bug.add(command) elif (IBugTaskEmailCommand.providedBy(command) and command.RANK == 0): # Multiple or explicit bugtasks are being edited. this_bug.add(this_bugtask) this_bugtask = BugTaskCommandGroup(command) elif IBugTaskEditEmailCommand.providedBy(command): this_bugtask.add(command) this_bug.add(this_bugtask) self.add(this_bug)
def process(self, signed_msg, to_addr, filealias=None, log=None): """See IMailHandler.""" try: ( final_result, add_comment_to_bug, commands, ) = self.extractAndAuthenticateCommands(signed_msg, to_addr) if final_result is not None: return final_result bug = None bug_event = None bugtask = None bugtask_event = None processing_errors = [] while len(commands) > 0: command = commands.pop(0) try: if IBugEmailCommand.providedBy(command): # Finish outstanding work from the previous bug. self.notify_bug_event(bug_event) self.notify_bugtask_event(bugtask_event, bug_event) bugtask = None bugtask_event = None # Get or start building a new bug. bug, bug_event = command.execute(signed_msg, filealias) if add_comment_to_bug: message = self.appendBugComment( bug, signed_msg, filealias) add_comment_to_bug = False self.processAttachments(bug, message, signed_msg) elif IBugTaskEmailCommand.providedBy(command): self.notify_bugtask_event(bugtask_event, bug_event) bugtask, bugtask_event, bug_event = command.execute( bug, bug_event) if isinstance(bug, CreateBugParams): bug = bugtask.bug message = bug.initial_message self.processAttachments(bug, message, signed_msg) elif IBugEditEmailCommand.providedBy(command): bug, bug_event = command.execute(bug, bug_event) elif IBugTaskEditEmailCommand.providedBy(command): if bugtask is None: if isinstance(bug, CreateBugParams): self.handleNoAffectsTarget() bugtask = guess_bugtask( bug, getUtility(ILaunchBag).user) if bugtask is None: self.handleNoDefaultAffectsTarget(bug) bugtask, bugtask_event = command.execute( bugtask, bugtask_event) except EmailProcessingError as error: processing_errors.append((error, command)) if error.stop_processing: commands = [] transaction.abort() else: continue if len(processing_errors) > 0: raise IncomingEmailError( '\n'.join( str(error) for error, command in processing_errors), [command for error, command in processing_errors]) if isinstance(bug, CreateBugParams): # A new bug without any commands was sent. self.handleNoAffectsTarget() self.notify_bug_event(bug_event) self.notify_bugtask_event(bugtask_event, bug_event) except IncomingEmailError as error: send_process_error_notification( str(getUtility(ILaunchBag).user.preferredemail.email), 'Submit Request Failure', error.message, signed_msg, error.failing_command) return True
def process(self, signed_msg, to_addr, filealias=None, log=None): """See IMailHandler.""" try: (final_result, add_comment_to_bug, commands, ) = self.extractAndAuthenticateCommands( signed_msg, to_addr) if final_result is not None: return final_result bug = None bug_event = None bugtask = None bugtask_event = None processing_errors = [] while len(commands) > 0: command = commands.pop(0) try: if IBugEmailCommand.providedBy(command): # Finish outstanding work from the previous bug. self.notify_bug_event(bug_event) self.notify_bugtask_event(bugtask_event, bug_event) bugtask = None bugtask_event = None # Get or start building a new bug. bug, bug_event = command.execute(signed_msg, filealias) if add_comment_to_bug: message = self.appendBugComment( bug, signed_msg, filealias) add_comment_to_bug = False self.processAttachments(bug, message, signed_msg) elif IBugTaskEmailCommand.providedBy(command): self.notify_bugtask_event(bugtask_event, bug_event) bugtask, bugtask_event, bug_event = command.execute( bug, bug_event) if isinstance(bug, CreateBugParams): bug = bugtask.bug message = bug.initial_message self.processAttachments(bug, message, signed_msg) elif IBugEditEmailCommand.providedBy(command): bug, bug_event = command.execute(bug, bug_event) elif IBugTaskEditEmailCommand.providedBy(command): if bugtask is None: if isinstance(bug, CreateBugParams): self.handleNoAffectsTarget() bugtask = guess_bugtask( bug, getUtility(ILaunchBag).user) if bugtask is None: self.handleNoDefaultAffectsTarget(bug) bugtask, bugtask_event = command.execute( bugtask, bugtask_event) except EmailProcessingError as error: processing_errors.append((error, command)) if error.stop_processing: commands = [] transaction.abort() else: continue if len(processing_errors) > 0: raise IncomingEmailError( '\n'.join(str(error) for error, command in processing_errors), [command for error, command in processing_errors]) if isinstance(bug, CreateBugParams): # A new bug without any commands was sent. self.handleNoAffectsTarget() self.notify_bug_event(bug_event) self.notify_bugtask_event(bugtask_event, bug_event) except IncomingEmailError as error: send_process_error_notification( str(getUtility(ILaunchBag).user.preferredemail.email), 'Submit Request Failure', error.message, signed_msg, error.failing_command) return True