Merge "Resolved encoding/decoding problem."
This commit is contained in:
commit
188d497959
@ -15,18 +15,19 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from email.header import Header
|
||||
from email.mime import text
|
||||
|
||||
import json
|
||||
import requests
|
||||
import smtplib
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from mistral.actions import base
|
||||
from mistral import exceptions as exc
|
||||
from mistral.utils import javascript
|
||||
from mistral.utils import ssh_utils
|
||||
from mistral.workflow import utils as wf_utils
|
||||
from oslo_log import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -286,9 +287,8 @@ class SendEmailAction(base.Action):
|
||||
(self.sender, self.to, self.subject,
|
||||
self.smtp_server, self.body[:128]))
|
||||
|
||||
# TODO(dzimine): handle utf-8, http://stackoverflow.com/a/14506784
|
||||
message = text.MIMEText(self.body)
|
||||
message['Subject'] = self.subject
|
||||
message = text.MIMEText(self.body, _charset='utf-8')
|
||||
message['Subject'] = Header(self.subject, 'utf-8')
|
||||
message['From'] = self.sender
|
||||
message['To'] = self.to
|
||||
|
||||
|
@ -14,8 +14,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import base64
|
||||
from email.header import decode_header
|
||||
from email import parser
|
||||
import mock
|
||||
import six
|
||||
import testtools
|
||||
|
||||
from mistral.actions import std_actions as std
|
||||
@ -103,8 +106,26 @@ class SendEmailActionTest(base.BaseTest):
|
||||
|
||||
self.assertEqual(self.from_addr, message['from'])
|
||||
self.assertEqual(self.to_addrs_str, message['to'])
|
||||
self.assertEqual(self.subject, message['subject'])
|
||||
self.assertEqual(self.body, message.get_payload())
|
||||
if six.PY3:
|
||||
self.assertEqual(
|
||||
self.subject,
|
||||
decode_header(message['subject'])[0][0].decode('utf-8')
|
||||
)
|
||||
else:
|
||||
self.assertEqual(
|
||||
self.subject.decode('utf-8'),
|
||||
decode_header(message['subject'])[0][0].decode('utf-8')
|
||||
)
|
||||
if six.PY3:
|
||||
self.assertEqual(
|
||||
self.body,
|
||||
base64.b64decode(message.get_payload()).decode('utf-8')
|
||||
)
|
||||
else:
|
||||
self.assertEqual(
|
||||
self.body.decode('utf-8'),
|
||||
base64.b64decode(message.get_payload()).decode('utf-8')
|
||||
)
|
||||
|
||||
@mock.patch('smtplib.SMTP')
|
||||
def test_with_password(self, smtp):
|
||||
|
Loading…
Reference in New Issue
Block a user