intelmqmail package

Submodules

intelmqmail.cb module

intelmqmail.db module

intelmqmail.mail module

intelmqmail.notification module

intelmqmail.script module

Load user supplied scripts

class intelmqmail.script.Script(filename, entry_point)

Bases: object

Represents a script or plugin.

The script can be run by simply calling the Script object. All parameters will be forwarded to the actual entry point and its return value will be returned.

The public attribute filename is the name of the python file the script was loaded from.

__init__(filename, entry_point)
intelmqmail.script.load_scripts(script_directory, entry_point, logger=None)

intelmqmail.tableformat module

Basic support for tabular data formats such as CSV

class intelmqmail.tableformat.Column(title)

Bases: object

Specifies a single column for a TableFormat.

This base class only provides a title for the column.

Derived classes should implement the following attributes and methods:

Title:

the column title

Event_table_column:

the column of the event table to retrieve

Column_key:

a key to use for the row dictionary. All columns of a single format must have different column_key values.

Value_from_event(event):

Return the value of the column for the given event. The event parameter is a dictionary that has at least a value for the event_table_column.

__init__(title)
class intelmqmail.tableformat.ExtraColumn(title, extra_key)

Bases: Column

Column filled with a value taken from the IntelMQ extra field.

The extra_key parameter of the constructor gives the name key to look up in the JSON dictionary contained in the extra field.

__init__(title, extra_key)
property column_key
property event_table_column
value_from_event(event)
class intelmqmail.tableformat.IntelMQColumn(title, field_name)

Bases: Column

Column filled directly from an IntelMQ field.

__init__(title, field_name)
property column_key
property event_table_column
value_from_event(event)
class intelmqmail.tableformat.TableFormat(name, columns)

Bases: object

Describe a table format.

__init__(name, columns)

Initialize the format specification. The columns parameter should be a list of Column instances.

column_keys()

Return a list with the keys used for the rows. The list is intended to be used as the field names parameter for e.g. the csv.DictWriter class and matches the dictionaries returned by the row_from_event method.

column_titles()

Return a dictionary with the column titles for use as a header. This could be the header line in a CSV file, for instance. The keys of the dictionary are the same that row_from_event also uses.

event_table_columns()

Return a list with the columns to retrieve from the event table.

row_from_event(event)

Return the row for the given event as a dictionary.

intelmqmail.tableformat.build_table_column(col)

Return a Column instance built from a column specification. A column specification may either be a tuple of strings of the form (intelmq_field, column_title) or an instance of Column.

In the former case, if intelmq_field starts with “extra.”, an ExtraColumn instance is created using the rest of intelmq_field as the extra_key parameter. Otherwise a IntelMQColumn instance is created.

Instances of Column will be used as is.

intelmqmail.tableformat.build_table_format(name, columns)

Build a TableFormat instance for name. The columns parameter should be a list of column specifications which are passed to build_table_column to create the list of columns for the TableFormat instance.

intelmqmail.tableformat.build_table_formats(formats)

Return a dictionary mapping format names to format specifications. The parameter is a list of (formatname, columns) pairs, where formatname is the name of the format as a string and columns is a list of column specifications. The formatname values are used as the keys in the dictionary and both formatname and columns are passed to build_table_format to create the corresponding format specification.

intelmqmail.tableformat.format_as_csv(table_format, events)

Return a list of event dictionaries as a CSV formatted string. :table_format: The table format, assumed to be a TableFormat instance. :events: list of event dictionaries

intelmqmail.templates module

Template handling

class intelmqmail.templates.IntelMQStringTemplate(template)

Bases: Template

Variant of string.Template that allows ‘.’ characters in identifiers.

idpattern = '[_a-z][_a-z0-9.]*'
pattern = re.compile('\n    \\$(?:\n      (?P<escaped>\\$) |   # Escape sequence of two delimiters\n      (?P<named>[_a-z][_a-z0-9.]*)      |   # delimiter and a Python identifier\n      {(?P<braced>[_a-z][_a-z0-9.]*)}  |, re.IGNORECASE|re.VERBOSE)
class intelmqmail.templates.Template(subject, body)

Bases: object

A template for email contents.

The template contains two separate templates, one for the subject and one for the body. To fill in values, use the substitute() method.

__init__(subject, body)

Initialize the template with subject and body. Both parameters should behave like string.Template instances.

classmethod from_strings(subject, body)

Convenience method that creates a template from strings. The strings are converted to templates with IntelMQStringTemplate.

substitute(substitutions)

Fill-in the template with the given substitutions.

The substitutions parameter should be a dictionary mapping the keys that might be in the template to the respective values. This is done by passing the dictionary to the subject/body’s substitute method.

The return value is a pair (subject, body) with the filled in subject and body.

intelmqmail.templates.full_template_filename(template_dir, template_name)

Return the full absolute file name of a template.

The template_name parameter is interpreted relative to template_dir and must refer to a file under that directory. If the resulting file name would name a file outside of template_dir, a ValueError exception is raised. This check is done to guard against malicious template names.

intelmqmail.templates.read_template(template_dir, template_name)

Read the email template indicated by template_dir and template_name.

The name of the template file is determined with full_template_filename.

File Format:

  • The first non-empty line of the file is assumed to be the template string for the subject line of the email.

  • The rest of the lines are the email body. Leading and trailing white space is removed from the body and a newline added at the end. This allows e.g. an empty line in the template between the subject line and the body.

    The resulting string is used as template string in a Python Template object, thus allowing some simple substitutions. See the different formatter implementations for the substitutions they support.

The return value is an instance of the Template class.

Module contents