summaryrefslogtreecommitdiff
path: root/alot/addressbook/abook.py
blob: 02bd62af05cc862b35b7b03a193b33a89c0a157d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright (C) 2011-2015  Patrick Totzke <patricktotzke@gmail.com>
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file

import os

from .                  import AddressBook
from ..settings.utils   import read_config


class AbookAddressBook(AddressBook):
    """:class:`AddressBook` that parses abook's config/database files"""
    def __init__(self, path='~/.abook/addressbook', **kwargs):
        """
        :param path: path to abook addressbook file
        :type path: str
        """
        super().__init__(**kwargs)
        DEFAULTSPATH = os.path.join(os.path.dirname(__file__), '..',
                                    'defaults')
        self._spec = os.path.join(DEFAULTSPATH, 'abook_contacts.spec')
        path = os.path.expanduser(path)
        self._config = read_config(path, self._spec)
        del self._config['format']

    def get_contacts(self):
        c = self._config
        res = []
        for id in c.sections:
            for email in c[id]['email']:
                if email:
                    res.append((c[id]['name'], email))
        return res