Turning off GMails draconian spam filter

Okay, so there is no way to turn off GMails spam filter (or even turn it down to the point where it stops putting more legitimate emails than spam into the “Spam” folder).

To fix this behavior I have thrown together this short python script that simply moves any email found in the Spam folder into the Inbox. I used to achieve the same thing by creating a filter which told GMail not to spam any email that has an ‘@’ in the ‘From’ address but GMail has suddenly decided to start ignoring that filter so a more permanent solution is required.

#!/usr/bin/env python

import imaplib

IMAP_USER='<your_user_name>@gmail.com'
IMAP_PASSWORD='<your_password>'


if __name__ == '__main__':
  imap4 = imaplib.IMAP4_SSL('imap.gmail.com')
  imap4.login(IMAP_USER, IMAP_PASSWORD)
  imap4.select('[Gmail]/Spam')
  typ, data = imap4.search(None, 'ALL')
  for num in data[0].split():
    message_subj = imap4.fetch(num, '(BODY.PEEK[HEADER.FIELDS (SUBJECT FROM TO DATE)])')[1]
    print "Moving message '%s' from Spam to INBOX" % (', '.join(message_subj[0][1].rstrip().split("\r\n")))
    imap4.copy(num, 'INBOX')
    imap4.store(num, '+FLAGS', '\\Deleted')
  imap4.expunge()
  imap4.close()
  imap4.logout()

2 thoughts on “Turning off GMails draconian spam filter”

  1. When you select your spam folder, click on any message and at the top of the message you’ll see an explanation for why the message was marked with spam. These range from the boring old, “It’s similar to messages that were detected by our spam filters,” to the more exciting, “It might contain a virus or malicious link.” Next to each message is a Learn More link that will lead you to Gmail’s series on spam that will tell you if you need to take action to stop the spam or if you can let it be. It can be helpful if your spam folder is filled with phishing scams, but it’s also handy for those one or two messages from friends that seem to end up in your spam folder for no reason. The feature should be live in your Gmail account right now.

  2. Bryce: The problem is that it’s not just one or two messages. Almost all of the messages that get put into my spam folder are legitimate emails I want to receive, only the odd one or two are genuinely spam.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>