On Thu, Jan 18, 2018 at 09:12:36AM -0500, Ben Boeckel wrote:
> On Thu, Jan 18, 2018 at 17:29:38 +0800, Yubin Ruan wrote:
> > I know one can hit / or l (i.e., limit) and then apply a search pattern to
> > search for messages in the current mailbox. But can we apply this to 
> > multiple
> > mailboxes? I would like to search for matched messages in all mailboxes and
> > then put them into a separate mailbox. For example, I have 10 mailboxes and
> > now I want to search in these 10 mailboxes for messages that have me in the
> > "To: " field and then put them into a separate mailbox.
> 
> I use notmuch for this (using Maildir):
> 
>     https://notmuchmail.org/

Thanks Ben and all others in this thread,

I have taken a look at notmuch and it work well. 

> with these bindings:
> 
>     macro index \Cn "\
>     <enter-command> set my_wait_key = \$wait_key<enter>\
>     <enter-command> unset wait_key<enter>\
>     <shell-escape>notmuch-mutt --prompt search<enter>\
>     <change-folder-readonly>~/.cache/notmuch/mutt/results<enter>\
>     <enter-command> set wait_key = \$my_wait_key<enter>\
>     <enter-command> unset my_wait_key<enter>\
>     " "search mail (using notmuch)"
>     macro index <F9> "\
>     <enter-command> set my_wait_key = \$wait_key<enter>\
>     <enter-command> unset wait_key<enter>\
>     <pipe-message>notmuch-mutt thread<enter>\
>     <change-folder-readonly>~/.cache/notmuch/mutt/results<enter>\
>     <enter-command> set wait_key = \$my_wait_key<enter>\
>     <enter-command> unset my_wait_key<enter>\
>     " "search and reconstruct owning thread (using notmuch)"
> 
> Notmuch reindexing is triggered by offlineimap, but whatever fetches
> email for you should also be able to trigger a reindex.

Ben, I believe this is from a script from Stefano Zacchiroli at

    https://upsilon.cc/~zack/blog/posts/2011/01/how_to_use_Notmuch_with_Mutt/

right? That works well, except for the bug below.

[added Stefano Zacchiroli to the Cc: ...]

Hi Stefano,

how about the patch below? I believe it is safer to escape special character
such as whitespace when passing filename through bash pipe (e.g., Gmail has
the "Sent Mail" folder)

--- /tmp/mutt-notmuch-old       2018-01-21 17:52:11.946415454 +0800
+++ /tmp/mutt-notmuch-new       2018-01-21 17:40:12.926430126 +0800
@@ -35,6 +35,7 @@
 
     empty_maildir($maildir);
     system("notmuch search --output=files $query"
+          . " | sed -e \'s/ /\\\\ /\' "
        . " | xargs --no-run-if-empty ln -s -t $maildir/cur/");
 }

Another thing I find sorry is that modifications in the search results listing
do not carry over (i.e., modifications in ~/.cache/mutt_result do not carry
over to the original mail, even though mails in ~/.cache/mutt_results/ are
symlinked to their origins). I can change <change-folder-readonly> to
<change-folder>, but it doesn't work. I don't know what a modification should
be for the Maildir format, so hopefully anyone can help here...

        Yubin

Reply via email to