{"action":"created","issue":{"url":"https://api.github.com/repos/mattupstate/flask-mail/issues/126","repository_url":"https://api.github.com/repos/mattupstate/flask-mail","labels_url":"https://api.github.com/repos/mattupstate/flask-mail/issues/126/labels{/name}","comments_url":"https://api.github.com/repos/mattupstate/flask-mail/issues/126/comments","events_url":"https://api.github.com/repos/mattupstate/flask-mail/issues/126/events","html_url":"https://github.com/mattupstate/flask-mail/issues/126","id":141989235,"number":126,"title":"Non-ascii SUBJECT and FROM turns into \" =?utf-8?b?\" even when charset is set to iso-8859-2","user":{"login":"zoltan-fedor","id":3887295,"avatar_url":"https://avatars.githubusercontent.com/u/3887295?v=3","gravatar_id":"","url":"https://api.github.com/users/zoltan-fedor","html_url":"https://github.com/zoltan-fedor","followers_url":"https://api.github.com/users/zoltan-fedor/followers","following_url":"https://api.github.com/users/zoltan-fedor/following{/other_user}","gists_url":"https://api.github.com/users/zoltan-fedor/gists{/gist_id}","starred_url":"https://api.github.com/users/zoltan-fedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zoltan-fedor/subscriptions","organizations_url":"https://api.github.com/users/zoltan-fedor/orgs","repos_url":"https://api.github.com/users/zoltan-fedor/repos","events_url":"https://api.github.com/users/zoltan-fedor/events{/privacy}","received_events_url":"https://api.github.com/users/zoltan-fedor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-18T22:04:23Z","updated_at":"2016-03-18T23:04:12Z","closed_at":null,"body":"Hi,\r\nSo this is an interesting one.\r\nI am trying to send email with a non-ascii subject line (Hungarian). The problem is that at the first non-ascii character the \" =?utf-8?\" string gets added - which is not a problem, but when the email client - both GMail and Yahoo Mail displays it that additional space is left there. So basically at random places there are spaces added to the subject line.\r\n\r\nSettings the encoding specifically to iso-8859-2 doesn't help, as it seems the UTF8 encodeded version always takes precendence.\r\n\r\nSending the email like this:\r\n```\r\n    app = current_app._get_current_object()\r\n    msg = Message(subject='Sikeres regisztracio es belepo a SF Kiallitasra (belépő)',\r\n                              sender=('SF Biztonságtechnikai Kiállítás & Konferencia', 'kiallitas@sf.com'),\r\n                              recipients=[('Fedoráéő Zoltan' , 'e@yahoo.com')],\r\n                              charset='iso-8859-2', bcc=[bcc])\r\n    msg.body = render_template((template + '.txt'), **kwargs).encode('iso-8859-2')\r\n    msg.html = render_template((template + '.html'), **kwargs).encode('iso-8859-2')\r\n    print(msg.charset)\r\n    thr = Thread(target=send_async_email, args=[app, msg])\r\n    thr.start()\r\n```\r\n\r\nThis is what flask-mail generates:\r\n`Content-Type: multipart/mixed; boundary=\"===============2657123796784931499==\"\\r\\nMIME-Version: 1.0\\r\\nSubject: Sikeres regisztracio es belepo az SF Kiallitasra (b\\r\\n =?utf-8?b?ZWzDqXDFkSk=?=\\r\\nFrom: SF =?utf-8?q?Biztons=C3=A1gtechnikai?=\\r\\n =?utf-8?b?S2nDoWxsw610w6Fz?= & Konferen cia <kiallitas@s.com>\\r\\nTo: =?iso-8859-2?q?Fedor=E1=E9=F5_Zoltan?= <e@yahoo.com>\\r\\nDate: Fri, 18 Mar 2016 22:50:40 +0100\\r\\nMessage-ID: <145833784033.2011.13923204934281192694@sf.com>\\r\\n\\r\\n--===============2657123796784931499==\\r\\nContent-Type: multipart/alternative;\\r\\n boundary=\"===============5571071455436956408==\"\\r\\nMIME-Version: 1.0\\r\\n\\r\\n--===============5571071455436956408==\\r\\nContent-Type: text/plain; charset=\"iso-8859-2\"\\r\\nMIME-Version: 1.0\\r\\nContent-Transfer-Encoding: quoted-printable\\r\\n\\r\\nTisztelt Fedor=E1=E9=F5 Zoltan etc`\r\n\r\nAs you can see, the funny thing is that the TO field correctly encoded with iso-8859-2, but the Subject and From is still encoded with utf-8. Those encodings are fine (if the client knows utf-8), but they added an additional \" =?utf-8?\", so after the client encoding it it will have an additional space/loses a space.\r\n\r\nSo in GMail and Yahoo Mail this will show like:\r\n\r\n> From: SF BiztonságtechnikaiKiállítás &amp; Konferen cia (kiallitas@sf.com)\r\n> To: Fedoráéő Zoltan (e@yahoo.com)\r\n> Subject: Sikeres regisztracio es belepo a SF Kiallitasra (b elépő)\r\n\r\n - observe the additional space in the subject \"(b elépő)\" and the additional and lost spaces in the \"FROM\" field.\r\n\r\n\r\nIf you look at the header above, then you can see that the reason why the TO is displaying correctly and the FROM and SUBJECT doesn't that the \"\\r\\n =?utf-8?b?\" is inserted mid-text and that additional space is sometimes adds a text to display, sometimes taken away.\r\n\r\nInteresting thing is that the flask_mail.py file's sanitize_subject() method correctly returns the iso-8859-r encoded version of the subject, but what makes into the email header is that utf8 encoded MIME version.\r\n\r\nAny idea how to actually use Flask-Mail to send international characters in the FROM and SUBJECT field without additional / lost spaces?\r\n"},"comment":{"url":"https://api.github.com/repos/mattupstate/flask-mail/issues/comments/198572911","html_url":"https://github.com/mattupstate/flask-mail/issues/126#issuecomment-198572911","issue_url":"https://api.github.com/repos/mattupstate/flask-mail/issues/126","id":198572911,"user":{"login":"zoltan-fedor","id":3887295,"avatar_url":"https://avatars.githubusercontent.com/u/3887295?v=3","gravatar_id":"","url":"https://api.github.com/users/zoltan-fedor","html_url":"https://github.com/zoltan-fedor","followers_url":"https://api.github.com/users/zoltan-fedor/followers","following_url":"https://api.github.com/users/zoltan-fedor/following{/other_user}","gists_url":"https://api.github.com/users/zoltan-fedor/gists{/gist_id}","starred_url":"https://api.github.com/users/zoltan-fedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zoltan-fedor/subscriptions","organizations_url":"https://api.github.com/users/zoltan-fedor/orgs","repos_url":"https://api.github.com/users/zoltan-fedor/repos","events_url":"https://api.github.com/users/zoltan-fedor/events{/privacy}","received_events_url":"https://api.github.com/users/zoltan-fedor/received_events","type":"User","site_admin":false},"created_at":"2016-03-18T23:04:12Z","updated_at":"2016-03-18T23:04:12Z","body":"ps, I am using Python 3.5.1"}}