caterpillar/smtp.py.tmp

53 lines
1.3 KiB
Plaintext
Raw Normal View History

2024-02-29 15:40:54 +00:00
## 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