diff --git a/test/Makefile.in b/test/Makefile.in deleted file mode 100644 index 0745aea2..00000000 --- a/test/Makefile.in +++ /dev/null @@ -1,55 +0,0 @@ -SHELL = @SHELL@ - -prefix = @prefix@ -exec_prefix = @exec_prefix@ -bindir = @bindir@ -sbindir = @sbindir@ -includedir = @includedir@ -libdir = @libdir@ -libexecdir = @libexecdir@ -srcdir = @srcdir@ -sysconfdir = @sysconfdir@ -mandir = @mandir@ -datarootdir = @datarootdir@ -localstatedir = @localstatedir@ - -CC = @CC@ -CFLAGS = @CFLAGS@ @CPPFLAGS@ -DEFS = @defs@ -INCDIR = -I. -I.. -I../.. -I../../src -I../src @INCDIR@ @sql_includes@ -LIBDIR = -L. @LIBDIR@ @LDFLAGS@ -L../src -LIBS = @LIBS@ @sql_libs@ -RUNNING_USER = @RUNNING_USER@ -RUNNING_GROUP = `@id_bin@ -gn $(RUNNING_USER)` -OBJS = import_helper.o - -INSTALL = @INSTALL@ - -all: $(OBJS) parser debug import ptest test - -parser: parser.c ../src/libpiler.a - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) - -ptest: ptest.c ../src/libpiler.a - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) - -debug: debug.c ../src/libpiler.a - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) - -import: import.c ../src/libpiler.a - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler import_helper.o $(LIBS) $(LIBDIR) - -test: test.c ../src/libpiler.a - $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) - -%.o: $(srcdir)/%.c - $(CC) $(CFLAGS) -fPIC $(INCDIR) $(DEFS) -c $< -o $@ - - -install: - -clean: - rm -f parser debug import ptest test - -distclean: clean - rm -f Makefile diff --git a/test/check.sh b/test/check.sh deleted file mode 100755 index cb066694..00000000 --- a/test/check.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -for i in ../testemails/raw/*; do - ./test $i > aa; - diff aa ../testemails/parsed/`basename $i`; - if [ $? -eq 0 ]; then echo OK; else echo `basename $i`": ERROR"; fi -done - -rm -f aa - - diff --git a/test/debug.c b/test/debug.c deleted file mode 100644 index e29952e5..00000000 --- a/test/debug.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -int main(int argc, char **argv){ - struct stat st; - struct session_data sdata; - struct _state state; - struct __data data; - struct __config cfg; - - - if(argc < 2){ - fprintf(stderr, "usage: %s \n", argv[0]); - exit(1); - } - - if(stat(argv[1], &st) != 0){ - fprintf(stderr, "%s is not found\n", argv[1]); - return 0; - } - - - cfg = read_config(CONFIG_FILE); - - - init_session_data(&sdata, &cfg); - - sdata.sent = 0; - sdata.tot_len = st.st_size; - - snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", argv[1]); - snprintf(sdata.filename, SMALLBUFSIZE-1, "%s", argv[1]); - snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", argv[1]); - - cfg.debug = 1; - - state = parse_message(&sdata, 0, &data, &cfg); - post_parse(&sdata, &state, &cfg); - - printf("message-id: %s\n", state.message_id); - printf("from: *%s (%s)*\n", state.b_from, state.b_from_domain); - printf("to: *%s (%s)*\n", state.b_to, state.b_to_domain); - printf("reference: *%s*\n", state.reference); - printf("subject: *%s*\n", state.b_subject); - printf("body: *%s*\n", state.b_body); - - printf("sent: %ld\n", sdata.sent); - - make_digests(&sdata, &cfg); - - return 0; -} diff --git a/test/import.c b/test/import.c deleted file mode 100644 index a655c98c..00000000 --- a/test/import.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * pilerimport.c, SJ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -extern char *optarg; -extern int optind; - - -int connect_to_imap_server(int sd, int *seq, char *imapserver, char *username, char *password); -int list_folders(int sd, int *seq, char *folders, int foldersize); -int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sdata, struct __data *data, struct __config *cfg); -int import_message2(char *filename, struct session_data *sdata, struct __data *data, struct __config *cfg); - - -int import_from_mailbox(char *mailbox, struct session_data *sdata, struct __data *data, struct __config *cfg){ - FILE *F, *f=NULL; - int rc=ERR, tot_msgs=0, ret=OK; - char buf[MAXBUFSIZE], fname[SMALLBUFSIZE]; - time_t t; - - - F = fopen(mailbox, "r"); - if(!F){ - printf("cannot open mailbox: %s\n", mailbox); - return rc; - } - - t = time(NULL); - - while(fgets(buf, sizeof(buf)-1, F)){ - - if(buf[0] == 'F' && buf[1] == 'r' && buf[2] == 'o' && buf[3] == 'm' && buf[4] == ' '){ - tot_msgs++; - if(f){ - fclose(f); - rc = import_message2(fname, sdata, data, cfg); - printf("processed: %7d\r", tot_msgs); fflush(stdout); - - if(rc == ERR) ret = ERR; - unlink(fname); - } - - snprintf(fname, sizeof(fname)-1, "%ld-%d", t, tot_msgs); - f = fopen(fname, "w+"); - continue; - } - - if(f) fprintf(f, "%s", buf); - } - - if(f){ - fclose(f); - rc = import_message2(fname, sdata, data, cfg); - printf("processed: %7d\r", tot_msgs); fflush(stdout); - - if(rc == ERR) ret = ERR; - unlink(fname); - } - - fclose(F); - - printf("\n"); - - return ret; -} - - -int import_from_maildir(char *directory, struct session_data *sdata, struct __data *data, struct __config *cfg){ - DIR *dir; - struct dirent *de; - int rc=ERR, ret=OK, tot_msgs=0; - char fname[SMALLBUFSIZE]; - struct stat st; - - dir = opendir(directory); - if(!dir){ - printf("cannot open directory: %s\n", directory); - return ERR; - } - - - while((de = readdir(dir))){ - if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; - - snprintf(fname, sizeof(fname)-1, "%s/%s", directory, de->d_name); - - if(stat(fname, &st) == 0){ - if(S_ISDIR(st.st_mode)){ - rc = import_from_maildir(fname, sdata, data, cfg); - if(rc == ERR) ret = ERR; - } - else { - - if(S_ISREG(st.st_mode)){ - rc = import_message2(fname, sdata, data, cfg); - if(rc == OK) tot_msgs++; - else ret = ERR; - } - else { - printf("%s is not a file\n", fname); - } - - } - } - else { - printf("cannot stat() %s\n", fname); - } - - } - closedir(dir); - - return ret; -} - - -int import_from_imap_server(char *imapserver, char *username, char *password, struct session_data *sdata, struct __data *data, struct __config *cfg){ - int rc=ERR, ret=OK, sd, seq=1, result; - char *p, puf[MAXBUFSIZE]; - char folders[MAXBUFSIZE]; - - if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1){ - printf("cannot create socket\n"); - return ERR; - } - - if(connect_to_imap_server(sd, &seq, imapserver, username, password) == ERR){ - close(sd); - return ERR; - } - - - list_folders(sd, &seq, &folders[0], sizeof(folders)); - - - p = &folders[0]; - do { - memset(puf, 0, sizeof(puf)); - p = split(p, '\n', puf, sizeof(puf)-1, &result); - - printf("processing folder: %s... ", puf); - - rc = process_imap_folder(sd, &seq, puf, sdata, data, cfg); - if(rc == ERR) ret = ERR; - - } while(p); - - - close(sd); - - return ret; -} - - -void usage(){ - printf("usage: pilerimport [-c ] -e | -m | -d | -i -u -p \n"); - exit(0); -} - - -int main(int argc, char **argv){ - int i, rc=0; - char *configfile=CONFIG_FILE, *mailbox=NULL, *emlfile=NULL, *directory=NULL; - char *imapserver=NULL, *username=NULL, *password=NULL; - struct session_data sdata; - struct __config cfg; - struct __data data; - - - while((i = getopt(argc, argv, "c:m:e:d:i:u:p:h?")) > 0){ - switch(i){ - - case 'c' : - configfile = optarg; - break; - - case 'e' : - emlfile = optarg; - break; - - case 'd' : - directory = optarg; - break; - - case 'm' : - mailbox = optarg; - break; - - case 'i' : - imapserver = optarg; - break; - - case 'u' : - username = optarg; - break; - - case 'p' : - password = optarg; - break; - - case 'h' : - case '?' : - usage(); - break; - - - default : - break; - } - } - - - - if(!mailbox && !emlfile && !directory && !imapserver) usage(); - - - cfg = read_config(configfile); - - setlocale(LC_CTYPE, cfg.locale); - - initrules(data.archiving_rules); - initrules(data.retention_rules); - - if(emlfile) rc = import_message2(emlfile, &sdata, &data, &cfg); - if(mailbox) rc = import_from_mailbox(mailbox, &sdata, &data, &cfg); - if(directory) rc = import_from_maildir(directory, &sdata, &data, &cfg); - if(imapserver && username && password) rc = import_from_imap_server(imapserver, username, password, &sdata, &data, &cfg); - - clearrules(data.archiving_rules); - clearrules(data.retention_rules); - - return rc; -} - - diff --git a/test/import_helper.c b/test/import_helper.c deleted file mode 100644 index a7b68826..00000000 --- a/test/import_helper.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * import.c, SJ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -int import_message2(char *filename, struct session_data *sdata, struct __data *data, struct __config *cfg){ - int rc=ERR, i, fd; - char *rule; - struct stat st; - struct _state state; - - - init_session_data(sdata, cfg); - - - if(strcmp(filename, "-") == 0){ - - if(read_from_stdin(sdata) == ERR){ - printf("error reading from stdin\n"); - return rc; - } - - snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", sdata->ttmpfile); - - } - else { - - if(stat(filename, &st) != 0){ - printf("cannot stat() %s\n", filename); - return rc; - } - - if(S_ISREG(st.st_mode) == 0){ - printf("%s is not a file\n", filename); - return rc; - } - - fd = open(filename, O_RDONLY); - if(fd == -1){ - printf("cannot open %s\n", filename); - return rc; - } - close(fd); - - snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", filename); - - sdata->tot_len = st.st_size; - } - - - - sdata->sent = 0; - - state = parse_message(sdata, 1, data, cfg); - post_parse(sdata, &state, cfg); - - if(sdata->sent > sdata->now) sdata->sent = sdata->now; - if(sdata->sent == -1) sdata->sent = 0; - - /* fat chances that you won't import emails before 1990.01.01 */ - - if(sdata->sent > 631148400) sdata->retained = sdata->sent; - - rule = check_againt_ruleset(data->archiving_rules, &state, sdata->tot_len, sdata->spam_message); - - if(rule){ - printf("discarding %s by archiving policy: %s\n", filename, rule); - rc = OK; - goto ENDE; - } - - make_digests(sdata, cfg); - -ENDE: - unlink(sdata->tmpframe); - - if(strcmp(filename, "-") == 0) unlink(sdata->ttmpfile); - - for(i=1; i<=state.n_attachments; i++) unlink(state.attachments[i].internalname); - - return OK; -} - diff --git a/test/parser.c b/test/parser.c deleted file mode 100644 index 0a073d14..00000000 --- a/test/parser.c +++ /dev/null @@ -1,192 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -int test_url(char *url, char *expected_result){ - char buf[SMALLBUFSIZE]; - - snprintf(buf, sizeof(buf)-1, "%s", url); - fixURL(buf); - - if(strcmp(buf, expected_result)){ - printf("FAILED: '%s' => fixed: '%s', expected: '%s'\n", url, buf, expected_result); - return 1; - } - - return 0; -} - - -int test_translate(char *what, char *expected, struct _state *state){ - char buf[SMALLBUFSIZE]; - - snprintf(buf, sizeof(buf)-1, "%s", what); - - translateLine((unsigned char*)buf, state); - - if(strcmp(buf, expected)){ - printf("FAILED: '%s' => fixed: '%s', expected: '%s'\n", what, buf, expected); - return 1; - } - - return 0; -} - - -int test_urls(){ - int count=0; - - count += test_url("http://sourceforge.net/projects/blogsmanager/", "__URL__sourceforgeXnet "); - count += test_url("http://localhost/blogs/_authors_list.php?a=search&value=1&SearchFor=muuratsalo&SearchOption=Contains&SearchField=[SQL", "__URL__localhost "); - count += test_url("http://www.debian.org/security/faq", "__URL__wwwXdebianXorg "); - count += test_url("http://www.debian.org/", "__URL__wwwXdebianXorg "); - count += test_url("https://www.debian.org", "__URL__wwwXdebianXorg "); - count += test_url("HTTP://www.debian.o", "__URL__wwwXdebianXo "); - count += test_url("http://www.debian.", "__URL__wwwXdebian "); - count += test_url("www.debian.org", "__URL__wwwXdebianXorg "); - count += test_url("http://web.nvd.nist.gov/view/vuln/detail?vulnId=3DCVE-2011-3892", "__URL__webXnvdXnistXgov "); - count += test_url("http://bugs.sitracker.org/view.php?id=1737", "__URL__bugsXsitrackerXorg "); - count += test_url("http://googlechromereleases.blogspot.com/2011/11/stable-channel-update.ht", "__URL__googlechromereleasesXblogspotXcom "); - count += test_url("http://security.gentoo.org/glsa/glsa-201111-05.xml", "__URL__securityXgentooXorg "); - count += test_url("https://bugs.gentoo.org.", "__URL__bugsXgentooXorg "); - count += test_url("https://bugs.gentoo.org./ajajajajaaj", "__URL__bugsXgentooXorg "); - count += test_url("http://creativecommons.org/licenses/by-sa/2.5", "__URL__creativecommonsXorg "); - count += test_url("http://www.site.com/[path]/wp-content/plugins/advanced-text-widget/advancedtext.php?page=[xss]", "__URL__wwwXsiteXcom "); - count += test_url("http://canadamedshealth.ru", "__URL__canadamedshealthXru "); - count += test_url("http://[HOSTNAME]:4848/configuration/httpListenerEdit.jsf?name=&configName=server-config", "__URL__[HOSTNAME]:4848 "); - count += test_url("http://go.theregister.com/news/http://www.theregister.co.uk/2007/07/", "__URL__goXtheregisterXcom "); - count += test_url("http://dl.shadowserver.org/IpE6yFKxIPARB8447vAQoyeVtbs?Rq123jTRTTrzApVs0vTzyQ", "__URL__dlXshadowserverXorg "); - count += test_url("http://dl.shadowserver.org/IpE6yFKx%EAPARB8447vAQoyeVtbs?Rq123jTRTTrzApVs0vTzyQ", "__URL__dlXshadowserverXorg "); - count += test_url("", ""); - - return count; -} - - -int test_translates(){ - int count=0; - struct _state state; - - init_state(&state); - - count += test_translate("To: \"Suto, Janos\" ", "To Suto Janos Janos.Suto@foo.bar", &state); - count += test_translate("Ez most akkor beteg, vagy sem?", "Ez most akkor beteg vagy sem ", &state); - count += test_translate("MAIL FROM: ", "MAIL FROM zoltan.szabo@zte.com.cn ", &state); - count += test_translate("Enjoy your game, and then enjoy your jackpot!", "Enjoy your game and then enjoy your jackpot!", &state); - count += test_translate("Az Ãn által megküldött,", "Az Ãn által megküldött ", &state); - - return count; -} - - -int test_html(char *what, char *expected, struct _state *state){ - char buf[SMALLBUFSIZE]; - - snprintf(buf, sizeof(buf)-1, "%s", what); - - markHTML(buf, state); - - if(strcmp(buf, expected)){ - printf("FAILED: '%s' => fixed: '%s', expected: '%s'\n", what, buf, expected); - return 1; - } - - //printf("OK: '%s' => fixed: '%s', expected: '%s'\n", what, buf, expected); - - return 0; -} - - -int test_htmls(){ - int count=0; - struct _state state; - - init_state(&state); - - count += test_html("", " ", &state); - count += test_html("jackpot!

", "jackpot! ", &state); - count += test_html("

Enjoy your game, and then enjoy your =", " Enjoy your game, and then enjoy your =", &state); - count += test_html("

ooooo", " ooooo", &state); - count += test_html(" ", " ", &state); - count += test_html("

", " ", &state); - count += test_html("
", " ", &state); - count += test_html("Viagra50/100mg - $1.85 |BUY NOW|
", " Viagra50/100mg - $1.85 |BUY NOW| ", &state); - count += test_html("High Qua1ityMedications + Discount On All Reorders +
", "High Qua1ityMedications + Discount On All Reorders + ", &state); - count += test_html("Free Shipping Options + Free Pills With Every Order = Best Deal Ever!
''''''''''click here''''''''''

", " Free Shipping Options + Free Pills With Every Order = Best Deal Ever! ''''''''''click here'''''''''", &state); - count += test_html("http://bbb.fu/2.gif", "http://bbb.fu/2.gif", &state); - - count += test_html("", " ", &state); - count += test_html("