[PATCH] T460-emacs-tree: sync $EXPECTED with test name

2018-04-19 Thread Florian Klink
This syncs the $EXPECTED directory name with the tests filename.

Signed-off-by: Florian Klink 
---
 test/T460-emacs-tree.sh | 2 +-
 .../notmuch-tree-show-window| 0
 .../notmuch-tree-single-thread  | 0
 .../notmuch-tree-tag-inbox  | 0
 .../notmuch-tree-tag-inbox-tagged   | 0
 .../notmuch-tree-tag-inbox-thread-tagged| 0
 6 files changed, 1 insertion(+), 1 deletion(-)
 rename test/{tree.expected-output => 
emacs-tree.expected-output}/notmuch-tree-show-window (100%)
 rename test/{tree.expected-output => 
emacs-tree.expected-output}/notmuch-tree-single-thread (100%)
 rename test/{tree.expected-output => 
emacs-tree.expected-output}/notmuch-tree-tag-inbox (100%)
 rename test/{tree.expected-output => 
emacs-tree.expected-output}/notmuch-tree-tag-inbox-tagged (100%)
 rename test/{tree.expected-output => 
emacs-tree.expected-output}/notmuch-tree-tag-inbox-thread-tagged (100%)

diff --git a/test/T460-emacs-tree.sh b/test/T460-emacs-tree.sh
index 0f4e4503..cb2c90b8 100755
--- a/test/T460-emacs-tree.sh
+++ b/test/T460-emacs-tree.sh
@@ -3,7 +3,7 @@
 test_description="emacs tree view interface"
 . $(dirname "$0")/test-lib.sh || exit 1
 
-EXPECTED=$NOTMUCH_SRCDIR/test/tree.expected-output
+EXPECTED=$NOTMUCH_SRCDIR/test/emacs-tree.expected-output
 
 add_email_corpus
 
diff --git a/test/tree.expected-output/notmuch-tree-show-window 
b/test/emacs-tree.expected-output/notmuch-tree-show-window
similarity index 100%
rename from test/tree.expected-output/notmuch-tree-show-window
rename to test/emacs-tree.expected-output/notmuch-tree-show-window
diff --git a/test/tree.expected-output/notmuch-tree-single-thread 
b/test/emacs-tree.expected-output/notmuch-tree-single-thread
similarity index 100%
rename from test/tree.expected-output/notmuch-tree-single-thread
rename to test/emacs-tree.expected-output/notmuch-tree-single-thread
diff --git a/test/tree.expected-output/notmuch-tree-tag-inbox 
b/test/emacs-tree.expected-output/notmuch-tree-tag-inbox
similarity index 100%
rename from test/tree.expected-output/notmuch-tree-tag-inbox
rename to test/emacs-tree.expected-output/notmuch-tree-tag-inbox
diff --git a/test/tree.expected-output/notmuch-tree-tag-inbox-tagged 
b/test/emacs-tree.expected-output/notmuch-tree-tag-inbox-tagged
similarity index 100%
rename from test/tree.expected-output/notmuch-tree-tag-inbox-tagged
rename to test/emacs-tree.expected-output/notmuch-tree-tag-inbox-tagged
diff --git a/test/tree.expected-output/notmuch-tree-tag-inbox-thread-tagged 
b/test/emacs-tree.expected-output/notmuch-tree-tag-inbox-thread-tagged
similarity index 100%
rename from test/tree.expected-output/notmuch-tree-tag-inbox-thread-tagged
rename to test/emacs-tree.expected-output/notmuch-tree-tag-inbox-thread-tagged
-- 
2.16.3

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: DRAFT Introduce CFFI-based Python bindings

2017-11-30 Thread Florian Klink

I guess you'll have to convince the maintainers / users of alot and afew
that this makes sense before we go much further. I'd point out that
Debian stable is only at python 3.5, so that makes me a bit wary of this
(being able to run the test suite on debian stable and similar aged
distros useful for me, and I suspect other developers).

I know there are issues with memory management in the current bindings,
so that may be a strong reason to push to python 3.6; it seems to need
more investigation at the moment.


I am generally in favour of modernizing the notmuch python bindings,
especially when it comes to memory management and exception handling.

At the moment, the alot interface officially only supports python v2.7
but our dependencies have now mostly been updated and we are working on
port to python 3, see here: https://github.com/pazz/alot/pull/1055


afew maintainer here ;-)

I'm also very much in favor of a more modern and pythonic interface, and would
gladly support retiring python 2, moving to the new interface.

I had a quick glimpse on the code, and would like to do some annotations. I fear
it's a bit awkward to do this inside the huge patch, which might already have
changed, and send back via email.
Did you publish a changeset to github, or somewhere else where I could comment
on it?

Cheers,
Florian


signature.asc
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v2 1/2] python: open messages in binary mode

2017-10-02 Thread Florian Klink

merged series to master. Thanks for the fix. BTW, I noticed the bug only
happens with python3.


Thanks for merging :-)
Yes, most distributions still symlink /usr/bin/python to python2 - maybe that's
the reason why a lot of code still runs on python 2…
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2 2/2] T390-python: add test for get_message_parts and special characters

2017-09-24 Thread Florian Klink
This imports a message with ISO-8859-2 encoded characters, then opens
the database using the python bindings. We peek through all mesage
parts, afterwards print the message id.

Signed-off-by: Florian Klink 
Signed-off-by: Andreas Rammhold 
---
 test/T390-python.sh | 17 +
 1 file changed, 17 insertions(+)

