Created
May 3, 2012 19:51
-
-
Save melpomene/2588790 to your computer and use it in GitHub Desktop.
Uploads emails ending with "if republished"-threats to Pastebin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExampleFilter: | |
def run(self, email): | |
# searching for threatening language | |
return False | |
def __str__(self): | |
return "Example Filter" | |
class SwedishKeywordFilter: | |
""" Filter used for searching through emails """ | |
def run(self, email): | |
""" Returns true if email is suspected of containing threat""" | |
#search email after swedish threats. | |
return False | |
def __str__(self): | |
return "Swedish Keyword Filter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getpass | |
import imaplib | |
import ConfigParser | |
import httplib | |
import urllib | |
import pastebin | |
import emailfilter | |
#Add filters here | |
email_filters = [emailfilter.ExampleFilter(), emailfilter.SwedishKeywordFilter()] | |
"""Script that searches the specified mail and filters out emails that seem to contain legal threats and publish them on pastebin.com """ | |
print "WARNING! THIS SOFTWARE WILL PUBLISH YOUR EMAIL ON A PUBLIC FORUM!" | |
print "Tired of all the empty threats from coorperations emailing you?\nThen show them that you are tired of their threats by running this script on your email inbox" | |
print "First we need your IMAP login credidentials" | |
def get_emails(): | |
""" Connects to the IMAP server specified in the input and returns all the emails ( | |
currently it searches for spefified input. ) | |
""" | |
server = raw_input("Server adress: ") | |
username = raw_input("Username: ") | |
server = "mail.kejsarmakten.se" | |
username = "[email protected]" | |
passwd = getpass.getpass() | |
searchfor = raw_input("Search for: ") | |
mail = imaplib.IMAP4_SSL(server) | |
mail.login(username, passwd) | |
mail.select() | |
typ, data = mail.search(None, '(SUBJECT "' + searchfor +'")') | |
#typ, data = mail.search(None, 'ALL') | |
email_list = [] | |
for num in data[0].split(): | |
typ, data = mail.fetch(num, '(RFC822)') | |
email_list.append('Message %s\n%s\n' % (num, data[0][1])) | |
mail.close() | |
mail.logout() | |
return email_list | |
def print_emails(emails): | |
"""Prints a readable version of all emails in emails""" | |
for m in emails: | |
print m | |
def send_to_pastebin(dev_key, email): | |
""" Uses pastebin.py to send the input email to pastebin and returns the url""" | |
url = pastebin.Pastebin.submit(paste_code = email, paste_format = "email") | |
print "Sent to " + url | |
return url | |
emails = get_emails() | |
suspected = [] | |
# Run all filters on all emails | |
for email in emails: | |
for filter_ in email_filters: | |
print "tried filter " + filter_.__str__() | |
if filter_.run(email): | |
suspected.append(email) | |
break | |
#Post all suspected TODO: promt user first | |
i = 0 | |
for suspect in suspected: | |
i+=1 | |
print "Sending... " | |
# send_to_pastebin(dev_key, suspect) #uncomment on live version | |
print str(i) + " has been sent \n" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Copyright (c) 2009-2011, Mario Vilas | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions are met: | |
# | |
# * Redistributions of source code must retain the above copyright notice, | |
# this list of conditions and the following disclaimer. | |
# * Redistributions in binary form must reproduce the above copyright | |
# notice,this list of conditions and the following disclaimer in the | |
# documentation and/or other materials provided with the distribution. | |
# * Neither the name of the copyright holder nor the names of its | |
# contributors may be used to endorse or promote products derived from | |
# this software without specific prior written permission. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
# POSSIBILITY OF SUCH DAMAGE. | |
import urllib | |
# Python interface to the Pastebin API | |
# More information here: http://pastebin.com/api.php | |
# Blog post: http://http://breakingcode.wordpress.com/2010/03/06/using-the-pastebin-api-with-python/ | |
class Pastebin(object): | |
# Base domain name | |
base_domain = 'pastebin.com' | |
# Valid Pastebin URLs begin with this string | |
prefix_url = 'http://%s/' % base_domain | |
# Valid Pastebin URLs with a custom subdomain begin with this string | |
subdomain_url = 'http://%%s.%s/' % base_domain | |
# URL to the POST API | |
api_url = 'http://%s/api_public.php' % base_domain | |
# Valid paste_expire_date values | |
paste_expire_date = ('N', '10M', '1H', '1D', '1M') | |
# Valid parse_format values | |
paste_format = ( | |
'abap', 'actionscript', 'actionscript3', 'ada', 'apache', | |
'applescript', 'apt_sources', 'asm', 'asp', 'autoit', 'avisynth', | |
'bash', 'basic4gl', 'bibtex', 'blitzbasic', 'bnf', 'boo', 'bf', 'c', | |
'c_mac', 'cill', 'csharp', 'cpp', 'caddcl', 'cadlisp', 'cfdg', | |
'klonec', 'klonecpp', 'cmake', 'cobol', 'cfm', 'css', 'd', 'dcs', | |
'delphi', 'dff', 'div', 'dos', 'dot', 'eiffel', 'email', 'erlang', | |
'fo', 'fortran', 'freebasic', 'gml', 'genero', 'gettext', 'groovy', | |
'haskell', 'hq9plus', 'html4strict', 'idl', 'ini', 'inno', 'intercal', | |
'io', 'java', 'java5', 'javascript', 'kixtart', 'latex', 'lsl2', | |
'lisp', 'locobasic', 'lolcode', 'lotusformulas', 'lotusscript', | |
'lscript', 'lua', 'm68k', 'make', 'matlab', 'matlab', 'mirc', | |
'modula3', 'mpasm', 'mxml', 'mysql', 'text', 'nsis', 'oberon2', 'objc', | |
'ocaml-brief', 'ocaml', 'glsl', 'oobas', 'oracle11', 'oracle8', | |
'pascal', 'pawn', 'per', 'perl', 'php', 'php-brief', 'pic16', | |
'pixelbender', 'plsql', 'povray', 'powershell', 'progress', 'prolog', | |
'properties', 'providex', 'python', 'qbasic', 'rails', 'rebol', 'reg', | |
'robots', 'ruby', 'gnuplot', 'sas', 'scala', 'scheme', 'scilab', | |
'sdlbasic', 'smalltalk', 'smarty', 'sql', 'tsql', 'tcl', 'tcl', | |
'teraterm', 'thinbasic', 'typoscript', 'unreal', 'vbnet', 'verilog', | |
'vhdl', 'vim', 'visualprolog', 'vb', 'visualfoxpro', 'whitespace', | |
'whois', 'winbatch', 'xml', 'xorg_conf', 'xpp', 'z80' | |
) | |
# Submit a code snippet to Pastebin | |
@classmethod | |
def submit(cls, paste_code, | |
paste_name = None, paste_subdomain = None, | |
paste_private = None, paste_expire_date = None, | |
paste_format = None): | |
# Code snippet to submit | |
argv = { 'paste_code' : str(paste_code) } | |
# Name of the poster | |
if paste_name is not None: | |
argv['paste_name'] = str(paste_name) | |
# Custom subdomain | |
if paste_subdomain is not None: | |
paste_subdomain = str(paste_subdomain).strip().lower() | |
argv['paste_subdomain'] = paste_subdomain | |
# Is the snippet private? | |
if paste_private is not None: | |
argv['paste_private'] = int(bool(int(paste_private))) | |
# Expiration for the snippet | |
if paste_expire_date is not None: | |
paste_expire_date = str(paste_expire_date).strip().upper() | |
if not paste_expire_date in cls.paste_expire_date: | |
raise ValueError, "Bad expire date: %s" % paste_expire_date | |
# Syntax highlighting | |
if paste_format is not None: | |
paste_format = str(paste_format).strip().lower() | |
if not paste_format in cls.paste_format: | |
raise ValueError, "Bad format: %s" % paste_format | |
argv['paste_format'] = paste_format | |
# Make the request to the Pastebin API | |
fd = urllib.urlopen(cls.api_url, urllib.urlencode(argv)) | |
try: | |
response = fd.read() | |
finally: | |
fd.close() | |
del fd | |
# Return the new snippet URL on success, raise exception on error | |
if argv.has_key('paste_subdomain'): | |
prefix = cls.subdomain_url % paste_subdomain | |
else: | |
prefix = cls.prefix_url | |
if not response.startswith(prefix): | |
raise RuntimeError, response | |
return response | |
if __name__ == "__main__": | |
import sys | |
import optparse | |
# Build the command line parser | |
parser = optparse.OptionParser(usage = '%prog <file> [options]') | |
parser.add_option("-n", "--name", | |
action="store", type="string", metavar="NAME", | |
help="Name of poster") | |
parser.add_option("-s", "--subdomain", | |
action="store", type="string", metavar="SUBDOMAIN", | |
help="Custom subdomain") | |
parser.add_option("--private", | |
action="store_true", | |
help="The snippet is private") | |
parser.add_option("--public", | |
action="store_false", dest="private", | |
help="The snippet is public") | |
parser.add_option("-e", "--expire", | |
action="store", type="string", metavar="TIME", | |
help="Expiration time: N (never), 10M (10 minutes), 1H (1 hour), 1D (1 day), 1M (1 month)") | |
parser.add_option("-f", "--format", "--syntax", "--highlight", | |
action="store", type="string", metavar="FORMAT", dest="format", | |
help="Syntax highlighting, see source for full list") | |
# Parse the command line and submit each snippet | |
options, args = parser.parse_args(sys.argv) | |
args = args[1:] | |
if not args: | |
parser.print_help() | |
for filename in args: | |
data = open(filename, 'rb').read() | |
url = Pastebin.submit(paste_code = data, | |
paste_name = options.name, paste_subdomain = options.subdomain, | |
paste_private = options.private, paste_expire_date = options.expire, | |
paste_format = options.format) | |
print "%s --> %s" % (filename, url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment