diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2016-08-06 18:27:01 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2016-08-06 18:27:38 +0200 |
commit | 524ee127958ee8be8b530154488f6f7faca1635e (patch) | |
tree | 484b3c20080c8eb4c9836dca21d8c0defc41ffd7 /msort.c | |
parent | 1fece7b090e00d57d3a7182e577358d41dc62457 (diff) | |
download | mblaze-524ee127958ee8be8b530154488f6f7faca1635e.tar.gz mblaze-524ee127958ee8be8b530154488f6f7faca1635e.tar.xz mblaze-524ee127958ee8be8b530154488f6f7faca1635e.zip |
msort: add -U and -I to sort by flags
Diffstat (limited to 'msort.c')
-rw-r--r-- | msort.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/msort.c b/msort.c index e003fb5..323717a 100644 --- 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); } |