[Python-modules-commits] [afew] 01/01: New upstream version 1.2.0
Free Ekanayaka
freee at moszumanska.debian.org
Tue Oct 31 21:12:19 UTC 2017
This is an automated email from the git hooks/post-receive script.
freee pushed a commit to branch upstream
in repository afew.
commit 515866770ff8828931f6ab7e6110b3d82b04cb41
Author: Free Ekanayaka <freee at debian.org>
Date: Mon Oct 30 13:47:20 2017 +0000
New upstream version 1.2.0
---
.gitignore | 2 +
.travis.yml | 23 +++
PKG-INFO | 19 +++
README.md | 256 -------------------------------
README.rst | 245 +++++++++++++++++++++++++++++
afew.egg-info/PKG-INFO | 19 +++
afew.egg-info/SOURCES.txt | 51 ++++++
afew.egg-info/dependency_links.txt | 1 +
afew.egg-info/entry_points.txt | 14 ++
afew.egg-info/requires.txt | 2 +
afew.egg-info/top_level.txt | 1 +
afew/DBACL.py | 112 --------------
afew/Database.py | 17 --
afew/MailMover.py | 7 +-
afew/NotmuchSettings.py | 3 +-
afew/Settings.py | 6 +-
afew/{NotmuchSettings.py => __main__.py} | 21 +--
afew/commands.py | 164 ++++++++------------
afew/defaults/afew.config | 1 -
afew/filters/BaseFilter.py | 11 +-
afew/filters/ClassifyingFilter.py | 41 -----
afew/filters/FolderNameFilter.py | 21 ++-
afew/main.py | 37 -----
afew/tests/test_settings.py | 11 +-
afew/tests/test_utils.py | 12 ++
afew/utils.py | 92 +----------
afew/version.py | 4 +
docs/source/classification.rst | 57 -------
docs/source/commandline.rst | 38 +----
docs/source/configuration.rst | 1 -
docs/source/filters.rst | 21 ++-
docs/source/implementation.rst | 10 --
docs/source/index.rst | 7 +-
docs/source/installation.rst | 10 +-
docs/source/quickstart.rst | 2 -
setup.cfg | 4 +
setup.py | 27 +++-
37 files changed, 546 insertions(+), 824 deletions(-)
diff --git a/.gitignore b/.gitignore
index 9869866..0774894 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,5 @@ bin/
include/
lib/
/afew.egg-info
+afew/version.py
+/.eggs
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..f758bcd
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,23 @@
+dist: trusty
+language: python
+python:
+ - "2.7"
+ - "3.4"
+ - "3.5"
+ - "3.6"
+
+addons:
+ apt:
+ packages:
+ - notmuch
+ - python-notmuch
+ - python3-notmuch
+
+install:
+ - ln -s /usr/lib/python3/dist-packages/notmuch ${VIRTUAL_ENV}/lib/python*/site-packages
+ - pip install codeclimate-test-reporter
+ - python setup.py install
+script:
+ - coverage run --source=afew setup.py test
+after_success:
+ - codeclimate-test-reporter
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..f00c196
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,19 @@
+Metadata-Version: 1.1
+Name: afew
+Version: 1.2.0
+Summary: UNKNOWN
+Home-page: UNKNOWN
+Author: UNKNOWN
+Author-email: UNKNOWN
+License: UNKNOWN
+Description: UNKNOWN
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Environment :: Console
+Classifier: Intended Audience :: End Users/Desktop
+Classifier: Programming Language :: Python
+Classifier: Topic :: Communications :: Email
+Classifier: Topic :: Communications :: Email :: Filters
+Classifier: Topic :: Utilities
+Classifier: Topic :: Database
+Provides: afew
diff --git a/README.md b/README.md
deleted file mode 100644
index 4d1dd6e..0000000
--- a/README.md
+++ /dev/null
@@ -1,256 +0,0 @@
-About
-=====
-
-afew is an initial tagging script for notmuch mail:
-
-* http://notmuchmail.org/
-* http://notmuchmail.org/initial_tagging/
-
-Its basic task is to provide automatic tagging each time new mail is registered
-with notmuch. In a classic setup, you might call it after 'notmuch new' in an
-offlineimap post sync hook.
-
-In addition to more elementary features such as adding tags based on email
-headers or maildir folders, handling killed threads and spam, it can do some
-heavy magic in order to /learn/ how to initially tag your mails based on their
-content.
-
-In move mode, afew will move mails between maildir folders according to
-configurable rules that can contain arbitrary notmuch queries to match against
-any searchable attributes.
-
-fyi: afew plays nicely with alot, a GUI for notmuch mail ;)
-
-* https://github.com/pazz/alot
-
-
-Current NEWS
-============
-
-afew is quite young, so expect a few user visible API or configuration
-format changes, though I'll try to minimize such disruptive events.
-
-Please keep an eye on NEWS.md for important news.
-
-
-Features
-========
-
-* text classification, magic tags aka the mailing list without server
-* spam handling (flush all tags, add spam)
-* killed thread handling
-* tags posts to lists with `lists`, `$list-id`
-* autoarchives mails sent from you
-* catchall -> remove `new`, add `inbox`
-* can operate on new messages [default], `--all` messages or on custom
- query results
-* can move mails based on arbitrary notmuch queries, so your sorting
- may show on your traditional mail client (well, almost ;))
-* has a `--dry-run` mode for safe testing
-* works with python 2.7, 3.1 and 3.2
-
-
-Installation
-============
-
-You'll need dbacl for the text classification:
-
- # aptitude install dbacl
-
-And I'd like to suggest to install afew as your unprivileged user.
-If you do, make sure `~/.local/bin` is in your path.
-
- $ python setup.py install --prefix=~/.local
- $ mkdir -p ~/.config/afew ~/.local/share/afew/categories
-
-
-Configuration
-=============
-
-Make sure that `~/.notmuch-config` reads:
-
-```
-[new]
-tags=new
-```
-
-Put a list of filters into `~/.config/afew/config`:
-
-```
-# This is the default filter chain
-[SpamFilter]
-[ClassifyingFilter]
-[KillThreadsFilter]
-[ListMailsFilter]
-[ArchiveSentMailsFilter]
-[InboxFilter]
-```
-
-And configure rules to sort mails on your disk, if you want:
-
-```
-[MailMover]
-folders = INBOX Junk
-max_age = 15
-
-# rules
-INBOX = 'tag:spam':Junk 'NOT tag:inbox':Archive
-Junk = 'NOT tag:spam AND tag:inbox':INBOX 'NOT tag:spam':Archive
-```
-
-
-Commandline help
-================
-
-```
-$ afew --help
-Usage: afew [options] [--] [query]
-
-Options:
- -h, --help show this help message and exit
-
- Actions:
- Please specify exactly one action (both update actions can be
- specified simultaniously).
-
- -t, --tag run the tag filters
- -l LEARN, --learn=LEARN
- train the category with the messages matching the
- given query
- -u, --update update the categories [requires no query]
- -U, --update-reference
- update the reference category (takes quite some time)
- [requires no query]
- -c, --classify classify each message matching the given query (to
- test the trained categories)
- -m, --move-mails move mail files between maildir folders
-
- Query modifiers:
- Please specify either --all or --new or a query string. The default
- query for the update actions is a random selection of
- REFERENCE_SET_SIZE mails from the last REFERENCE_SET_TIMEFRAME days.
-
- -a, --all operate on all messages
- -n, --new operate on all new messages
-
- General options:
- -C NOTMUCH_CONFIG, --notmuch-config=NOTMUCH_CONFIG
- path to the notmuch configuration file [default:
- $NOTMUCH_CONFIG or ~/.notmuch-config]
- -e ENABLE_FILTERS, --enable-filters=ENABLE_FILTERS
- filter classes to use, separated by ',' [default:
- filters specified in afew's config]
- -d, --dry-run don't change the db [default: False]
- -R REFERENCE_SET_SIZE, --reference-set-size=REFERENCE_SET_SIZE
- size of the reference set [default: 1000]
- -T DAYS, --reference-set-timeframe=DAYS
- do not use mails older than DAYS days [default: 30]
- -v, --verbose be more verbose, can be given multiple times
-```
-
-
-Boring stuff
-============
-
-Simulation
-----------
-Adding `--dry-run` to any `--tag` or `--sync-tags` action prevents
-modification of the notmuch db. Add some `-vv` goodness to see some
-action.
-
-
-Initial tagging
----------------
-Basic tagging stuff requires no configuration, just run
-
- $ afew --tag --new
-
-To do this automatically you can add the following hook into your
-~/.offlineimaprc:
-
- postsynchook = ionice -c 3 chrt --idle 0 /bin/sh -c "notmuch new && afew --tag --new"
-
-
-Tag filters
------------
-Tag filters are plugin-like modules that encapsulate tagging
-functionality. There is a filter that handles the archiving of mails
-you sent, one that handles spam, one for killed threads, one for
-mailing list magic...
-
-The tag filter concept allows you to easily extend afew's tagging
-abilities by writing your own filters. Take a look at the default
-configuration file (`afew/defaults/afew.config`) for a list of
-available filters and how to enable filters and create customized
-filter types.
-
-
-Move mode
----------
-
-To invoke afew in move mode, provide the `--move-mails` option on the
-command line. Move mode will respect `--dry-run`, so throw in
-`--verbose` and watch what effects a real run would have.
-
-In move mode, afew will check all mails (or only recent ones) in the
-configured maildir folders, deciding whether they should be moved to
-another folder.
-
-The decision is based on rules defined in your config file. A rule is
-bound to a source folder and specifies a target folder into which a
-mail will be moved that is matched by an associated query.
-
-This way you will be able to transfer your sorting principles roughly
-to the classic folder based maildir structure understood by your
-traditional mail server. Tag your mails with notmuch, call afew
-`--move-mails` in an offlineimap presynchook and enjoy a clean inbox
-in your webinterface/GUI-client at work.
-
-For information on how to configure rules for move mode, what you can
-do with it and what you can't, please refer to `docs/move_mode`.
-
-
-The real deal
-=============
-
-Let's train on an existing tag `spam`:
-
- $ afew --learn spam -- tag:spam
-
-Let's build the reference category. This is important to reduce the
-false positive rate. This may take a while...
-
- $ afew --update-reference
-
-And now let's create a new tag from an arbitrary query result:
-
- $ afew -vv --learn sourceforge -- sourceforge
-
-Let's see how good the classification is:
-
- $ afew --classify -- tag:inbox and not tag:killed
- Sergio López <slpml at sinrega.org> (2011-10-08) (bug-hurd inbox lists unread) --> no match
- Patrick Totzke <reply+i-1840934-9a702d09342dca2b120126b26b008d0deea1731e at reply.github.com> (2011-10-08) (alot inbox lists) --> alot
- [...]
-
-As soon as you trained some categories, afew will automatically
-tag your new mails using the classifier. If you want to disable this
-feature, either use the `--enable-filters` option to override the default
-set of filters or remove the files in your afew state dir:
-
- $ ls ~/.local/share/afew/categories
- alot juggling reference_category sourceforge spam
-
-You need to update the category files periodically. I'd suggest to run
-
- $ afew --update
-
-on a weekly and
-
- $ afew --update-reference
-
-on a monthly basis.
-
-
-
-Have fun :)
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..b0b25b0
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,245 @@
+====
+afew
+====
+
+|GithubTag| |TravisStatus|
+
+About
+-----
+
+afew is an initial tagging script for notmuch mail:
+
+* http://notmuchmail.org/
+* http://notmuchmail.org/initial_tagging/
+
+Its basic task is to provide automatic tagging each time new mail is registered
+with notmuch. In a classic setup, you might call it after 'notmuch new' in an
+offlineimap post sync hook.
+
+It can do basic thing such as adding tags based on email headers or maildir
+folders, handling killed threads and spam.
+
+In move mode, afew will move mails between maildir folders according to
+configurable rules that can contain arbitrary notmuch queries to match against
+any searchable attributes.
+
+fyi: afew plays nicely with alot, a GUI for notmuch mail ;)
+
+* https://github.com/pazz/alot
+
+
+
+Current NEWS
+------------
+
+afew is quite young, so expect a few user visible API or configuration
+format changes, though I'll try to minimize such disruptive events.
+
+Please keep an eye on NEWS.md for important news.
+
+Also, feel free to ask your questions and discuss usage in the [#afewmail IRC Channel](http://webchat.freenode.net/?channels=#afewmail) on freenode.
+
+
+
+Features
+--------
+
+* spam handling (flush all tags, add spam)
+* killed thread handling
+* tags posts to lists with ``lists``, ``$list-id``
+* autoarchives mails sent from you
+* catchall -> remove ``new``, add ``inbox``
+* can operate on new messages [default], ``--all`` messages or on custom
+ query results
+* can move mails based on arbitrary notmuch queries, so your sorting
+ may show on your traditional mail client (well, almost ;))
+* has a ``--dry-run`` mode for safe testing
+* works with python 2.7, 3.1 and 3.2
+
+
+
+Installation
+------------
+
+Make sure you have already installed your distribution's `notmuch`
+package, and the notmuch python bindings, which might come in separate
+`python-notmuch` and `python3-notmuch` packages.
+
+Note: if you are installing `notmuch` using Homebrew on macOS, make sure
+to run ``$ brew install --with-python3 notmuch``, because the brew formula
+doesn't install python3 notmuch bindings by default.
+
+It is recommended to install `afew` itself inside a virtualenv as an unprivileged
+user, either via checking out the source code and installing via setup.py, or
+via pip.
+
+.. code:: bash
+
+ # create and activate virtualenv
+ $ python -m venv --system-site-packages .venv
+ $ source .venv/bin/activate
+
+ # install via pip from PyPI:
+ $ pip install afew
+
+ # or install from source:
+ $ python setup.py install
+
+You might want to symlink `.venv/bin/afew` somewhere inside your path
+(~/bin/ in this case):
+
+.. code:: bash
+
+ $ ln -snr .venv/bin/afew ~/.bin/afew
+
+
+
+Configuration
+-------------
+
+Make sure that ``~/.notmuch-config`` reads:
+
+.. code:: ini
+
+ [new]
+ tags=new
+
+Put a list of filters into ``~/.config/afew/config``:
+
+.. code:: ini
+
+ # This is the default filter chain
+ [SpamFilter]
+ [KillThreadsFilter]
+ [ListMailsFilter]
+ [ArchiveSentMailsFilter]
+ [InboxFilter]
+
+And configure rules to sort mails on your disk, if you want:
+
+.. code:: ini
+
+ [MailMover]
+ folders = INBOX Junk
+ max_age = 15
+
+ # rules
+ INBOX = 'tag:spam':Junk 'NOT tag:inbox':Archive
+ Junk = 'NOT tag:spam AND tag:inbox':INBOX 'NOT tag:spam':Archive
+
+
+
+Commandline help
+----------------
+
+.. code:: ini
+
+ $ afew --help
+ Usage: afew [options] [--] [query]
+
+ Options:
+ -h, --help show this help message and exit
+
+ Actions:
+ Please specify exactly one action.
+
+ -t, --tag run the tag filters
+ -m, --move-mails move mail files between maildir folders
+
+ Query modifiers:
+ Please specify either --all or --new or a query string.
+
+ -a, --all operate on all messages
+ -n, --new operate on all new messages
+
+ General options:
+ -C NOTMUCH_CONFIG, --notmuch-config=NOTMUCH_CONFIG
+ path to the notmuch configuration file [default:
+ $NOTMUCH_CONFIG or ~/.notmuch-config]
+ -e ENABLE_FILTERS, --enable-filters=ENABLE_FILTERS
+ filter classes to use, separated by ',' [default:
+ filters specified in afew's config]
+ -d, --dry-run don't change the db [default: False]
+ -R REFERENCE_SET_SIZE, --reference-set-size=REFERENCE_SET_SIZE
+ size of the reference set [default: 1000]
+ -T DAYS, --reference-set-timeframe=DAYS
+ do not use mails older than DAYS days [default: 30]
+ -v, --verbose be more verbose, can be given multiple times
+
+
+
+Boring stuff
+============
+
+Simulation
+----------
+Adding ``--dry-run`` to any ``--tag`` or ``--sync-tags`` action prevents
+modification of the notmuch db. Add some ``-vv`` goodness to see some
+action.
+
+
+
+Initial tagging
+---------------
+Basic tagging stuff requires no configuration, just run
+
+.. code:: bash
+
+ $ afew --tag --new
+
+To do this automatically you can add the following hook into your
+``~/.offlineimaprc``:
+
+.. code:: ini
+
+ postsynchook = ionice -c 3 chrt --idle 0 /bin/sh -c "notmuch new && afew --tag --new"
+
+
+
+Tag filters
+-----------
+Tag filters are plugin-like modules that encapsulate tagging
+functionality. There is a filter that handles the archiving of mails
+you sent, one that handles spam, one for killed threads, one for
+mailing list magic...
+
+The tag filter concept allows you to easily extend afew's tagging
+abilities by writing your own filters. Take a look at the default
+configuration file (``afew/defaults/afew.config``) for a list of
+available filters and how to enable filters and create customized
+filter types.
+
+
+
+Move mode
+---------
+
+To invoke afew in move mode, provide the ``--move-mails`` option on the
+command line. Move mode will respect ``--dry-run``, so throw in
+``--verbose`` and watch what effects a real run would have.
+
+In move mode, afew will check all mails (or only recent ones) in the
+configured maildir folders, deciding whether they should be moved to
+another folder.
+
+The decision is based on rules defined in your config file. A rule is
+bound to a source folder and specifies a target folder into which a
+mail will be moved that is matched by an associated query.
+
+This way you will be able to transfer your sorting principles roughly
+to the classic folder based maildir structure understood by your
+traditional mail server. Tag your mails with notmuch, call afew
+``--move-mails`` in an offlineimap presynchook and enjoy a clean inbox
+in your webinterface/GUI-client at work.
+
+For information on how to configure rules for move mode, what you can
+do with it and what you can't, please refer to ``docs/move_mode``.
+
+
+Have fun :)
+
+
+.. |GithubTag| image:: https://img.shields.io/github/tag/afewmail/afew.svg
+ :target: https://travis-ci.org/afewmail/afew
+.. |TravisStatus| image:: https://travis-ci.org/afewmail/afew.svg?branch=master
+ :target: https://github.com/afewmail/afew/releases
diff --git a/afew.egg-info/PKG-INFO b/afew.egg-info/PKG-INFO
new file mode 100644
index 0000000..f00c196
--- /dev/null
+++ b/afew.egg-info/PKG-INFO
@@ -0,0 +1,19 @@
+Metadata-Version: 1.1
+Name: afew
+Version: 1.2.0
+Summary: UNKNOWN
+Home-page: UNKNOWN
+Author: UNKNOWN
+Author-email: UNKNOWN
+License: UNKNOWN
+Description: UNKNOWN
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Environment :: Console
+Classifier: Intended Audience :: End Users/Desktop
+Classifier: Programming Language :: Python
+Classifier: Topic :: Communications :: Email
+Classifier: Topic :: Communications :: Email :: Filters
+Classifier: Topic :: Utilities
+Classifier: Topic :: Database
+Provides: afew
diff --git a/afew.egg-info/SOURCES.txt b/afew.egg-info/SOURCES.txt
new file mode 100644
index 0000000..2fd7d9e
--- /dev/null
+++ b/afew.egg-info/SOURCES.txt
@@ -0,0 +1,51 @@
+.gitignore
+.travis.yml
+NEWS.md
+README.rst
+setup.py
+afew/Database.py
+afew/FilterRegistry.py
+afew/MailMover.py
+afew/NotmuchSettings.py
+afew/Settings.py
+afew/__init__.py
+afew/__main__.py
+afew/commands.py
+afew/configparser.py
+afew/files.py
+afew/main.py
+afew/utils.py
+afew/version.py
+afew.egg-info/PKG-INFO
+afew.egg-info/SOURCES.txt
+afew.egg-info/dependency_links.txt
+afew.egg-info/entry_points.txt
+afew.egg-info/requires.txt
+afew.egg-info/top_level.txt
+afew/defaults/afew.config
+afew/filters/ArchiveSentMailsFilter.py
+afew/filters/BaseFilter.py
+afew/filters/FolderNameFilter.py
+afew/filters/HeaderMatchingFilter.py
+afew/filters/InboxFilter.py
+afew/filters/KillThreadsFilter.py
+afew/filters/ListMailsFilter.py
+afew/filters/SentMailsFilter.py
+afew/filters/SpamFilter.py
+afew/filters/__init__.py
+afew/tests/__init__.py
+afew/tests/test_settings.py
+afew/tests/test_utils.py
+docs/Makefile
+docs/source/commandline.rst
+docs/source/conf.py
+docs/source/configuration.rst
+docs/source/extending.rst
+docs/source/filters.rst
+docs/source/implementation.rst
+docs/source/index.rst
+docs/source/installation.rst
+docs/source/move_mode.rst
+docs/source/quickstart.rst
+docs/source/_static/.keep
+docs/source/_templates/.keep
\ No newline at end of file
diff --git a/afew.egg-info/dependency_links.txt b/afew.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/afew.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/afew.egg-info/entry_points.txt b/afew.egg-info/entry_points.txt
new file mode 100644
index 0000000..1b0c837
--- /dev/null
+++ b/afew.egg-info/entry_points.txt
@@ -0,0 +1,14 @@
+[afew.filter]
+ArchiveSentMailsFilter = afew.filters.ArchiveSentMailsFilter:ArchiveSentMailsFilter
+Filter = afew.filters.BaseFilter:Filter
+FolderNameFilter = afew.filters.FolderNameFilter:FolderNameFilter
+HeaderMatchingFilter = afew.filters.HeaderMatchingFilter:HeaderMatchingFilter
+InboxFilter = afew.filters.InboxFilter:InboxFilter
+KillThreadsFilter = afew.filters.KillThreadsFilter:KillThreadsFilter
+ListMailsFilter = afew.filters.ListMailsFilter:ListMailsFilter
+SentMailsFilter = afew.filters.SentMailsFilter:SentMailsFilter
+SpamFilter = afew.filters.SpamFilter:SpamFilter
+
+[console_scripts]
+afew = afew.commands:main
+
diff --git a/afew.egg-info/requires.txt b/afew.egg-info/requires.txt
new file mode 100644
index 0000000..faa6a6f
--- /dev/null
+++ b/afew.egg-info/requires.txt
@@ -0,0 +1,2 @@
+notmuch
+chardet
diff --git a/afew.egg-info/top_level.txt b/afew.egg-info/top_level.txt
new file mode 100644
index 0000000..f769f3e
--- /dev/null
+++ b/afew.egg-info/top_level.txt
@@ -0,0 +1 @@
+afew
diff --git a/afew/DBACL.py b/afew/DBACL.py
deleted file mode 100644
index 0fb82b8..0000000
--- a/afew/DBACL.py
+++ /dev/null
@@ -1,112 +0,0 @@
-# coding=utf-8
-from __future__ import print_function, absolute_import, unicode_literals
-
-#
-# Copyright (c) Justus Winter <4winter at informatik.uni-hamburg.de>
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-#
-
-import os
-import glob
-import logging
-import functools
-import subprocess
-
-class ClassificationError(Exception): pass
-class BackendError(ClassificationError): pass
-
-default_db_path = os.path.join(os.environ.get('XDG_DATA_HOME',
- os.path.expanduser('~/.local/share')),
- 'afew', 'categories')
-
-class Classifier(object):
- reference_category = 'reference_category'
-
- def __init__(self, categories, database_directory = default_db_path):
- self.categories = set(categories)
- self.database_directory = database_directory
-
- def learn(self, category, texts):
- pass
-
- def classify(self, text):
- pass
-
-class DBACL(Classifier):
- def __init__(self, database_directory = default_db_path):
- categories = glob.glob1(database_directory, '*')
- super(DBACL, self).__init__(categories, database_directory)
-
- sane_environ = {
- key: value
- for key, value in os.environ.items()
- if not (
- key.startswith('LC_') or
- key == 'LANG' or
- key == 'LANGUAGE'
- )
- }
-
- def _call_dbacl(self, args, **kwargs):
- command_line = ['dbacl', '-T', 'email'] + args
- logging.debug('executing %r' % command_line)
- return subprocess.Popen(
- command_line,
- shell = False,
- stdin = subprocess.PIPE,
- stdout = subprocess.PIPE,
- stderr = subprocess.PIPE,
- env = self.sane_environ,
- **kwargs
- )
-
- def get_category_path(self, category):
- return os.path.join(self.database_directory, category.replace('/', '_'))
-
- def learn(self, category, texts):
- process = self._call_dbacl(['-l', self.get_category_path(category)])
-
- for text in texts:
- process.stdin.write((text + '\n').encode('utf-8'))
-
- process.stdin.close()
- process.wait()
-
- if process.returncode != 0:
- raise BackendError('dbacl learning failed:\n%s' % process.stderr.read())
-
- def classify(self, text):
- if not self.categories:
- raise ClassificationError('No categories defined')
-
- categories = functools.reduce(list.__add__, [
- ['-c', self.get_category_path(category)]
- for category in self.categories
- ], [])
-
- process = self._call_dbacl(categories + ['-n'])
- stdout, stderr = process.communicate(text.encode('utf-8'))
-
- if len(stderr) == 0:
- result = stdout.split()
- scores = list()
- while result:
- category = result.pop(0).decode('utf-8', 'replace')
- score = float(result.pop(0))
- scores.append((category, score))
- scores.sort(key = lambda category_score: category_score[1])
- else:
- raise BackendError('dbacl classification failed:\n%s' % stderr)
-
- return scores
diff --git a/afew/Database.py b/afew/Database.py
index 4b38f0c..59b9a6a 100644
--- a/afew/Database.py
+++ b/afew/Database.py
@@ -23,7 +23,6 @@ import logging
import notmuch
from .NotmuchSettings import notmuch_settings, get_notmuch_new_tags
-from .utils import extract_mail_body
class Database(object):
'''
@@ -111,22 +110,6 @@ class Database(object):
for message in self.walk_thread(thread):
yield message
-
- def mail_bodies_matching(self, *args, **kwargs):
- '''
- Filters each message yielded from
- :func:`Database.get_messages` through
- :func:`afew.utils.extract_mail_body`.
-
- This functions accepts the same arguments as
- :func:`Database.get_messages`.
-
- :returns: an iterator over :class:`list` of :class:`str`
- '''
- query = self.get_messages(*args, **kwargs)
- for message in query:
- yield extract_mail_body(message)
-
def walk_replies(self, message):
'''
Returns all replies to the given message.
diff --git a/afew/MailMover.py b/afew/MailMover.py
index faa89c7..718e4d8 100644
--- a/afew/MailMover.py
+++ b/afew/MailMover.py
@@ -65,6 +65,7 @@ class MailMover(Database):
# identify and move messages
logging.info("checking mails in '{}'".format(maildir))
to_delete_fnames = []
+ moved = False
for query in rules.keys():
destination = '{}/{}/cur/'.format(self.db_path, rules[query])
main_query = self.query.format(folder=maildir, subquery=query)
@@ -78,6 +79,7 @@ class MailMover(Database):
if maildir in name]
if not to_move_fnames:
continue
+ moved = True
self.__log_move_action(message, maildir, rules[query],
self.dry_run)
for fname in to_move_fnames:
@@ -99,9 +101,10 @@ class MailMover(Database):
os.remove(fname)
# update notmuch database
- logging.info("updating database")
if not self.dry_run:
- self.__update_db(maildir)
+ if moved:
+ logging.info("updating database")
+ self.__update_db(maildir)
else:
logging.info("Would update database")
diff --git a/afew/NotmuchSettings.py b/afew/NotmuchSettings.py
index 13655e0..83b78e6 100644
--- a/afew/NotmuchSettings.py
+++ b/afew/NotmuchSettings.py
@@ -30,7 +30,8 @@ def read_notmuch_settings(path = None):
notmuch_settings.readfp(open(path))
def get_notmuch_new_tags():
- return notmuch_settings.get_list('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())
diff --git a/afew/Settings.py b/afew/Settings.py
index fe2ed61..ed3edc5 100644
--- a/afew/Settings.py
+++ b/afew/Settings.py
@@ -77,7 +77,7 @@ def get_filter_chain(database):
return filter_chain
def get_mail_move_rules():
- rule_pattern = re.compile(r"'(.+?)':(\S+)")
+ rule_pattern = re.compile(r"'(.+?)':((?P<quote>['\"])(.*?)(?P=quote)|\S+)")
if settings.has_option(mail_mover_section, 'folders'):
all_rules = collections.OrderedDict()
@@ -87,7 +87,9 @@ def get_mail_move_rules():
raw_rules = re.findall(rule_pattern,
settings.get(mail_mover_section, folder))
for rule in raw_rules:
- rules[rule[0]] = rule[1]
+ query = rule[0]
+ destination = rule[3] or rule[1]
+ rules[query] = destination
all_rules[folder] = rules
else:
raise NameError("No rules specified for maildir '{}'.".format(folder))
diff --git a/afew/NotmuchSettings.py b/afew/__main__.py
similarity index 59%
copy from afew/NotmuchSettings.py
copy to afew/__main__.py
index 13655e0..a5b71a5 100644
--- a/afew/NotmuchSettings.py
+++ b/afew/__main__.py
@@ -2,7 +2,7 @@
from __future__ import print_function, absolute_import, unicode_literals
#
-# Copyright (c) Justus Winter <4winter at informatik.uni-hamburg.de>
+# Copyright (c) Lucas Hoffmann
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -17,20 +17,5 @@ from __future__ import print_function, absolute_import, unicode_literals
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
-import os
-
-from .configparser import RawConfigParser
-
-notmuch_settings = RawConfigParser()
-
-def read_notmuch_settings(path = None):
- if path == None:
- path = os.environ.get('NOTMUCH_CONFIG', os.path.expanduser('~/.notmuch-config'))
... 1003 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/afew.git
More information about the Python-modules-commits
mailing list