#!/usr/bin/env python

""" moves messages from new to cur, and marks them as seen.
    Quick and dirty hack, which moves every new message in a
    Mailbox!!!
    
    You call it like this in the maildropfilter:
    
    if ((/^X-Spam-Flag:.*YES/))
    {
       cc "./Maildir/.Junk/."
       JUNK=`/usr/local/sbin/markAsSeen.py "./Maildir/.Junk/."`
       exit
    }
    
    More Info:
    
    http://cr.yp.to/proto/maildir.html
    http://www.qmail.org/man/man5/maildir.html
    http://www.courier-mta.org/maildropfilter.html
    
    Written by Robert Penz <robert@penz.name>
"""

import sys
import os

infoField = ":2,S"
    
# Main program: parse command line and start processing
def main():
    if len(sys.argv) != 2:   
        print "Error: Provide Mailbox"
        sys.exit(-1)

    for filename in os.listdir(os.path.join(sys.argv[1], "new")):
        os.rename(os.path.join(sys.argv[1], "new", filename), os.path.join(sys.argv[1], "cur", filename + infoField))

if __name__ == '__main__':
    main()