diff --git a/test/T390-python.sh b/test/T390-python.sh
index a9a61145..5921cac9 100755
--- a/test/T390-python.sh
+++ b/test/T390-python.sh
@@ -56,5 +56,22 @@ grep '^[0-9a-f]' OUTPUT > INITIAL_OUTPUT
 test_begin_subtest "output of count matches test code"
 notmuch count --lastmod '*' | cut -f2-3 > OUTPUT
 test_expect_equal_file INITIAL_OUTPUT OUTPUT
+add_message '[content-type]="text/plain; charset=iso-8859-2"' \
+'[content-transfer-encoding]=8bit' \
+'[subject]="ISO-8859-2 encoded message"' \
+"[body]=$'Czech word tu\350\362\341\350\350\355 means 
pinguin\'s.'" # ISO-8859-2 characters are generated by shell's escape sequences
+test_begin_subtest "Add ISO-8859-2 encoded message, call get_message_parts"
+test_python < EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
 
 test_done
-- 
2.14.1

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2 1/2] python: open messages in binary mode

2017-09-24 Thread Florian Klink
currently, notmuch's get_message_parts() opens the file in text mode and passes
the file object to email.message_from_file(fp). In case the email contains
UTF-8 characters, reading might fail inside email.parser with the following 
exception:

  File "/usr/lib/python3.6/site-packages/notmuch/message.py", line 591, in 
get_message_parts
email_msg = email.message_from_binary_file(fp)
  File "/usr/lib/python3.6/email/__init__.py", line 62, in 
message_from_binary_file
return BytesParser(*args, **kws).parse(fp)
  File "/usr/lib/python3.6/email/parser.py", line 110, in parse
return self.parser.parse(fp, headersonly)
  File "/usr/lib/python3.6/email/parser.py", line 54, in parse
data = fp.read(8192)
  File "/usr/lib/python3.6/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 1865: 
invalid continuation byte

To fix this, read file in binary mode and pass to
email.message_from_binary_file(fp).

Unfortunately, Python 2 doesn't support
email.message_from_binary_file(fp), so keep using
email.message_from_file(fp) there.

Signed-off-by: Florian Klink 
---
 bindings/python/notmuch/message.py | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/bindings/python/notmuch/message.py 
b/bindings/python/notmuch/message.py
index cce377d0..d5b98e4f 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -41,6 +41,7 @@ from .tag import Tags
 from .filenames import Filenames
 
 import email
+import sys
 
 
 class Message(Python3StringMixIn):
@@ -587,8 +588,11 @@ class Message(Python3StringMixIn):
 
 def get_message_parts(self):
 """Output like notmuch show"""
-fp = open(self.get_filename())
-email_msg = email.message_from_file(fp)
+fp = open(self.get_filename(), 'rb')
+if sys.version_info[0] < 3:
+email_msg = email.message_from_file(fp)
+else:
+email_msg = email.message_from_binary_file(fp)
 fp.close()
 
 out = []
-- 
2.14.1

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] python: open messages in binary mode

2017-08-25 Thread Florian Klink

that function is only since python 3.2. I'm not sure if/when we'll drop
python 2.7 support, but not without deprecating it for a few releases.


Is there anyone still exclusively on Python 2.7? Perhaps the time is 
ripe for starting that process? Encoding compatability is an unholy 
mess to maintain for one Python distro.


If Python 2 doesn't have email.message_from_binary_file(), it might be the bug
occuring to be can't really be fixed in Python 2 anyways. Maybe it's possible to
open the file in binary mode on Python 2, and pass this to
email.message_from_file() though, I will tinker around a bit this evening, and
let you know. 


Is any of alot, afew, etc still on Python 2 only?


afew works on both Python 2 and 3
alot seems to currently be Python 2 only (at least the Travis runs are), but it
looks like they are thinking about moving to Python 3 and dropping Python 2:
https://github.com/pazz/alot/issues/1047#issuecomment-300713819

Florian
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] python: open messages in binary mode

2017-08-24 Thread Florian Klink
currently, notmuch's get_message_parts() opens the file in text mode and passes
the file object to email.message_from_file(fp). In case the email contains
UTF-8 characters, reading might fail inside email.parser with the following 
exception:

  File "/usr/lib/python3.6/site-packages/notmuch/message.py", line 591, in 
get_message_parts
email_msg = email.message_from_binary_file(fp)
  File "/usr/lib/python3.6/email/__init__.py", line 62, in 
message_from_binary_file
return BytesParser(*args, **kws).parse(fp)
  File "/usr/lib/python3.6/email/parser.py", line 110, in parse
return self.parser.parse(fp, headersonly)
  File "/usr/lib/python3.6/email/parser.py", line 54, in parse
data = fp.read(8192)
  File "/usr/lib/python3.6/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 1865: 
invalid continuation byte

To fix this, read file in binary mode and pass to
email.message_from_binary_file(fp).

Signed-off-by: Florian Klink 
---
 bindings/python/notmuch/message.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bindings/python/notmuch/message.py 
b/bindings/python/notmuch/message.py
index cce377d0..531b22d0 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -587,8 +587,8 @@ class Message(Python3StringMixIn):
 
 def get_message_parts(self):
 """Output like notmuch show"""
-fp = open(self.get_filename())
-email_msg = email.message_from_file(fp)
+fp = open(self.get_filename(), 'rb')
+email_msg = email.message_from_binary_file(fp)
 fp.close()
 
 out = []
-- 
2.14.1

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch