Discussion:
find matched message in all mailboxes and put them into a separate mailbox
Yubin Ruan
2018-01-18 09:29:38 UTC
Permalink
Hi,

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.

Yubin
Yubin Ruan
2018-01-18 09:49:16 UTC
Permalink
Post by Yubin Ruan
Hi,
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.
Oh, I am using Maildir. So maybe some standalone script will help?

Yubin
Jörg Sommer
2018-01-18 11:56:22 UTC
Permalink
Hi Yubin,
Post by Yubin Ruan
Post by Yubin Ruan
Hi,
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.
Oh, I am using Maildir. So maybe some standalone script will help?
If it's Maildir, it's pretty simple. Create a new mailbox

mkdir -p /tmp/matches/cur /tmp/matches/new /tmp/matches/tmp

and copy all matching files there

cp $(grep -rli PATTERN ~/Mail) /tmp/matches/new
mutt -f /tmp/matches

Bye Jörg
Yubin Ruan
2018-01-18 23:41:20 UTC
Permalink
Post by Yubin Ruan
Hi,
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.
Yubin
Take a look at grepm http://www.barsnick.net/sw/grepm.html.
grepm puts the matching messages into a temporay mailbox under /tmp.
Thanks Ulrich,

but I am using the Maildir format while grepmail can only handle mbox format.

Yubin
Patrick Shanahan
2018-01-18 13:25:07 UTC
Permalink
Post by Yubin Ruan
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.
mairix is what you are looking for
--
(paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri
http://en.opensuse.org openSUSE Community Member facebook/ptilopteri
Registered Linux User #207535 @ http://linuxcounter.net
Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode
Darac Marjal
2018-01-18 09:47:09 UTC
Permalink
Post by Yubin Ruan
Hi,
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.
mutt might not be able to do this, but mairix[1] is geared around this
work flow. Here are some notes on using it [2]. And, additionally to
that, you might find it comfortable to set up and alias that calls
Mairix, then opens mutt on the search folder.


[1] http://www.rpcurnow.force9.co.uk/mairix/
[2] https://gitlab.com/muttmua/mutt/wikis/UseCases/SearchingMail#mairix
Post by Yubin Ruan
Yubin
--
For more information, please reread.
Ben Boeckel
2018-01-18 14:12:36 UTC
Permalink
Post by Yubin Ruan
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/

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
Patrick Shanahan
2018-01-18 18:19:22 UTC
Permalink
Post by Ben Boeckel
Post by Yubin Ruan
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.
https://notmuchmail.org/
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.
the OP has mbox which notmuch doesn't support
--
(paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri
http://en.opensuse.org openSUSE Community Member facebook/ptilopteri
Registered Linux User #207535 @ http://linuxcounter.net
Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode
Ben Boeckel
2018-01-18 18:30:01 UTC
Permalink
Post by Patrick Shanahan
the OP has mbox which notmuch doesn't support
Oh, I am using Maildir. So maybe some standalone script will help?
--Ben
Yubin Ruan
2018-01-20 22:00:54 UTC
Permalink
Post by Ben Boeckel
Post by Yubin Ruan
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.
https://notmuchmail.org/
Thanks Ben and all others in this thread,

I have taken a look at notmuch and it work well.
Post by Ben Boeckel
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

Loading...