mirror of
https://github.com/gnh1201/caterpillar.git
synced 2025-03-11 16:35:14 +00:00
Create smtp.py.tmp
This commit is contained in:
parent
6e2ca2e87f
commit
2279a3b595
52
smtp.py.tmp
Normal file
52
smtp.py.tmp
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
## 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
|
Loading…
Reference in New Issue
Block a user