Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This type of encoding is known as <a href="http://en.wikipedia.org/wiki/MIME#Encoded-Word" rel="noreferrer">MIME encoded-word</a> and the <a href="http://docs.python.org/library/email.html#module-email" rel="noreferrer">email</a> module can decode it:</p> <pre><code>from email.header import decode_header print decode_header("""=?UTF-8?B?IERyZWltb25hdHNmcmlzdCBmw7xyIFZlcnBmbGVndW5nc21laHJhdWZ3ZW5kdW4=?=""") </code></pre> <p>This outputs a list of tuples, containing the decoded string and the encoding used. This is because the format supports different encodings in a single header. To merge these into a single string you need to convert them into a shared encoding and then concatenate this, which can be accomplished using Python's unicode object:</p> <pre><code>from email.header import decode_header dh = decode_header("""[ 201105161048 ] GewSt:=?UTF-8?B?IFdlZ2ZhbGwgZGVyIFZvcmzDpHVmaWdrZWl0?=""") default_charset = 'ASCII' print ''.join([ unicode(t[0], t[1] or default_charset) for t in dh ]) </code></pre> <h2>Update 2:</h2> <p>The problem with this Subject line not decoding:</p> <pre><code>Subject: [ 201101251025 ] ELStAM;=?UTF-8?B?IFZlcmbDvGd1bmcgdm9tIDIx?=. Januar 2011 ^ </code></pre> <p>Is actually the senders fault, which violates the requirement of encoded-words in a header being separated by white-space, specified in <a href="http://tools.ietf.org/html/rfc2047#section-5" rel="noreferrer">RFC 2047, section 5, paragraph 1</a>: <em>an 'encoded-word' that appears in a header field defined as '*text' MUST be separated from any adjacent 'encoded-word' or 'text' by 'linear-white-space'.</em></p> <p>If need be, you can work around this by pre-processing these corrupt headers with a regex that inserts a whitespace after the encoded-word part (unless it's at the end), like so:</p> <pre><code>import re header_value = re.sub(r"(=\?.*\?=)(?!$)", r"\1 ", header_value) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload