diff options
-rw-r--r-- | man/msort.1 | 6 | ||||
-rw-r--r-- | msort.c | 36 |
2 files changed, 39 insertions, 3 deletions
diff --git a/man/msort.1 b/man/msort.1 index 44cd332..8b9fb38 100644 --- 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 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); } |