Skip to content

Instantly share code, notes, and snippets.

@TauPan
Forked from iMilnb/subspam.py
Created August 18, 2016 07:26
Show Gist options
  • Save TauPan/9eb35eabd609145203741044f2665f14 to your computer and use it in GitHub Desktop.
Save TauPan/9eb35eabd609145203741044f2665f14 to your computer and use it in GitHub Desktop.
Automatic SpamCop report validation with python mechanize
#!/usr/bin/env python2
# adapted from https://gist.github.com/iMilnb/75d65d88ce649b1f191a
import ConfigParser
import mechanize
import os
CONFIG = os.environ.get('SPAMCOP_CONFIG',
os.path.expanduser('~/secret/spamcop-config.ini'))
config = ConfigParser.SafeConfigParser()
config.read(CONFIG)
br = mechanize.Browser()
br.set_handle_robots(False)
br.open("http://www.spamcop.net/")
br.select_form(nr=0)
br.form['username'] = config.get('spamcop', 'username')
br.form['password'] = config.get('spamcop', 'password')
br.submit()
has_report = True
while has_report is True:
try:
l = br.click_link(text='Report Now')
except:
has_report = False
print('No report found.')
break
br.open(l)
try:
br.select_form(name='sendreport')
except:
continue
print('Sending report for {0}'.format(br.form['reports']))
# the following will possibly fill br with a new 'Report Now' link
br.submit(label='Send Spam Report(s) Now')
@TauPan
Copy link
Author

TauPan commented Aug 18, 2016

Update: reads username + password from [spamcop] section of ini file ~/secret/spamcop-config.ini

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment