small fixes and improvements
This commit is contained in:
@@ -9,6 +9,7 @@ import yaml
|
||||
import email
|
||||
from fetch_mail import fetch_mail
|
||||
import bs4
|
||||
import re
|
||||
class FullMailSchema(Schema):
|
||||
id=fields.Integer()
|
||||
text=fields.String()
|
||||
@@ -56,6 +57,8 @@ class Mail(Base):
|
||||
return mm
|
||||
|
||||
def get_email(self):
|
||||
if self.body is None:
|
||||
raise ValueError("body not yet loaded")
|
||||
em=email.message_from_string(yaml.load(self.body))
|
||||
return em
|
||||
|
||||
@@ -91,11 +94,10 @@ class Mail(Base):
|
||||
|
||||
def dict_envelope(self):
|
||||
d={}
|
||||
i=0
|
||||
for p in yaml.load(self.subject):
|
||||
if p is not None:
|
||||
d["subject_"+str(i)]=p
|
||||
i=i+1
|
||||
if self.to_ is None:
|
||||
self.compile_envelope()
|
||||
if self.to_ is None:
|
||||
raise ValueError("Self.to_ of mail not yet compiled")
|
||||
i=0
|
||||
for p in yaml.load(self.to_):
|
||||
if p["host"] is not None:
|
||||
@@ -126,3 +128,19 @@ class Mail(Base):
|
||||
self.text= yaml.dump(b4.get_text())
|
||||
else:
|
||||
self.text =yaml.dump( pl)
|
||||
def print_text(self):
|
||||
txt=""
|
||||
fr=yaml.load(self.from_)
|
||||
txt= txt+ "Gesendet von: "+str(fr[0]["mail"])+"@"+str(fr[0]["host"])+" am "+ str(self.date) + "\n"
|
||||
t=yaml.load(self.text)
|
||||
if type(t) is unicode:
|
||||
#txt=txt
|
||||
txt=txt+t
|
||||
else:
|
||||
t=t.decode("ISO-8859-1")
|
||||
txt=txt+t
|
||||
txt=re.sub(r'\n\s*\n',r'\n',txt)
|
||||
txt=re.sub(r'<!--.*-->',r'',txt,flags=re.MULTILINE|re.DOTALL)
|
||||
txt=re.sub(r'\s*>+ .*\n',r'',txt)
|
||||
|
||||
return txt
|
||||
|
||||
Reference in New Issue
Block a user