Ejemplo n.º 1
0
def context_getsource(request):
    message_id =  request.POST['message_id']
    ctxIO = ContextIO(consumer_key=api_key, consumer_secret=api_secret)
    accntList = ctxIO.get_accounts(email=mailbox_to_query)
    logging.info('ctxIO Account: %r' % accntList)
    message = Account(ctxIO, {'id':accntList[0].id}).get_message_source(message_id=message_id)
    _process_incoming_mail(message, '*****@*****.**', 'e/e/e/isworld@e')
    return True
Ejemplo n.º 2
0
def context_getsource(request):
    message_id = request.POST['message_id']
    ctxIO = ContextIO(consumer_key=api_key, consumer_secret=api_secret)
    accntList = ctxIO.get_accounts(email=mailbox_to_query)
    logging.info('ctxIO Account: %r' % accntList)
    message = Account(ctxIO, {
        'id': accntList[0].id
    }).get_message_source(message_id=message_id)
    _process_incoming_mail(message, '*****@*****.**',
                           'e/e/e/isworld@e')
    return True
Ejemplo n.º 3
0
def context_buildindex(request,iolimit,iooffset):
    ctxIO = ContextIO(consumer_key=api_key, consumer_secret=api_secret)
    accntList = ctxIO.get_accounts(email=mailbox_to_query)
    logging.info('ctxIO Account: %r' % accntList)
    messages = Account(ctxIO, {'id':accntList[0].id}).get_messages(limit=iolimit,offset=iooffset)
    txt = 'All done!'
    for message in messages:
        ctxmsg = models.Contextio(key_name=message.message_id)
        ctxmsg.message_date = message.date
        ctxmsg.put()
    # get messages with limit and offset
    return HttpResponse(txt, content_type='text/plain')
Ejemplo n.º 4
0
    def get(self):
        if users.get_current_user():

            # Get the email address of the user and see if that mailbox is available
            # in our Context.IO account by using the /imap/accountinfo.json API call
            current_user = users.get_current_user()
            current_email = current_user.email()

            # Figure out if there's an account corresponding to the current users's email address.
            # Normally, your app would maintain the Context.IO account id corresponding to each user
            # account but for the sake of keeping this example simple, we're checking every time and
            # setting a cookie with the account id every time an authentified user logs in this demo.

            ctxIO = ContextIO(consumer_key=settings.CONTEXTIO_OAUTH_KEY,
                              consumer_secret=settings.CONTEXTIO_OAUTH_SECRET)
            accntList = ctxIO.get_accounts(email=current_email)
            if len(accntList) >= 1:
                # The mailbox is available under our Context.IO account

                # The following is to avoid implementing a user property storage for this app
                # (see comment above)
                self.response.headers.add_header(
                    'Set-Cookie', 'ctxioid=' + accntList[0].id + '; path=/;')
                m = md5.new()
                m.update(accntList[0].id)
                m.update(current_email)
                self.response.headers.add_header(
                    'Set-Cookie', 'ctxiohash=' + m.hexdigest() + '; path=/;')

                # show the application main UI. This UI will get data from the mailbox
                # through XMLHttpRequest calls handled by handlers.py
                url = users.create_logout_url(self.request.uri)
                template_values = {
                    'url': url,
                    'url_linktext': 'sign out',
                }
                path = os.path.join(os.path.dirname(__file__), 'templates',
                                    'app.html')
                self.response.out.write(template.render(path, template_values))
            else:
                # This mailbox isn't available under our Context.IO account, show
                # users the page prompting them to connect their Gmail account
                # through OAuth. See imapoauth.py for steps on obtaining Access
                # Token and adding the mailbox to our Context.IO account.
                template_values = {'connect_link': '/imapoauth_step1'}
                path = os.path.join(os.path.dirname(__file__), 'templates',
                                    'connect.html')
                self.response.out.write(template.render(path, template_values))
        else:
            self.response.out.write(
                "Oops, forgot to login: required option for this script in app.yaml?"
            )
Ejemplo n.º 5
0
def context_buildindex(request, iolimit, iooffset):
    ctxIO = ContextIO(consumer_key=api_key, consumer_secret=api_secret)
    accntList = ctxIO.get_accounts(email=mailbox_to_query)
    logging.info('ctxIO Account: %r' % accntList)
    messages = Account(ctxIO, {
        'id': accntList[0].id
    }).get_messages(limit=iolimit, offset=iooffset)
    txt = 'All done!'
    for message in messages:
        ctxmsg = models.Contextio(key_name=message.message_id)
        ctxmsg.message_date = message.date
        ctxmsg.put()
    # get messages with limit and offset
    return HttpResponse(txt, content_type='text/plain')