File: NotmuchSettings.py

package info (click to toggle)
afew 3.0.1-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: python: 1,484; makefile: 10; sh: 6
file content (33 lines) | stat: -rw-r--r-- 879 bytes parent folder | download
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
# SPDX-License-Identifier: ISC
# Copyright (c) Justus Winter <4winter@informatik.uni-hamburg.de>

import os

from afew.configparser import RawConfigParser

notmuch_settings = RawConfigParser()


def read_notmuch_settings(path=None):
    if path is None:
        path = os.environ.get('NOTMUCH_CONFIG', os.path.expanduser('~/.notmuch-config'))

    with open(path) as fp:
        notmuch_settings.read_file(fp)


def write_notmuch_settings(path=None):
    if path is None:
        path = os.environ.get('NOTMUCH_CONFIG', os.path.expanduser('~/.notmuch-config'))

    with open(path, 'w+') as fp:
        notmuch_settings.write(fp)


def get_notmuch_new_tags():
    # see issue 158
    return filter(lambda x: x != 'unread', notmuch_settings.get_list('new', 'tags'))


def get_notmuch_new_query():
    return '(%s)' % ' AND '.join('tag:%s' % tag for tag in get_notmuch_new_tags())