1. Home
  2. Computing & Technology
  3. Python

Building a Whitelist for a Spam Filter

From , former About.com Guide

2 of 6

Import First Things First

First things first, we need to import the sys module so we can accept the path of the mailbox as an argument instead of hardwiring it into the program.

import sys
Next, we need to import the mailbox module. The mailbox module enables one to manipulate email messages, representing mailboxes as objects and messages as dictionaries. Unlike poplib and other email-related modules, mailbox is for local use only.
import mailbox
If you want to take a peak at the module documentation that comes with the mailboxmodule, open a Python shell, import the module (as above), and type "help(mailbox)" at the prompt.

Next, we define the main function of our program. Note that, as a matter of good practice, it is worth putting a bang line at the head of the program file, as well as a docstring:

#!/usr/bin/env python
"""Extract and print all email recipients from a user-defined mailbox."""

Explore Python
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python
  4. Python Library
  5. Python Programming - Email Whitelist for Spam Filters - Building an Email Whitelist to Train Your Spam Filter - Import First Things First

©2009 About.com, a part of The New York Times Company.

All rights reserved.