Skip to content

Instantly share code, notes, and snippets.

@wmantly
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmantly/3ed5e4619fbe94154682 to your computer and use it in GitHub Desktop.
Save wmantly/3ed5e4619fbe94154682 to your computer and use it in GitHub Desktop.
 def _handle_request(self, method, params):
        if method == 'helloWorld':
            (a, b) = params
            return a + '-' + b
        elif method == 'add':
            (a, b) = params
            return a + b
        elif method == 'statusBar':
            message, = params
...( +800 lines)
 if method in dir( self.apiDir ):
     statusCode, data = object.__getattribute__( _handle_request, method )( self, *params )
        response = {
            'data': data,
            'status': statusCode,
            'method': method
        }
        return json.dumps( response )
        elif method == 'getAllSentMessages':
            queryreturn = sqlQuery('''SELECT msgid, toaddress, fromaddress, subject, lastactiontime, message, encodingtype, status, ackdata FROM sent where folder='sent' ORDER BY lastactiontime''')
            data = '{"sentMessages":['
            for row in queryreturn:
                msgid, toAddress, fromAddress, subject, lastactiontime, message, encodingtype, status, ackdata = row
                subject = shared.fixPotentiallyInvalidUTF8Data(subject)
                message = shared.fixPotentiallyInvalidUTF8Data(message)
                if len(data) > 25:
                    data += ','
                data += json.dumps({'msgid':msgid.encode('hex'), 'toAddress':toAddress, 'fromAddress':fromAddress, 'subject':subject.encode('base64'), 'message':message.encode('base64'), 'encodingType':encodingtype, 'lastActionTime':lastactiontime, 'status':status, 'ackData':ackdata.encode('hex')}, indent=4, separators=(',', ': '))
            data += ']}'
            return data
def getAllSentMessages( self, *args ):
        '''()
Returns an object with these properties:
msgid (hex)
toAddress (ascii/utf-8)
fromAddress (ascii/utf-8)
subject (base64, decodes into utf-8)
message (base64, decodes into utf-8)
encodingType (integer)
lastActionTime (integer, Unix time)
status (ascii/utf-8)
ackData (hex)'''

        queryreturn = sqlQuery(
            '''SELECT msgid, toAddress, fromAddress, subject, message, encodingtype, lastactiontime, status, ackdata FROM sent where folder='sent' ORDER BY lastactiontime'''
        )
        data = sentMessage( queryreturn )

        return 200, data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment