Rename account.folder into account.folders and make it a list

This commit is contained in:
Patrick Ulbrich
2015-04-03 18:53:04 +02:00
parent 52b0a03c03
commit 67fbc8fcdb
6 changed files with 40 additions and 40 deletions

View File

@@ -26,6 +26,7 @@ import poplib
import logging
import Mailnag.common.imaplib2 as imaplib
from Mailnag.common.i18n import _
from Mailnag.common.utils import splitstr
account_defaults = {
'enabled' : '0',
@@ -47,7 +48,7 @@ CREDENTIAL_KEY = 'Mailnag password for %s://%s@%s'
#
class Account:
def __init__(self, enabled = False, name = _('Unnamed'), user = '', \
password = '', oauth2string = '', server = '', port = '', ssl = True, imap = True, idle = True, folder = '' ):
password = '', oauth2string = '', server = '', port = '', ssl = True, imap = True, idle = True, folders = []):
self.enabled = enabled # bool
self.name = name
@@ -59,7 +60,7 @@ class Account:
self.ssl = ssl # bool
self.imap = imap # bool
self.idle = idle # bool
self.folder = folder
self.folders = folders
self._conn = None
@@ -87,7 +88,7 @@ class Account:
def get_id(self):
# TODO : this id is not really unique...
return str(hash(self.user + self.server + self.folder))
return str(hash(self.user + self.server + ', '.join(self.folders)))
def _has_IMAP_connection(self):
@@ -236,13 +237,13 @@ class AccountManager:
ssl = bool(int( self._get_account_cfg(cfg, section_name, 'ssl') ))
imap = bool(int( self._get_account_cfg(cfg, section_name, 'imap') ))
idle = bool(int( self._get_account_cfg(cfg, section_name, 'idle') ))
folder = self._get_account_cfg(cfg, section_name, 'folder')
folders = splitstr(self._get_account_cfg(cfg, section_name, 'folder'), ',')
if self._credentialstore != None:
protocol = 'imap' if imap else 'pop'
password = self._credentialstore.get(CREDENTIAL_KEY % (protocol, user, server))
acc = Account(enabled, name, user, password, '', server, port, ssl, imap, idle, folder)
acc = Account(enabled, name, user, password, '', server, port, ssl, imap, idle, folders)
self._accounts.append(acc)
i = i + 1
@@ -289,7 +290,7 @@ class AccountManager:
cfg.set(section_name, 'ssl', int(acc.ssl))
cfg.set(section_name, 'imap', int(acc.imap))
cfg.set(section_name, 'idle', int(acc.idle))
cfg.set(section_name, 'folder', acc.folder)
cfg.set(section_name, 'folder', ', '.join(acc.folders))
if self._credentialstore != None:
protocol = 'imap' if acc.imap else 'pop'

View File

@@ -3,7 +3,7 @@
#
# utils.py
#
# Copyright 2011 - 2014 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2011 - 2015 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2007 Marco Ferragina <marco.ferragina@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
@@ -56,6 +56,10 @@ def get_data_file(filename):
return None
def splitstr(strn, delimeter):
return [s.strip() for s in strn.split(delimeter) if s.strip()]
def fix_cwd():
# Change into local Mailnag source dir, where paths
# in dist_cfg.py point to (e.g. "./locale").

View File

