this is just a suggestion
what i have seen so far is that if u get spams from a particular mail id register it as spam in your database and when any new entry arrives check the header email id with the barred values in the database.for any match delete the mail...i dont know the exact imap syntax to delete but i think u must have got that...
hope this helps 🙂