iro/model/message.py
branchdevel
changeset 152 14c99c89edf4
parent 135 f8640c663e3e
child 166 6d6890f7e3f8
equal deleted inserted replaced
151:ff8448fb07e7 152:14c99c89edf4
     2 
     2 
     3 from email.mime.text import MIMEText
     3 from email.mime.text import MIMEText
     4 from email.header import Header
     4 from email.header import Header
     5 
     5 
     6 class Message:
     6 class Message:
     7     def __init__(self,content):
     7     def __init__(self,content, typ="Message"):
     8         self.content=content
     8         self.content=content
       
     9         self.typ = typ
       
    10 
     9 
    11 
    10     def getContent(self):
    12     def getContent(self):
    11         return self.content
    13         return self.content
    12 
    14 
    13     def __eq__(self,other):
    15     def __eq__(self,other):
    16     def __ne__(self,other):
    18     def __ne__(self,other):
    17         return not self.__eq__(other)
    19         return not self.__eq__(other)
    18 
    20 
    19 class SMS(Message):
    21 class SMS(Message):
    20     def __init__(self, cont):
    22     def __init__(self, cont):
    21         Message.__init__(self,cont)
    23         Message.__init__(self, cont, typ="sms")
    22 
    24 
    23     def sendto(self,anbieter,recipients):
    25     def sendto(self,anbieter,recipients):
    24         anbieter.sendSMS(self,recipients)
    26         anbieter.sendSMS(self,recipients)
    25 
    27 
    26 
    28 
    27 class Fax(Message):
    29 class Fax(Message):
    28     def __init__(self,header,cont,attachments):
    30     def __init__(self,header,cont,attachments):
    29         Message.__init__(self,cont)
    31         Message.__init__(self,cont, typ="fax")
    30         self.header=header
    32         self.header=header
    31         self.attachments=attachments
    33         self.attachments=attachments
    32 
    34 
    33     def getAttachment(self,i):
    35     def getAttachment(self,i):
    34         return self.attachments[i]
    36         return self.attachments[i]
    54     def __init__(self, subject, body, frm):
    56     def __init__(self, subject, body, frm):
    55         con=MIMEText(body.encode("utf-8"), _charset='utf-8')
    57         con=MIMEText(body.encode("utf-8"), _charset='utf-8')
    56         sub=Header(subject.encode('utf-8'), 'utf-8')
    58         sub=Header(subject.encode('utf-8'), 'utf-8')
    57         con['Subject']=sub
    59         con['Subject']=sub
    58         self.frm=frm
    60         self.frm=frm
    59         Message.__init__(self, con)
    61         Message.__init__(self, con, typ='mail')
    60 
    62 
    61     def as_string(self):
    63     def as_string(self):
    62         return self.Message.as_string()
    64         return self.Message.as_string()
    63 
    65 
    64     def getFrom(self):
    66     def getFrom(self):