From: Hasan Wan Date: Wed, 29 Aug 2012 08:26:47 +0000 (+0800) Subject: Revert "bug fix: use base64 encoded string to pass email env" X-Git-Tag: 0.9~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=17e8d8e17fbb84ce3304bfd08979736f3f94c975;p=services%2Fjenkins-scripts.git Revert "bug fix: use base64 encoded string to pass email env" This reverts commit f8adc8b006c6f50b994df8ef9238e4adf6230e6a. --- diff --git a/buildcheck.py b/buildcheck.py index 79561d4..7d19a6d 100755 --- a/buildcheck.py +++ b/buildcheck.py @@ -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 diff --git a/common/send_mail.py b/common/send_mail.py index 448ee79..c2e013b 100644 --- a/common/send_mail.py +++ b/common/send_mail.py @@ -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') diff --git a/requests/mailer.py b/requests/mailer.py index 908c1a5..ded70f6 100644 --- a/requests/mailer.py +++ b/requests/mailer.py @@ -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