1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 |
2 """All available message typs to send send. |
|
3 """ |
3 from email.mime.text import MIMEText |
4 from email.mime.text import MIMEText |
4 from email.header import Header |
5 from email.header import Header |
5 from email.Utils import formatdate |
6 from email.Utils import formatdate |
6 |
7 |
7 class Message: |
8 class Message: |
|
9 """ Baseclass for all different message typs.""" |
8 def __init__(self,content, typ="Message"): |
10 def __init__(self,content, typ="Message"): |
|
11 """Constructor of Message class. |
|
12 |
|
13 :param content: content of the message |
|
14 :param string typ: typ of the message |
|
15 |
|
16 .. automethod:: __eq__ |
|
17 .. automethod:: __neq__ |
|
18 """ |
9 self.content=content |
19 self.content=content |
10 self.typ = typ |
20 self.typ = typ |
11 |
21 |
12 |
22 |
13 def getContent(self): |
23 def getContent(self): |
|
24 """returns the content of the message""" |
14 return self.content |
25 return self.content |
15 |
26 |
16 def __eq__(self,other): |
27 def __eq__(self,other): |
|
28 """return ``True`` if **other** has the same content.""" |
17 return self.content == other.content |
29 return self.content == other.content |
18 |
30 |
19 def __ne__(self,other): |
31 def __neq__(self,other): |
|
32 """return ``False`` if **other** has the same content.""" |
20 return not self.__eq__(other) |
33 return not self.__eq__(other) |
21 |
34 |
22 class SMS(Message): |
35 class SMS(Message): |
|
36 """ A representation of one SMS""" |
23 def __init__(self, cont, from_ = None): |
37 def __init__(self, cont, from_ = None): |
|
38 """Constructor of SMS class. |
|
39 |
|
40 :param string cont: SMS content |
|
41 :param string from_: the telnumber from the SMS should be sended. |
|
42 """ |
24 Message.__init__(self, cont.encode("utf-8"), typ="sms") |
43 Message.__init__(self, cont.encode("utf-8"), typ="sms") |
25 self.from_ = from_ |
44 self.from_ = from_ |
26 |
45 |
27 class Fax(Message): |
46 class Fax(Message): |
|
47 """A representation of one fax.""" |
28 def __init__(self,header,cont,attachments=[]): |
48 def __init__(self,header,cont,attachments=[]): |
|
49 """Constructor of one fax. |
|
50 |
|
51 :param string header: Headline of fax |
|
52 :param string cont: fax content |
|
53 :param list attachments: attachments of fax |
|
54 """ |
29 Message.__init__(self,cont.encode("utf-8"),typ="fax") |
55 Message.__init__(self,cont.encode("utf-8"),typ="fax") |
30 self.header=header |
56 self.header=header |
31 self.attachments=attachments |
57 self.attachments=attachments |
32 |
58 |
33 def getAttachment(self,i): |
59 def getAttachment(self,i): |
|
60 """returns a attachment |
|
61 :param integer i: the i-th attachment |
|
62 """ |
34 return self.attachments[i] |
63 return self.attachments[i] |
35 |
64 |
36 def __eq__(self,other): |
65 def __eq__(self,other): |
37 if not Message.__eq__(self,other): |
66 if not Message.__eq__(self,other): |
38 return False |
67 return False |
49 return True |
78 return True |
50 |
79 |
51 |
80 |
52 |
81 |
53 class Mail(Message): |
82 class Mail(Message): |
|
83 """A representation of one Mail""" |
54 def __init__(self, subject, body, frm): |
84 def __init__(self, subject, body, frm): |
|
85 """Constructor of one mail. |
|
86 |
|
87 :param string subject: subject of the mail |
|
88 :param string body: body of the mail |
|
89 :param string frm: mailaddress to send mail from |
|
90 |
|
91 .. automethod:: __repr__ |
|
92 """ |
55 con = MIMEText(body.encode("utf-8"), _charset='utf-8') |
93 con = MIMEText(body.encode("utf-8"), _charset='utf-8') |
56 sub = Header(subject.encode('utf-8'), 'utf-8') |
94 sub = Header(subject.encode('utf-8'), 'utf-8') |
57 con['Subject'] = sub |
95 con['Subject'] = sub |
58 con['Date'] = formatdate(localtime=True) |
96 con['Date'] = formatdate(localtime=True) |
59 self.subject = subject |
97 self.subject = subject |
60 self.body = body |
98 self.body = body |
61 self.frm=frm |
99 self.frm=frm |
62 Message.__init__(self, con, typ='mail') |
100 Message.__init__(self, con, typ='mail') |
63 |
101 |
64 def as_string(self): |
102 def as_string(self): |
|
103 """returns created mail""" |
65 return self.content.as_string() |
104 return self.content.as_string() |
66 |
105 |
67 def getFrom(self): |
106 def getFrom(self): |
|
107 """returns the from mailaddress""" |
68 return self.frm |
108 return self.frm |
69 |
109 |
70 def __eq__(self,other): |
110 def __eq__(self,other): |
71 if self.as_string() != other.as_string(): |
111 if self.as_string() != other.as_string(): |
72 return False |
112 return False |