Browse Source

Handle mailboxes with spaces

The IMAP4 protocol optionally uses double quoting when mailboxes contain
spaces. This is always allowed. So to fix this, first we use shlex to
perform double-quote-aware splitting (a bit like bash would split
command line arguments) and then we send folder names with quotes to the
IMAP server.

I tested this manually with a couple real IMAP servers.
pull/342/head
Leonardo Pistone 6 years ago
committed by Leonardo Pistone
parent
commit
9d1c5cf7b5
  1. 6
      mail_check_mailbox_size/models/fetchmail.py

6
mail_check_mailbox_size/models/fetchmail.py

@ -1,4 +1,5 @@
import logging
import shlex
from odoo import models, fields, api, _
_logger = logging.getLogger(__name__)
@ -53,12 +54,11 @@ class Fetchmail(models.Model):
number_of_messages_all = 0
size_all = 0
for item in list:
x = item.decode().split()
x = shlex.split(item.decode())
mailbox = x[-1]
# Select the desired folder
result, number_of_messages = imap_server.select(
mailbox, readonly=1)
'"{}"'.format(mailbox), readonly=1)
if result != 'OK':
_logger.info(
"Server %s responded %s for folder %s"

Loading…
Cancel
Save