mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit 6fbe731671789a70cf5e9e9d4ebbe66a1f37ee55
parent 418555f53a76f26f9527a43849172c9471b70f1e
Author: Duncaen <mail@duncano.de>
Date:   Sat, 23 Jul 2016 18:45:23 +0200

mpick: add parent and child test

Diffstat:
mpick.c | 40++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/mpick.c b/mpick.c @@ -120,6 +120,8 @@ static struct thread *thr; static char *argv0; static int Tflag; +static int need_thr; + static long kept; static long num; @@ -399,6 +401,12 @@ parse_flag() flag = FLAG_NEW; } else if (token("cur")) { flag = FLAG_CUR; + } else if (token("parent")) { + flag = FLAG_PARENT; + need_thr = 1; + } else if (token("child")) { + flag = FLAG_CHILD; + need_thr = 1; } else return parse_strcmp(); @@ -924,9 +932,14 @@ collect(char *file) } thr->matched = 0; - thr->cur = thr->childs; + ml = thr->cur = thr->childs; thr->cur->m = m; } else { + /* previous mail is a prent, current one is a child */ + if (thr->cur->m->depth < m->depth) + thr->cur->m->flags |= FLAG_PARENT; + m->flags |= FLAG_CHILD; + ml = thr->cur + 1; thr->cur->next = ml; thr->cur = ml; @@ -935,14 +948,15 @@ collect(char *file) m->fpath = strdup(m->fpath); - /* already one match in thread */ - if (Tflag && thr->matched) - return; + if (Tflag) { + if (thr->matched) + return; - if (expr && !eval(expr, m)) - return; + if (expr && !eval(expr, m)) + return; - thr->matched++; + thr->matched++; + } } void @@ -970,13 +984,12 @@ main(int argc, char *argv[]) { long i; int c; - void (*cb)(char *); argv0 = argv[0]; while ((c = getopt(argc, argv, "Tt:")) != -1) switch (c) { - case 'T': Tflag = 1; break; + case 'T': Tflag = need_thr = 1; break; case 't': expr = chain(expr, EXPR_AND, parse_expr(optarg)); break; } @@ -984,15 +997,10 @@ main(int argc, char *argv[]) for (c = optind; c < argc; c++) expr = chain(expr, EXPR_AND, parse_msglist(argv[c])); - if (Tflag) - cb = collect; - else - cb = oneline; - if (isatty(0)) { - i = blaze822_loop1(":", cb); + i = blaze822_loop1(":", need_thr ? collect : oneline); } else - i = blaze822_loop(0, NULL, cb); + i = blaze822_loop(0, NULL, need_thr ? collect : oneline); /* print and free last thread */ if (Tflag && thr)