1. Home
  2. Computing & Technology
  3. Python

Building a Whitelist for a Spam Filter

From , former About.com Guide

3 of 6

Define Main()

As with most languages, the main() function is where all the action happens. In this program, it will be the only function defined. If you would like to see an example of main() as the heart of a program, see "Building an RSS Reader".

For this guide, main() will take as an argument the path to the mailbox. We will then create an empty set for addresses and an object called box to represent the mailbox.

def main(path_to_mailbox):
         addresses = set()
         box = Mailbox.PortableUnixMailbox(file(path_to_mailbox))
Note that the mailbox module provides interfaces for each of Maildir, mbox, MH, Babyl, and MMDF mailbox formats. If you are unsure of what kind of mailbox you are using, try the mbox format. This format is used by many of the most popular email clients, including Mozilla Thunderbird.

Note, however, that Outlook is not here supported. In order to access Outlook email, one must use the win32com module, and use COM calls to call out the data.

Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. 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

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

All rights reserved.