def process_mailbox (mailboxname_in, mailboxname_out, filter_function):
    """This processes a each message in the 'in' mailbox and optionally
    writes the message to the 'out' mailbox. Each message is passed to
    the  filter_function. The filter function may return None to ignore
    the message or may return the document to be saved in the 'out' mailbox.
    See passthrough_filter().
    """

    # Open the mailbox.
    mb = mailbox.UnixMailbox (file(mailboxname_in,'r'))
    fout = file(mailboxname_out, 'w')

    msg = mb.next()
    while msg is not None:
        # Properties of msg cannot be modified, so we pull out the
        # document to handle is separately. We keep msg around to
        # keep track of headers and stuff.
        document = msg.fp.read()

        document = filter_function (msg, document)
        
        if document is not None:
            write_message (fout, msg, document)

        msg = mb.next()

    fout.close()
This processes a each message in the 'in' mailbox and optionally
    writes the message to the 'out' mailbox. Each message is passed to
    the  filter_function. The filter function may return None to ignore
    the message or may return the document to be saved in the 'out' mailbox.
    See passthrough_filter().
    
recipes/Python/157437_Reading_writing_mbox_style_mailbox/recipe-157437.py