Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative path in database.path of notmuch config breaks FolderNameFilter #303

Closed
rustikus opened this issue Nov 18, 2020 · 1 comment · Fixed by #321
Closed

Relative path in database.path of notmuch config breaks FolderNameFilter #303

rustikus opened this issue Nov 18, 2020 · 1 comment · Fixed by #321

Comments

@rustikus
Copy link

Hi,

I found an issue related to FolderNameFilter which breaks the portability of config files between i.e. MacOS and Linux. I sync configs between systems leveraging specifics with variables like $HOME in paths. Unfortunately notmuch does not support variables but setting database.path as a relative path. This helps portability between MacOS and Linux if you sync to the same mail folder.

That is my example of database.path set to Mail in notmuch.

DEBUG:afew.filters.FolderNameFilter.FolderNameFilter:found folders set() for message 'Großartige Neuigkeiten: M.Zuiko Digital ED 150-400mm F4.5 TC1.25x IS PRO Objektiv, Firmwareupdate für die E-M1X und tolle Winteraktionen'

That is my example of database.path set to /Users/name/Mail in notmuch.

DEBUG:afew.filters.FolderNameFilter.FolderNameFilter:found folders {'Trash', 'home'} for message 'Großartige Neuigkeiten: M.Zuiko Digital ED 150-400mm F4.5 TC1.25x IS PRO Objektiv, Firmwareupdate für die E-M1X und tolle Winteraktionen'

I think the problem is in file FolderNameFilter.py and specifically this part

        self.__filename_pattern = '{mail_root}/(?P<maildirs>.*)/(cur|new)/[^/]+'.format(
            mail_root=notmuch_settings.get('database', 'path').rstrip('/'))

Interestingly the Database.py already has a solution which is i.e. used by MailMover to get the database path.

   def _calculate_db_path(self):
        """
        Calculates the path to use for the database. Supports notmuch's
        methodology including falling back to $MAILDIR or $HOME/mail if a path
        is not specified and using $HOME/<path> if path is relative.
        """
        default_path = os.environ.get('MAILDIR', '{}/mail'.format(os.environ.get('HOME')))
        db_path = notmuch_settings.get('database', 'path', fallback=default_path)

        # If path is relative, notmuch prepends $HOME in front
        if not os.path.isabs(db_path):
            db_path = '{}/{}'.format(os.environ.get('HOME'), db_path)

        return db_path

Hope this helps!
Thanks

@GuillaumeSeren
Copy link
Collaborator

Hello !
Ah yes I think that code should use the '_calculate_db_path()' and also this filter really a dedicated test.

If you want to help on those, feel free to open a pull-request.

aya added a commit to aya/afew that referenced this issue Dec 6, 2021
It fixes afewmail#303 and closes afewmail#267, allowing FolderNameFilter to work with
relative path in database.path of notmuch config file.
GuillaumeSeren pushed a commit to GuillaumeSeren/afew that referenced this issue Sep 13, 2022
It fixes afewmail#303 and closes afewmail#267, allowing FolderNameFilter to work with
relative path in database.path of notmuch config file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants