added flask interface

This commit is contained in:
Andreas Stephanides
2017-08-06 10:16:30 +02:00
parent 4060a77c48
commit ff0bdc6d3b
23 changed files with 14913 additions and 63 deletions

View File

@@ -9,6 +9,8 @@ import yaml
import email
from mail_model import Mail
#from fetch_mail import fetch_mail
import re
class FullThreadSchema(Schema):
id=fields.Integer()
@@ -28,13 +30,16 @@ class MailThread(Base):
__jsonid__='thread'
__whiteattrs__= ["body"]
__jsonattrs__=None
answered=False
maintopic="information"
def bdy(self):
return yaml.load(self.body)
def to_text(self):
mmm=self.mails()
txt=""
for m in mmm:
m.compile_envelope()
# m.compile_envelope()
txt=txt+"mail: \n"
for f in yaml.load(m.from_):
txt=txt+f["mail"]+"@"+f["host"]
@@ -42,6 +47,10 @@ class MailThread(Base):
txt=txt+" ".join(yaml.load(m.subject))
txt=txt+"\n"
return txt
def tstr(self):
fr=yaml.load(self.mails()[0].from_)
return "(" + str(self.answered)+ ", "+ str(self.maintopic) + ") " + str(self.firstmail)+": "+str(fr[0]["mail"])+"@"+str(fr[0]["host"]) + " | ".join(yaml.load(self.mails()[0].subject))
def mails(self):
a=[]
@@ -60,6 +69,7 @@ class MailThread(Base):
m.compile_envelope()
a.append(m.dict_envelope())
return a
def mail_flat_dict(self):
a=[]
d={}
@@ -69,25 +79,41 @@ class MailThread(Base):
for k, v in dc[i].iteritems():
d["mail_"+str(i)+"_"+k]=v
return d
def subject(self):
a=""
for m in self.mails():
m.compile_envelope()
a=a + " ".join(yaml.load(m.subject))+"\n"
return a
def text(self):
a=u""
def compile(self):
for m in self.mails():
m.compile_envelope()
m.compile_text()
db_session.add(m)
db_session.commit()
def text(self,filter="all"):
a=u""
def mail_txt(m):
t=yaml.load(m.text)
if type(t) is unicode:
txt=t
else:
# print "withintm:"+str(type(t))
t=t.decode("ISO-8859-1")
txt=t
a=a+txt+"***........................................***\n"
return txt
mm=self.mails()
if filter=="all":
for m in mm:
a=a+mail_txt(m)+"****........................................***\n"
elif filter=="first":
a=mail_txt(m[0])
a=re.sub(r'\n\s*\n',r'\n',a)
a=re.sub(r'<!--.*-->',r'',a,flags=re.MULTILINE|re.DOTALL)
a=re.sub(r'\s*>+ .*\n',r'',a)
return a