import shutil
import time
import gzip
-import base64
# internal
from common import obspkg
""" 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
import os
import smtplib
-import base64
-import re
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart
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:
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())
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')
from string import Template
import copy
import os
-import base64
"""
def := { event_name1: ( trigger, trigger ),
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