#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    146
    Rep Power
    12

    imaplib - retrieving and deleting files


    Hi all,

    I am writing a piece of code that retrieves emails from a server and is processing them accordingly (testing for spam). To add some additional functionality, I wish to delete emails from the server (in my case 'moppsy.comp.glam.ac.uk') once they have been read.

    Does anyone have any knowledge or experince of doing this?

    The function in which I connect to the server and retrieve the emails is below.

    Code:
    def collectEmail():
        m = imaplib.IMAP4('moppsy.comp.glam.ac.uk')
        m.login(getpass.getuser(), getpass.getpass())
        m.select()
        typ, data = m.search(None, 'ALL')
        print data
        for num in string.split(data[0]):
            print "\n"
            print "Email Number:", num
            typ, data = m.fetch(num, '(RFC822)')
            handleEmail(data[0][1])
        m.logout()
    Edit: Added tags.

    Cheers

    Tryst
    Last edited by netytan; February 17th, 2004 at 01:29 PM.
    Tryst
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    Well, I can't seem to find a function to delete a message in imaplib, but I found one to expunge deleted ones ... odd. Other than using the send() method to send a raw command to delete a message, I am not sure how one would accomplish this.
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.

IMN logo majestic logo threadwatch logo seochat tools logo