aboutsummaryrefslogtreecommitdiff
path: root/cros_utils/email_sender.py
diff options
context:
space:
mode:
authorAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-02-05 21:08:23 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-02-05 21:08:23 +0000
commitcfb8763e2bfd3fbba55c880a2858b8c73a1cd3ad (patch)
treef592e7ccc058bdd6c0beda99a104df4f73c5e1d3 /cros_utils/email_sender.py
parentb6ed922ff73f31b13749595f02b62a849a904dcc (diff)
parent928fba9d7416ccbbeb8fc2bfccf5b9bfd8906444 (diff)
downloadtoolchain-utils-cfb8763e2bfd3fbba55c880a2858b8c73a1cd3ad.tar.gz
Merging 8 commit(s) from Chromium's toolchain-utils am: 928fba9d74
Change-Id: I1f4781ba6673c19a7563925520ee4016ca8500f6
Diffstat (limited to 'cros_utils/email_sender.py')
-rwxr-xr-xcros_utils/email_sender.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/cros_utils/email_sender.py b/cros_utils/email_sender.py
index 3f724f64..0019982e 100755
--- a/cros_utils/email_sender.py
+++ b/cros_utils/email_sender.py
@@ -97,12 +97,14 @@ class EmailSender(object):
if not text_to_send:
text_to_send = 'Empty message body.'
- body_fd, body_filename = tempfile.mkstemp()
- to_be_deleted = [body_filename]
+ to_be_deleted = []
try:
- os.write(body_fd, text_to_send)
- os.close(body_fd)
+ with tempfile.NamedTemporaryFile(
+ 'w', encoding='utf-8', delete=False) as f:
+ f.write(text_to_send)
+ f.flush()
+ to_be_deleted.append(f.name)
# Fix single-quotes inside the subject. In bash, to escape a single quote
# (e.g 'don't') you need to replace it with '\'' (e.g. 'don'\''t'). To
@@ -113,11 +115,10 @@ class EmailSender(object):
if msg_type == 'html':
command = ("sendgmr --to='%s' --from='%s' --subject='%s' "
"--html_file='%s' --body_file=/dev/null" %
- (to_list, email_from, subject, body_filename))
+ (to_list, email_from, subject, f.name))
else:
- command = (
- "sendgmr --to='%s' --from='%s' --subject='%s' "
- "--body_file='%s'" % (to_list, email_from, subject, body_filename))
+ command = ("sendgmr --to='%s' --from='%s' --subject='%s' "
+ "--body_file='%s'" % (to_list, email_from, subject, f.name))
if email_cc:
cc_list = ','.join(email_cc)
@@ -133,10 +134,11 @@ class EmailSender(object):
report_suffix = '_report.html'
else:
report_suffix = '_report.txt'
- fd, fname = tempfile.mkstemp(suffix=report_suffix)
- os.write(fd, attachment.content)
- os.close(fd)
- attachment_files.append(fname)
+ with tempfile.NamedTemporaryFile(
+ 'w', encoding='utf-8', delete=False, suffix=report_suffix) as f:
+ f.write(attachment.content)
+ f.flush()
+ attachment_files.append(f.name)
files = ','.join(attachment_files)
command += " --attachment_files='%s'" % files
to_be_deleted += attachment_files