1# Copyright 2011 - 2021 Patrick Ulbrich <zulu99@gmx.net>
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16# MA 02110-1301, USA.
17#
18
19import os
20import xdg.BaseDirectory as bd
21from configparser import RawConfigParser
22
23mailnag_defaults = {
24	'core':
25	{
26		'poll_interval'		 : '10',
27		'imap_idle_timeout'	 : '10',
28		'mailbox_seen_flags' : '1',
29		'autostart'			 : '1',
30		'connectivity_test'	 : 'networkmonitor',
31		'enabled_plugins'	 : 'dbusplugin, soundplugin, libnotifyplugin'
32	}
33}
34
35cfg_folder = os.path.join(bd.xdg_config_home, "mailnag")
36cfg_file = os.path.join(cfg_folder, "mailnag.cfg")
37
38def cfg_exists():
39	return os.path.exists(cfg_file)
40
41
42def read_cfg():
43	cfg = RawConfigParser()
44	cfg.read_dict(mailnag_defaults)
45
46	if os.path.exists(cfg_file):
47		cfg.read(cfg_file)
48
49	return cfg
50
51
52def write_cfg(cfg):
53	if not os.path.exists(cfg_folder):
54		os.makedirs(cfg_folder)
55
56	with open(cfg_file, 'w') as configfile: cfg.write(configfile)
57