mirror of
https://github.com/gnh1201/caterpillar.git
synced 2024-10-04 15:11:57 +00:00
53 lines
1.3 KiB
Plaintext
53 lines
1.3 KiB
Plaintext
|
## todo
|
||
|
|
||
|
def jsonrpc2_create_id(data):
|
||
|
return hashlib.sha1(json.dumps(data).encode(client_encoding)).hexdigest()
|
||
|
|
||
|
def jsonrpc2_encode(method, params = None):
|
||
|
data = {
|
||
|
"jsonrpc": "2.0",
|
||
|
"method": method,
|
||
|
"params": params
|
||
|
}
|
||
|
id = jsonrpc2_create_id(data)
|
||
|
data['id'] = id
|
||
|
return (id, json.dumps(data))
|
||
|
|
||
|
def jsonrpc2_decode(data):
|
||
|
type, id, method, rpcdata = (None, None, None, None)
|
||
|
typemap = {
|
||
|
"params": "call",
|
||
|
"error": "error",
|
||
|
"result": "result"
|
||
|
}
|
||
|
|
||
|
jsondata = json.loads(data)
|
||
|
if jsondata['jsonrpc'] == "2.0":
|
||
|
for k, v in typemap.items():
|
||
|
if k in jsondata:
|
||
|
type = v
|
||
|
rpcdata = jsondata[k]
|
||
|
id = jsondata['id']
|
||
|
|
||
|
if type == "call":
|
||
|
method = jsondata['method']
|
||
|
|
||
|
return type, id, method, rpcdata
|
||
|
|
||
|
class CaterpillarSMTPServer(SMTPServer):
|
||
|
def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
|
||
|
message_lines = data.decode('utf-8').split('\n')
|
||
|
subject = ''
|
||
|
to = ''
|
||
|
for line in message_lines:
|
||
|
pos = line.find(':')
|
||
|
if pos > -1:
|
||
|
k = line[0:pos]
|
||
|
v = line[pos+1:]
|
||
|
if k = 'Subject':
|
||
|
subject = v
|
||
|
elif k = 'To':
|
||
|
subject = v
|
||
|
|
||
|
## todo
|