w3mail

program to send a web page by email
git clone https://logand.com/git/w3mail.git/
Log | Files | Refs | README | LICENSE

commit 14df8156ef6c6ae8c42a409c04b4b19431ae9894
parent fd36e76ea06985c72c27bf42f12156e4f5f9a11e
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sat, 22 Jan 2011 14:22:31 +0100

use filters in cb_tidy

Diffstat:
Mw3mail.c | 53+++++++++++++++++++++++++++++------------------------
1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/w3mail.c b/w3mail.c @@ -49,7 +49,13 @@ static void now(char *buf) { strftime(buf, BLEN, "%a, %d %b %Y %T %z", tm); } -#define pr(...) {fprintf(out, __VA_ARGS__); fprintf(out, "\n");} +static int head(char *sub, char *str) { + return 0 == strncmp(sub, str, strlen(sub)); +} + +static int equal(char *str1, char *str2) { + return 0 == strcmp(str1, str2); +} struct tidy { char *fin; @@ -59,21 +65,26 @@ struct tidy { static void cb_tidy(void *udata, FILE* in) { struct tidy *x = udata; - char name[BLEN], arg[BLEN]; - strcpy(name, "bbc"); - strcpy(arg, ""); - // TODO compute filter name from url - /* while(!feof(in)) { */ - /* char line[BLEN]; */ - /* if(!fgets(line, BLEN, in)) break; */ - /* rtrim(line); */ - /* // TODO run filter based on url */ - /* // if head(url) then */ - /* // if filters/%s filter exist */ - /* // in(???, ???, "filters/%s '%s'", filter, arg); */ - /* } */ - // w3m -dump /tmp/a.html - systemf("~/.w3mail/filter/%s '%s' <%s >%s", name, arg, x->fin, x->fout); + while(!feof(in)) { + char line[BLEN]; + if(!fgets(line, BLEN, in)) break; + rtrim(line); + if('#' == line[0]) continue; + char name[BLEN], url[BLEN], type[BLEN]; + int n; + sscanf(line, "%s %s %s %n", name, url, type, &n); + if(url[0] && head(url, x->url)) { + if(equal("xpath", type)) { + if(!systemf("~/.w3mail/filter/xpath \"%s\" <%s >%s", &line[n], x->fin, x->fout)) + return; + } + else if(equal("filter", type)) { + if(!systemf("~/.w3mail/filter/%s <%s >%s", &line[n], x->fin, x->fout)) + return; + } + } + } + systemf("~/.w3mail/filter/default <%s >%s", x->fin, x->fout); } static void tidy(char *fin, char *fout, char *url) { @@ -94,6 +105,8 @@ static void cb_xtidy(void *udata, char *fname) { //in(x->out, cb_echo, "w3m -dump -T text/html %s", fname); } +#define pr(...) {fprintf(out, __VA_ARGS__); fprintf(out, "\n");} + struct sendmail { char *from; char *to; @@ -132,14 +145,6 @@ static void cb_read_first_line(void *udata, FILE* in) { rtrim(fgets(udata, BLEN, in)); } -static int head(char *sub, char *str) { - return 0 == strncmp(sub, str, strlen(sub)); -} - -static int equal(char *str1, char *str2) { - return 0 == strcmp(str1, str2); -} - static int is_html(char *elt) { return equal("html", elt) || equal("xhtml", elt); }