Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Over the shoulder supervision is more a need of the manager than the programming task.


devel / comp.lang.python / Re: Decoding of EmailMessage text

SubjectAuthor
* Decoding of EmailMessage textLoris Bennett
`* Re: Decoding of EmailMessage textLoris Bennett
 `* Re: Decoding of EmailMessage textJon Ribbens
  `* Re: Decoding of EmailMessage textLoris Bennett
   `* Re: Decoding of EmailMessage textjak
    `- Re: Decoding of EmailMessage textLoris Bennett

1
Decoding of EmailMessage text

<87wnocy17a.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14721&group=comp.lang.python#14721

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Decoding of EmailMessage text
Date: Mon, 23 Aug 2021 11:12:09 +0200
Organization: Freie Universitaet Berlin
Lines: 56
Message-ID: <87wnocy17a.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 5TnwaIwyrGPeQHcx8WPAUAA5Aox+YxVGbWhcMMQtZ6uVKZ
Cancel-Lock: sha1:OVXNbVXNThUQpgznznGJh8e8nWI=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Mon, 23 Aug 2021 09:12 UTC

Hi,

I have written a command-line program to send email using

from email.message import EmailMessage

which has an option '--verbose' which prints the email via

if args.verbose:
print(f"{mail.as_string()}")

If I run this with

$ poetry run send_email loris -l en -s "Another test" -t ~/tmp/blorp_bleep.txt --verbose

the following is printed to the terminal:

Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
MIME-Version: 1.0
From: hpc@zedat.fu-berlin.de
To: loris@zedat.fu-berlin.de
Subject: Another test

RGVhciBEci4gQmVubmV0dCwKCkJsb3JwISBCbGVlcCEKCgotLQpNYWlsYm90IEluYy4KMDEwMTAx │
IEJvdCBCb3VsZXZhcmQKQm90aGFtIENpdHkKQsO2dGxhbmQK

However I would like to see the text as

Dear Dr. Bennett,

Blorp! Bleep!

Regards,

Mailbot

--
Mailbot Inc.
010101 Bot Boulevard
Botham City
Bötland

which is how the text appears in the mail.

The 'ö' in 'Bötland' triggers the encoding - with 'Botland' the text
printed to the terminal is the same way as that in the mail.

How do I decode the message properly for an terminal which uss UTF-8?

Regards

Loris

--
This signature is currently under construction.

Re: Decoding of EmailMessage text

<87o89oxyzj.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14723&group=comp.lang.python#14723

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Decoding of EmailMessage text
Date: Mon, 23 Aug 2021 12:00:00 +0200
Organization: Freie Universitaet Berlin
Lines: 200
Message-ID: <87o89oxyzj.fsf@hornfels.zedat.fu-berlin.de>
References: <87wnocy17a.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de NVKtgIV6IShz4/fMn5lYwAVA0yAPw13GwcaNEFxVToNhmV
Cancel-Lock: sha1:BkItp1Psc+hAHMNe3nwqBitigV0=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Mon, 23 Aug 2021 10:00 UTC

"Loris Bennett" <loris.bennett@fu-berlin.de> writes:

> Hi,
>
> I have written a command-line program to send email using
>
> from email.message import EmailMessage
>
> which has an option '--verbose' which prints the email via
>
> if args.verbose:
> print(f"{mail.as_string()}")
>
> If I run this with
>
> $ poetry run send_email loris -l en -s "Another test" -t ~/tmp/blorp_bleep.txt --verbose
>
> the following is printed to the terminal:
>
> Content-Type: text/plain; charset="utf-8"
> Content-Transfer-Encoding: base64
> MIME-Version: 1.0
> From: hpc@zedat.fu-berlin.de
> To: loris@zedat.fu-berlin.de
> Subject: Another test
>
> RGVhciBEci4gQmVubmV0dCwKCkJsb3JwISBCbGVlcCEKCgotLQpNYWlsYm90IEluYy4KMDEwMTAx │
> IEJvdCBCb3VsZXZhcmQKQm90aGFtIENpdHkKQsO2dGxhbmQK
>
> However I would like to see the text as
>
> Dear Dr. Bennett,
>
> Blorp! Bleep!
>
> Regards,
>
> Mailbot
>
> --
> Mailbot Inc.
> 010101 Bot Boulevard
> Botham City
> Bötland
>
> which is how the text appears in the mail.
>
> The 'ö' in 'Bötland' triggers the encoding - with 'Botland' the text
> printed to the terminal is the same way as that in the mail.
>
> How do I decode the message properly for an terminal which uss UTF-8?

If I do

From: "Loris Bennett" <loris.bennett@fu-berlin.de>
Newsgroups: comp.lang.python
Subject: Re: Decoding of EmailMessage text
Gcc: "nnimap+fu_exchange:Gesendete Elemente"
--text follows this line--
"Loris Bennett" <loris.bennett@fu-berlin.de> writes:

> Hi,
>
> I have written a command-line program to send email using
>
> from email.message import EmailMessage
>
> which has an option '--verbose' which prints the email via
>
> if args.verbose:
> print(f"{mail.as_string()}")
>
> If I run this with
>
> $ poetry run send_email loris -l en -s "Another test" -t ~/tmp/blorp_bleep.txt --verbose
>
> the following is printed to the terminal:
>
> Content-Type: text/plain; charset="utf-8"
> Content-Transfer-Encoding: base64
> MIME-Version: 1.0
> From: hpc@zedat.fu-berlin.de
> To: loris@zedat.fu-berlin.de
> Subject: Another test
>
> RGVhciBEci4gQmVubmV0dCwKCkJsb3JwISBCbGVlcCEKCgotLQpNYWlsYm90IEluYy4KMDEwMTAx │
> IEJvdCBCb3VsZXZhcmQKQm90aGFtIENpdHkKQsO2dGxhbmQK
>
> However I would like to see the text as
>
> Dear Dr. Bennett,
>
> Blorp! Bleep!
>
> Regards,
>
> Mailbot
>
> --
> Mailbot Inc.
> 010101 Bot Boulevard
> Botham City
> Bötland
>
> which is how the text appears in the mail.
>
> The 'ö' in 'Bötland' triggers the encoding - with 'Botland' the text
> printed to the terminal is the same way as that in the mail.
>
> How do I decode the message properly for an terminal which uss UTF-8?

If I do

From: "Loris Bennett" <loris.bennett@fu-berlin.de>
Newsgroups: comp.lang.python
Subject: Re: Decoding of EmailMessage text
Gcc: "nnimap+fu_exchange:Gesendete Elemente"
--text follows this line--
"Loris Bennett" <loris.bennett@fu-berlin.de> writes:

> Hi,
>
> I have written a command-line program to send email using
>
> from email.message import EmailMessage
>
> which has an option '--verbose' which prints the email via
>
> if args.verbose:
> print(f"{mail.as_string()}")
>
> If I run this with
>
> $ poetry run send_email loris -l en -s "Another test" -t ~/tmp/blorp_bleep.txt --verbose
>
> the following is printed to the terminal:
>
> Content-Type: text/plain; charset="utf-8"
> Content-Transfer-Encoding: base64
> MIME-Version: 1.0
> From: hpc@zedat.fu-berlin.de
> To: loris@zedat.fu-berlin.de
> Subject: Another test
>
> RGVhciBEci4gQmVubmV0dCwKCkJsb3JwISBCbGVlcCEKCgotLQpNYWlsYm90IEluYy4KMDEwMTAx │
> IEJvdCBCb3VsZXZhcmQKQm90aGFtIENpdHkKQsO2dGxhbmQK
>
> However I would like to see the text as
>
> Dear Dr. Bennett,
>
> Blorp! Bleep!
>
> Regards,
>
> Mailbot
>
> --
> Mailbot Inc.
> 010101 Bot Boulevard
> Botham City
> Bötland
>
> which is how the text appears in the mail.
>
> The 'ö' in 'Bötland' triggers the encoding - with 'Botland' the text
> printed to the terminal is the same way as that in the mail.
>
> How do I decode the message properly for an terminal which uss UTF-8?

If instead of

mail.set_content(body)

I do

mail.set_content(body, cte="quoted-printable")

then I get

Dear Dr. Bennett,

Blorp! Bleep!

--
Mailbot Inc.
010101 Bot Boulevard
Botham City
B=C3=B6tland

That a bit better, but still not what I want since the main text could
also be in German and thus also contain umlauts, etc.

Cheers,

Loris

--
This signature is currently under construction.

Re: Decoding of EmailMessage text

<slrnsi70a7.78u.jon+usenet@raven.unequivocal.eu>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14724&group=comp.lang.python#14724

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Decoding of EmailMessage text
Date: Mon, 23 Aug 2021 11:06:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <slrnsi70a7.78u.jon+usenet@raven.unequivocal.eu>
References: <87wnocy17a.fsf@hornfels.zedat.fu-berlin.de>
<87o89oxyzj.fsf@hornfels.zedat.fu-berlin.de>
Injection-Date: Mon, 23 Aug 2021 11:06:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c73626523969d525f0f5a21063e453ad";
logging-data="25616"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195tROaEgdtCQR8EgP3CtZbo5PBPeIG3SA="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Igh8u0vvcjUHT/ylDzv2v7Luv9Q=
 by: Jon Ribbens - Mon, 23 Aug 2021 11:06 UTC

On 2021-08-23, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
> If instead of
>
> mail.set_content(body)
>
> I do
>
> mail.set_content(body, cte="quoted-printable")

Try print(mail.get_content()) rather than print(mail.as_string())

Re: Decoding of EmailMessage text

<87fsv0xvly.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14725&group=comp.lang.python#14725

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Decoding of EmailMessage text
Date: Mon, 23 Aug 2021 13:12:57 +0200
Organization: Freie Universitaet Berlin
Lines: 21
Message-ID: <87fsv0xvly.fsf@hornfels.zedat.fu-berlin.de>
References: <87wnocy17a.fsf@hornfels.zedat.fu-berlin.de>
<87o89oxyzj.fsf@hornfels.zedat.fu-berlin.de>
<slrnsi70a7.78u.jon+usenet@raven.unequivocal.eu>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de bjkeKOMd0X2SbKoMhnsO0w9Jq6it8krZXXNfsXkr8R5+uF
Cancel-Lock: sha1:L8/PjQsRUoatKTm1M91uvL66g4o=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Mon, 23 Aug 2021 11:12 UTC

Jon Ribbens <jon+usenet@unequivocal.eu> writes:

> On 2021-08-23, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>> If instead of
>>
>> mail.set_content(body)
>>
>> I do
>>
>> mail.set_content(body, cte="quoted-printable")
>
> Try print(mail.get_content()) rather than print(mail.as_string())

That did the trick - thanks!

Cheers,

Loris

--
This signature is currently under construction.

Re: Decoding of EmailMessage text

<sg18vf$9a4$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14731&group=comp.lang.python#14731

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!aMvPw28RRDodSZuR2p5vSA.user.46.165.242.91.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.python
Subject: Re: Decoding of EmailMessage text
Date: Tue, 24 Aug 2021 00:54:40 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sg18vf$9a4$1@gioia.aioe.org>
References: <87wnocy17a.fsf@hornfels.zedat.fu-berlin.de>
<87o89oxyzj.fsf@hornfels.zedat.fu-berlin.de>
<slrnsi70a7.78u.jon+usenet@raven.unequivocal.eu>
<87fsv0xvly.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="9540"; posting-host="aMvPw28RRDodSZuR2p5vSA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: it
 by: jak - Mon, 23 Aug 2021 22:54 UTC

Il 23/08/2021 13:12, Loris Bennett ha scritto:
> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>
>> On 2021-08-23, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>>> If instead of
>>>
>>> mail.set_content(body)
>>>
>>> I do
>>>
>>> mail.set_content(body, cte="quoted-printable")
>>
>> Try print(mail.get_content()) rather than print(mail.as_string())
>
> That did the trick - thanks!
>
> Cheers,
>
> Loris
>

If you also want to know about the text, then that is probably utf8
encoded and converted to base64:

from base64 import b64decode

coded=(b'RGVhciBEci4gQmVubmV0dCwKCkJsb3JwISBCbGVlcCEKCgotLQpNYWlsYm90IEl'
b'uYy4KMDEwMTAxIEJvdCBCb3VsZXZhcmQKQm90aGFtIENpdHkKQsO2dGxhbmQK')

uncoded = b64decode(coded).decode('utf8')
print(uncoded)

output:

Dear Dr. Bennett,

Blorp! Bleep!

--
Mailbot Inc.
010101 Bot Boulevard
Botham City
Bötland

Re: Decoding of EmailMessage text

<875yvv5rl0.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14733&group=comp.lang.python#14733

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.be...@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Decoding of EmailMessage text
Date: Tue, 24 Aug 2021 07:39:39 +0200
Organization: Freie Universitaet Berlin
Lines: 57
Message-ID: <875yvv5rl0.fsf@hornfels.zedat.fu-berlin.de>
References: <87wnocy17a.fsf@hornfels.zedat.fu-berlin.de>
<87o89oxyzj.fsf@hornfels.zedat.fu-berlin.de>
<slrnsi70a7.78u.jon+usenet@raven.unequivocal.eu>
<87fsv0xvly.fsf@hornfels.zedat.fu-berlin.de>
<sg18vf$9a4$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de mZUhvQi5fab3jkTPDpQYKAvh5z3QQXx3JxUmqNqx9jWj5c
Cancel-Lock: sha1:VbQEWlxSG/dF+5VXoD4dj7jQSoE=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Tue, 24 Aug 2021 05:39 UTC

jak <nospam@please.ty> writes:

> Il 23/08/2021 13:12, Loris Bennett ha scritto:
>> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>>
>>> On 2021-08-23, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>>>> If instead of
>>>>
>>>> mail.set_content(body)
>>>>
>>>> I do
>>>>
>>>> mail.set_content(body, cte="quoted-printable")
>>>
>>> Try print(mail.get_content()) rather than print(mail.as_string())
>>
>> That did the trick - thanks!
>>
>> Cheers,
>>
>> Loris
>>
>
>
> If you also want to know about the text, then that is probably utf8
> encoded and converted to base64:
>
> from base64 import b64decode
>
> coded=(b'RGVhciBEci4gQmVubmV0dCwKCkJsb3JwISBCbGVlcCEKCgotLQpNYWlsYm90IEl'
> b'uYy4KMDEwMTAxIEJvdCBCb3VsZXZhcmQKQm90aGFtIENpdHkKQsO2dGxhbmQK')
>
> uncoded = b64decode(coded).decode('utf8')
> print(uncoded)
>
> output:
>
> Dear Dr. Bennett,
>
> Blorp! Bleep!
>
>
> --
> Mailbot Inc.
> 010101 Bot Boulevard
> Botham City
> Bötland

Thanks! I don't need that right now, but it's good to know which
decoding hoop I would have to jump through, if I did.

Cheers,

Loris

--
This signature is currently under construction.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor