def report(self, path_to_spam_mail_file): """ Report a spam, and hopefully press the confirm button as well :param path_to_spam_mail_file: :return: """ reporting_session = requests.Session() reporting_session.cookies = self.cookie_jar payload = self._build_submit_payload(path_to_spam_mail_file) logging.debug("the reporting payload spam is: %s" % payload['spam']) report_response = reporting_session.post(self.reporting_url, data=payload, allow_redirects=False) logging.debug("report response code/text is: %s/%s" % (report_response.status_code, report_response.text)) report_redirect_response = reporting_session.get( report_response.headers["location"]) logging.debug("redirect request to %s resulted in %s/%s" % (report_response.headers["location"], report_redirect_response.status_code, report_redirect_response.text)) # now detect if a meta refresh tag is present, and if so, the time refresh = SpamCopFinder.meta_refresh_seconds( report_redirect_response.text) if refresh: time.sleep(refresh) # now GET the ... same URL? logging.debug("getting the same (?) url again: %s" % report_response.headers["location"]) after_interstitial_response = reporting_session.get( report_response.headers["location"]) logging.debug("post-interstitial status code/response: %s/%s" % (after_interstitial_response.status_code, after_interstitial_response.text)) else: logging.debug("you are paid and/or on the confirm page already?") after_interstitial_response = report_redirect_response # now get the confirm for from whichever page it was confirmation_payload = SpamCopFinder.confirm_form( after_interstitial_response.text) if confirmation_payload: logging.debug( json.dumps(confirmation_payload, indent=4, sort_keys=True)) # now submit the confirmation form. confirm_response = reporting_session.post( self.reporting_url, data=confirmation_payload, allow_redirects=False) logging.info("confirmation url responded with %s/%s" % (confirm_response.text, confirm_response.status_code))
def report(self, path_to_spam_mail_file): """ Report a spam, and hopefully press the confirm button as well :param path_to_spam_mail_file: :return: """ reporting_session = requests.Session() reporting_session.cookies = self.cookie_jar payload = self._build_submit_payload(path_to_spam_mail_file) logging.debug("the reporting payload spam is: %s" % payload["spam"]) report_response = reporting_session.post(self.reporting_url, data=payload, allow_redirects=False) logging.debug("report response code/text is: %s/%s" % (report_response.status_code, report_response.text)) report_redirect_response = reporting_session.get(report_response.headers["location"]) logging.debug( "redirect request to %s resulted in %s/%s" % (report_response.headers["location"], report_redirect_response.status_code, report_redirect_response.text) ) # now detect if a meta refresh tag is present, and if so, the time refresh = SpamCopFinder.meta_refresh_seconds(report_redirect_response.text) if refresh: time.sleep(refresh) # now GET the ... same URL? logging.debug("getting the same (?) url again: %s" % report_response.headers["location"]) after_interstitial_response = reporting_session.get(report_response.headers["location"]) logging.debug( "post-interstitial status code/response: %s/%s" % (after_interstitial_response.status_code, after_interstitial_response.text) ) else: logging.debug("you are paid and/or on the confirm page already?") after_interstitial_response = report_redirect_response # now get the confirm for from whichever page it was confirmation_payload = SpamCopFinder.confirm_form(after_interstitial_response.text) if confirmation_payload: logging.debug(json.dumps(confirmation_payload, indent=4, sort_keys=True)) # now submit the confirmation form. confirm_response = reporting_session.post( self.reporting_url, data=confirmation_payload, allow_redirects=False ) logging.info( "confirmation url responded with %s/%s" % (confirm_response.text, confirm_response.status_code) )
#!/usr/bin/env python3 import sys import json from spamcop.response import SpamCopFinder finder = SpamCopFinder() payload = finder.confirm_form(open(sys.argv[1]).read()) print(json.dumps(payload, indent=4, sort_keys=True))
#!/usr/bin/env python3 import sys from spamcop.response import SpamCopFinder finder = SpamCopFinder() refresh = finder.meta_refresh_seconds(open(sys.argv[1]).read()) print("the refresh is: %s" % refresh)