gs.group.list.command API Reference

The API for email-commands is in two parts: processing commands, and the result enumeration.

Processing commands

The gs.group.list.command.process_command() function is used to process the commands in an email message.

gs.group.list.command.process_command(group, email, request)[source]

Process a command in an email message

Parameters:
  • group (obj) – The group that recieved the email message.
  • email (str or email.message.Message) – The email message that was recieved (which may or may not contain a command).
  • request (obj) – The current browser request object.
Returns:

If a command was processed, and if email processing should continue.

Return type:

CommandResult

When an email is recieved it needs to checked to see if its Subject header is command, and the command executed if necessary. The process_command() function performs both of these tasks. The result will be either

  • CommandResut.notACommand if the email is a normal message,
  • CommandResut.commandStop if the email contained a command and processing should stop, or
  • CommandResut.commandContinue if the email contained a command and processing should continue.

Example

r = process_command(self.group, email, request)
if r == gs.group.list.command.CommandResult.commandStop:
  return

Command Abstract Base Class

The CommandABC abstract base-class provides some useful functionality

class gs.group.list.command.CommandABC(group)[source]

Abstract base-class for command-adaptors

Parameters:group (object) – The group that is adapted.
static get_command_components(email)[source]

Get the components of the command in the Subject

Parameters:email (email.message.Message) – The email message that contains the command.
Returns:The Subject of the email, split into components and lower-cased.
Return type:list of strings

The get_command_components() method splits the command in the Subject into parts using the shlex.split() function. The components of the command are in lower-case, with all re: parts discarded.

process(email, request)[source]

Process the command in the email

Parameters:
  • email (email.message.Message) – The email message that contains the command.
  • request – The HTTP request made to process the email.
Returns:

If a command was processed, and if email processing should continue.

Return type:

CommandResult

Concrete classes must implement this method.

Sub-classes of CommandABC will need to provide the process() method. The browser-request is passed in so the command can issue email-notifications.

The Result Enumeration

The result enumeration is returned by the gs.group.list.command.process_command() function, and the command that are registered.

class gs.group.list.command.CommandResult[source]

An enumeration of the different results from processing a command.

commandContinue = <CommandResult.commandContinue: 2>

The command was processed, and processing of this email should continue.

commandStop = <CommandResult.commandStop: 1>

The command was processed, and processing of this email should stop.

notACommand = <CommandResult.notACommand: 0>

The Subject did not contain a command