dmc

dynamic mail client
git clone git://git.suckless.org/dmc
Log | Files | Refs | README | LICENSE

commit f4cc5828e8431a510beee324d3417373b4bc496b
parent 3c2d922256d1c07bd34f50354e8863c14ed36bd3
Author: nibble <unknown>
Date:   Tue,  3 Nov 2009 23:05:18 +0100

* Fixups in dmc-filter
Diffstat:
filter.c | 36+++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/filter.c b/filter.c @@ -5,8 +5,8 @@ #include <string.h> int main(int argc, char **argv) { - char b[1024], *ptr; - int edit = argc, print = 0, i; + char b[1024], argv2[1024][1024], *ptr; + int edit = argc, print = 0, i, j; for (i = 0; i < argc; i++) if (!strcmp (argv[i], "-h")) { @@ -14,33 +14,35 @@ int main(int argc, char **argv) { return 1; } else if (!strcmp (argv[i], "-e")) edit = i; + for (i = 0; i < argc; i++) { + strncpy(argv2[i], argv[i], 1023); + argv2[i][1023] = '\0'; + } memset (b, '\0', 1024); /* Headers */ while (fgets (b, 1023, stdin) && b[0] != '\n') - if (print && (b[0] == ' ' || b[0] == '\t')) - fputs (b, stdout); - else for (i = 1; i < edit && argv[i]; i++) - if (strstr (b, argv[i])) { + if ((b[0] == ' ' || b[0] == '\t')) { + if (print) fputs (b, stdout); + } else for (i = 1; i < edit && argv[i]; i++) + if (!strncmp (b, argv[i], strlen(argv[i])) || argv[i][0] == ':') { /* Edit/Remove Headers */ print = 1; - for (i = edit + 1; i < argc && argv[i]; i++) - if ((ptr = strchr (argv[i], ':')) && - !strncmp (b, argv[i], ptr - argv[i])) { - if (ptr[1] != '\0') - puts (argv[i]); - argv[i][0] = '\0'; + for (j = edit + 1; j < argc && argv[j]; j++) + if ((ptr = strchr (argv[j], ':')) && + !strncmp (b, argv[j], ptr - argv[j] + 1)) { + if (ptr[1] != '\0' && argv2[j][0]) + puts (argv[j]); + argv2[j][0] = '\0'; print = 0; break; } if (print) fputs (b, stdout); break; - } else if (b[0] != ' ' && b[0] != '\t') - print = 0; + } else print = 0; /* New Headers */ for (i = edit + 1; i < argc; i++) - if (argv[i][0]) puts (argv[i]); - if (edit < argc) - puts (""); + if (argv2[i][0]) puts (argv2[i]); + if (edit < argc) puts (""); /* Body */ while ((argc < 2 || edit < argc) && fgets (b, 1023, stdin)) fputs (b, stdout);