Browse Source

[IMP] fetchmail_attach_from_folder. Show available folders.

Also do not reset connection status on change of underlying folders.
pull/1317/merge
Ronald Portier 7 years ago
committed by Holger Brunn
parent
commit
d0e10233e4
  1. 36
      fetchmail_attach_from_folder/models/fetchmail_server.py
  2. 4
      fetchmail_attach_from_folder/views/fetchmail_server.xml

36
fetchmail_attach_from_folder/models/fetchmail_server.py

@ -2,6 +2,7 @@
# Copyright - 2013-2018 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
import re
import simplejson
from lxml import etree
@ -12,10 +13,41 @@ from odoo.tools.misc import UnquoteEvalContext
_logger = logging.getLogger(__name__)
list_response_pattern = re.compile(
r'\((?P<flags>.*?)\) "(?P<delimiter>.*)" (?P<name>.*)')
class FetchmailServer(models.Model):
_inherit = 'fetchmail.server'
@api.multi
def _compute_folders_available(self):
"""Retrieve available folders from IMAP server."""
def parse_list_response(line):
flags, delimiter, mailbox_name = \
list_response_pattern.match(line).groups()
mailbox_name = mailbox_name.strip('"')
return (flags, delimiter, mailbox_name)
for this in self:
if this.state != 'done':
this.folders_available = _('Confirm connection first.')
continue
connection = this.connect()
list_result = connection.list()
if list_result[0] != 'OK':
this.folders_available = _('Unable to retrieve folders.')
continue
folders_available = []
for folder_entry in list_result[1]:
folders_available.append(parse_list_response(folder_entry)[2])
this.folders_available = '\n'.join(folders_available)
connection.logout()
folders_available = fields.Text(
string='Available folders',
compute='_compute_folders_available',
readonly=True)
folder_ids = fields.One2many(
comodel_name='fetchmail.server.folder',
inverse_name='server_id',
@ -33,10 +65,6 @@ class FetchmailServer(models.Model):
super(FetchmailServer, self).onchange_server_type()
self.state = 'draft'
@api.onchange('folder_ids')
def onchange_folder_ids(self):
self.onchange_server_type()
@api.multi
def fetch_mail(self):
for this in self:

4
fetchmail_attach_from_folder/views/fetchmail_server.xml

@ -78,6 +78,10 @@
</form>
</field>
</group>
<separator
string="Folders available on server"
colspan="6" />
<field name="folders_available" />
</page>
</xpath>
</field>

Loading…
Cancel
Save