def main(fingerprint): """main entry point, sorta. Fetches & replies to emails, etc.. :arg str fingerprint: fingerprint of the bot itself """ # XXX rename fingerprint to fingerprint # jinja2 template_loader = jinja2.FileSystemLoader(searchpath="templates") template_env = jinja2.Environment(loader=template_loader, trim_blocks=True) # email fetcher logging.info("Fetching email messages") fetcher = EmailFetcher(use_maildir=config.USE_MAILDIR) messages = fetcher.get_all_mail() logging.info("Found {0} messages".format(len(messages))) db = unsubscribe.getDatabase(config.DATABASE_URL) if db is None: print "Failed to connect to unsubscribe database url '%s'" % config.DATABASE_URL sys.exit(1) for message in messages: if not db.find(message.sender_address): # respond to the email EmailSender(message, template_env, fingerprint) # delete the email # (note: by default Gmail ignores the IMAP standard and archives email instead of deleting it # http://gmailblog.blogspot.com/2008/10/new-in-labs-advanced-imap-controls.html ) fetcher.delete(message.message_id)
def unsubscribe(): if request.method == 'POST': email_address = request.form['email'] db = unsub.getDatabase(config.DATABASE_URL) db.add(email_address) return "%s unsubscribed!" % email_address else: return render_template('unsubscribe.html')
#!/usr/bin/env python import config import unsubscribe as unsub from flask import Flask, render_template, request app = Flask(__name__) db = None @app.route('/unsubscribe', methods=['GET', 'POST']) def unsubscribe(): if request.method == 'POST': email_address = request.form['email'] db = unsub.getDatabase(config.DATABASE_URL) db.add(email_address) return "%s unsubscribed!" % email_address else: return render_template('unsubscribe.html') if __name__ == '__main__': db = unsub.getDatabase(config.DATABASE_URL) if db is None: print "Failed to connect to unsubscribe database url '%s'" % config.DATABASE_URL sys.exit(1) app.run()
def setUp(self): self.db = unsubscribe.getDatabase('sqlite:///test/homedir/test.db', setup=True)