Created
March 10, 2020 08:10
-
-
Save ilya-muhortov/5a32d639afa20b5c89831baed9ec0532 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re,base64, quopri | |
def encoded_words_to_text(encoded_words): | |
encoded_word_regex = r'=\?{1}(.+)\?{1}([B|Q])\?{1}(.+)\?{1}=' | |
charset, encoding, encoded_text = re.match(encoded_word_regex, encoded_words).groups() | |
if encoding is 'B': | |
byte_string = base64.b64decode(encoded_text) | |
elif encoding is 'Q': | |
byte_string = quopri.decodestring(encoded_text) | |
else: | |
raise ValueError | |
return byte_string.decode(charset) | |
print(encoded_words_to_text('=?UTF-8?B?0LLQtdGI0LjQstCw0L3QuNC1LlhMUw==?=')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment