1 # -*- coding: utf-8 -*- |
|
2 #Copyright (C) 2009 Sandro Knauß <bugs@sandroknauss.de> |
|
3 |
|
4 #This program is free software; you can redistribute it and/or modify it under the terms |
|
5 #of the GNU General Public License as published by the Free Software Foundation; |
|
6 #either version 3 of the License, or any later version. |
|
7 #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|
8 #without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
9 #See the GNU General Public License for more details. |
|
10 |
|
11 #You should have received a copy of the GNU General Public License |
|
12 #along with this program; if not, see <http://www.gnu.org/licenses/>. |
|
13 |
|
14 from email.mime.text import MIMEText |
|
15 from email.header import Header |
|
16 |
|
17 class content: |
|
18 def __init__(self,content): |
|
19 self.content=content |
|
20 |
|
21 def sendto(self,anbieter,recipients): |
|
22 pass |
|
23 |
|
24 def getContent(self): |
|
25 return self.content |
|
26 |
|
27 def __eq__(self,other): |
|
28 return self.content == other.content |
|
29 |
|
30 def __ne__(self,other): |
|
31 return not self.__eq__(other) |
|
32 |
|
33 class SMS(content): |
|
34 def __init__(self, cont): |
|
35 content.__init__(self,cont) |
|
36 |
|
37 def sendto(self,anbieter,recipients): |
|
38 anbieter.sendSMS(self,recipients) |
|
39 |
|
40 |
|
41 class FAX(content): |
|
42 def __init__(self,header,cont,attachments): |
|
43 content.__init__(self,cont) |
|
44 self.header=header |
|
45 self.attachments=attachments |
|
46 |
|
47 def sendto(self,anbieter,recipients): |
|
48 anbieter.sendFAX(self,recipients) |
|
49 |
|
50 def getAttachment(self,i): |
|
51 return self.attachments[i] |
|
52 |
|
53 def __eq__(self,other): |
|
54 if not content.__eq__(self,other): |
|
55 return False |
|
56 |
|
57 if self.header != other.header: |
|
58 return False |
|
59 |
|
60 if len(self.attachments) != len(other.attachments): |
|
61 return False |
|
62 |
|
63 for i in range(len(self.attachments)): |
|
64 if self.attachments[i] != other.attachments[i]: |
|
65 return False |
|
66 |
|
67 return True |
|
68 |
|
69 |
|
70 |
|
71 class Mail(content): |
|
72 def __init__(self, subject, body, frm): |
|
73 con=MIMEText(body.encode("utf-8"), _charset='utf-8') |
|
74 sub=Header(subject.encode('utf-8'), 'utf-8') |
|
75 con['Subject']=sub |
|
76 self.frm=frm |
|
77 content.__init__(self, con) |
|
78 |
|
79 def sendto(self,anbieter,recipients): |
|
80 anbieter.sendMail(self,recipients) |
|
81 |
|
82 def as_string(self): |
|
83 return self.content.as_string() |
|
84 |
|
85 def getFrom(self): |
|
86 return self.frm |
|
87 |
|
88 def __eq__(self,other): |
|
89 if self.as_string() != other.as_string(): |
|
90 return False |
|
91 |
|
92 if self.frm != other.frm: |
|
93 return False |
|
94 |
|
95 return True |
|