New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imaplib does not run under Python 3 #45551
Comments
imaplib does not run under Python 3. The following two-line python program, named testimap.py, import imaplib
mail=imaplib.IMAP4("mail.rtmq.infosathse.com") e:\python25\python testimap.py The last line produced the trace: Traceback (most recent call last):
File "testimap.py", line 10, in <module>
mail=imaplib.IMAP4("mail.rtmq.infosathse.com")
File "e:\python30\lib\imaplib.py", line 184, in __init__
self.welcome = self._get_response()
File "e:\python30\lib\imaplib.py", line 962, in _get_response
self._append_untagged(typ, dat)
File "e:\python30\lib\imaplib.py", line 800, in _append_untagged
if typ in ur:
TypeError: unhashable type: 'bytes' |
Would you like to work on a patch? |
Just to further understand the issue, I added "imaplib.Debug=5" and here 20:19.52 imaplib version 2.58 So it appears that the response is of type "bytes" which in turn is due I would like to see how the problem can be fixed but any pointers are |
I have gone through the python-3000 discussions about similar problems |
The transition is done. Can you work on a patch and maybe add some $ ./python -bb -c 'import imaplib; imaplib.Debug=5;
imaplib.IMAP4("mail.rtmq.infosathse.com")'
52:01.86 imaplib version 2.58
52:01.86 new IMAP4 connection, tag=PNFO
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/heimes/dev/python/py3k/Lib/imaplib.py", line 184, in __init__
self.welcome = self._get_response()
File "/home/heimes/dev/python/py3k/Lib/imaplib.py", line 907, in
_get_response
resp = self._get_line()
File "/home/heimes/dev/python/py3k/Lib/imaplib.py", line 1009, in
_get_line
self._mesg('< %s' % line)
File "/home/heimes/dev/python/py3k/Lib/warnings.py", line 62, in warn
globals)
File "/home/heimes/dev/python/py3k/Lib/warnings.py", line 102, in
warn_explicit
raise message
BytesWarning: str() on a bytes instance |
I will see what I can do but it may take a while. |
Index: Lib/imaplib.py --- Lib/imaplib.py (revision 58956)
+++ Lib/imaplib.py (working copy)
@@ -228,7 +228,7 @@
self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((host, port))
- self.file = self.sock.makefile('rb')
+ self.file = self.sock.makefile('r', encoding='ASCII', newline='')
def read(self, size): This patch fixes the issue but I am not entirely sure that it is As for the tests, we need a imap server to connect to. Perhaps, google |
You're correct in pointing out that IMAP4 supports arbitrary encodings, |
IMAP doesn't really support multiple charsets (just looked at RFC 3501). So probably setting the default encoding at this level isn't quite |
Is this still a problem? |
Still fails with beta2: >>> import imaplib
>>> mail=imaplib.IMAP4("mail.rtmq.infosathse.com")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.0/imaplib.py", line 185, in __init__
self.welcome = self._get_response()
File "/usr/local/lib/python3.0/imaplib.py", line 912, in _get_response
if self._match(self.tagre, resp):
File "/usr/local/lib/python3.0/imaplib.py", line 1021, in _match
self.mo = cre.match(s)
TypeError: can't use a string pattern on a bytes-like object |
This may not be a real release blocker, but I want to raise the |
This should be fixed but it's not a release blocker. |
Take a look at the thread here: http://mailman2.u.washington.edu/mailman/htdig/imap-protocol/2008-February/000811.html I think the summary is, arbitrary bytes may occur in some places, but |
Here is a patch for imaplib:
I choosed ISO-8859-1 as the default charset. I tested the library on |
Victor, what kind of content have you tried this with? For instance, have Bill On Tue, Oct 14, 2008 at 4:27 AM, STINNER Victor <report@bugs.python.org>wrote:
|
IMAP_stream() is also broken because it uses os.popen2() which has Here is a patch replacing os.popen2() by subprocess, but also using |
I only tried the most basic commands like capability(). I retried with Then I tried to get the content of an email but fetch(num, '(RFC822)') |
Maybe the first thing to do is to expand the Lib/test/test_imaplib.py Perhaps Python.org is running an IMAP server? |
The server can send raw 8 bits email in any charset (charset is Types used in my new patch:
I chooosed to keep unicode for some variables to minimize the changes Patch TODO:
I also wrote a patch for a "pure bytes string" version, but the patch |
New version of my bytes patch:
|
Oops, my previous patch didn't include changes to the documentation.
|
Can anyone review my last patch (imaplib_bytes-3.patch)? |
The assertion on line 813 is indented incorrectly. Please fix that. I'm concerned we really need better test coverage for this code, but Go ahead and land it after that minor fix. |
Le Tuesday 04 November 2008 00:59:02 Barry A. Warsaw, vous avez écrit :
Ooops. I'm using the following command because my editor is configured to The line 813 was an assertion. I added many assertions to check types (for |
Committed in r67107 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: