示例#1
0
def get_messages(filt="NEW"):
    cf = basicconfig.get_config(CONFIGFILE)
    if not cf.user:
        user = termtools.getuser()
    else:
        user = cf.user

    if not cf.password:
        password = termtools.getpass()
    else:
        password = cf.password

    M = imaplib.IMAP4(cf.server)
    resp, data = M.login(user, password)
    if resp != "OK":
        print "Unable to log in."
        return

    M.select(cf.folder)
    resp, data = M.search(None, filt)
    if resp == "OK":
        for num in data[0].split():
            resp, data = M.fetch(num, "(RFC822)")
            handle_message(data[0][1])
    M.close()
    M.logout()