From 1b9e2e639d604368774c7456a82cdf59e4cfacf5 Mon Sep 17 00:00:00 2001 From: SJ Date: Thu, 2 Jul 2015 14:35:45 +0200 Subject: [PATCH] gui fixes --- test/Makefile.in | 6 +- test/check.sh | 11 ++++ test/test.c | 105 +++++++++++++++++++++++++++++++++ webui/model/group/group.php | 6 +- webui/model/search/message.php | 6 +- 5 files changed, 126 insertions(+), 8 deletions(-) create mode 100755 test/check.sh create mode 100644 test/test.c diff --git a/test/Makefile.in b/test/Makefile.in index 207622c0..0745aea2 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -25,7 +25,7 @@ OBJS = import_helper.o INSTALL = @INSTALL@ -all: $(OBJS) parser debug import ptest +all: $(OBJS) parser debug import ptest test parser: parser.c ../src/libpiler.a $(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR) @@ -39,6 +39,8 @@ debug: debug.c ../src/libpiler.a 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 $@ @@ -47,7 +49,7 @@ import: import.c ../src/libpiler.a install: clean: - rm -f parser debug import ptest + rm -f parser debug import ptest test distclean: clean rm -f Makefile diff --git a/test/check.sh b/test/check.sh new file mode 100755 index 00000000..cb066694 --- /dev/null +++ b/test/check.sh @@ -0,0 +1,11 @@ +#!/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/test.c b/test/test.c new file mode 100644 index 00000000..d4b141dd --- /dev/null +++ b/test/test.c @@ -0,0 +1,105 @@ +/* + * test.c, SJ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv){ + int i; + struct stat st; + struct session_data sdata; + struct _state state; + struct __config cfg; + struct __data data; + struct import import; + + srand(getpid()); + + if(argc < 2){ + fprintf(stderr, "usage: %s \n", argv[0]); + exit(1); + } + + if(!can_i_write_current_directory()) __fatal("cannot write current directory!"); + + if(stat(argv[1], &st) != 0){ + fprintf(stderr, "%s is not found\n", argv[1]); + return 0; + } + + (void) openlog("test", LOG_PID, LOG_MAIL); + + cfg = read_config(CONFIG_FILE); + + if(open_database(&sdata, &cfg) == ERR) return 0; + + setlocale(LC_MESSAGES, cfg.locale); + setlocale(LC_CTYPE, cfg.locale); + + import.extra_recipient = NULL; + + data.import = &import; + + data.folder = 0; + data.recursive_folder_names = 0; + + inithash(data.mydomains); + + init_session_data(&sdata, &cfg); + + sdata.sent = 0; + sdata.delivered = 0; + sdata.tot_len = st.st_size; + sdata.import = 1; + + 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]); + + state = parse_message(&sdata, 1, &data, &cfg); + + post_parse(&sdata, &state, &cfg); + + printf("message-id: %s / %s\n", state.message_id, state.message_id_hash); + 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, delivered-date: %ld\n", sdata.sent, sdata.delivered); + + make_digests(&sdata, &cfg); + + printf("hdr len: %d\n", sdata.hdr_len); + + printf("body digest: %s\n", sdata.bodydigest); + + clearhash(data.mydomains); + + for(i=1; i<=state.n_attachments; i++){ + printf("i:%d, name=*%s*, type: *%s*, size: %d, int.name: %s, digest: %s\n", i, state.attachments[i].filename, state.attachments[i].type, state.attachments[i].size, state.attachments[i].internalname, state.attachments[i].digest); + unlink(state.attachments[i].internalname); + } + + unlink(sdata.tmpframe); + + printf("attachments:%s\n", sdata.attachments); + + close_database(&sdata); + + return 0; +} + + diff --git a/webui/model/group/group.php b/webui/model/group/group.php index de2c9b0b..82501b3f 100644 --- a/webui/model/group/group.php +++ b/webui/model/group/group.php @@ -72,16 +72,16 @@ class ModelGroupGroup extends Model { $where_cond = ""; $Q = array(); - $search = preg_replace("/\s{1,}/", "", $search) . '%'; + if($search) { + $search = preg_replace("/\s{1,}/", "", $search) . '%'; - if($search){ $where_cond .= " WHERE `groupname` like '?'"; array_push($Q, $search); } $query = $this->db->query("SELECT COUNT(*) AS num FROM `" . TABLE_GROUP . "` $where_cond", $Q); - return $query->num_rows; + return $query->row['num']; } diff --git a/webui/model/search/message.php b/webui/model/search/message.php index d1f89134..51cda32c 100644 --- a/webui/model/search/message.php +++ b/webui/model/search/message.php @@ -300,10 +300,10 @@ class ModelSearchMessage extends Model { $msg = $p; $p = ''; } - } - if($boundary) { - $msg = substr($msg, 0, strlen($msg) - strlen($boundary) - 6); + if($boundary) { + $msg = substr($msg, 0, strlen($msg) - strlen($boundary) - 6); + } } return $has_journal;