-
Notifications
You must be signed in to change notification settings - Fork 42
/
server.py
35 lines (32 loc) · 1.02 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
import socket
import analysisEmail
import splitEmail
if __name__ == '__main__':
#加载历史邮件资料库,即建立判断条件
init = splitEmail.SplitEmail()
words = init.init_wordslist()
trie = init.words_2_trie(words)
init.split(trie, ['./data/'])
init.ratio = init.getRatio()
#for key in dic_of_ratio:
# print key, dic_of_ratio[key]
####################################################################
host = '' # Symbolic name meaning all available interfaces
port = 8888
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(5)
while True:
print "Waiting for clients..."
conn, addr = s.accept()
print 'Connected by', addr
msg = ""
while True:
data = conn.recv(1024)
if not len(data):
break
msg += data
conn.close()
P = analysisEmail.JudgeMail().judge(init, trie, msg)
print "P(spam) = ", P