7.1.1.1.4. isbg.sa_unwrap module

Parse an rfc2822 email message and unwrap it if contains spam attached.

To know it it checks for an x-spam-type=original payload.

Does not perfectly preserve whitespace (esp. rn vs. n and t vs space), but this should not impact spam-learning purposes.

Examples

It will return the original mail into a spamassassin mail:
>>> import isbg.sa_unwrap
>>> f = open('examples/spam.from.spamassassin.eml','rb')
>>> spams = isbg.sa_unwrap.unwrap(f)
>>> f.close()
>>> for spam in spams:
>>>     print(spam)

or:

$ isbg_sa_unwrap.py < examples/spam.from.spamassassin.eml
$ isbg_sa_unwrap.py < examples/spam.eml
isbg.sa_unwrap.sa_unwrap_from_email(msg)

Unwrap a email from the spamassasin email.

Parameters

msg (email.message.Message) – email to unwrap.

Returns

A list with the unwraped mails.

Return type

[email.message.Message]

isbg.sa_unwrap.unwrap(mail)

Unwrap a email from the spamassasin email.

the mail could be a email.message.Email, a file or a string or buffer. It ruturns a list with all the email.message.Email founds.

Parameters

mail (email.message.Message, FILE_TYPES, str) – the mail to unwrap.

Returns

A list with the unwraped mails.

Return type

[email.message.Message]

isbg.sa_unwrap.__isbg_sa_unwrap_opts__()

isbg-sa-unwrap.py unwrap a mail bundled by SpamAssassin.

it parses a rfc2822 email message and unwrap it if contains spam attached.

Command line Options:

Usage:
 isbg_sa_unwrap.py [--from <FROM_FILE>] [--to <TO_FILE>]
 isbg_sa_unwrap.py (-h | --help)
 isbg_sa_unwrap.py --usage
 isbg_sa_unwrap.py --version

Options:
 -h, --help    Show the help screen.
 --usage       Show the usage information.
 --version     Show the version information.

 -f FILE, --from=FILE  Filename of the email to read and unwrap. If not
                       informed, the stdin will be used.
 -t FILE, --to=FILE    Filename to write the unwrapped  email. If not
                       informed, the stdout will be used.
isbg.sa_unwrap.isbg_sa_unwrap()

Run when this module is called from the command line.