[PATCH 2/2] [python] fix unsafe utf-8 decodings
From: pazzThis prevents unsafe calls to decode for return value None in get_authors/get_subject --- bindings/python/notmuch/tag.py|4 +++- bindings/python/notmuch/thread.py | 10 -- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py index d6abf28..9eb9fe2 100644 --- a/bindings/python/notmuch/tag.py +++ b/bindings/python/notmuch/tag.py @@ -86,7 +86,9 @@ class Tags(object): if not nmlib.notmuch_tags_valid(self._tags): self._tags = None raise StopIteration -tag = Tags._get(self._tags).decode('utf-8') +tag = Tags._get(self._tags) +if tag: +tag = tag.decode('UTF-8') nmlib.notmuch_tags_move_to_next(self._tags) return tag diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py index 120f925..2a55bd9 100644 --- a/bindings/python/notmuch/thread.py +++ b/bindings/python/notmuch/thread.py @@ -292,7 +292,10 @@ class Thread(object): """ if self._thread is None: raise NotmuchError(STATUS.NOT_INITIALIZED) -return Thread._get_authors(self._thread).decode('UTF-8') +authors = Thread._get_authors(self._thread) +if authors: +return authors.decode('UTF-8') +return None def get_subject(self): """Returns the Subject of 'thread' @@ -302,7 +305,10 @@ class Thread(object): """ if self._thread is None: raise NotmuchError(STATUS.NOT_INITIALIZED) -return Thread._get_subject(self._thread).decode('UTF-8') +subject = Thread._get_subject(self._thread) +if subject: +return subject.decode('UTF-8') +return None def get_newest_date(self): """Returns time_t of the newest message date -- 1.7.4.1
configure indentation width instead? (was: Re: [PATCH 2/2] Emacs: Add variable to toggle thread indentation to notmuch-show)
On Tue, 19 Jul 2011, Gregor Zattler wrote: > Hi Felix, notmuch develpers, > > Felix introduces a boolean configuration variable in order to > disable/enable indentation. Wouldn't it be more helpful and > powerful to customise the indentation width with "0" meaning no > indentation, "1" being the current behaviour, "2" meaning double > indentation, "3" threefold indentation ... ? +1 Sometimes I find indenting by one character too small to find the replied message in long threads. -Michal
queries switching from MH-E to notmuch
I'm considering switch emacs mailers, from MH-E to notmuch, as I would like to find an emacs mailer with decent IMAP support. Compared to gnus, notmuch seems much quicker, and I like the sound of tags + fast searching. Can anyone help with the following points: 1. Deleting emails I've seen the suggestions on the emacstips for keybindings to bind 'd' to adding deleted tags. But how do you then delete the mails from the local Maildir (and then for offlineimap to propagate back the deletions to the remote imap server)? Do you run cron jobs to do this? 2. viewing both the search results and current thread I'm used to the MH-E (and VM) idea that when browsing a folder (or, here, search results) the top window shows the subject lines, and the bottom, larger, window shows the current message. e.g. see the top screenshot at: http://mh-e.sourceforge.net/screenshots/. As you scroll through the folder contents at the top, the bottom window shows the corresponding message. By contrast, in notmuch it seems that you either see just the search results, or one thread, but not both. Would it be feasible to get something more like the behaviour of VM and MH-E? I can write elisp fluently, but before I look into it, I thought I'd check to see whether this is feasible. (I've just seen that this is the bottom item on Keith P's wish list: http://keithp.com/notmuch/) Thanks, Stephen
PATCH: (more) compability with emacs 22
Hi Currently, notmuch-lib.el does not have enough emacs 23 compability functions. This patch makes notmuch better compatible with emacs 22: --8888888888-- diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index f93c957..d6b4108 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -144,12 +144,35 @@ within the current window. ;; Compatibility functions for versions of emacs before emacs 23. ;; -;; Both functions here were copied from emacs 23 with the following copyright: +;; All functions here were copied from emacs 23 with the following copyright: ;; ;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1999, 2000, 2001, 2002, 2003, ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. ;; ;; and under the GPL version 3 (or later) exactly as notmuch itself. + +(compile-on-emacs-prior-to-23 + (load cl-macs)) + +(compile-on-emacs-prior-to-23 + (defun process-lines (program rest args) + Execute PROGRAM with ARGS, returning its output as a list of lines. +Signal an error if the program returns with a non-zero exit status. + (with-temp-buffer + (let ((status (apply 'call-process program nil (current-buffer) nil args))) + (unless (eq status 0) +(error %s exited with status %s program status)) + (goto-char (point-min)) + (let (lines) +(while (not (eobp)) + (setq lines (cons (buffer-substring-no-properties + (line-beginning-position) + (line-end-position)) +lines)) + (forward-line 1)) +(nreverse lines)) + + (compile-on-emacs-prior-to-23 (defun apply-partially (fun rest args) Return a function that is a partial application of FUN to ARGS. --8888888888-- I personally would like to move emacs 23 functionality to separate file, like 'notmuch-lib22.el' and then write the following to notmuch-lib.el: (when ( emacs-major-version 23) (require 'notmuch-lib22)) Tomi ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Memory management issue in notmuch-haskell bindings
It seems that the notmuch-haskell bindings (version 0.2.2 built against notmuch from git master; passes notmuch-test) aren't dealing with memory management properly. In particular, the attached test code[1] causes talloc to abort. Unfortunately, while the issue is consistently reproducible, it only occurs with some queries (see source[1]). I have been unable to establish the exact criterion for failure. It seems that the crash is caused by an invalid access to a freed Query object while freeing a Messages object (see Valgrind trace[3]). I've taken a brief look at the bindings themselves but, being only minimally familiar with the FFI, there's nothing obviously wrong (the finalizers passed to newForeignPtr look sane). I was under the impression that talloc was reference counted, so the Query object shouldn't have been freed unless if there was still a Messages object holding a reference. Any idea what might have gone wrong here? Thanks! Cheers, - Ben [1] Test case, import Data.List import Control.Monad import System.Environment import Foreign.Notmuch dbpath = /home/ben/.mail getAddresses :: Database - String - IO [String] getAddresses db q = do query - queryCreate db q msgs - queryMessages query addrs - mapM (flip messageGetHeader $ From) msgs return addrs main = do db - databaseOpen dbpath DatabaseModeReadOnly --addrs2 - getAddresses db tag:haskell -- This succeeds addrs3 - getAddresses db to:dietz -- This fails --print addrs2 --print addrs3 databaseClose db [2] Crashed session and backtrace, [1217 ben@ben-laptop ~] $ ghc test.hs -auto-all -rtsopts -prof gdb ./test GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type show copying and show warranty for details. This GDB was configured as x86_64-linux-gnu. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/... Reading symbols from /home/ben/test...(no debugging symbols found)...done. (gdb) run Starting program: /home/ben/test [Thread debugging using libthread_db enabled] Program received signal SIGABRT, Aborted. 0x75979d05 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. in ../nptl/sysdeps/unix/sysv/linux/raise.c (gdb) bt #0 0x75979d05 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 #1 0x7597dab6 in abort () at abort.c:92 #2 0x76de038c in talloc_abort (reason=0x76de56e8 Bad talloc magic value - access after free) at ../talloc.c:210 #3 0x76de0271 in talloc_abort_access_after_free (ptr=0x769190, location=0x77bd4e04 lib/messages.c:142) at ../talloc.c:229 #4 talloc_chunk_from_ptr (ptr=0x769190, location=0x77bd4e04 lib/messages.c:142) at ../talloc.c:250 #5 _talloc_free (ptr=0x769190, location=0x77bd4e04 lib/messages.c:142) at ../talloc.c:1164 #6 0x77bc7e65 in notmuch_messages_destroy (messages=0x769190) at lib/messages.c:142 #7 0x004de1c9 in scheduleFinalizers () #8 0x004e013d in GarbageCollect () #9 0x004d9e40 in scheduleDoGC.clone.18 () #10 0x004db0e0 in exitScheduler () #11 0x004d9066 in hs_exit_ () #12 0x004d940a in shutdownHaskellAndExit () #13 0x004d8a91 in real_main () #14 0x004d8ade in hs_main () #15 0x75964eff in __libc_start_main (main=0x408ed0 main, argc=1, ubp_av=0x7fffe4f8, init=value optimized out, fini=value optimized out, rtld_fini=value optimized out, stack_end=0x7fffe4e8) at libc-start.c:226 #16 0x00407791 in _start () (gdb) [3] Valgrind output, ==25241== Memcheck, a memory error detector ==25241== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==25241== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info ==25241== Command: ./test ==25241== ==25241== Conditional jump or move depends on uninitialised value(s) ==25241==at 0x52BB510: inflateReset2 (in /lib/x86_64-linux-gnu/libz.so.1.2.3.4) ==25241==by 0x52BB605: inflateInit2_ (in /lib/x86_64-linux-gnu/libz.so.1.2.3.4) ==25241==by 0x5F211BE: ChertTable::lazy_alloc_inflate_zstream() const (chert_table.cc:1672) ==25241==by 0x5F23B06: ChertTable::read_tag(Cursor*, std::string*, bool) const (chert_table.cc:1264) ==25241==by 0x5F260F9: ChertTable::get_exact_entry(std::string const, std::string) const (chert_table.cc:1210) ==25241==by 0x5F26DE2: ChertTermList::ChertTermList(Xapian::Internal::RefCntPtrChertDatabase const, unsigned int) (chert_termlist.cc:44) ==25241==by 0x5EFF2E5: ChertDatabase::open_term_list(unsigned int) const (chert_database.cc:891) ==25241==by 0x5E7E7FB:
Re: configure indentation width instead? (was: Re: [PATCH 2/2] Emacs: Add variable to toggle thread indentation to notmuch-show)
On Tue, 19 Jul 2011, Gregor Zattler wrote: Hi Felix, notmuch develpers, Felix introduces a boolean configuration variable in order to disable/enable indentation. Wouldn't it be more helpful and powerful to customise the indentation width with 0 meaning no indentation, 1 being the current behaviour, 2 meaning double indentation, 3 threefold indentation ... ? +1 Sometimes I find indenting by one character too small to find the replied message in long threads. -Michal ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH 2/2] [python] fix unsafe utf-8 decodings
From: pazz patricktot...@gmail.com This prevents unsafe calls to decode for return value None in get_authors/get_subject --- bindings/python/notmuch/tag.py|4 +++- bindings/python/notmuch/thread.py | 10 -- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py index d6abf28..9eb9fe2 100644 --- a/bindings/python/notmuch/tag.py +++ b/bindings/python/notmuch/tag.py @@ -86,7 +86,9 @@ class Tags(object): if not nmlib.notmuch_tags_valid(self._tags): self._tags = None raise StopIteration -tag = Tags._get(self._tags).decode('utf-8') +tag = Tags._get(self._tags) +if tag: +tag = tag.decode('UTF-8') nmlib.notmuch_tags_move_to_next(self._tags) return tag diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py index 120f925..2a55bd9 100644 --- a/bindings/python/notmuch/thread.py +++ b/bindings/python/notmuch/thread.py @@ -292,7 +292,10 @@ class Thread(object): if self._thread is None: raise NotmuchError(STATUS.NOT_INITIALIZED) -return Thread._get_authors(self._thread).decode('UTF-8') +authors = Thread._get_authors(self._thread) +if authors: +return authors.decode('UTF-8') +return None def get_subject(self): Returns the Subject of 'thread' @@ -302,7 +305,10 @@ class Thread(object): if self._thread is None: raise NotmuchError(STATUS.NOT_INITIALIZED) -return Thread._get_subject(self._thread).decode('UTF-8') +subject = Thread._get_subject(self._thread) +if subject: +return subject.decode('UTF-8') +return None def get_newest_date(self): Returns time_t of the newest message date -- 1.7.4.1 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch