def init(self): with self._lock: if self._disposed: raise InvalidOperationException("Daemon has been disposed") if self._initialized: raise InvalidOperationException( "Daemon has already been initialized") self._cfg = read_cfg() accountman = AccountManager() accountman.load_from_cfg(self._cfg, enabled_only=True) self._accounts = accountman.to_list() self._hookreg = HookRegistry() self._conntest = ConnectivityTest(testmode_mapping[self._cfg.get( 'core', 'connectivity_test')]) memorizer = Memorizer() memorizer.load() self._mailchecker = MailChecker(self._cfg, memorizer, self._hookreg, self._conntest) # Note: all code following _load_plugins() should be executed # asynchronously because the dbus plugin requires an active mainloop # (usually started in the programs main function). self._load_plugins(self._cfg, self._hookreg, memorizer) # Start checking for mails asynchronously. self._start_thread = threading.Thread(target=self._start) self._start_thread.start() self._initialized = True
def test_imap_config_values_should_be_stored(): am = AccountManager() option_spec = get_mailbox_parameter_specs('imap') options = { 'user': '******', 'password': '', 'server': 'imap.example.org', 'port': '', 'ssl': True, 'imap': True, 'idle': True, 'folders': ['a', 'b'], } config = RawConfigParser() config.add_section('account1') am._set_cfg_options(config, 'account1', options, option_spec) expected_config_items = [ ('user', 'you'), ('password', ''), ('server', 'imap.example.org'), ('port', ''), ('ssl', '1'), ('imap', '1'), ('idle', '1'), ('folder', '["a", "b"]'), ] assert set(expected_config_items) == set(config.items('account1'))
def test_load_from_config(config): am = AccountManager() am.load_from_cfg(config, enabled_only=False) accounts = am.to_list() assert len(accounts) == 6 imap_account = get_account(am.to_list(), 'IMAP mailbox config') pop3_account = get_account(am.to_list(), 'POP3 mailbox config') assert imap_account.get_config()['password'] == 'drowssap' assert pop3_account.get_config()['password'] == 'poppoppop'
def test_save_removed_accounts_to_config_with_credential_store(config): cs = FakeCredentialStore() cs.set('Mailnag password for imap://[email protected]', 'verry seecret') cs.set('Mailnag password for pop://[email protected]', 'seecret too') am = AccountManager(cs) am.load_from_cfg(config, enabled_only=False) am.clear() am.save_to_cfg(config) assert len(config.sections()) == 0 assert cs.secrets == {}
def test_load_from_config_with_credential_store(config): cs = FakeCredentialStore() cs.set('Mailnag password for imap://[email protected]', 'verry seecret') cs.set('Mailnag password for pop://[email protected]', 'seecret too') am = AccountManager(cs) am.load_from_cfg(config, enabled_only=False) accounts = am.to_list() assert len(accounts) == 6 imap_account = get_account(am.to_list(), 'IMAP mailbox config') pop3_account = get_account(am.to_list(), 'POP3 mailbox config') assert imap_account.get_config()['password'] == 'verry seecret' assert pop3_account.get_config()['password'] == 'seecret too'
def test_pop3_config_defaults(config): am = AccountManager() option_spec = get_mailbox_parameter_specs('pop3') options = am._get_cfg_options(config, 'account3', option_spec) expected_options = { 'user': '', 'password': '', 'server': '', 'port': '', 'ssl': True, 'imap': False, 'idle': False, } assert expected_options == options
def test_imap_config_options(config): am = AccountManager() option_spec = get_mailbox_parameter_specs('imap') options = am._get_cfg_options(config, 'account1', option_spec) expected_options = { 'user': '******', 'password': '******', 'server': 'imap.example.org', 'port': '', 'ssl': True, 'imap': True, 'idle': True, 'folders': [], } assert expected_options == options
def __init__(self, fatal_error_handler=None, shutdown_request_handler=None): self._fatal_error_handler = fatal_error_handler self._shutdown_request_handler = shutdown_request_handler self._plugins = [] self._poll_thread = None self._poll_thread_stop = threading.Event() self._idlrunner = None self._disposed = False self._cfg = read_cfg() accountman = AccountManager() accountman.load_from_cfg(self._cfg, enabled_only=True) self._accounts = accountman.to_list() self._hookreg = HookRegistry() self._conntest = ConnectivityTest(testmode_mapping[self._cfg.get( 'core', 'connectivity_test')]) self._memorizer = Memorizer() self._memorizer.load() dbus_service = DBusService(self) self._mailchecker = MailChecker(self._cfg, self._memorizer, self._hookreg, self._conntest, dbus_service) # Note: all code following _load_plugins() should be executed # asynchronously because the dbus plugin requires an active mainloop # (usually started in the programs main function). self._load_plugins(self._cfg) # Start checking for mails asynchronously. self._start_thread = threading.Thread(target=self._start) self._start_thread.start()
def __init__(self, app): builder = Gtk.Builder() builder.set_translation_domain(PACKAGE_NAME) builder.add_from_file(get_data_file("config_window.ui")) builder.connect_signals({ \ "config_window_deleted" : self._on_config_window_deleted, \ "btn_info_clicked" : self._on_btn_info_clicked, \ "btn_add_account_clicked" : self._on_btn_add_account_clicked, \ "btn_edit_account_clicked" : self._on_btn_edit_account_clicked, \ "btn_remove_account_clicked" : self._on_btn_remove_account_clicked, \ "treeview_accounts_row_activated" : self._on_treeview_accounts_row_activated, \ "liststore_accounts_row_deleted" : self._on_liststore_accounts_row_deleted, \ "liststore_accounts_row_inserted" : self._on_liststore_accounts_row_inserted, \ "btn_edit_plugin_clicked" : self._on_btn_edit_plugin_clicked, \ "treeview_plugins_row_activated" : self._on_treeview_plugins_row_activated, \ "treeview_plugins_cursor_changed" : self._on_treeview_plugins_cursor_changed, \ }) self._window = builder.get_object("config_window") self._window.set_icon_name("mailnag") self._window.set_application(app) self._cfg = read_cfg() self._daemon_enabled = False self._switch_daemon_enabled = builder.get_object( "switch_daemon_enabled") # # accounts page # self._accountman = AccountManager( CredentialStore.from_string( self._cfg.get('core', 'credentialstore'))) self._treeview_accounts = builder.get_object("treeview_accounts") self._liststore_accounts = builder.get_object("liststore_accounts") self._button_edit_account = builder.get_object("btn_edit_account") self._button_remove_account = builder.get_object("btn_remove_account") self._button_edit_account.set_sensitive(False) self._button_remove_account.set_sensitive(False) renderer_acc_enabled = Gtk.CellRendererToggle() renderer_acc_enabled.connect("toggled", self._on_account_toggled) column_acc_enabled = Gtk.TreeViewColumn(_('Enabled'), renderer_acc_enabled) column_acc_enabled.add_attribute(renderer_acc_enabled, "active", 1) column_acc_enabled.set_alignment(0.5) self._treeview_accounts.append_column(column_acc_enabled) renderer_acc_name = Gtk.CellRendererText() column_acc_name = Gtk.TreeViewColumn(_('Name'), renderer_acc_name, text=2) self._treeview_accounts.append_column(column_acc_name) # # plugins page # self._treeview_plugins = builder.get_object("treeview_plugins") self._liststore_plugins = builder.get_object("liststore_plugins") self._button_edit_plugin = builder.get_object("btn_edit_plugin") self._button_edit_plugin.set_sensitive(False) def renderer_plugin_enabled_func(column, cell_renderer, model, iter, data): plugin = model.get_value(iter, 0) name, desc, ver, author, mandatory = plugin.get_manifest() cell_renderer.set_sensitive(not mandatory) renderer_plugin_enabled = Gtk.CellRendererToggle() renderer_plugin_enabled.connect("toggled", self._on_plugin_toggled) column_plugin_enabled = Gtk.TreeViewColumn(_('Enabled'), renderer_plugin_enabled) column_plugin_enabled.add_attribute(renderer_plugin_enabled, "active", 1) column_plugin_enabled.set_alignment(0.5) column_plugin_enabled.set_cell_data_func(renderer_plugin_enabled, renderer_plugin_enabled_func) self._treeview_plugins.append_column(column_plugin_enabled) renderer_plugin_name = Gtk.CellRendererText() column_plugin_name = Gtk.TreeViewColumn(_('Name'), renderer_plugin_name, markup=2) self._treeview_plugins.append_column(column_plugin_name) # load config self._load_config() self._window.show_all()
def test_save_zero_accounts_to_config_with_credential_store(config): cs = FakeCredentialStore() am = AccountManager(cs) am.save_to_cfg(config) assert len(config.sections()) == 0 assert cs.secrets == {}
def test_save_all_accounts_to_config(config): am = AccountManager() am.load_from_cfg(config, enabled_only=False) am.save_to_cfg(config) assert len(config.sections()) == 6
def test_save_zero_accounts_to_config(config): am = AccountManager() am.save_to_cfg(config) assert len(config.sections()) == 0
def test_imap_new_folder_option(config): am = AccountManager() option_spec = get_mailbox_parameter_specs('imap') options = am._get_cfg_options(config, 'account6', option_spec) assert options['folders'] == ['folderA', 'folderB', 'folderC']
def __init__(self): builder = Gtk.Builder() builder.set_translation_domain(PACKAGE_NAME) builder.add_from_file(get_data_file("config_window.ui")) builder.connect_signals({ \ "config_window_deleted" : self._on_config_window_deleted, \ "btn_page_toggled" : self._on_btn_page_toggled, \ "btn_add_account_clicked" : self._on_btn_add_account_clicked, \ "btn_edit_account_clicked" : self._on_btn_edit_account_clicked, \ "btn_remove_account_clicked" : self._on_btn_remove_account_clicked, \ "treeview_accounts_row_activated" : self._on_treeview_accounts_row_activated, \ "liststore_accounts_row_deleted" : self._on_liststore_accounts_row_deleted, \ "liststore_accounts_row_inserted" : self._on_liststore_accounts_row_inserted, \ "btn_edit_plugin_clicked" : self._on_btn_edit_plugin_clicked, \ "treeview_plugins_row_activated" : self._on_treeview_plugins_row_activated, \ "treeview_plugins_cursor_changed" : self._on_treeview_plugins_cursor_changed, \ }) # Add icons in alternative data paths (e.g. ./data/icons) # to the icon search path in case Mailnag is launched # from a local directory (without installing). icon_theme = Gtk.IconTheme.get_default() for path in get_data_paths(): icon_theme.append_search_path(os.path.join(path, "icons")) self._window = builder.get_object("config_window") self._window.set_icon_name("mailnag") self._load_stylesheet('config_window.css') self._cfg = read_cfg() self.daemon_enabled = False # # toggle buttons / notebook # self._notebook = builder.get_object("notebook") self._box_navigation = builder.get_object("box_navigation") self._box_navigation.get_children()[0].set_active(True) # # general page # # The dimension of the png is expected to be 180x180 px pb = GdkPixbuf.Pixbuf.new_from_file(get_data_file("mailnag.png")) pb = pb.new_subpixbuf(0, 10, 180, 146) # crop whitespace at the bottom self._image_logo = builder.get_object("image_logo") self._image_logo.set_from_pixbuf(pb) self._label_app_desc = builder.get_object("label_app_desc") self._label_app_desc.set_markup( "<span font=\"24\"><b>Mailnag</b></span>\nVersion %s" % str(APP_VERSION)) self._switch_daemon_enabled = builder.get_object( "switch_daemon_enabled") # # accounts page # self._accountman = AccountManager( CredentialStore.from_string( self._cfg.get('core', 'credentialstore'))) self._treeview_accounts = builder.get_object("treeview_accounts") self._liststore_accounts = builder.get_object("liststore_accounts") self._button_edit_account = builder.get_object("btn_edit_account") self._button_remove_account = builder.get_object("btn_remove_account") self._button_edit_account.set_sensitive(False) self._button_remove_account.set_sensitive(False) renderer_acc_enabled = Gtk.CellRendererToggle() renderer_acc_enabled.connect("toggled", self._on_account_toggled) column_acc_enabled = Gtk.TreeViewColumn(_('Enabled'), renderer_acc_enabled) column_acc_enabled.add_attribute(renderer_acc_enabled, "active", 1) column_acc_enabled.set_alignment(0.5) self._treeview_accounts.append_column(column_acc_enabled) renderer_acc_name = Gtk.CellRendererText() column_acc_name = Gtk.TreeViewColumn(_('Name'), renderer_acc_name, text=2) self._treeview_accounts.append_column(column_acc_name) # # plugins page # self._treeview_plugins = builder.get_object("treeview_plugins") self._liststore_plugins = builder.get_object("liststore_plugins") self._button_edit_plugin = builder.get_object("btn_edit_plugin") self._button_edit_plugin.set_sensitive(False) def renderer_plugin_enabled_func(column, cell_renderer, model, iter, data): plugin = model.get_value(iter, 0) name, desc, ver, author, mandatory = plugin.get_manifest() cell_renderer.set_sensitive(not mandatory) renderer_plugin_enabled = Gtk.CellRendererToggle() renderer_plugin_enabled.connect("toggled", self._on_plugin_toggled) column_plugin_enabled = Gtk.TreeViewColumn(_('Enabled'), renderer_plugin_enabled) column_plugin_enabled.add_attribute(renderer_plugin_enabled, "active", 1) column_plugin_enabled.set_alignment(0.5) column_plugin_enabled.set_cell_data_func(renderer_plugin_enabled, renderer_plugin_enabled_func) self._treeview_plugins.append_column(column_plugin_enabled) renderer_plugin_name = Gtk.CellRendererText() column_plugin_name = Gtk.TreeViewColumn(_('Name'), renderer_plugin_name, markup=2) self._treeview_plugins.append_column(column_plugin_name) # load config self._load_config() self._window.show()