Path: ...!news.roellig-ltd.de!open-news-network.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Cameron Simpson Newsgroups: comp.lang.python Subject: Re: Printing UTF-8 mail to terminal Date: Sat, 2 Nov 2024 08:47:39 +1100 Lines: 23 Message-ID: References: <875xp7nwus.fsf@zedat.fu-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de aiGkdu7mnBlC+QpbtciATQM7CP9PzZlKXCabZx5ABdCg== Cancel-Lock: sha1:0D12DiuWhBmeStqJ0I7xYwzKgns= sha256:HzT96hZXHpHL9RF1EoAIDjF2IBOYjROoIoDVQ3LdPZI= Return-Path: 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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string': 0.07; 'cc:addr :python-list': 0.09; 'cc:no real name:2**0': 0.14; 'that.': 0.15; 'bennett': 0.16; 'conversion': 0.16; 'expected.': 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; 'objective': 0.16; 'presumably': 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; 'skip:> 10': 0.16; 'unicode': 0.16; 'wrote:': 0.16; 'python': 0.16; 'cc:addr:python.org': 0.20; 'cc:2**0': 0.25; 'object': 0.26; 'header:User-Agent:1': 0.30; 'question': 0.32; 'obtain': 0.32; 'header:In-Reply-To:1': 0.34; 'received:au': 0.35; '...': 0.37; 'necessary': 0.39; 'text': 0.39; 'otherwise': 0.39; 'still': 0.40; 'skip:m 20': 0.63; 'received:13': 0.64; 'received:userid': 0.66; 'body': 0.67; 'order': 0.69; 'subject:UTF': 0.91; 'subject:mail': 0.95; 'turned': 0.95 Mail-Followup-To: Loris Bennett , python-list@python.org Content-Disposition: inline In-Reply-To: <875xp7nwus.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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <875xp7nwus.fsf@zedat.fu-berlin.de> Bytes: 3770 On 01Nov2024 10:10, Loris Bennett wrote: >as expected. The non-UTF-8 text occurs when I do > > mail = EmailMessage() > mail.set_content(body, cte="quoted-printable") > ... > > if args.verbose: > print(mail) > >which is presumably also correct. > >The question is: What conversion is necessary in order to print the >EmailMessage object to the terminal, such that the quoted-printable >parts are turned (back) into UTF-8? Do you still have access to `body` ? That would be the original message text? Otherwise maybe: print(mail.get_content()) The objective is to obtain the message body Unicode text (i.e. a regular Python string with the original text, unencoded). And to print that.