mblaze

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

commit 524ee127958ee8be8b530154488f6f7faca1635e
parent 1fece7b090e00d57d3a7182e577358d41dc62457
Author: Christian Neukirchen <chneukirchen@gmail.com>
Date:   Sat,  6 Aug 2016 18:27:01 +0200

msort: add -U and -I to sort by flags

Diffstat:
man/msort.1 | 6+++++-
msort.c | 36++++++++++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/man/msort.1 b/man/msort.1 @@ -7,7 +7,7 @@ .Sh SYNOPSIS .Nm .Op Fl r -.Op Fl f | Fl d | Fl s | Fl F | Fl M | Fl S +.Op Fl f | Fl d | Fl s | Fl F | Fl M | Fl S | Fl U | Fl I .Op Ar msgs\ ... .Sh DESCRIPTION .Nm @@ -44,6 +44,10 @@ Sort by file name, using proper order for numbers in file names. Sort by message file modification time. .It Fl S Sort by message file size. +.It Fl U +Sort unread messages after read messages. +.It Fl I +Sort flagged messages before unflagged messages. .El .Sh EXIT STATUS .Ex -std diff --git a/msort.c b/msort.c @@ -213,6 +213,36 @@ fileorder(const void *a, const void *b) } int +unreadorder(const void *a, const void *b) +{ + struct mail *ia = (struct mail *)a; + struct mail *ib = (struct mail *)b; + + char *fa = strstr(ia->file, ":2,"); + char *fb = strstr(ib->file, ":2,"); + + int unreada = fa ? !strchr(fa, 'S') : 0; + int unreadb = fb ? !strchr(fb, 'S') : 0; + + return unreada - unreadb; +} + +int +flaggedorder(const void *a, const void *b) +{ + struct mail *ia = (struct mail *)a; + struct mail *ib = (struct mail *)b; + + char *fa = strstr(ia->file, ":2,"); + char *fb = strstr(ib->file, ":2,"); + + int unreada = fa ? !!strchr(fa, 'F') : 0; + int unreadb = fb ? !!strchr(fb, 'F') : 0; + + return unreadb - unreada; +} + +int idxorder(const void *a, const void *b) { struct mail *ia = (struct mail *)a; @@ -269,7 +299,7 @@ main(int argc, char *argv[]) { int c, i; - while ((c = getopt(argc, argv, "fdsFMSr")) != -1) + while ((c = getopt(argc, argv, "fdsFMSUIr")) != -1) switch(c) { case 'f': addorder(fromorder); break; case 'd': addorder(dateorder); break; @@ -277,10 +307,12 @@ main(int argc, char *argv[]) case 'F': addorder(fileorder); break; case 'M': addorder(mtimeorder); break; case 'S': addorder(sizeorder); break; + case 'U': addorder(unreadorder); break; + case 'I': addorder(flaggedorder); break; case 'r': rflag = !rflag; break; default: fprintf(stderr, - "Usage: msort [-r] [-fdsFMS] [msgs...]\n"); + "Usage: msort [-r] [-fdsFMSUI] [msgs...]\n"); exit(1); }