iro/model/message.py
author Sandro Knauß <knauss@netzguerilla.net>
Mon, 13 Feb 2012 15:38:50 +0100
branchdevel
changeset 144 1cc164bbb068
parent 135 f8640c663e3e
child 152 14c99c89edf4
permissions -rw-r--r--
adding reload tests (not implemented)

# -*- coding: utf-8 -*-

from email.mime.text import MIMEText
from email.header import Header

class Message:
    def __init__(self,content):
        self.content=content

    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):
        Message.__init__(self,cont)

    def sendto(self,anbieter,recipients):
        anbieter.sendSMS(self,recipients)


class Fax(Message):
    def __init__(self,header,cont,attachments):
        Message.__init__(self,cont)
        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 i in range(len(self.attachments)):
            if self.attachments[i] != other.attachments[i]:
                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
        self.frm=frm
        Message.__init__(self, con)

    def as_string(self):
        return self.Message.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