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

FolderNameFilter now looks at all folders that a message is in. #145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions afew/filters/FolderNameFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ def __init__(self, database, folder_blacklist='', folder_transforms='',


def handle_message(self, message):
maildirs = re.match(self.__filename_pattern, message.get_filename())
# Find all the dirs in the mail directory that this message
# belongs to
maildirs = [re.match(self.__filename_pattern, filename)
for filename in message.get_filenames()]
maildirs = filter(None, maildirs)
if maildirs:
folders = set(maildirs.group('maildirs').split(self.__maildir_separator))
# Make the folders relative to mail_root and split them.
folder_groups = [maildir.group('maildirs').split(self.__maildir_separator)
for maildir in maildirs]
folders = set([folder
for folder_group in folder_groups
for folder in folder_group])
self.log.debug('found folders {} for message {!r}'.format(
folders, message.get_header('subject')))

Expand Down
6 changes: 3 additions & 3 deletions docs/source/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ only slightly more complicated than the above examples.
FolderNameFilter
----------------

This looks at which folder each email is in and uses that name as a tag for the
email. So if you have a procmail or sieve set up that puts emails in folders
for you, this might be useful.
For each email, it looks at all folders it is in, and uses the path and filename
as a tag, for the email. So if you have a procmail or sieve set up that puts emails
in folders for you, this might be useful.

* folder_explicit_list = <folder list>

Expand Down