# -*- coding: utf-8 -*-
from email.mime.text import MIMEText
from email.header import Header
from email.Utils import formatdate
class Message:
def __init__(self,content, typ="Message"):
self.content=content
self.typ = typ
def getContent(self):
return self.content
def __eq__(self,other):
return self.content == other.content
def __ne__(self,other):
return not self.__eq__(other)
class SMS(Message):
def __init__(self, cont, from_ = None):
Message.__init__(self, cont.encode("utf-8"), typ="sms")
self.from_ = from_
class Fax(Message):
def __init__(self,header,cont,attachments=[]):
Message.__init__(self,cont.encode("utf-8"),typ="fax")
self.header=header
self.attachments=attachments
def getAttachment(self,i):
return self.attachments[i]
def __eq__(self,other):
if not Message.__eq__(self,other):
return False
if self.header != other.header:
return False
if len(self.attachments) != len(other.attachments):
return False
for a in self.attachments:
if a not in other.attachments:
return False
return True
class Mail(Message):
def __init__(self, subject, body, frm):
con = MIMEText(body.encode("utf-8"), _charset='utf-8')
sub = Header(subject.encode('utf-8'), 'utf-8')
con['Subject'] = sub
con['Date'] = formatdate(localtime=True)
self.subject = subject
self.body = body
self.frm=frm
Message.__init__(self, con, typ='mail')
def as_string(self):
return self.content.as_string()
def getFrom(self):
return self.frm
def __eq__(self,other):
if self.as_string() != other.as_string():
return False
if self.frm != other.frm:
return False
return True
def __repr__(self):
return "<Mail(%s,%s,%s)>"%(self.subject,self.body,self.frm)