Revert "Included charset detection"

This reverts commit 62490ff183.
This commit is contained in:
Joseph Ishac 2021-02-21 22:31:49 -05:00
parent 9e8e30794c
commit c8b275cdc3
2 changed files with 3 additions and 17 deletions

View File

@ -20,11 +20,9 @@ import socket
import time import time
import re import re
import os import os
from pathlib import Path
from sys import exc_info from sys import exc_info
from threading import Lock from threading import Lock
from hashlib import md5 from hashlib import md5
import chardet
from offlineimap import OfflineImapError, emailutil from offlineimap import OfflineImapError, emailutil
from .Base import BaseFolder from .Base import BaseFolder
@ -258,18 +256,11 @@ class MaildirFolder(BaseFolder):
def getmessage(self, uid): def getmessage(self, uid):
"""Return the content of the message.""" """Return the content of the message."""
# TODO: Perhaps, force the encoding using config file
filename = self.messagelist[uid]['filename'] filename = self.messagelist[uid]['filename']
filepath = os.path.join(self.getfullname(), filename) filepath = os.path.join(self.getfullname(), filename)
# Open the file as binary and read it file = open(filepath, 'rt')
file = Path(filepath) retval = file.read()
blob = file.read_bytes() file.close()
# Detect the encoding
detection = chardet.detect(blob)
encoding = detection["encoding"]
# Read the file as text
retval = blob.decode(encoding)
# TODO: WHY are we replacing \r\n with \n here? And why do we # TODO: WHY are we replacing \r\n with \n here? And why do we
# read it as text? # read it as text?
return retval.replace("\r\n", "\n") return retval.replace("\r\n", "\n")

View File

@ -3,8 +3,3 @@ gssapi[kerberos]
portalocker[cygwin] portalocker[cygwin]
rfc6555 rfc6555
distro distro
imaplib2~=3.5
urllib3~=1.25.9
certifi~=2020.6.20
chardet~=3.0.4