Revert "bug fix: use base64 encoded string to pass email env"
authorHasan Wan <hasan.wan@intel.com>
Wed, 29 Aug 2012 08:26:47 +0000 (16:26 +0800)
committerHasan Wan <hasan.wan@intel.com>
Thu, 30 Aug 2012 05:30:54 +0000 (13:30 +0800)
This reverts commit f8adc8b006c6f50b994df8ef9238e4adf6230e6a.

buildcheck.py
common/send_mail.py
requests/mailer.py

index 79561d4..7d19a6d 100755 (executable)
@@ -11,7 +11,6 @@ import glob
 import shutil
 import time
 import gzip
-import base64
 
 # internal
 from common import obspkg
@@ -53,7 +52,7 @@ def sendmail(subject, body, mail_from, mail_to, attachment = None):
     """ Prepare the envorinment parameter for trigger mail_sender job"""
     mail_env = {}
     mail_env['subject'] = subject
-    mail_env['body'] = base64.b64encode(body)
+    mail_env['body'] = body.replace('\n', '\\n')
     mail_env['From'] = mail_from
     mail_env['To'] = mail_to
 
index 448ee79..c2e013b 100644 (file)
@@ -2,8 +2,6 @@
 
 import os
 import smtplib
-import base64
-import re
 
 from email.mime.text import MIMEText
 from email.MIMEMultipart import MIMEMultipart
@@ -12,16 +10,6 @@ from email import Encoders
 from email.Header import Header
 from email.Utils import parseaddr, formataddr
 
-def is_base64str(string):
-    ''' return Ture or False '''
-    try:
-        if (len(string) % 4) == 0:
-            if re.match("[A-Za-z0-9/+=]*$", string):
-                return True
-    except:
-        return False
-    return False
-
 def sendmail(from_email, to, msg, smtp_server):
 
     if type(to) != list:
@@ -72,35 +60,23 @@ def makemail(subject = '', body = '', from_email = None, to = [],
         return formataddr((name, addr))
 
     # We must choose the body charset manually
-
-    if type(to) != list:
-        to = [to]
-    if type(cc) != list:
-        cc = [cc]
-
-    if is_base64str(body):
-        body_plain = base64.b64decode(body)
-        encoded_flag = True
-    else:
-        body_plain = body
-        encoded_flag = False
-
     for body_charset in 'US-ASCII', 'UTF-8':
         try:
-            body_plain.decode(body_charset)
+            body.decode(body_charset)
         except UnicodeError:
             pass
         else:
             break
 
-    msg_body = MIMEText(body, 'plain', body_charset)
-    if encoded_flag:
-        msg_body.add_header('Content-Transfer-Encoding','base64')
+    if type(to) != list:
+        to = [to]
+    if type(cc) != list:
+        cc = [cc]
 
     # Create the message ('plain' stands for Content-Type: text/plain)
     if attachment and os.path.isfile(attachment):
         msg = MIMEMultipart()
-        msg.attach(msg_body)
+        msg.attach(MIMEText(body, 'plain', body_charset))
 
         attach = MIMEBase('application',"octet-stream")
         attach.set_payload(open(attachment, "rb").read())
@@ -108,7 +84,7 @@ def makemail(subject = '', body = '', from_email = None, to = [],
         attach.add_header("Content-Disposition", 'attachment; filename="%s"' %(os.path.basename(attachment)))
         msg.attach(attach)
     else:
-        msg = msg_body
+        msg = MIMEText(body, 'plain', body_charset)
 
     # Normalize all headers
     msg['Subject'] = Header(unicode(subject), 'ISO-8859-1')
index 908c1a5..ded70f6 100644 (file)
@@ -18,7 +18,6 @@
 from string import Template
 import copy
 import os
-import base64
 
 """
 def := { event_name1: ( trigger, trigger ),
@@ -343,6 +342,6 @@ def mailer(request, bs, wi, noreply_sender, ml, bccs, request_data,
             from string import Template
             template = Template(template_str)
             body = template.safe_substitute(return_dict, msg="\n".join(msg))
-        return_dict['body'] = base64.b64encode(body)
+        return_dict['body'] = body.replace('\n','\\n')
 
     return return_dict