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

This commit is contained in:
Christian Neukirchen 2016-08-06 18:27:01 +02:00
parent 1fece7b090
commit 524ee12795
2 changed files with 39 additions and 3 deletions

View File

@ -7,7 +7,7 @@
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl r .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\ ... .Op Ar msgs\ ...
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
@ -44,6 +44,10 @@ Sort by file name, using proper order for numbers in file names.
Sort by message file modification time. Sort by message file modification time.
.It Fl S .It Fl S
Sort by message file size. Sort by message file size.
.It Fl U
Sort unread messages after read messages.
.It Fl I
Sort flagged messages before unflagged messages.
.El .El
.Sh EXIT STATUS .Sh EXIT STATUS
.Ex -std .Ex -std

36
msort.c
View File

@ -212,6 +212,36 @@ fileorder(const void *a, const void *b)
return mystrverscmp(ia->file, ib->file); return mystrverscmp(ia->file, ib->file);
} }
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 int
idxorder(const void *a, const void *b) idxorder(const void *a, const void *b)
{ {
@ -269,7 +299,7 @@ main(int argc, char *argv[])
{ {
int c, i; int c, i;
while ((c = getopt(argc, argv, "fdsFMSr")) != -1) while ((c = getopt(argc, argv, "fdsFMSUIr")) != -1)
switch(c) { switch(c) {
case 'f': addorder(fromorder); break; case 'f': addorder(fromorder); break;
case 'd': addorder(dateorder); break; case 'd': addorder(dateorder); break;
@ -277,10 +307,12 @@ main(int argc, char *argv[])
case 'F': addorder(fileorder); break; case 'F': addorder(fileorder); break;
case 'M': addorder(mtimeorder); break; case 'M': addorder(mtimeorder); break;
case 'S': addorder(sizeorder); break; case 'S': addorder(sizeorder); break;
case 'U': addorder(unreadorder); break;
case 'I': addorder(flaggedorder); break;
case 'r': rflag = !rflag; break; case 'r': rflag = !rflag; break;
default: default:
fprintf(stderr, fprintf(stderr,
"Usage: msort [-r] [-fdsFMS] [msgs...]\n"); "Usage: msort [-r] [-fdsFMSUI] [msgs...]\n");
exit(1); exit(1);
} }