summaryrefslogtreecommitdiffstats
path: root/cnucnu/mail.py
diff options
context:
space:
mode:
authorTill Maas <opensource@till.name>2009-07-19 17:08:24 +0200
committerTill Maas <opensource@till.name>2009-07-19 17:08:24 +0200
commitce1383726feefa1e0f8aa53b4803f36733726611 (patch)
treef1c675b5d3bf6441b136f6dc74e695c36880332c /cnucnu/mail.py
parentc6c86d92cc56628a86d566a838940a7c062252b0 (diff)
downloadcnucnu-ce1383726feefa1e0f8aa53b4803f36733726611.tar.gz
cnucnu-ce1383726feefa1e0f8aa53b4803f36733726611.tar.xz
cnucnu-ce1383726feefa1e0f8aa53b4803f36733726611.zip
remove dir lib for saner imports(?)
Diffstat (limited to 'cnucnu/mail.py')
-rwxr-xr-xcnucnu/mail.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/cnucnu/mail.py b/cnucnu/mail.py
new file mode 100755
index 0000000..7928973
--- /dev/null
+++ b/cnucnu/mail.py
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+# vim: fileencoding=utf8 foldmethod=marker
+#{{{ License header: GPLv2+
+# This file is part of cnucnu.
+#
+# Cnucnu is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# Cnucnu is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cnucnu. If not, see <http://www.gnu.org/licenses/>.
+#}}}
+
+import smtplib
+from email.mime.text import MIMEText
+from email.header import Header
+from email.utils import parseaddr, formataddr
+
+
+def encode_addr(addr):
+ real_name, email_address = parseaddr(addr)
+ try:
+ # check for non-ascii characters
+ real_name = real_name.encode("ascii")
+ except (UnicodeEncodeError, UnicodeDecodeError), e:
+ real_name = str(Header(ensure_encoding(real_name), "UTF-8"))
+ return formataddr((real_name, email_address))
+
+def ensure_encoding(text, encoding="UTF-8"):
+ try:
+ text = text.encode("UTF-8")
+ # text not a unicode string like e.g. u"unicode string"
+ # Assume that it is encoded in UTF-8 for convenience
+ except UnicodeDecodeError, e:
+ text = text.decode("UTF-8").encode("UTF-8")
+
+ return text
+
+class Message:
+ def __init__(self, sender, receipient, subject, message):
+ self.sender = sender
+ self.receipient = receipient
+
+ msg = MIMEText(ensure_encoding(message), _charset="UTF-8")
+ msg['Subject'] = Header(ensure_encoding(subject), "UTF-8")
+ msg['From'] = encode_addr(sender)
+ msg['To'] = encode_addr(receipient)
+
+ self.msg = msg
+ self.as_string = msg.as_string
+
+
+class Mailer:
+ def __init__(self, smtp_host):
+ self.smtp_host = smtp_host
+
+ def send(self, message):
+
+ s = smtplib.SMTP(self.smtp_host)
+ s.sendmail(message.sender, [message.receipient], mesagge.as_string())
+ s.quit()
+
+message_template_outdated = """ The latest upstream release for %(name)s is %(latest_upstream)s, but Fedora Rawhide only contains %(repo_version)s.
+
+This mail is sent, because your package is listed at:
+https://fedoraproject.org/wiki/Using_FEver_to_track_upstream_changes
+
+Eventually, there will be bugs filed for outdated packages, but this is not yet implemented.
+"""
+
+
+if __name__ == "__main__":
+ import pickle
+ mailer = Mailer(smtp_host="")
+
+ data_file = open("../../data.pickle")