@@ -3,7 +3,7 @@
#
# accountdialog.py
#
# Copyright 2011 - 2014 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2011 - 2015 Patrick Ulbrich <zulu99@gmx.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
from gi.repository import GLib, Gtk
from Mailnag.common.dist_cfg import PACKAGE_NAME
from Mailnag.common.i18n import _
from Mailnag.common.utils import get_data_file
from Mailnag.common.utils import get_data_file, splitstr
IDX_GMAIL = 0
IDX_GMX = 1
@@ -66,14 +66,14 @@ class AccountDialog:
self._entry_account_server = builder.get_object("entry_account_server")
self._label_account_port = builder.get_object("label_account_port")
self._entry_account_port = builder.get_object("entry_account_port")
self._label_account_folder = builder.get_object("label_account_folder")
self._entry_account_folder = builder.get_object("entry_account_folder")
self._label_account_folders = builder.get_object("label_account_folders")
self._entry_account_folders = builder.get_object("entry_account_folders")
self._chk_account_push = builder.get_object("chk_account_push")
self._chk_account_ssl = builder.get_object("chk_account_ssl")
self._button_save = builder.get_object("button_save")
self._entry_account_port.set_placeholder_text(_("optional"))
self._entry_account_folder.set_placeholder_text(_("optional"))
self._entry_account_folders.set_placeholder_text(_("optional"))
def run(self):
@@ -84,7 +84,7 @@ class AccountDialog:
self._entry_account_password.set_text(self._acc.password)
self._entry_account_server.set_text(self._acc.server)
self._entry_account_port.set_text(self._acc.port)
self._entry_account_folder.set_text(self._acc.folder)
self._entry_account_folders.set_text(', '.join(self._acc.folders))
self._chk_account_push.set_active(self._acc.idle)
self._chk_account_ssl.set_active(self._acc.ssl)
@@ -102,11 +102,11 @@ class AccountDialog:
if acctype == IDX_POP3:
self._acc.imap = False
self._acc.folder = ''
self._acc.folders = []
self._acc.idle = False
elif acctype == IDX_IMAP:
self._acc.imap = True
self._acc.folder = self._entry_account_folder.get_text()
self._acc.folders = splitstr(self._entry_account_folders.get_text(), ',')
self._acc.idle = self._chk_account_push.get_active()
else: # known provider (imap only)
@@ -115,7 +115,7 @@ class AccountDialog:
self._acc.password = self._entry_account_password.get_text()
self._acc.ssl = True
self._acc.imap = True
self._acc.folder = self._entry_account_folder.get_text()
self._acc.folders = splitstr(self._entry_account_folders.get_text(), ',')
self._acc.idle = not self._has_multiple_folders()
if acctype < len(PROVIDER_CONFIGS):
@@ -161,7 +161,7 @@ class AccountDialog:
def _has_multiple_folders(self):
return ("," in self._entry_account_folder.get_text())
return ("," in self._entry_account_folders.get_text())
def _on_btn_cancel_clicked(self, widget):
@@ -173,7 +173,7 @@ class AccountDialog:
def _on_entry_changed(self, widget):
if widget is self._entry_account_folder:
if widget is self._entry_account_folders:
# disable IMAP Push checkbox if multiple folders are specifed
if self._has_multiple_folders():
self._chk_account_push.set_active(False)
@@ -205,8 +205,8 @@ class AccountDialog:
self._entry_account_server.set_visible(True)
self._label_account_port.set_visible(True)
self._entry_account_port.set_visible(True)
self._label_account_folder.set_visible(False)
self._entry_account_folder.set_visible(False)
self._label_account_folders.set_visible(False)
self._entry_account_folders.set_visible(False)
self._chk_account_push.set_visible(False)
self._chk_account_ssl.set_visible(True)
elif acctype == IDX_IMAP:
@@ -216,8 +216,8 @@ class AccountDialog:
self._entry_account_server.set_visible(True)
self._label_account_port.set_visible(True)
self._entry_account_port.set_visible(True)
self._label_account_folder.set_visible(True)
self._entry_account_folder.set_visible(True)
self._label_account_folders.set_visible(True)
self._entry_account_folders.set_visible(True)
self._chk_account_push.set_visible(True)
self._chk_account_ssl.set_visible(True)
else: # known provider (imap only)
@@ -227,8 +227,8 @@ class AccountDialog:
self._entry_account_server.set_visible(False)
self._label_account_port.set_visible(False)
self._entry_account_port.set_visible(False)
self._label_account_folder.set_visible(True)
self._entry_account_folder.set_visible(True)
self._label_account_folders.set_visible(True)
self._entry_account_folders.set_visible(True)
self._chk_account_push.set_visible(False)
self._chk_account_ssl.set_visible(False)

View File

@@ -55,7 +55,7 @@ class Idler(object):
# Need to get out of AUTH mode of fresh connections.
if self._conn.state == AUTH:
self._select(self._conn, account.folder)
self._select(self._conn, account)
def start(self):
@@ -146,13 +146,12 @@ class Idler(object):
logging.info("Successfully reconnected Idler thread for account '%s'." % self._account.name)
if self._conn != None:
self._select(self._conn, self._account.folder)
self._select(self._conn, self._account)
def _select(self, conn, folder):
folder = folder.strip()
if len(folder) > 0:
conn.select(folder)
def _select(self, conn, account):
if len(account.folders) == 1:
conn.select(acount.folders[0])
else:
conn.select("INBOX")

View File

@@ -3,7 +3,7 @@
#
# mails.py
#
# Copyright 2011 - 2014 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2011 - 2015 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2011 Leighton Earl <leighton.earl@gmx.com>
# Copyright 2011 Ralf Hersel <ralf.hersel@gmx.net>
#
@@ -65,16 +65,12 @@ class MailCollector:
if srv == None:
continue
elif acc.imap: # IMAP
if len(acc.folder.strip()) == 0:
folder_list = ["INBOX"]
if len(acc.folders) == 0:
folder_list = [ 'INBOX' ]
else:
folder_list = acc.folder.split(',')
folder_list = acc.folders
for folder in folder_list:
folder = folder.strip()
if len(folder) == 0:
continue
# select IMAP folder
srv.select(folder, readonly = True)
try:

View File

@@ -133,7 +133,7 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_account_folder">
<object class="GtkEntry" id="entry_account_folders">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
@@ -259,7 +259,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="label_account_folder">
<object class="GtkLabel" id="label_account_folders">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>