What do these '=?utf-8?' sequences mean in python?

Keith Thompson Keith.S.Thompson+u at gmail.com
Sun May 7 20:53:04 EDT 2023


Chris Green <cl at isbd.net> writes:
> Chris Green <cl at isbd.net> wrote:
>> I'm having a real hard time trying to do anything to a string (?)
>> returned by mailbox.MaildirMessage.get().
>> 
> What a twit I am :-)
>
> Strings are immutable, I have to do:-
>
>     newstring = oldstring.replace("_", " ")
>
> Job done!

Not necessarily.

The subject in the original article was:
=?utf-8?Q?aka_Marne_=C3=A0_la_Sa=C3=B4ne_(Waterways_Continental_Europe)?=

That's some kind of MIME encoding.  Just replacing underscores by spaces
won't necessarily give you anything meaningful.  (What if there are
actual underscores in the original subject line?)

You should probably apply some kind of MIME-specific decoding.  (I don't
have a specific suggestion for how to do that.)

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u at gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */


More information about the Python-list mailing list