Deutsch   English   Français   Italiano  
<mailman.63.1730408232.4695.python-list@python.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: Cameron Simpson <cs@cskk.id.au>
Newsgroups: comp.lang.python
Subject: Re: Printing UTF-8 mail to terminal
Date: Fri, 1 Nov 2024 07:50:56 +1100
Lines: 39
Message-ID: <mailman.63.1730408232.4695.python-list@python.org>
References: <878qu49tii.fsf@zedat.fu-berlin.de>
 <ZyPtsLSme7IJ-q4j@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de eueGt4p5U65xaq1mR8PxNAhtC0RlZedJTp6w3TONyGkA==
Cancel-Lock: sha1:fwqPqU8xHCjdYBXm0N4qn+ayPuQ= sha256:moixbWxwXl21haXc1zVE1B3IysyZvGPuDX9r7sF0a0c=
Return-Path: <cameron@cskk.id.au>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
 dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'looks': 0.02;
 'containing': 0.05; 'utf-8': 0.07; 'cc:addr:python-list': 0.09;
 'module:': 0.09; 'parse': 0.09; 'terminal': 0.09; 'cheers,': 0.11;
 'cc:no real name:2**0': 0.14; 'bennett': 0.16; 'cameron': 0.16;
 'command-line': 0.16; 'dies': 0.16; 'directly,': 0.16; 'displays':
 0.16; 'encoding': 0.16; 'encoding.': 0.16; 'far,': 0.16;
 'from:addr:cs': 0.16; 'from:addr:cskk.id.au': 0.16;
 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net':
 0.16; 'received:13.237': 0.16; 'received:13.237.201': 0.16;
 'received:13.237.201.189': 0.16; 'received:cskk.id.au': 0.16;
 'received:id.au': 0.16; 'received:mail.cskk.id.au': 0.16;
 'simpson': 0.16; 'stdlib': 0.16; 'undo': 0.16; 'unicode': 0.16;
 'wrote:': 0.16; 'python': 0.16; 'probably': 0.17;
 'cc:addr:python.org': 0.20; 'option': 0.20; 'creates': 0.22;
 "i'd": 0.24; 'cc:2**0': 0.25; 'binary': 0.26; 'object': 0.26;
 'expect': 0.28; 'header:User-Agent:1': 0.30; 'module': 0.31;
 'program': 0.32; 'good.': 0.32; 'header:In-Reply-To:1': 0.34;
 'received:au': 0.35; 'using': 0.37; 'url-ip:151.101.0.223/32':
 0.38; 'url-ip:151.101.128.223/32': 0.38; 'url-
 ip:151.101.192.223/32': 0.38; 'url-ip:151.101.64.223/32': 0.38;
 '8bit%:14': 0.38; 'use': 0.39; 'text': 0.39; 'happen': 0.40;
 'subject': 0.63; 'email': 0.63; 'your': 0.64; 'german': 0.64;
 'imagine': 0.64; 'received:13': 0.64; 'receiving': 0.66;
 'received:userid': 0.66; 'body': 0.67; 'prevent': 0.67; 'ist':
 0.69; 'transport': 0.69; 'dr.': 0.77; 'client': 0.82; 'mail,':
 0.91; 'subject:UTF': 0.91; 'skip:\xc3 10': 0.95; 'subject:mail':
 0.95
Mail-Followup-To: Loris Bennett <loris.bennett@fu-berlin.de>,
 python-list@python.org
Content-Disposition: inline
In-Reply-To: <878qu49tii.fsf@zedat.fu-berlin.de>
User-Agent: Mutt/2.2.13 (2024-03-09)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
 <python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
 <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
 <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <ZyPtsLSme7IJ-q4j@cskk.homeip.net>
X-Mailman-Original-References: <878qu49tii.fsf@zedat.fu-berlin.de>
Bytes: 4932

On 31Oct2024 16:33, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>I have a command-line program which creates an email containing German
>umlauts.  On receiving the mail, my mail client displays the subject and
>body correctly:
[...]
>So far, so good.  However, when I use the --verbose option to print
>the mail to the terminal via
>
>  if args.verbose:
>      print(mail)
>
>I get:
>
>  Subject: Übungsbetreff
>
>  Sehr geehrter Herr Dr. Bennett,
>
>  Dies ist eine =C3=9Cbung.
>
>What do I need to do to prevent the body from getting mangled?

That looks to me like quoted-printable. This is an encoding for binary 
transport of text to make it robust against not 8-buit clean transports.  
So your Unicode text is encodings as UTF-8, and then that is encoded in 
quoted-printable for transport through the email system.

Your terminal probably accepts UTF-8 - I imagine other German text 
renders corectly?

You need to get the text and undo the quoted-printable encoding.

If you're using the Python email module to parse (or construct) the 
message as a `Message` object I'd expect that to happen automatically.

If you're just dealing with this directly, use the `quopri` stdlib 
module: https://docs.python.org/3/library/quopri.html

Cheers,
Cameron Simpson <cs@cskk.id.au>