mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-24 19:00:11 +01:00
added fixmetadata utility
Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
parent
b9a3f8d7c0
commit
67891084e4
@ -33,7 +33,7 @@ MAKE = `which make`
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
|
||||
all: libpiler.a piler pilerconf pilerget pileraget pilerimport pilerexport pilerpurge reindex test
|
||||
all: libpiler.a piler pilerconf pilerget pileraget pilerimport pilerexport pilerpurge reindex test fixmetadata
|
||||
install: install-piler
|
||||
|
||||
|
||||
@ -69,6 +69,9 @@ pilerconf: pilerconf.c libpiler.a
|
||||
reindex: reindex.c libpiler.a
|
||||
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR)
|
||||
|
||||
fixmetadata: fixmetadata.c libpiler.a
|
||||
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR)
|
||||
|
||||
test: test.c libpiler.a
|
||||
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o pilertest $< -lpiler $(LIBS) $(LIBDIR) @LDFLAGS@
|
||||
|
||||
@ -93,7 +96,7 @@ install-piler:
|
||||
$(INSTALL) -m 6755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) pilertest $(DESTDIR)$(bindir)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a libpiler.so* piler pilerconf pilerget pileraget pilerimport pilerexport pilerpurge pilertest reindex
|
||||
rm -f *.o *.a libpiler.so* piler pilerconf pilerget pileraget pilerimport pilerexport pilerpurge pilertest reindex fixmetadata
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#define VERSION "1.2.0-master"
|
||||
|
||||
#define BUILD 940
|
||||
#define BUILD 941
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
@ -105,6 +105,7 @@
|
||||
#define SQL_PREPARED_STMT_GET_FOLDER_ID "SELECT `id` FROM " SQL_FOLDER_TABLE " WHERE `name`=? AND `parent_id`=?"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE "INSERT INTO `" SQL_FOLDER_TABLE "` (`name`, `parent_id`) VALUES(?,?)"
|
||||
#define SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE "UPDATE " SQL_METADATA_TABLE " SET reference=? WHERE message_id=? AND reference=''"
|
||||
#define SQL_PREPARED_STMT_UPDATE_META_TABLE "UPDATE " SQL_METADATA_TABLE " SET subject=?, attachments=? WHERE id=?"
|
||||
#define SQL_PREPARED_STMT_GET_GUI_IMPORT_JOBS "SELECT id, type, username, password, server FROM " SQL_IMPORT_TABLE " WHERE started=0 ORDER BY id LIMIT 0,1"
|
||||
#define SQL_PREPARED_STMT_INSERT_FOLDER_MESSAGE "INSERT INTO " SQL_FOLDER_MESSAGE_TABLE " (`folder_id`, `id`) VALUES(?,?)"
|
||||
|
||||
|
@ -334,6 +334,7 @@ struct __data {
|
||||
MYSQL_STMT *stmt_get_folder_id;
|
||||
MYSQL_STMT *stmt_insert_into_folder_table;
|
||||
MYSQL_STMT *stmt_update_metadata_reference;
|
||||
MYSQL_STMT *stmt_update_metadata;
|
||||
MYSQL_STMT *stmt_select_from_meta_table;
|
||||
MYSQL_STMT *stmt_select_non_referenced_attachments;
|
||||
#endif
|
||||
|
128
src/fixmetadata.c
Normal file
128
src/fixmetadata.c
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* fixmetadata.c, SJ
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <locale.h>
|
||||
#include <syslog.h>
|
||||
#include <piler.h>
|
||||
|
||||
|
||||
uint64 get_metaid_by_messageid(struct session_data *sdata, struct __data *data, char *message_id, struct __config *cfg);
|
||||
|
||||
|
||||
int update_meta_data(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg){
|
||||
int ret=ERR;
|
||||
uint64 id=0;
|
||||
char *subj;
|
||||
|
||||
id = get_metaid_by_messageid(sdata, data, state->message_id, cfg);
|
||||
|
||||
if(id <= 0) return ERR;
|
||||
|
||||
subj = state->b_subject;
|
||||
if(*subj == ' ') subj++;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_update_metadata), SQL_PREPARED_STMT_UPDATE_META_TABLE, cfg) == ERR) return ret;
|
||||
|
||||
p_bind_init(data);
|
||||
|
||||
data->sql[data->pos] = subj; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
data->sql[data->pos] = (char *)&state->n_attachments; data->type[data->pos] = TYPE_LONG; data->pos++;
|
||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONGLONG; data->pos++;
|
||||
|
||||
if(p_exec_query(sdata, data->stmt_update_metadata, data) == OK) ret = OK;
|
||||
|
||||
close_prepared_statement(data->stmt_update_metadata);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int i;
|
||||
struct stat st;
|
||||
struct session_data sdata;
|
||||
struct parser_state state;
|
||||
struct __config cfg;
|
||||
struct __data data;
|
||||
|
||||
srand(getpid());
|
||||
|
||||
if(argc < 2){
|
||||
fprintf(stderr, "usage: %s <message>\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("fixmetadata", LOG_PID, LOG_MAIL);
|
||||
|
||||
cfg = read_config(CONFIG_FILE);
|
||||
|
||||
if(open_database(&sdata, &cfg) == ERR) return 0;
|
||||
|
||||
setlocale(LC_CTYPE, cfg.locale);
|
||||
|
||||
data.folder = 0;
|
||||
data.recursive_folder_names = 0;
|
||||
|
||||
inithash(data.mydomains);
|
||||
|
||||
//initrules(data.archiving_rules);
|
||||
//initrules(data.retention_rules);
|
||||
//initrules(data.folder_rules);
|
||||
|
||||
load_mydomains(&sdata, &data, &cfg);
|
||||
|
||||
//load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE, &cfg);
|
||||
//load_rules(&sdata, &data, data.retention_rules, SQL_RETENTION_RULE_TABLE, &cfg);
|
||||
//load_rules(&sdata, &data, data.folder_rules, SQL_FOLDER_RULE_TABLE, &cfg);
|
||||
|
||||
|
||||
init_session_data(&sdata, &cfg);
|
||||
|
||||
sdata.delivered = 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]);
|
||||
|
||||
state = parse_message(&sdata, 1, &data, &cfg);
|
||||
post_parse(&sdata, &state, &cfg);
|
||||
|
||||
update_meta_data(&sdata, &state, &data, &cfg);
|
||||
|
||||
//sdata.retained = sdata.now + query_retain_period(&data, &state, st.st_size, sdata.spam_message, &cfg);
|
||||
|
||||
//clearrules(data.archiving_rules);
|
||||
//clearrules(data.retention_rules);
|
||||
//clearrules(data.folder_rules);
|
||||
|
||||
clearhash(data.mydomains);
|
||||
|
||||
for(i=1; i<=state.n_attachments; i++){
|
||||
unlink(state.attachments[i].internalname);
|
||||
}
|
||||
|
||||
unlink(sdata.tmpframe);
|
||||
|
||||
close_database(&sdata);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user