coddingtonbear / django-mailbox

Import mail from POP3, IMAP, local email mailboxes or directly from Postfix or Exim4 into your Django application automatically.
MIT License
356 stars 164 forks source link

folders with spaces in the name #291

Closed enaut closed 3 months ago

enaut commented 3 months ago

I'd like to receive mails from the Junk Mail folder. However, when I try to get the messages from that mailbox, I get an error:

Request Method:     POST
Request URL:    http://127.0.0.1:8000/admin/django_mailbox/mailbox/
Django Version:     5.0.6
Exception Type:     error
Exception Value:    

SELECT command error: BAD [b"Unexpected value 'Mail'."]

Exception Location:     /usr/lib64/python3.12/imaplib.py, line 1055, in _command_complete

The URL I used:

imap+ssl://solawis-dev%40domain.de:repassword%5DN%2Ce9B@domain.de?archive=Archived&folder=Junk%20Mail

Should that work or am I using this wrong?

pfouque commented 3 months ago

Hi @enaut , As far as i can see, the issue is related to imaplib and It seems to be a pretty common issue. I didn't test but it seems you. have to quote the folder in the url when it contains spaces: ?archive=Archived&folder="Junk Mail". Once encoded properly it should give you an url like that: imap+ssl://solawis-dev%2540domain.de%3Arepassword%255DN%252Ce9B%40domain.de%3Farchive%3DArchived%26folder%3D%22Junk%20Mail%22

enaut commented 3 months ago

You were right but you encoded too much only the quotes need to be encoded not the equals sign and all the previous special characters:

imap+ssl://solawis-dev%40domain.de:repassword%5DN%2Ce9B@domain.de?archive=Archived&folder=%22Junk%20Mail%22