Skip to content

Commit 99a7f9c

Browse files
committed
Python2/3 compatibility: Added force_str or force_bytes in some places, to ensure the argument right type
- Legacy-Id: 16453
1 parent a5e31c3 commit 99a7f9c

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

ietf/ipr/mail.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Copyright The IETF Trust 2014-2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from __future__ import absolute_import, print_function, unicode_literals
26

37
import base64
48
import email
@@ -9,7 +13,7 @@
913
import re
1014

1115
from django.template.loader import render_to_string
12-
from django.utils.encoding import force_text
16+
from django.utils.encoding import force_text, force_str
1317

1418
import debug # pyflakes:ignore
1519

@@ -171,7 +175,7 @@ def process_response_email(msg):
171175
a matching value in the reply_to field, associated to an IPR disclosure through
172176
IprEvent. Create a Message object for the incoming message and associate it to
173177
the original message via new IprEvent"""
174-
message = email.message_from_string(msg)
178+
message = email.message_from_string(force_str(msg))
175179
to = message.get('To')
176180

177181
# exit if this isn't a response we're interested in (with plus addressing)

ietf/message/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# Copyright The IETF Trust 2012-2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from __future__ import absolute_import, print_function, unicode_literals
6+
27
import re, datetime, email
38

4-
from ietf.utils.mail import send_mail_text, send_mail_mime
9+
from django.utils.encoding import force_str
10+
11+
from ietf.utils.mail import send_mail_text, send_mail_mime, get_payload
512
from ietf.message.models import Message
613

714
first_dot_on_line_re = re.compile(r'^\.', re.MULTILINE)
815

916
def infer_message(s):
10-
parsed = email.message_from_string(s)
17+
parsed = email.message_from_string(force_str(s))
1118

1219
m = Message()
1320
m.subject = parsed.get("Subject", "")
@@ -16,7 +23,7 @@ def infer_message(s):
1623
m.cc = parsed.get("Cc", "")
1724
m.bcc = parsed.get("Bcc", "")
1825
m.reply_to = parsed.get("Reply-To", "")
19-
m.body = parsed.get_payload()
26+
m.body = get_payload(parsed)
2027

2128
return m
2229

@@ -41,7 +48,7 @@ def send_scheduled_message_from_send_queue(send_queue):
4148
# make body a real message so we can parse it
4249
body = ("MIME-Version: 1.0\r\nContent-Type: %s\r\n" % message.content_type) + body
4350

44-
msg = email.message_from_string(body)
51+
msg = email.message_from_string(force_str(body))
4552
send_mail_mime(None, message.to, message.frm, message.subject,
4653
msg, cc=message.cc, bcc=message.bcc)
4754

ietf/submit/mail.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Copyright The IETF Trust 2013-2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from __future__ import absolute_import, print_function, unicode_literals
26

37
import re
48
import email
@@ -12,7 +16,7 @@
1216
from django.core.validators import ValidationError
1317
from django.contrib.sites.models import Site
1418
from django.template.loader import render_to_string
15-
from django.utils.encoding import force_text
19+
from django.utils.encoding import force_text, force_str
1620

1721
import debug # pyflakes:ignore
1822

@@ -186,7 +190,7 @@ def process_response_email(msg):
186190
a matching value in the reply_to field, associated to a submission.
187191
Create a Message object for the incoming message and associate it to
188192
the original message via new SubmissionEvent"""
189-
message = email.message_from_string(msg)
193+
message = email.message_from_string(force_str(msg))
190194
to = message.get('To')
191195

192196
# exit if this isn't a response we're interested in (with plus addressing)

0 commit comments

Comments
 (0)