compatibility fixes
Message-ID: <54eaf012.R28foFdS7Ge2k9GO%lm(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: a3dafed0913c7a16e425bd2b1e5005ee5d3f4776
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a3dafed0913c7a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Feb 23 10:17:00 2015 +0100
Additional python <2.5 (centos 5.x) compatibility fixes
---
notifications/mail | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/notifications/mail b/notifications/mail
index 60ba26c..67b6d11 100755
--- a/notifications/mail
+++ b/notifications/mail
@@ -36,10 +36,20 @@
import os, re, sys, subprocess
-from email.mime.multipart import MIMEMultipart
-from email.mime.text import MIMEText
-from email.mime.application import MIMEApplication
-from email.mime.image import MIMEImage
+
+try:
+ from email.mime.multipart import MIMEMultipart
+ from email.mime.text import MIMEText
+ from email.mime.application import MIMEApplication
+ from email.mime.image import MIMEImage
+except ImportError:
+ # python <2.5 compat
+ from email.MIMEMultipart import MIMEMultipart
+ from email.MIMEText import MIMEText
+ from email.MIMEImage import MIMEImage
+ from email.MIMEBase import MIMEBase
+ from email import Encoders
+ MIMEApplication = None
tmpl_head_html = '''
<html>
@@ -346,7 +356,14 @@ def multipart_mail(target, subject, from_address, reply_to,
content_txt, content
if what == 'img':
part = MIMEImage(contents, name = name)
else:
- part = MIMEApplication(contents, name = name)
+ if MIMEApplication != None:
+ part = MIMEApplication(contents, name = name)
+ else:
+ # python <2.5 compat
+ part = MimeBase('application', 'octet-stream')
+ part.set_payload(contents)
+ Encoders.encode_base64(part)
+
part.add_header('Content-ID', '<%s>' % name)
# how must be inline or attachment
part.add_header('Content-Disposition', how, filename = name)