|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 from email.mime.text import MIMEText |
|
4 from email.header import Header |
|
5 |
|
6 class Message: |
|
7 def __init__(self,content): |
|
8 self.content=content |
|
9 |
|
10 def getContent(self): |
|
11 return self.content |
|
12 |
|
13 def __eq__(self,other): |
|
14 return self.content == other.content |
|
15 |
|
16 def __ne__(self,other): |
|
17 return not self.__eq__(other) |
|
18 |
|
19 class SMS(Message): |
|
20 def __init__(self, cont): |
|
21 Message.__init__(self,cont) |
|
22 |
|
23 def sendto(self,anbieter,recipients): |
|
24 anbieter.sendSMS(self,recipients) |
|
25 |
|
26 |
|
27 class Fax(Message): |
|
28 def __init__(self,header,cont,attachments): |
|
29 Message.__init__(self,cont) |
|
30 self.header=header |
|
31 self.attachments=attachments |
|
32 |
|
33 def getAttachment(self,i): |
|
34 return self.attachments[i] |
|
35 |
|
36 def __eq__(self,other): |
|
37 if not Message.__eq__(self,other): |
|
38 return False |
|
39 |
|
40 if self.header != other.header: |
|
41 return False |
|
42 |
|
43 if len(self.attachments) != len(other.attachments): |
|
44 return False |
|
45 |
|
46 for i in range(len(self.attachments)): |
|
47 if self.attachments[i] != other.attachments[i]: |
|
48 return False |
|
49 return True |
|
50 |
|
51 |
|
52 |
|
53 class Mail(Message): |
|
54 def __init__(self, subject, body, frm): |
|
55 con=MIMEText(body.encode("utf-8"), _charset='utf-8') |
|
56 sub=Header(subject.encode('utf-8'), 'utf-8') |
|
57 con['Subject']=sub |
|
58 self.frm=frm |
|
59 Message.__init__(self, con) |
|
60 |
|
61 def as_string(self): |
|
62 return self.Message.as_string() |
|
63 |
|
64 def getFrom(self): |
|
65 return self.frm |
|
66 |
|
67 def __eq__(self,other): |
|
68 if self.as_string() != other.as_string(): |
|
69 return False |
|
70 |
|
71 if self.frm != other.frm: |
|
72 return False |
|
73 |
|
74 return True |