diff options
author | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-02-05 21:28:40 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-02-05 21:28:40 +0000 |
commit | cddd960b0ba2eb62c372c0d3176c75f0bd05d5e8 (patch) | |
tree | f592e7ccc058bdd6c0beda99a104df4f73c5e1d3 /cros_utils/email_sender.py | |
parent | 81bca172159b02808081a57062a1c61ee9c54d76 (diff) | |
parent | 3c0fcaf157c060979b09c0d8e7a982ff5d1acdab (diff) | |
download | toolchain-utils-cddd960b0ba2eb62c372c0d3176c75f0bd05d5e8.tar.gz |
Merging 8 commit(s) from Chromium's toolchain-utils am: 928fba9d74 am: cfb8763e2b am: 3c0fcaf157
Change-Id: Ie5c5dbcb6f4cfb497c32c3c73466e844ebf1dd6c
Diffstat (limited to 'cros_utils/email_sender.py')
-rwxr-xr-x | cros_utils/email_sender.py | 26 |
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 |