-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkdups.py
executable file
·115 lines (88 loc) · 3.23 KB
/
checkdups.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/local/bin/python3 -bb
# check that messages in dupearea really the same as in database
import os
import sys
from ftnconfig import *
import ftn.msg
import postgresql
import xml.etree.ElementTree
import ast
from ftnimport import normalize_message
from stringutil import *
import ftnexport
db=connectdb()
Q_msgget = db.prepare("select m.id, m.msgid, m.header, m.body, m.origcharset, s.domain, s.text, d.domain, d.text "
"from messages m, addresses s, addresses d "
"where m.msgid=$1 and m.source=s.id and m.destination=d.id")
for c in Q_msgget("2:280/5003.4 56eee1c4")[0][3]:
print(ord(c), c)
if ord(c)==144:
print("***")
break
import time
time.sleep(2)
exit()
#DUPDIR=BADDIR
if len(sys.argv)<2:
print(DUPDIR)
filelist=os.listdir(DUPDIR)
else:
filelist=sys.argv[1:]
for f in filelist:
fn, fext = os.path.splitext(f)
if fext==".msg" and fn.find(".db")==-1:
print(f, end=' ')
m=ftn.msg.MSG(os.path.join(DUPDIR,f))
(origdomname, origaddr), (destdomname, destaddr), msgid, header, body, charset = normalize_message(m)
print("msgid='%s'"%msgid,end=' ')
# if destdomname!="echo":
# print ("not echomail")
# continue
# print("---")
# print("From:",header.find("sendername").text, origdomname, origaddr)
# print("To: ",header.find("recipientname").text, destdomname, destaddr)
# print("Date:",header.find("date").text)
# print("Subj:",header.find("subject").text)
#print(body)
# print("message in database ---")
dbmessages=Q_msgget(msgid)
if len(dbmessages)>1:
raise Exception("multiple messages in database with this MSGID")
dbid, dbmsgid, dbheader, dbbody, dbcharset, dbsd, dbst, dbdd, dbdt = dbmessages[0]
dbsd = db.FTN_backdomains[dbsd]
dbdd = db.FTN_backdomains[dbdd]
# print("From:",dbheader.find("sendername").text, dbsd, dbst)
# print("To: ",dbheader.find("recipientname").text, dbdd, dbdt)
# print("Date:",dbheader.find("date").text)
# print("Subj:",dbheader.find("subject").text)
# print("----------------------------------------------------------------------")
subj1 = header.find("subject").text
subj2 = dbheader.find("subject").text
if subj1 is None:
subj1 = ""
if subj2 is None:
subj2 = ""
#print (subj1==subj2, body==dbbody)
subjmatch = subj1==subj2
if not subjmatch:
subjmatch = subj1==clean_str(subj2)
# if not subjmatch:
# subj1=ast.literal_eval('"'+subj1+'"')
# subjmatch = subj1.replace("\x0A","")==subj2.replace("\x0A","")
print ("Same subject:",subjmatch)
match = subjmatch and (body.strip()==dbbody.strip() or dbbody.strip().startswith(body.strip()))
print("and same body:", match)
if destdomname=="echo" and match and (destdomname,destaddr)==(dbdd,dbdt):
os.unlink(os.path.join(DUPDIR,f))
os.unlink(os.path.join(DUPDIR,f[:-4]+".status"))
try:
os.unlink(os.path.join(DUPDIR, fn+".db%d.msg"%dbid))
except:
pass
else:
dupf=open(os.path.join(DUPDIR, fn+".db%d.msg"%dbid), "wb")
dbmsg,_=ftnexport.denormalize_message(
(dbsd, dbst), (dbdd, dbdt),
dbmsgid, dbheader, dbbody, dbcharset, echodest=ADDRESS, addpath=ADDRESS)
dupf.write(dbmsg.pack())
dupf.close()