iro/model/message.py
branchdevel
changeset 135 f8640c663e3e
parent 62 35228d665310
child 152 14c99c89edf4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iro/model/message.py	Tue Feb 07 01:56:59 2012 +0100
@@ -0,0 +1,74 @@
+# -*- 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