コード例 #1
0
ファイル: bot.py プロジェクト: 0x829a74bc/cryptobot-email
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)
コード例 #2
0
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)
コード例 #3
0
ファイル: app.py プロジェクト: 0x829a74bc/cryptobot-email
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')
コード例 #4
0
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')
コード例 #5
0
ファイル: app.py プロジェクト: 0x829a74bc/cryptobot-email
#!/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()
コード例 #6
0
 def setUp(self):
     self.db = unsubscribe.getDatabase('sqlite:///test/homedir/test.db',
                                       setup=True)
コード例 #7
0
#!/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()
コード例 #8
0
ファイル: test.py プロジェクト: 0x829a74bc/cryptobot-email
 def setUp(self):
   self.db = unsubscribe.getDatabase('sqlite:///test/homedir/test.db', setup=True)