mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 23:01:58 +01:00
added reimport option for pilerimport
This commit is contained in:
parent
67891084e4
commit
65fc0b377e
@ -33,7 +33,7 @@ MAKE = `which make`
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
|
||||
all: libpiler.a piler pilerconf pilerget pileraget pilerimport pilerexport pilerpurge reindex test fixmetadata
|
||||
all: libpiler.a piler pilerconf pilerget pileraget pilerimport pilerexport pilerpurge reindex test
|
||||
install: install-piler
|
||||
|
||||
|
||||
|
@ -222,7 +222,7 @@ int retrieve_email_from_archive(struct session_data *sdata, struct __data *data,
|
||||
return 1;
|
||||
}
|
||||
|
||||
attachments = query_attachments(sdata, data, &ptr_arr[0], cfg);
|
||||
attachments = query_attachments(sdata, data, &ptr_arr[0]);
|
||||
|
||||
if(attachments == -1){
|
||||
printf("problem querying the attachment of %s\n", sdata->ttmpfile);
|
||||
|
@ -21,8 +21,8 @@ int store_attachments(struct session_data *sdata, struct parser_state *state, st
|
||||
int i, rc=1, found, affected_rows;
|
||||
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_attachment_table), SQL_PREPARED_STMT_INSERT_INTO_ATTACHMENT_TABLE, cfg) == ERR) return rc;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_attachment_id_by_signature), SQL_PREPARED_STMT_GET_ATTACHMENT_ID_BY_SIGNATURE, cfg) == ERR) return rc;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_attachment_table), SQL_PREPARED_STMT_INSERT_INTO_ATTACHMENT_TABLE) == ERR) return rc;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_attachment_id_by_signature), SQL_PREPARED_STMT_GET_ATTACHMENT_ID_BY_SIGNATURE) == ERR) return rc;
|
||||
|
||||
|
||||
for(i=1; i<=state->n_attachments; i++){
|
||||
@ -42,13 +42,13 @@ int store_attachments(struct session_data *sdata, struct parser_state *state, st
|
||||
|
||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONGLONG; data->len[data->pos] = sizeof(uint64); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_get_attachment_id_by_signature, data);
|
||||
p_store_results(data->stmt_get_attachment_id_by_signature, data);
|
||||
if(p_fetch_results(data->stmt_get_attachment_id_by_signature) == OK) found = 1;
|
||||
p_free_results(data->stmt_get_attachment_id_by_signature);
|
||||
}
|
||||
|
||||
if(found == 0){
|
||||
if(store_file(sdata, state->attachments[i].internalname, 0, 0, cfg) == 0){
|
||||
if(store_file(sdata, state->attachments[i].internalname, 0, cfg) == 0){
|
||||
syslog(LOG_PRIORITY, "%s: error storing attachment: %s", sdata->ttmpfile, state->attachments[i].internalname);
|
||||
goto CLOSE;
|
||||
}
|
||||
@ -91,10 +91,10 @@ CLOSE:
|
||||
}
|
||||
|
||||
|
||||
int query_attachment_pointers(struct session_data *sdata, struct __data *data, uint64 ptr, char *piler_id, int *id, struct __config *cfg){
|
||||
int query_attachment_pointers(struct session_data *sdata, struct __data *data, uint64 ptr, char *piler_id, int *id){
|
||||
int rc=0;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_attachment_pointer), SQL_PREPARED_STMT_GET_ATTACHMENT_POINTER, cfg) == ERR) return rc;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_attachment_pointer), SQL_PREPARED_STMT_GET_ATTACHMENT_POINTER) == ERR) return rc;
|
||||
|
||||
|
||||
p_bind_init(data);
|
||||
@ -108,7 +108,7 @@ int query_attachment_pointers(struct session_data *sdata, struct __data *data, u
|
||||
data->sql[data->pos] = piler_id; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = RND_STR_LEN; data->pos++;
|
||||
data->sql[data->pos] = (char *)id; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_get_attachment_pointer, data);
|
||||
p_store_results(data->stmt_get_attachment_pointer, data);
|
||||
|
||||
if(p_fetch_results(data->stmt_get_attachment_pointer) == OK) rc = 1;
|
||||
p_free_results(data->stmt_get_attachment_pointer);
|
||||
@ -120,13 +120,13 @@ int query_attachment_pointers(struct session_data *sdata, struct __data *data, u
|
||||
}
|
||||
|
||||
|
||||
int query_attachments(struct session_data *sdata, struct __data *data, struct ptr_array *ptr_arr, struct __config *cfg){
|
||||
int query_attachments(struct session_data *sdata, struct __data *data, struct ptr_array *ptr_arr){
|
||||
int i, rc, id, attachments=0;
|
||||
uint64 ptr;
|
||||
|
||||
for(i=0; i<MAX_ATTACHMENTS; i++) memset((char*)&ptr_arr[i], 0, sizeof(struct ptr_array));
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_query_attachment), SQL_PREPARED_STMT_QUERY_ATTACHMENT, cfg) == ERR) return attachments;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_query_attachment), SQL_PREPARED_STMT_QUERY_ATTACHMENT) == ERR) return attachments;
|
||||
|
||||
p_bind_init(data);
|
||||
|
||||
@ -139,14 +139,14 @@ int query_attachments(struct session_data *sdata, struct __data *data, struct pt
|
||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||
data->sql[data->pos] = (char *)&ptr; data->type[data->pos] = TYPE_LONGLONG; data->len[data->pos] = sizeof(uint64); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_query_attachment, data);
|
||||
p_store_results(data->stmt_query_attachment, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_query_attachment) == OK){
|
||||
|
||||
if(id > 0 && id < MAX_ATTACHMENTS){
|
||||
if(ptr > 0){
|
||||
ptr_arr[id].ptr = ptr;
|
||||
rc = query_attachment_pointers(sdata, data, ptr, &(ptr_arr[id].piler_id[0]), &(ptr_arr[id].attachment_id), cfg);
|
||||
rc = query_attachment_pointers(sdata, data, ptr, &(ptr_arr[id].piler_id[0]), &(ptr_arr[id].attachment_id));
|
||||
if(!rc){
|
||||
attachments = -1;
|
||||
goto CLOSE;
|
||||
|
@ -17,7 +17,7 @@ int string_parser(char *src, char *target, int limit){
|
||||
return 0;
|
||||
};
|
||||
|
||||
int multi_line_string_parser(char *src, char *target, int limit){
|
||||
int multi_line_string_parser(char *src, char *target, unsigned int limit){
|
||||
if(strlen(src) > 0 && strlen(target) + strlen(src) + 3 < limit){
|
||||
strncat(target, src, limit-strlen(target));
|
||||
strncat(target, "\r\n", limit-strlen(target));
|
||||
@ -28,14 +28,14 @@ int multi_line_string_parser(char *src, char *target, int limit){
|
||||
return 1;
|
||||
};
|
||||
|
||||
int int_parser(char *src, int *target, int limit){
|
||||
int int_parser(char *src, int *target){
|
||||
*target = strtol(src, (char **) NULL, 10);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
int float_parser(char *src, float *target, int limit){
|
||||
int float_parser(char *src, float *target){
|
||||
*target = strtof(src, (char **) NULL);
|
||||
|
||||
return 0;
|
||||
@ -110,7 +110,7 @@ struct _parse_rule config_parse_rules[] =
|
||||
{ "verbosity", "integer", (void*) int_parser, offsetof(struct __config, verbosity), "1", sizeof(int)},
|
||||
{ "workdir", "string", (void*) string_parser, offsetof(struct __config, workdir), WORK_DIR, MAXVAL-1},
|
||||
|
||||
{NULL, NULL, NULL, 0, 0}
|
||||
{NULL, NULL, NULL, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#define VERSION "1.2.0-master"
|
||||
|
||||
#define BUILD 941
|
||||
#define BUILD 942
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
@ -94,10 +94,11 @@
|
||||
#define SQL_ATTACHMENTS_VIEW "v_attachment"
|
||||
|
||||
#define SQL_PREPARED_STMT_GET_DOMAINS "SELECT `domain` FROM `" SQL_DOMAIN_TABLE "`"
|
||||
#define SQL_PREPARED_STMT_GET_META_ID_BY_MESSAGE_ID "SELECT id FROM " SQL_METADATA_TABLE " WHERE message_id=?"
|
||||
#define SQL_PREPARED_STMT_GET_META_ID_BY_MESSAGE_ID "SELECT id, piler_id FROM " SQL_METADATA_TABLE " WHERE message_id=?"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_RCPT_TABLE "INSERT INTO " SQL_RECIPIENT_TABLE " (`id`,`to`,`todomain`) VALUES(?,?,?)"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_SPHINX_TABLE "INSERT INTO " SQL_SPHINX_TABLE " (`id`, `from`, `to`, `fromdomain`, `todomain`, `subject`, `body`, `arrived`, `sent`, `size`, `direction`, `folder`, `attachments`, `attachment_types`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_META_TABLE "INSERT INTO " SQL_METADATA_TABLE " (`from`,`fromdomain`,`subject`,`spam`,`arrived`,`sent`,`retained`,`size`,`hlen`,`direction`,`attachments`,`piler_id`,`message_id`,`reference`,`digest`,`bodydigest`,`vcode`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||
#define SQL_PREPARED_STMT_UPDATE_META_TABLE "UPDATE " SQL_METADATA_TABLE " SET `from`=?,`fromdomain`=?,`subject`=?,`spam`=?,`arrived`=?,`sent`=?,`retained`=?,`size`=?,`hlen`=?,`direction`=?,`attachments`=?,`reference`=?,`digest`=?,`bodydigest`=?,`vcode`=? WHERE id=?"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_ATTACHMENT_TABLE "INSERT INTO " SQL_ATTACHMENT_TABLE " (`piler_id`,`attachment_id`,`sig`,`name`,`type`,`size`,`ptr`) VALUES(?,?,?,?,?,?,?)"
|
||||
#define SQL_PREPARED_STMT_GET_ATTACHMENT_ID_BY_SIGNATURE "SELECT `id` FROM `" SQL_ATTACHMENT_TABLE "` WHERE `sig`=? AND `ptr`=0 AND `size`=?"
|
||||
#define SQL_PREPARED_STMT_GET_ATTACHMENT_POINTER "SELECT `piler_id`, `attachment_id` FROM " SQL_ATTACHMENT_TABLE " WHERE id=?"
|
||||
@ -105,7 +106,6 @@
|
||||
#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(?,?)"
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <piler.h>
|
||||
|
||||
|
||||
struct __counters load_counters(struct session_data *sdata, struct __data *data, struct __config *cfg){
|
||||
struct __counters load_counters(struct session_data *sdata, struct __data *data){
|
||||
char buf[SMALLBUFSIZE];
|
||||
struct __counters counters;
|
||||
|
||||
@ -20,7 +20,7 @@ struct __counters load_counters(struct session_data *sdata, struct __data *data,
|
||||
snprintf(buf, SMALLBUFSIZE-1, "SELECT `rcvd`, `virus`, `duplicate`, `ignore`, `size`, `stored_size` FROM `%s`", SQL_COUNTER_TABLE);
|
||||
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), buf, cfg) == ERR) return counters;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), buf) == ERR) return counters;
|
||||
|
||||
|
||||
p_bind_init(data);
|
||||
@ -36,7 +36,7 @@ struct __counters load_counters(struct session_data *sdata, struct __data *data,
|
||||
data->sql[data->pos] = (char *)&counters.c_size; data->type[data->pos] = TYPE_LONGLONG; data->len[data->pos] = sizeof(uint64); data->pos++;
|
||||
data->sql[data->pos] = (char *)&counters.c_stored_size; data->type[data->pos] = TYPE_LONGLONG; data->len[data->pos] = sizeof(uint64); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
p_store_results(data->stmt_generic, data);
|
||||
p_fetch_results(data->stmt_generic);
|
||||
p_free_results(data->stmt_generic);
|
||||
}
|
||||
@ -101,7 +101,7 @@ void update_counters(struct session_data *sdata, struct __data *data, struct __c
|
||||
}
|
||||
else {
|
||||
|
||||
c = load_counters(sdata, data, cfg);
|
||||
c = load_counters(sdata, data);
|
||||
|
||||
snprintf(buf, SMALLBUFSIZE-1, "%ld", sdata->now); memcached_add(&(data->memc), MEMCACHED_COUNTERS_LAST_UPDATE, strlen(MEMCACHED_COUNTERS_LAST_UPDATE), buf, strlen(buf), 0, 0);
|
||||
|
||||
|
@ -158,7 +158,8 @@ int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen){
|
||||
|
||||
|
||||
void decodeQP(char *p){
|
||||
int i, k=0, a, b;
|
||||
unsigned int i;
|
||||
int k=0, a, b;
|
||||
char c;
|
||||
|
||||
if(p == NULL) return;
|
||||
@ -247,7 +248,8 @@ void decodeHTML(char *p, int utf8){
|
||||
|
||||
|
||||
void decodeURL(char *p){
|
||||
int i, c, k=0, a, b;
|
||||
unsigned int i;
|
||||
int c, k=0, a, b;
|
||||
|
||||
if(p == NULL) return;
|
||||
|
||||
@ -303,30 +305,21 @@ inline void utf8_encode_char(unsigned char c, unsigned char *buf, int buflen, in
|
||||
count++;
|
||||
}
|
||||
|
||||
else if(c <= 0x7FF){
|
||||
else {
|
||||
*(buf+count) = ( 0xC0 | (c >> 6) );
|
||||
count++;
|
||||
*(buf+count) = ( 0x80 | (c & 0x3F) );
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
else if (c <= 0xFFFF){
|
||||
*(buf+count) = ( 0xE0 | (c >> 12) );
|
||||
count++;
|
||||
*(buf+count) = ( 0x80 | ((c >> 6) & 0x3F) );
|
||||
count++;
|
||||
*(buf+count) = ( 0x80 | (c & 0x3F) );
|
||||
count++;
|
||||
}
|
||||
|
||||
*len = count;
|
||||
}
|
||||
|
||||
|
||||
int utf8_encode(char *inbuf, int inbuflen, char *outbuf, int outbuflen, char *encoding){
|
||||
iconv_t cd;
|
||||
size_t size, inbytesleft, outbytesleft;
|
||||
size_t inbytesleft, outbytesleft;
|
||||
int ret = ERR;
|
||||
|
||||
memset(outbuf, 0, outbuflen);
|
||||
|
||||
@ -336,13 +329,14 @@ int utf8_encode(char *inbuf, int inbuflen, char *outbuf, int outbuflen, char *en
|
||||
inbytesleft = inbuflen;
|
||||
outbytesleft = outbuflen-1;
|
||||
|
||||
size = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
|
||||
if(iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft) == (size_t) -1)
|
||||
ret = ERR;
|
||||
else
|
||||
ret = OK;
|
||||
|
||||
iconv_close(cd);
|
||||
|
||||
if(size >= 0) return OK;
|
||||
}
|
||||
|
||||
return ERR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -294,6 +294,7 @@ struct import {
|
||||
int download_only;
|
||||
int keep_eml;
|
||||
int timeout;
|
||||
int reimport;
|
||||
int cap_uidplus;
|
||||
long total_size;
|
||||
time_t started, updated, finished;
|
||||
|
@ -30,7 +30,7 @@ int update_meta_data(struct session_data *sdata, struct parser_state *state, str
|
||||
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;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_update_metadata), SQL_PREPARED_STMT_UPDATE_META_TABLE) == ERR) return ret;
|
||||
|
||||
p_bind_init(data);
|
||||
|
||||
@ -81,17 +81,8 @@ int main(int argc, char **argv){
|
||||
|
||||
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;
|
||||
|
@ -40,7 +40,7 @@ void clearhash(struct node *xhash[]){
|
||||
}
|
||||
|
||||
|
||||
struct node *makenewnode(struct node *xhash[], char *s){
|
||||
struct node *makenewnode(char *s){
|
||||
struct node *h;
|
||||
int len;
|
||||
|
||||
@ -82,7 +82,7 @@ int addnode(struct node *xhash[], char *s){
|
||||
key = DJBHash(s, len);
|
||||
|
||||
if(xhash[hash(key)] == NULL){
|
||||
xhash[hash(key)] = makenewnode(xhash, s);
|
||||
xhash[hash(key)] = makenewnode(s);
|
||||
}
|
||||
else {
|
||||
q = xhash[hash(key)];
|
||||
@ -95,7 +95,7 @@ int addnode(struct node *xhash[], char *s){
|
||||
q = q->r;
|
||||
}
|
||||
}
|
||||
if(p) p->r = makenewnode(xhash, s);
|
||||
if(p) p->r = makenewnode(s);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
void inithash(struct node *xhash[]);
|
||||
void clearhash(struct node *xhash[]);
|
||||
struct node *makenewnode(struct node *xhash[], char *s);
|
||||
struct node *makenewnode(char *s);
|
||||
int addnode(struct node *xhash[], char *s);
|
||||
struct node *findnode(struct node *xhash[], char *s);
|
||||
int is_substr_in_hash(struct node *xhash[], char *s);
|
||||
|
@ -124,8 +124,8 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
|
||||
|
||||
|
||||
if(data->recursive_folder_names == 1){
|
||||
data->folder = get_folder_id(sdata, data, folder, 0, cfg);
|
||||
if(data->folder == ERR_FOLDER) data->folder = add_new_folder(sdata, data, folder, 0, cfg);
|
||||
data->folder = get_folder_id(sdata, data, folder, 0);
|
||||
if(data->folder == ERR_FOLDER) data->folder = add_new_folder(sdata, data, folder, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -307,7 +307,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
|
||||
}
|
||||
|
||||
|
||||
int connect_to_imap_server(int sd, int *seq, char *username, char *password, int port, struct __data *data, int use_ssl){
|
||||
int connect_to_imap_server(int sd, int *seq, char *username, char *password, struct __data *data, int use_ssl){
|
||||
int n;
|
||||
char buf[MAXBUFSIZE];
|
||||
X509* server_cert;
|
||||
|
27
src/import.c
27
src/import.c
@ -92,7 +92,10 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
||||
return ERR;
|
||||
}
|
||||
|
||||
rc = process_message(sdata, &state, data, cfg);
|
||||
if(data->import->reimport == 1)
|
||||
rc = reimport_message(sdata, &state, data, cfg);
|
||||
else
|
||||
rc = process_message(sdata, &state, data, cfg);
|
||||
unlink(state.message_id_hash);
|
||||
}
|
||||
|
||||
@ -103,11 +106,13 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
||||
|
||||
switch(rc) {
|
||||
case OK:
|
||||
bzero(&counters, sizeof(counters));
|
||||
counters.c_rcvd = 1;
|
||||
counters.c_size += sdata->tot_len;
|
||||
counters.c_stored_size = sdata->stored_len;
|
||||
update_counters(sdata, data, &counters, cfg);
|
||||
if(data->import->reimport == 0){
|
||||
bzero(&counters, sizeof(counters));
|
||||
counters.c_rcvd = 1;
|
||||
counters.c_size += sdata->tot_len;
|
||||
counters.c_stored_size = sdata->stored_len;
|
||||
update_counters(sdata, data, &counters, cfg);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@ -130,10 +135,10 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
||||
}
|
||||
|
||||
|
||||
int get_folder_id(struct session_data *sdata, struct __data *data, char *foldername, int parent_id, struct __config *cfg){
|
||||
int get_folder_id(struct session_data *sdata, struct __data *data, char *foldername, int parent_id){
|
||||
int id=ERR_FOLDER;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_folder_id), SQL_PREPARED_STMT_GET_FOLDER_ID, cfg) == ERR) return id;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_folder_id), SQL_PREPARED_STMT_GET_FOLDER_ID) == ERR) return id;
|
||||
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = foldername; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
@ -144,7 +149,7 @@ int get_folder_id(struct session_data *sdata, struct __data *data, char *foldern
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(unsigned long); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_get_folder_id, data);
|
||||
p_store_results(data->stmt_get_folder_id, data);
|
||||
p_fetch_results(data->stmt_get_folder_id);
|
||||
p_free_results(data->stmt_get_folder_id);
|
||||
}
|
||||
@ -155,12 +160,12 @@ int get_folder_id(struct session_data *sdata, struct __data *data, char *foldern
|
||||
}
|
||||
|
||||
|
||||
int add_new_folder(struct session_data *sdata, struct __data *data, char *foldername, int parent_id, struct __config *cfg){
|
||||
int add_new_folder(struct session_data *sdata, struct __data *data, char *foldername, int parent_id){
|
||||
int id=ERR_FOLDER;
|
||||
|
||||
if(foldername == NULL) return id;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_folder_table), SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE, cfg) == ERR) return id;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_folder_table), SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE) == ERR) return id;
|
||||
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = foldername; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
|
@ -17,10 +17,10 @@ int import_mbox_from_dir(char *directory, struct session_data *sdata, struct __d
|
||||
int import_from_pop3_server(char *server, char *username, char *password, int port, struct session_data *sdata, struct __data *data, int dryrun, struct __config *cfg);
|
||||
int import_from_imap_server(char *server, char *username, char *password, int port, struct session_data *sdata, struct __data *data, char *folder_imap, char *skiplist, int dryrun, struct __config *cfg);
|
||||
|
||||
int connect_to_pop3_server(int sd, char *username, char *password, int port, struct __data *data, int use_ssl);
|
||||
int connect_to_pop3_server(int sd, char *username, char *password, struct __data *data, int use_ssl);
|
||||
int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, int use_ssl, int dryrun, struct __config *cfg);
|
||||
|
||||
int connect_to_imap_server(int sd, int *seq, char *username, char *password, int port, struct __data *data, int use_ssl);
|
||||
int connect_to_imap_server(int sd, int *seq, char *username, char *password, struct __data *data, int use_ssl);
|
||||
int list_folders(int sd, int *seq, int use_ssl, struct __data *data);
|
||||
int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sdata, struct __data *data, int use_ssl, int dryrun, struct __config *cfg);
|
||||
void send_imap_close(int sd, int *seq, struct __data *data, int use_ssl);
|
||||
|
@ -31,7 +31,7 @@ int read_gui_import_data(struct session_data *sdata, struct __data *data, char *
|
||||
memset(s_password, 0, sizeof(s_password));
|
||||
memset(s_server, 0, sizeof(s_server));
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), SQL_PREPARED_STMT_GET_GUI_IMPORT_JOBS, cfg) == ERR) return ERR;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), SQL_PREPARED_STMT_GET_GUI_IMPORT_JOBS) == ERR) return ERR;
|
||||
|
||||
p_bind_init(data);
|
||||
|
||||
@ -45,7 +45,7 @@ int read_gui_import_data(struct session_data *sdata, struct __data *data, char *
|
||||
data->sql[data->pos] = &s_password[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(s_password)-2; data->pos++;
|
||||
data->sql[data->pos] = &s_server[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(s_server)-2; data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
p_store_results(data->stmt_generic, data);
|
||||
|
||||
if(p_fetch_results(data->stmt_generic) == OK) rc = OK;
|
||||
|
||||
|
@ -57,7 +57,7 @@ int import_from_imap_server(char *server, char *username, char *password, int po
|
||||
goto ENDE_IMAP;
|
||||
}
|
||||
|
||||
if(connect_to_imap_server(sd, &seq, username, password, port, data, use_ssl) == ERR){
|
||||
if(connect_to_imap_server(sd, &seq, username, password, data, use_ssl) == ERR){
|
||||
close(sd);
|
||||
ret = ERR;
|
||||
goto ENDE_IMAP;
|
||||
|
@ -111,9 +111,9 @@ int import_mbox_from_dir(char *directory, struct session_data *sdata, struct __d
|
||||
|
||||
if(S_ISREG(st.st_mode)){
|
||||
if(i == 0 && data->recursive_folder_names == 1){
|
||||
folder = get_folder_id(sdata, data, fname, data->folder, cfg);
|
||||
folder = get_folder_id(sdata, data, fname, data->folder);
|
||||
if(folder == ERR_FOLDER){
|
||||
folder = add_new_folder(sdata, data, fname, data->folder, cfg);
|
||||
folder = add_new_folder(sdata, data, fname, data->folder);
|
||||
|
||||
if(folder == ERR_FOLDER){
|
||||
printf("error: cannot get/add folder '%s' to parent id: %d\n", fname, data->folder);
|
||||
|
@ -60,9 +60,9 @@ int import_from_maildir(char *directory, struct session_data *sdata, struct __da
|
||||
return ERR;
|
||||
}
|
||||
|
||||
folder = get_folder_id(sdata, data, p, data->folder, cfg);
|
||||
folder = get_folder_id(sdata, data, p, data->folder);
|
||||
if(folder == ERR_FOLDER){
|
||||
folder = add_new_folder(sdata, data, p, data->folder, cfg);
|
||||
folder = add_new_folder(sdata, data, p, data->folder);
|
||||
|
||||
if(folder == ERR_FOLDER){
|
||||
printf("error: cannot get/add folder '%s' to parent id: %d\n", p, data->folder);
|
||||
|
@ -53,7 +53,7 @@ int import_from_pop3_server(char *server, char *username, char *password, int po
|
||||
}
|
||||
|
||||
|
||||
if(connect_to_pop3_server(sd, username, password, port, data, use_ssl) == ERR){
|
||||
if(connect_to_pop3_server(sd, username, password, data, use_ssl) == ERR){
|
||||
close(sd);
|
||||
ret = ERR;
|
||||
goto ENDE_POP3;
|
||||
|
126
src/message.c
126
src/message.c
@ -29,7 +29,7 @@ int store_index_data(struct session_data *sdata, struct parser_state *state, str
|
||||
if(*subj == ' ') subj++;
|
||||
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_sphinx_table), SQL_PREPARED_STMT_INSERT_INTO_SPHINX_TABLE, cfg) == ERR) return rc;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_sphinx_table), SQL_PREPARED_STMT_INSERT_INTO_SPHINX_TABLE) == ERR) return rc;
|
||||
|
||||
|
||||
fix_email_address_for_sphinx(state->b_from);
|
||||
@ -64,10 +64,10 @@ int store_index_data(struct session_data *sdata, struct parser_state *state, str
|
||||
}
|
||||
|
||||
|
||||
uint64 get_metaid_by_messageid(struct session_data *sdata, struct __data *data, char *message_id, struct __config *cfg){
|
||||
uint64 get_metaid_by_messageid(struct session_data *sdata, struct __data *data, char *message_id, char *piler_id){
|
||||
uint64 id=0;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_meta_id_by_message_id), SQL_PREPARED_STMT_GET_META_ID_BY_MESSAGE_ID, cfg) == ERR) return id;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_meta_id_by_message_id), SQL_PREPARED_STMT_GET_META_ID_BY_MESSAGE_ID) == ERR) return id;
|
||||
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = message_id; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
@ -76,8 +76,9 @@ uint64 get_metaid_by_messageid(struct session_data *sdata, struct __data *data,
|
||||
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONGLONG; data->len[data->pos] = sizeof(uint64); data->pos++;
|
||||
data->sql[data->pos] = piler_id; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = RND_STR_LEN; data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_get_meta_id_by_message_id, data);
|
||||
p_store_results(data->stmt_get_meta_id_by_message_id, data);
|
||||
|
||||
p_fetch_results(data->stmt_get_meta_id_by_message_id);
|
||||
|
||||
@ -94,7 +95,7 @@ int store_recipients(struct session_data *sdata, struct __data *data, char *to,
|
||||
int ret=OK, n=0;
|
||||
char *p, *q, puf[SMALLBUFSIZE];
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_rcpt_table), SQL_PREPARED_STMT_INSERT_INTO_RCPT_TABLE, cfg) == ERR) return ret;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_rcpt_table), SQL_PREPARED_STMT_INSERT_INTO_RCPT_TABLE) == ERR) return ret;
|
||||
|
||||
p = to;
|
||||
do {
|
||||
@ -128,12 +129,21 @@ int store_recipients(struct session_data *sdata, struct __data *data, char *to,
|
||||
}
|
||||
|
||||
|
||||
int store_folder_id(struct session_data *sdata, struct __data *data, uint64 id, struct __config *cfg){
|
||||
void remove_recipients(struct session_data *sdata, uint64 id){
|
||||
char s[SMALLBUFSIZE];
|
||||
|
||||
snprintf(s, sizeof(s)-1, "DELETE FROM " SQL_RECIPIENT_TABLE " WHERE id=%llu", id);
|
||||
|
||||
p_query(sdata, s);
|
||||
}
|
||||
|
||||
|
||||
int store_folder_id(struct session_data *sdata, struct __data *data, uint64 id){
|
||||
int rc = ERR;
|
||||
|
||||
if(data->folder == ERR_FOLDER) return rc;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_folder_message_table), SQL_PREPARED_STMT_INSERT_FOLDER_MESSAGE, cfg) == ERR) return rc;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_folder_message_table), SQL_PREPARED_STMT_INSERT_FOLDER_MESSAGE) == ERR) return rc;
|
||||
|
||||
p_bind_init(data);
|
||||
|
||||
@ -147,10 +157,19 @@ int store_folder_id(struct session_data *sdata, struct __data *data, uint64 id,
|
||||
}
|
||||
|
||||
|
||||
void remove_folder_id(struct session_data *sdata, uint64 id){
|
||||
char s[SMALLBUFSIZE];
|
||||
|
||||
snprintf(s, sizeof(s)-1, "DELETE FROM " SQL_FOLDER_MESSAGE_TABLE " WHERE id=%llu", id);
|
||||
|
||||
p_query(sdata, s);
|
||||
}
|
||||
|
||||
|
||||
int update_metadata_reference(struct session_data *sdata, struct parser_state *state, struct __data *data, char *ref, struct __config *cfg){
|
||||
int ret = ERR;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_update_metadata_reference), SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE, cfg) == ERR) return ret;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_update_metadata_reference), SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE) == ERR) return ret;
|
||||
|
||||
p_bind_init(data);
|
||||
|
||||
@ -167,7 +186,7 @@ int update_metadata_reference(struct session_data *sdata, struct parser_state *s
|
||||
}
|
||||
|
||||
|
||||
int store_meta_data(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg){
|
||||
int store_meta_data(struct session_data *sdata, struct parser_state *state, struct __data *data, uint64 old_id, struct __config *cfg){
|
||||
int rc, ret=ERR, result;
|
||||
char *subj, *p, s[MAXBUFSIZE], s2[SMALLBUFSIZE], vcode[2*DIGEST_LENGTH+1], ref[2*DIGEST_LENGTH+1];
|
||||
uint64 id=0;
|
||||
@ -187,7 +206,11 @@ int store_meta_data(struct session_data *sdata, struct parser_state *state, stru
|
||||
}
|
||||
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_meta_table), SQL_PREPARED_STMT_INSERT_INTO_META_TABLE, cfg) == ERR) return ERR;
|
||||
if(old_id > 0){
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_meta_table), SQL_PREPARED_STMT_UPDATE_META_TABLE) == ERR) return ERR;
|
||||
} else {
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_meta_table), SQL_PREPARED_STMT_INSERT_INTO_META_TABLE) == ERR) return ERR;
|
||||
}
|
||||
|
||||
memset(s2, 0, sizeof(s2));
|
||||
|
||||
@ -220,18 +243,34 @@ int store_meta_data(struct session_data *sdata, struct parser_state *state, stru
|
||||
data->sql[data->pos] = (char *)&sdata->hdr_len; data->type[data->pos] = TYPE_LONG; data->pos++;
|
||||
data->sql[data->pos] = (char *)&sdata->direction; data->type[data->pos] = TYPE_LONG; data->pos++;
|
||||
data->sql[data->pos] = (char *)&state->n_attachments; data->type[data->pos] = TYPE_LONG; data->pos++;
|
||||
data->sql[data->pos] = sdata->ttmpfile; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
data->sql[data->pos] = state->message_id; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
|
||||
if(old_id == 0){
|
||||
data->sql[data->pos] = sdata->ttmpfile; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
data->sql[data->pos] = state->message_id; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
}
|
||||
|
||||
data->sql[data->pos] = &ref[0]; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
data->sql[data->pos] = sdata->digest; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
data->sql[data->pos] = sdata->bodydigest; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
data->sql[data->pos] = &vcode[0]; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
|
||||
if(old_id > 0){
|
||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONGLONG; data->pos++;
|
||||
}
|
||||
|
||||
|
||||
if(p_exec_query(sdata, data->stmt_insert_into_meta_table, data) == ERR){
|
||||
ret = ERR_EXISTS;
|
||||
}
|
||||
else {
|
||||
id = p_get_insert_id(data->stmt_insert_into_meta_table);
|
||||
if(old_id > 0){
|
||||
remove_recipients(sdata, old_id);
|
||||
remove_folder_id(sdata, old_id);
|
||||
id = old_id;
|
||||
}
|
||||
else {
|
||||
id = p_get_insert_id(data->stmt_insert_into_meta_table);
|
||||
}
|
||||
|
||||
rc = store_recipients(sdata, data, state->b_to, id, cfg);
|
||||
|
||||
@ -242,7 +281,7 @@ int store_meta_data(struct session_data *sdata, struct parser_state *state, stru
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: stored indexdata, rc=%d", sdata->ttmpfile, rc);
|
||||
|
||||
if(cfg->enable_folders == 1){
|
||||
rc = store_folder_id(sdata, data, id, cfg);
|
||||
rc = store_folder_id(sdata, data, id);
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: stored folderdata, rc=%d", sdata->ttmpfile, rc);
|
||||
}
|
||||
|
||||
@ -264,10 +303,11 @@ void remove_stripped_attachments(struct parser_state *state){
|
||||
|
||||
int process_message(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg){
|
||||
int rc, fd;
|
||||
char piler_id[SMALLBUFSIZE];
|
||||
|
||||
/* discard if existing message_id */
|
||||
|
||||
sdata->duplicate_id = get_metaid_by_messageid(sdata, data, state->message_id, cfg);
|
||||
sdata->duplicate_id = get_metaid_by_messageid(sdata, data, state->message_id, piler_id);
|
||||
|
||||
if(sdata->duplicate_id > 0){
|
||||
remove_stripped_attachments(state);
|
||||
@ -319,7 +359,7 @@ int process_message(struct session_data *sdata, struct parser_state *state, stru
|
||||
}
|
||||
|
||||
|
||||
rc = store_file(sdata, sdata->tmpframe, 0, 0, cfg);
|
||||
rc = store_file(sdata, sdata->tmpframe, 0, cfg);
|
||||
if(rc == 0){
|
||||
syslog(LOG_PRIORITY, "%s: error storing message: %s", sdata->ttmpfile, sdata->tmpframe);
|
||||
return ERR;
|
||||
@ -328,7 +368,7 @@ int process_message(struct session_data *sdata, struct parser_state *state, stru
|
||||
|
||||
sdata->retained += query_retain_period(data, state, sdata->tot_len, sdata->spam_message, cfg);
|
||||
|
||||
rc = store_meta_data(sdata, state, data, cfg);
|
||||
rc = store_meta_data(sdata, state, data, 0, cfg);
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: stored metadata, rc=%d", sdata->ttmpfile, rc);
|
||||
if(rc == ERR_EXISTS){
|
||||
|
||||
@ -340,3 +380,55 @@ int process_message(struct session_data *sdata, struct parser_state *state, stru
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int reimport_message(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg){
|
||||
int i, rc;
|
||||
char piler_id[SMALLBUFSIZE];
|
||||
char oldfile[SMALLBUFSIZE], newfile[SMALLBUFSIZE];
|
||||
|
||||
memset(piler_id, 0, sizeof(piler_id));
|
||||
|
||||
sdata->duplicate_id = get_metaid_by_messageid(sdata, data, state->message_id, &piler_id[0]);
|
||||
|
||||
if(sdata->duplicate_id == 0){
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "cannot find this message: %s", state->message_id);
|
||||
return ERR;
|
||||
}
|
||||
|
||||
|
||||
/* store base64 encoded file attachments */
|
||||
|
||||
if(state->n_attachments > 0){
|
||||
|
||||
// rename .a* files!
|
||||
|
||||
for(i=1; i<=state->n_attachments; i++){
|
||||
snprintf(oldfile, sizeof(oldfile)-1, "%s.a%d", sdata->ttmpfile, i);
|
||||
snprintf(newfile, sizeof(newfile)-1, "%s.a%d", piler_id, i);
|
||||
rename(oldfile, newfile);
|
||||
}
|
||||
|
||||
rc = store_attachments(sdata, state, data, cfg);
|
||||
remove_stripped_attachments(state);
|
||||
if(rc) return ERR;
|
||||
}
|
||||
|
||||
// rename .m file!
|
||||
|
||||
snprintf(oldfile, sizeof(oldfile)-1, "%s.m", sdata->ttmpfile);
|
||||
snprintf(sdata->tmpframe, SMALLBUFSIZE-1, "%s.m", piler_id);
|
||||
rename(oldfile, sdata->tmpframe);
|
||||
|
||||
rc = store_file(sdata, sdata->tmpframe, 0, cfg);
|
||||
if(rc == 0){
|
||||
syslog(LOG_PRIORITY, "%s: error storing message for reimport: %s", sdata->ttmpfile, sdata->tmpframe);
|
||||
return ERR;
|
||||
}
|
||||
|
||||
sdata->retained += query_retain_period(data, state, sdata->tot_len, sdata->spam_message, cfg);
|
||||
|
||||
rc = store_meta_data(sdata, state, data, sdata->duplicate_id, cfg);
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: update metadata, rc=%d", sdata->ttmpfile, rc);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ int get_random_bytes(unsigned char *buf, int len, unsigned char server_id){
|
||||
* read random data from entropy pool
|
||||
*/
|
||||
|
||||
int readFromEntropyPool(int fd, void *_s, size_t n){
|
||||
int readFromEntropyPool(int fd, void *_s, ssize_t n){
|
||||
char *s = _s;
|
||||
ssize_t res, pos = 0;
|
||||
|
||||
|
@ -29,7 +29,7 @@ int extractEmail(char *rawmail, char *email);
|
||||
void make_random_string(char *buf, int buflen);
|
||||
void create_id(char *id, unsigned char server_id);
|
||||
int get_random_bytes(unsigned char *buf, int len, unsigned char server_id);
|
||||
int readFromEntropyPool(int fd, void *_s, size_t n);
|
||||
int readFromEntropyPool(int fd, void *_s, ssize_t n);
|
||||
int recvtimeout(int s, char *buf, int len, int timeout);
|
||||
int write1(int sd, void *buf, int buflen, int use_ssl, SSL *ssl);
|
||||
int recvtimeoutssl(int s, char *buf, int len, int timeout, int use_ssl, SSL *ssl);
|
||||
|
@ -17,7 +17,7 @@ void load_mydomains(struct session_data *sdata, struct __data *data, struct __co
|
||||
memset(s, 0, sizeof(s));
|
||||
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), SQL_PREPARED_STMT_GET_DOMAINS, cfg) == ERR) return;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), SQL_PREPARED_STMT_GET_DOMAINS) == ERR) return;
|
||||
|
||||
|
||||
p_bind_init(data);
|
||||
@ -28,7 +28,7 @@ void load_mydomains(struct session_data *sdata, struct __data *data, struct __co
|
||||
|
||||
data->sql[data->pos] = &s[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(s)-2; data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
p_store_results(data->stmt_generic, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_generic) == OK){
|
||||
rc = addnode(data->mydomains, s);
|
||||
|
@ -123,7 +123,7 @@ int p_exec_query(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *da
|
||||
}
|
||||
|
||||
|
||||
int p_store_results(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *data){
|
||||
int p_store_results(MYSQL_STMT *stmt, struct __data *data){
|
||||
MYSQL_BIND bind[MAX_SQL_VARS];
|
||||
int i, ret=ERR;
|
||||
|
||||
@ -205,7 +205,7 @@ int p_get_affected_rows(MYSQL_STMT *stmt){
|
||||
}
|
||||
|
||||
|
||||
int prepare_sql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s, struct __config *cfg){
|
||||
int prepare_sql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s){
|
||||
|
||||
*stmt = mysql_stmt_init(&(sdata->mysql));
|
||||
if(!*stmt){
|
||||
|
17
src/parser.c
17
src/parser.c
@ -18,7 +18,8 @@
|
||||
|
||||
struct parser_state parse_message(struct session_data *sdata, int take_into_pieces, struct __data *data, struct __config *cfg){
|
||||
FILE *f;
|
||||
int i, len;
|
||||
int i;
|
||||
unsigned int len;
|
||||
char *p, buf[MAXBUFSIZE], puf[SMALLBUFSIZE];
|
||||
char writebuffer[MAXBUFSIZE], abuffer[MAXBUFSIZE];
|
||||
struct parser_state state;
|
||||
@ -99,7 +100,8 @@ struct parser_state parse_message(struct session_data *sdata, int take_into_piec
|
||||
|
||||
|
||||
void post_parse(struct session_data *sdata, struct parser_state *state, struct __config *cfg){
|
||||
int i, len, rec=0;
|
||||
int i, rec=0;
|
||||
unsigned int len;
|
||||
char *p;
|
||||
|
||||
clearhash(state->boundaries);
|
||||
@ -173,7 +175,8 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
|
||||
char *p, *q, puf[SMALLBUFSIZE];
|
||||
unsigned char b64buffer[MAXBUFSIZE];
|
||||
char tmpbuf[MAXBUFSIZE];
|
||||
int n64, len, writelen, boundary_line=0, result;
|
||||
int n64, writelen, boundary_line=0, result;
|
||||
unsigned int len;
|
||||
|
||||
if(cfg->debug == 1) printf("line: %s", buf);
|
||||
|
||||
@ -238,7 +241,7 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
|
||||
if(state->b64fd != -1){
|
||||
abuffer[state->abufpos] = '\0';
|
||||
if(state->base64 == 1){
|
||||
n64 = base64_decode_attachment_buffer(abuffer, state->abufpos, &b64buffer[0], sizeof(b64buffer));
|
||||
n64 = base64_decode_attachment_buffer(abuffer, &b64buffer[0], sizeof(b64buffer));
|
||||
write(state->b64fd, b64buffer, n64);
|
||||
}
|
||||
else {
|
||||
@ -383,14 +386,14 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
|
||||
|
||||
if(strstr(buf, "=?") && strstr(buf, "?=")) fixupEncodedHeaderLine(buf, MAXBUFSIZE);
|
||||
|
||||
sdata->sent = parse_date_header(buf, cfg);
|
||||
sdata->sent = parse_date_header(buf);
|
||||
|
||||
/* allow +2 days drift in the parsed Date: value */
|
||||
|
||||
if(sdata->sent - sdata->now > 2*86400) sdata->sent = sdata->now;
|
||||
}
|
||||
|
||||
else if(strncasecmp(buf, "Delivery-date:", strlen("Delivery-date:")) == 0 && sdata->delivered == 0) sdata->delivered = parse_date_header(buf, cfg);
|
||||
else if(strncasecmp(buf, "Delivery-date:", strlen("Delivery-date:")) == 0 && sdata->delivered == 0) sdata->delivered = parse_date_header(buf);
|
||||
else if(strncasecmp(buf, "Received:", strlen("Received:")) == 0) state->message_state = MSG_RECEIVED;
|
||||
else if(cfg->extra_to_field[0] != '\0' && strncasecmp(buf, cfg->extra_to_field, strlen(cfg->extra_to_field)) == 0) state->message_state = MSG_TO;
|
||||
|
||||
@ -577,7 +580,7 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
|
||||
if(state->b64fd != -1){
|
||||
abuffer[state->abufpos] = '\0';
|
||||
if(state->base64 == 1){
|
||||
n64 = base64_decode_attachment_buffer(abuffer, state->abufpos, &b64buffer[0], sizeof(b64buffer));
|
||||
n64 = base64_decode_attachment_buffer(abuffer, &b64buffer[0], sizeof(b64buffer));
|
||||
write(state->b64fd, b64buffer, n64);
|
||||
}
|
||||
else {
|
||||
|
@ -14,7 +14,7 @@ void post_parse(struct session_data *sdata, struct parser_state *state, struct _
|
||||
int parse_line(char *buf, struct parser_state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __data *data, struct __config *cfg);
|
||||
|
||||
void init_state(struct parser_state *state);
|
||||
time_t parse_date_header(char *s, struct __config *cfg);
|
||||
time_t parse_date_header(char *s);
|
||||
int isHexNumber(char *p);
|
||||
int extract_boundary(char *p, struct parser_state *state);
|
||||
void fixupEncodedHeaderLine(char *buf, int buflen);
|
||||
@ -33,6 +33,6 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf);
|
||||
char *determine_attachment_type(char *filename, char *type);
|
||||
char *get_attachment_extractor_by_filename(char *filename);
|
||||
void parse_reference(struct parser_state *state, char *s);
|
||||
int base64_decode_attachment_buffer(char *p, int plen, unsigned char *b, int blen);
|
||||
int base64_decode_attachment_buffer(char *p, unsigned char *b, int blen);
|
||||
|
||||
#endif /* _PARSER_H */
|
||||
|
@ -112,7 +112,7 @@ long get_local_timezone_offset(){
|
||||
}
|
||||
|
||||
|
||||
time_t parse_date_header(char *datestr, struct __config *cfg){
|
||||
time_t parse_date_header(char *datestr){
|
||||
int n=0, len;
|
||||
long offset=0;
|
||||
time_t ts=0;
|
||||
@ -257,10 +257,6 @@ time_t parse_date_header(char *datestr, struct __config *cfg){
|
||||
|
||||
ts += get_local_timezone_offset() - offset;
|
||||
|
||||
#ifdef HAVE_TWEAK_SENT_TIME
|
||||
if(ts > 631148400) ts += cfg->tweak_sent_time_offset;
|
||||
#endif
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
@ -674,7 +670,8 @@ int does_it_seem_like_an_email_address(char *email){
|
||||
*/
|
||||
|
||||
void reassembleToken(char *p){
|
||||
int i, k=0;
|
||||
unsigned int i;
|
||||
int k=0;
|
||||
|
||||
for(i=0; i<strlen(p); i++){
|
||||
|
||||
@ -947,7 +944,7 @@ void parse_reference(struct parser_state *state, char *s){
|
||||
}
|
||||
|
||||
|
||||
int base64_decode_attachment_buffer(char *p, int plen, unsigned char *b, int blen){
|
||||
int base64_decode_attachment_buffer(char *p, unsigned char *b, int blen){
|
||||
int b64len=0;
|
||||
char puf[2*SMALLBUFSIZE];
|
||||
|
||||
|
@ -334,9 +334,9 @@ void initialise_configuration(){
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
|
||||
load_rules(&sdata, &data, data.retention_rules, SQL_RETENTION_RULE_TABLE);
|
||||
load_rules(&sdata, &data, data.folder_rules, SQL_FOLDER_RULE_TABLE);
|
||||
|
||||
load_mydomains(&sdata, &data, &cfg);
|
||||
|
||||
|
@ -40,10 +40,11 @@ int handle_pilerget_request(int new_sd, struct __data *data, struct __config *cf
|
||||
|
||||
void remove_stripped_attachments(struct parser_state *state);
|
||||
int process_message(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg);
|
||||
int store_file(struct session_data *sdata, char *filename, int startpos, int len, struct __config *cfg);
|
||||
int reimport_message(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg);
|
||||
int store_file(struct session_data *sdata, char *filename, int len, struct __config *cfg);
|
||||
int remove_stored_message_files(struct session_data *sdata, struct parser_state *state, struct __config *cfg);
|
||||
int store_attachments(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg);
|
||||
int query_attachments(struct session_data *sdata, struct __data *data, struct ptr_array *ptr_arr, struct __config *cfg);
|
||||
int query_attachments(struct session_data *sdata, struct __data *data, struct ptr_array *ptr_arr);
|
||||
|
||||
struct __config read_config(char *configfile);
|
||||
|
||||
@ -54,8 +55,8 @@ void update_counters(struct session_data *sdata, struct __data *data, struct __c
|
||||
int retrieve_email_from_archive(struct session_data *sdata, struct __data *data, FILE *dest, struct __config *cfg);
|
||||
int file_from_archive_to_network(char *filename, int sd, int tls_enable, struct __data *data, struct __config *cfg);
|
||||
|
||||
int get_folder_id(struct session_data *sdata, struct __data *data, char *foldername, int parent_id, struct __config *cfg);
|
||||
int add_new_folder(struct session_data *sdata, struct __data *data, char *foldername, int parent_id, struct __config *cfg);
|
||||
int get_folder_id(struct session_data *sdata, struct __data *data, char *foldername, int parent_id);
|
||||
int add_new_folder(struct session_data *sdata, struct __data *data, char *foldername, int parent_id);
|
||||
|
||||
int store_index_data(struct session_data *sdata, struct parser_state *state, struct __data *data, uint64 id, struct __config *cfg);
|
||||
|
||||
|
@ -343,7 +343,7 @@ int export_emails_matching_to_query(struct session_data *sdata, struct __data *d
|
||||
int rc=0;
|
||||
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), s, cfg) == ERR) return ERR;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), s) == ERR) return ERR;
|
||||
|
||||
|
||||
p_bind_init(data);
|
||||
@ -359,7 +359,7 @@ int export_emails_matching_to_query(struct session_data *sdata, struct __data *d
|
||||
data->sql[data->pos] = &digest[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(digest)-2; data->pos++;
|
||||
data->sql[data->pos] = &bodydigest[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(bodydigest)-2; data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
p_store_results(data->stmt_generic, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_generic) == OK){
|
||||
|
||||
|
@ -53,9 +53,11 @@ void usage(){
|
||||
printf(" -R Assign IMAP folder names as Piler folder names\n");
|
||||
printf(" -b <batch limit> Import only this many emails\n");
|
||||
printf(" -s <start position> Start importing POP3 emails from this position\n");
|
||||
printf(" -a <recipient> Add recipient to the To:/Cc: list\n");
|
||||
printf(" -D Dry-run, do not import anything\n");
|
||||
printf(" -o Only download emails for POP3/IMAP import\n");
|
||||
printf(" -r Remove imported emails\n");
|
||||
printf(" -z Reimport emails\n");
|
||||
printf(" -q Quiet mode\n");
|
||||
|
||||
exit(0);
|
||||
@ -81,7 +83,7 @@ int main(int argc, char **argv){
|
||||
|
||||
|
||||
import.import_job_id = import.total_messages = import.total_size = import.processed_messages = import.batch_processing_limit = 0;
|
||||
import.started = import.updated = import.finished = import.remove_after_import = 0;
|
||||
import.started = import.updated = import.finished = import.remove_after_import = import.reimport = 0;
|
||||
import.extra_recipient = import.move_folder = NULL;
|
||||
import.start_position = 1;
|
||||
import.download_only = 0;
|
||||
@ -121,6 +123,7 @@ int main(int argc, char **argv){
|
||||
{"remove-after-import",no_argument, 0, 'r' },
|
||||
{"move-folder", required_argument, 0, 'g' },
|
||||
{"only-download",no_argument, 0, 'o' },
|
||||
{"reimport", no_argument, 0, 'z' },
|
||||
{"gui-import", no_argument, 0, 'G' },
|
||||
{"dry-run", no_argument, 0, 'D' },
|
||||
{"help", no_argument, 0, 'h' },
|
||||
@ -129,9 +132,9 @@ int main(int argc, char **argv){
|
||||
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:GDRroqh?", long_options, &option_index);
|
||||
c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:GDRrozqh?", long_options, &option_index);
|
||||
#else
|
||||
c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:GDRroqh?");
|
||||
c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:GDRrozqh?");
|
||||
#endif
|
||||
|
||||
if(c == -1) break;
|
||||
@ -230,6 +233,10 @@ int main(int argc, char **argv){
|
||||
data.import->start_position = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'z' :
|
||||
data.import->reimport = 1;
|
||||
break;
|
||||
|
||||
case 'a' :
|
||||
data.import->extra_recipient = optarg;
|
||||
break;
|
||||
@ -291,10 +298,10 @@ int main(int argc, char **argv){
|
||||
#endif
|
||||
|
||||
if(folder){
|
||||
data.folder = get_folder_id(&sdata, &data, folder, 0, &cfg);
|
||||
data.folder = get_folder_id(&sdata, &data, folder, 0);
|
||||
|
||||
if(data.folder == ERR_FOLDER){
|
||||
data.folder = add_new_folder(&sdata, &data, folder, 0, &cfg);
|
||||
data.folder = add_new_folder(&sdata, &data, folder, 0);
|
||||
}
|
||||
|
||||
if(data.folder == ERR_FOLDER){
|
||||
@ -305,9 +312,9 @@ int main(int argc, char **argv){
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
|
||||
load_rules(&sdata, &data, data.retention_rules, SQL_RETENTION_RULE_TABLE);
|
||||
load_rules(&sdata, &data, data.folder_rules, SQL_FOLDER_RULE_TABLE);
|
||||
|
||||
load_mydomains(&sdata, &data, &cfg);
|
||||
|
||||
|
@ -31,10 +31,10 @@ unsigned long purged_size=0;
|
||||
#define SQL_STMT_DELETE_FROM_ATTACHMENT_TABLE "DELETE FROM `" SQL_ATTACHMENT_TABLE "` WHERE `id` IN ("
|
||||
|
||||
|
||||
int is_purge_allowed(struct session_data *sdata, struct __data *data, struct __config *cfg){
|
||||
int is_purge_allowed(struct session_data *sdata, struct __data *data){
|
||||
int rc=0;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), SQL_STMT_SELECT_PURGE_FROM_OPTION_TABLE, cfg) == ERR) return rc;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), SQL_STMT_SELECT_PURGE_FROM_OPTION_TABLE) == ERR) return rc;
|
||||
|
||||
|
||||
p_bind_init(data);
|
||||
@ -45,7 +45,7 @@ int is_purge_allowed(struct session_data *sdata, struct __data *data, struct __c
|
||||
|
||||
data->sql[data->pos] = (char *)&rc; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
p_store_results(data->stmt_generic, data);
|
||||
p_fetch_results(data->stmt_generic);
|
||||
p_free_results(data->stmt_generic);
|
||||
}
|
||||
@ -105,7 +105,8 @@ int remove_attachments(char *in, struct session_data *sdata, struct __data *data
|
||||
char filename[SMALLBUFSIZE];
|
||||
char *a, buf[NUMBER_OF_ATTACHMENTS_TO_REMOVE_IN_ONE_ROUND*(RND_STR_LEN+1)+10], update_meta_sql[strlen(SQL_STMT_DELETE_FROM_META_TABLE_BY_PILER_ID)+NUMBER_OF_ATTACHMENTS_TO_REMOVE_IN_ONE_ROUND*(RND_STR_LEN+3)+10], delete_attachment_stmt[MAXBUFSIZE];
|
||||
char piler_id[SMALLBUFSIZE], i[BUFLEN];
|
||||
int n=0, m=0, len, attachment_id=0, blen=0, ulen=0, dlen=0, piler_id_len;
|
||||
int n=0, m=0, len, attachment_id=0, piler_id_len;
|
||||
unsigned int blen=0, ulen=0, dlen=0;
|
||||
#ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT
|
||||
struct stat st;
|
||||
#endif
|
||||
@ -123,7 +124,7 @@ int remove_attachments(char *in, struct session_data *sdata, struct __data *data
|
||||
in[strlen(in)-1] = '\0';
|
||||
snprintf(a, len-1, "%s%s", SQL_STMT_SELECT_NON_REFERENCED_ATTACHMENTS, in);
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_select_non_referenced_attachments), a, cfg) == ERR){ free(a); return n; }
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_select_non_referenced_attachments), a) == ERR){ free(a); return n; }
|
||||
|
||||
if(dryrun == 1) printf("attachment select sql: *%s*\n\n", a);
|
||||
|
||||
@ -147,7 +148,7 @@ int remove_attachments(char *in, struct session_data *sdata, struct __data *data
|
||||
data->sql[data->pos] = (char *)&attachment_id; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||
data->sql[data->pos] = &i[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(i)-2; data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_select_non_referenced_attachments, data);
|
||||
p_store_results(data->stmt_select_non_referenced_attachments, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_select_non_referenced_attachments) == OK){
|
||||
|
||||
@ -254,7 +255,8 @@ ENDE:
|
||||
|
||||
|
||||
int purge_messages_round1(struct session_data *sdata, struct __data *data, char *attachment_condition, struct __config *cfg){
|
||||
int purged=0, size, blen=0, ulen=0;
|
||||
int purged=0, size;
|
||||
unsigned int blen=0, ulen=0;
|
||||
char id[BUFLEN], s[SMALLBUFSIZE], buf[MAXBUFSIZE], update_meta_sql[MAXBUFSIZE];
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
@ -267,7 +269,7 @@ int purge_messages_round1(struct session_data *sdata, struct __data *data, char
|
||||
|
||||
if(dryrun == 1) printf("purge sql: *%s*\n", s);
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_select_from_meta_table), s, cfg) == ERR) return purged;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_select_from_meta_table), s) == ERR) return purged;
|
||||
|
||||
p_bind_init(data);
|
||||
|
||||
@ -279,7 +281,7 @@ int purge_messages_round1(struct session_data *sdata, struct __data *data, char
|
||||
data->sql[data->pos] = &s[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(s)-2; data->pos++;
|
||||
data->sql[data->pos] = (char *)&size; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_select_from_meta_table, data);
|
||||
p_store_results(data->stmt_select_from_meta_table, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_select_from_meta_table) == OK){
|
||||
|
||||
@ -321,7 +323,8 @@ int purge_messages_round1(struct session_data *sdata, struct __data *data, char
|
||||
|
||||
|
||||
int purge_messages_with_attachments(struct session_data *sdata, struct __data *data, struct __config *cfg){
|
||||
int purged=0, size, idlist_len=0;
|
||||
int purged=0, size;
|
||||
unsigned int idlist_len=0;
|
||||
char s[SMALLBUFSIZE], idlist[MAXBUFSIZE];
|
||||
|
||||
memset(idlist, 0, sizeof(idlist));
|
||||
@ -330,7 +333,7 @@ int purge_messages_with_attachments(struct session_data *sdata, struct __data *d
|
||||
|
||||
if(dryrun == 1) printf("purge sql: *%s*\n", s);
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_select_from_meta_table), s, cfg) == ERR) return purged;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_select_from_meta_table), s) == ERR) return purged;
|
||||
|
||||
p_bind_init(data);
|
||||
if(p_exec_query(sdata, data->stmt_select_from_meta_table, data) == OK){
|
||||
@ -340,7 +343,7 @@ int purge_messages_with_attachments(struct session_data *sdata, struct __data *d
|
||||
data->sql[data->pos] = &s[0]; data->type[data->pos] = TYPE_STRING; data->len[data->pos] = sizeof(s)-2; data->pos++;
|
||||
data->sql[data->pos] = (char *)&size; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_select_from_meta_table, data);
|
||||
p_store_results(data->stmt_select_from_meta_table, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_select_from_meta_table) == OK){
|
||||
memcpy(&idlist[idlist_len], s, strlen(s)); idlist_len += strlen(s);
|
||||
@ -410,7 +413,7 @@ int main(int argc, char **argv){
|
||||
|
||||
init_session_data(&sdata, &cfg);
|
||||
|
||||
i = is_purge_allowed(&sdata, &data, &cfg);
|
||||
i = is_purge_allowed(&sdata, &data);
|
||||
if(i == 1){
|
||||
purged += purge_messages_round1(&sdata, &data, "attachments=0", &cfg);
|
||||
purged += purge_messages_with_attachments(&sdata, &data, &cfg);
|
||||
|
@ -36,7 +36,7 @@ int is_last_complete_pop3_packet(char *s, int len){
|
||||
}
|
||||
|
||||
|
||||
int connect_to_pop3_server(int sd, char *username, char *password, int port, struct __data *data, int use_ssl){
|
||||
int connect_to_pop3_server(int sd, char *username, char *password, struct __data *data, int use_ssl){
|
||||
int n;
|
||||
char buf[MAXBUFSIZE];
|
||||
X509* server_cert;
|
||||
|
@ -42,14 +42,14 @@ void p_clean_exit(char *msg, int rc){
|
||||
}
|
||||
|
||||
|
||||
uint64 get_max_meta_id(struct session_data *sdata, struct __data *data, struct __config *cfg){
|
||||
uint64 get_max_meta_id(struct session_data *sdata, struct __data *data){
|
||||
char s[SMALLBUFSIZE];
|
||||
uint64 id=0;
|
||||
|
||||
snprintf(s, sizeof(s)-1, "SELECT MAX(`id`) FROM %s", SQL_METADATA_TABLE);
|
||||
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), s, cfg) == ERR) return id;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), s) == ERR) return id;
|
||||
|
||||
|
||||
p_bind_init(data);
|
||||
@ -60,7 +60,7 @@ uint64 get_max_meta_id(struct session_data *sdata, struct __data *data, struct _
|
||||
|
||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONGLONG; data->len[data->pos] = sizeof(uint64); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
p_store_results(data->stmt_generic, data);
|
||||
p_fetch_results(data->stmt_generic);
|
||||
p_free_results(data->stmt_generic);
|
||||
}
|
||||
@ -88,7 +88,7 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data *
|
||||
snprintf(s, sizeof(s)-1, "SELECT `id`, `piler_id`, `arrived`, `sent` FROM %s WHERE (id BETWEEN %llu AND %llu) AND `deleted`=0", SQL_METADATA_TABLE, from_id, to_id);
|
||||
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), s, cfg) == ERR) return reindexed;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), s) == ERR) return reindexed;
|
||||
|
||||
p_bind_init(data);
|
||||
|
||||
@ -104,7 +104,7 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data *
|
||||
data->sql[data->pos] = (char *)&(data->folder); data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(unsigned long); data->pos++;
|
||||
}
|
||||
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
p_store_results(data->stmt_generic, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_generic) == OK){
|
||||
|
||||
@ -239,10 +239,10 @@ int main(int argc, char **argv){
|
||||
p_clean_exit("cannot connect to mysql server", 1);
|
||||
}
|
||||
|
||||
load_rules(&sdata, &data, data.folder_rules, SQL_FOLDER_RULE_TABLE, &cfg);
|
||||
load_rules(&sdata, &data, data.folder_rules, SQL_FOLDER_RULE_TABLE);
|
||||
|
||||
if(folder){
|
||||
data.folder = get_folder_id(&sdata, &data, folder, 0, &cfg);
|
||||
data.folder = get_folder_id(&sdata, &data, folder, 0);
|
||||
if(data.folder == 0){
|
||||
printf("error: could not get folder id for '%s'\n", folder);
|
||||
return 0;
|
||||
@ -254,7 +254,7 @@ int main(int argc, char **argv){
|
||||
|
||||
if(all == 1){
|
||||
from_id = 1;
|
||||
to_id = get_max_meta_id(&sdata, &data, &cfg);
|
||||
to_id = get_max_meta_id(&sdata, &data);
|
||||
}
|
||||
|
||||
n = retrieve_email_by_metadata_id(&sdata, &data, from_id, to_id, &cfg);
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "rules.h"
|
||||
|
||||
|
||||
void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table, struct __config *cfg){
|
||||
void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table){
|
||||
char s[SMALLBUFSIZE];
|
||||
struct rule_cond rule_cond;
|
||||
|
||||
@ -28,7 +28,7 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh
|
||||
|
||||
snprintf(s, sizeof(s)-1, "SELECT `domain`, `from`, `to`, `subject`, `body`, `_size`, `size`, `attachment_name`, `attachment_type`, `_attachment_size`, `attachment_size`, `spam`, `days`, `folder_id` FROM `%s`", table);
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), s, cfg) == ERR) return;
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_generic), s) == ERR) return;
|
||||
|
||||
|
||||
p_bind_init(data);
|
||||
@ -52,7 +52,7 @@ void load_rules(struct session_data *sdata, struct __data *data, struct node *xh
|
||||
data->sql[data->pos] = (char *)&rule_cond.days; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||
data->sql[data->pos] = (char *)&rule_cond.folder_id; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(int); data->pos++;
|
||||
|
||||
p_store_results(sdata, data->stmt_generic, data);
|
||||
p_store_results(data->stmt_generic, data);
|
||||
|
||||
while(p_fetch_results(data->stmt_generic) == OK){
|
||||
append_rule(xhash, &rule_cond, data);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table, struct __config *cfg);
|
||||
void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table);
|
||||
int append_rule(struct node *xhash[], struct rule_cond *rule_cond, struct __data *data);
|
||||
struct rule *create_rule_item(struct rule_cond *rule_cond, struct __data *data);
|
||||
char *check_againt_ruleset(struct node *xhash[], struct parser_state *state, int size, int spam);
|
||||
|
@ -351,7 +351,7 @@ AFTER_PERIOD:
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: got: %s", sdata.ttmpfile, buf);
|
||||
|
||||
if(strncasecmp(buf, SMTP_CMD_EHLO, strlen(SMTP_CMD_EHLO)) == 0 || strncasecmp(buf, LMTP_CMD_LHLO, strlen(LMTP_CMD_LHLO)) == 0){
|
||||
process_command_ehlo_lhlo(&sdata, data, &protocol_state, buf, &resp[0], sizeof(resp)-1, cfg);
|
||||
process_command_ehlo_lhlo(&sdata, data, &protocol_state, &resp[0], sizeof(resp)-1, cfg);
|
||||
continue;
|
||||
|
||||
/* FIXME: implement the ENHANCEDSTATUSCODE extensions */
|
||||
@ -367,7 +367,7 @@ AFTER_PERIOD:
|
||||
|
||||
#ifdef HAVE_STARTTLS
|
||||
if(cfg->tls_enable > 0 && strncasecmp(buf, SMTP_CMD_STARTTLS, strlen(SMTP_CMD_STARTTLS)) == 0 && strlen(data->starttls) > 4 && sdata.tls == 0){
|
||||
process_command_starttls(&sdata, data, &protocol_state, &starttls, buf, new_sd, &resp[0], sizeof(resp)-1, cfg);
|
||||
process_command_starttls(&sdata, data, &protocol_state, &starttls, new_sd, &resp[0], sizeof(resp)-1, cfg);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
@ -380,7 +380,7 @@ AFTER_PERIOD:
|
||||
|
||||
|
||||
if(strncasecmp(buf, SMTP_CMD_RCPT_TO, strlen(SMTP_CMD_RCPT_TO)) == 0){
|
||||
process_command_rcpt_to(&sdata, &protocol_state, buf, &resp[0], sizeof(resp)-1, cfg);
|
||||
process_command_rcpt_to(&sdata, &protocol_state, buf, &resp[0], sizeof(resp)-1);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -391,13 +391,13 @@ AFTER_PERIOD:
|
||||
inj = ERR;
|
||||
prevlen = 0;
|
||||
|
||||
process_command_data(&sdata, &protocol_state, buf, &resp[0], sizeof(resp)-1, cfg);
|
||||
process_command_data(&sdata, &protocol_state, &resp[0], sizeof(resp)-1);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(strncasecmp(buf, SMTP_CMD_QUIT, strlen(SMTP_CMD_QUIT)) == 0){
|
||||
process_command_quit(&sdata, &protocol_state, buf, &resp[0], sizeof(resp)-1, cfg);
|
||||
process_command_quit(&sdata, &protocol_state, &resp[0], sizeof(resp)-1, cfg);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -409,7 +409,7 @@ AFTER_PERIOD:
|
||||
|
||||
|
||||
if(strncasecmp(buf, SMTP_CMD_RESET, strlen(SMTP_CMD_RESET)) == 0){
|
||||
process_command_reset(&sdata, &protocol_state, buf, &resp[0], sizeof(resp)-1, cfg);
|
||||
process_command_reset(&sdata, &protocol_state, &resp[0], sizeof(resp)-1, cfg);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ AFTER_PERIOD:
|
||||
|
||||
|
||||
if(strlen(resp) > 0){
|
||||
send_buffered_response(&sdata, data, &protocol_state, starttls, buf, new_sd, &resp[0], sizeof(resp)-1, cfg);
|
||||
send_buffered_response(&sdata, data, starttls, new_sd, &resp[0], cfg);
|
||||
memset(resp, 0, sizeof(resp));
|
||||
}
|
||||
|
||||
|
15
src/smtp.c
15
src/smtp.c
@ -17,9 +17,10 @@
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#include <piler.h>
|
||||
#include <smtp.h>
|
||||
|
||||
|
||||
void process_command_ehlo_lhlo(struct session_data *sdata, struct __data *data, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg){
|
||||
void process_command_ehlo_lhlo(struct session_data *sdata, struct __data *data, int *protocol_state, char *resp, int resplen, struct __config *cfg){
|
||||
char tmpbuf[MAXBUFSIZE];
|
||||
|
||||
if(*protocol_state == SMTP_STATE_INIT) *protocol_state = SMTP_STATE_HELO;
|
||||
@ -32,7 +33,7 @@ void process_command_ehlo_lhlo(struct session_data *sdata, struct __data *data,
|
||||
|
||||
|
||||
#ifdef HAVE_STARTTLS
|
||||
void process_command_starttls(struct session_data *sdata, struct __data *data, int *protocol_state, int *starttls, char *buf, int new_sd, char *resp, int resplen, struct __config *cfg){
|
||||
void process_command_starttls(struct session_data *sdata, struct __data *data, int *protocol_state, int *starttls, int new_sd, char *resp, int resplen, struct __config *cfg){
|
||||
|
||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: starttls request from client", sdata->ttmpfile);
|
||||
|
||||
@ -85,7 +86,7 @@ void process_command_mail_from(struct session_data *sdata, int *protocol_state,
|
||||
}
|
||||
|
||||
|
||||
void process_command_rcpt_to(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg){
|
||||
void process_command_rcpt_to(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen){
|
||||
|
||||
if(*protocol_state == SMTP_STATE_MAIL_FROM || *protocol_state == SMTP_STATE_RCPT_TO){
|
||||
|
||||
@ -110,7 +111,7 @@ void process_command_rcpt_to(struct session_data *sdata, int *protocol_state, ch
|
||||
}
|
||||
|
||||
|
||||
void process_command_data(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg){
|
||||
void process_command_data(struct session_data *sdata, int *protocol_state, char *resp, int resplen){
|
||||
|
||||
if(*protocol_state != SMTP_STATE_RCPT_TO){
|
||||
strncat(resp, SMTP_RESP_503_ERR, resplen);
|
||||
@ -130,7 +131,7 @@ void process_command_data(struct session_data *sdata, int *protocol_state, char
|
||||
}
|
||||
|
||||
|
||||
void process_command_quit(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg){
|
||||
void process_command_quit(struct session_data *sdata, int *protocol_state, char *resp, int resplen, struct __config *cfg){
|
||||
char tmpbuf[MAXBUFSIZE];
|
||||
|
||||
*protocol_state = SMTP_STATE_FINISHED;
|
||||
@ -145,7 +146,7 @@ void process_command_quit(struct session_data *sdata, int *protocol_state, char
|
||||
}
|
||||
|
||||
|
||||
void process_command_reset(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg){
|
||||
void process_command_reset(struct session_data *sdata, int *protocol_state, char *resp, int resplen, struct __config *cfg){
|
||||
|
||||
strncat(resp, SMTP_RESP_250_OK, resplen);
|
||||
|
||||
@ -160,7 +161,7 @@ void process_command_reset(struct session_data *sdata, int *protocol_state, char
|
||||
}
|
||||
|
||||
|
||||
void send_buffered_response(struct session_data *sdata, struct __data *data, int *protocol_state, int starttls, char *buf, int new_sd, char *resp, int resplen, struct __config *cfg){
|
||||
void send_buffered_response(struct session_data *sdata, struct __data *data, int starttls, int new_sd, char *resp, struct __config *cfg){
|
||||
int rc;
|
||||
#ifdef HAVE_STARTTLS
|
||||
char ssl_error[SMALLBUFSIZE];
|
||||
|
14
src/smtp.h
14
src/smtp.h
@ -5,14 +5,14 @@
|
||||
#ifndef _SMTP_H
|
||||
#define _SMTP_H
|
||||
|
||||
void process_command_ehlo_lhlo(struct session_data *sdata, struct __data *data, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_starttls(struct session_data *sdata, struct __data *data, int *protocol_state, int *starttls, char *buf, int new_sd, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_ehlo_lhlo(struct session_data *sdata, struct __data *data, int *protocol_state, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_starttls(struct session_data *sdata, struct __data *data, int *protocol_state, int *starttls, int new_sd, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_mail_from(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_rcpt_to(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_data(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_quit(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_reset(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_rcpt_to(struct session_data *sdata, int *protocol_state, char *buf, char *resp, int resplen);
|
||||
void process_command_data(struct session_data *sdata, int *protocol_state, char *resp, int resplen);
|
||||
void process_command_quit(struct session_data *sdata, int *protocol_state, char *resp, int resplen, struct __config *cfg);
|
||||
void process_command_reset(struct session_data *sdata, int *protocol_state, char *resp, int resplen, struct __config *cfg);
|
||||
|
||||
void send_buffered_response(struct session_data *sdata, struct __data *data, int *protocol_state, int starttls, char *buf, int new_sd, char *resp, int resplen, struct __config *cfg);
|
||||
void send_buffered_response(struct session_data *sdata, struct __data *data, int starttls, int new_sd, char *resp, struct __config *cfg);
|
||||
|
||||
#endif /* _SMTP_H */
|
||||
|
@ -8,10 +8,10 @@
|
||||
|
||||
int open_database(struct session_data *sdata, struct __config *cfg);
|
||||
void close_database(struct session_data *sdata);
|
||||
int prepare_sql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s, struct __config *cfg);
|
||||
int prepare_sql_statement(struct session_data *sdata, MYSQL_STMT **stmt, char *s);
|
||||
void p_query(struct session_data *sdata, char *s);
|
||||
int p_exec_query(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *data);
|
||||
int p_store_results(struct session_data *sdata, MYSQL_STMT *stmt, struct __data *data);
|
||||
int p_store_results(MYSQL_STMT *stmt, struct __data *data);
|
||||
int p_fetch_results(MYSQL_STMT *stmt);
|
||||
void p_free_results(MYSQL_STMT *stmt);
|
||||
void p_bind_init(struct __data *data);
|
||||
|
@ -39,7 +39,7 @@ int read_key(struct __config *cfg){
|
||||
}
|
||||
|
||||
|
||||
int store_file(struct session_data *sdata, char *filename, int startpos, int len, struct __config *cfg){
|
||||
int store_file(struct session_data *sdata, char *filename, int len, struct __config *cfg){
|
||||
int ret=0, rc, fd, n;
|
||||
char *addr, *p, *p0, *p1, *p2, s[SMALLBUFSIZE];
|
||||
struct stat st;
|
||||
@ -147,6 +147,8 @@ int store_file(struct session_data *sdata, char *filename, int startpos, int len
|
||||
|
||||
*p0 = '/';
|
||||
|
||||
unlink(s);
|
||||
|
||||
fd = open(s, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP);
|
||||
if(fd == -1){
|
||||
syslog(LOG_PRIORITY, "%s: cannot open: %s", sdata->ttmpfile, s);
|
||||
|
@ -67,9 +67,9 @@ int main(int argc, char **argv){
|
||||
|
||||
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);
|
||||
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
|
||||
load_rules(&sdata, &data, data.retention_rules, SQL_RETENTION_RULE_TABLE);
|
||||
load_rules(&sdata, &data, data.folder_rules, SQL_FOLDER_RULE_TABLE);
|
||||
|
||||
|
||||
init_session_data(&sdata, &cfg);
|
||||
|
@ -30,8 +30,8 @@ struct digest_test tests[] = {
|
||||
};
|
||||
|
||||
|
||||
void static test_digest_string(){
|
||||
int i;
|
||||
static void test_digest_string(){
|
||||
unsigned int i;
|
||||
char digest[2*DIGEST_LENGTH+1];
|
||||
struct digest_test tests[] = {
|
||||
{"Piler archives every email it receives.", "68bcdb6f15eeabdcedce3e4fc8faf7eb620272ebd55f365d08aca40adf18fe83", ""},
|
||||
@ -51,7 +51,7 @@ void static test_digest_string(){
|
||||
|
||||
|
||||
static void test_digest_file(){
|
||||
int i;
|
||||
unsigned int i;
|
||||
char digest[2*DIGEST_LENGTH+1];
|
||||
|
||||
for(i=0; i<sizeof(tests)/sizeof(struct digest_test); i++){
|
||||
@ -64,7 +64,8 @@ static void test_digest_file(){
|
||||
|
||||
|
||||
static void test_make_digests(struct __config *cfg){
|
||||
int i, j;
|
||||
unsigned int i;
|
||||
int j;
|
||||
struct session_data sdata;
|
||||
struct parser_state state;
|
||||
struct __data data;
|
||||
|
@ -29,7 +29,7 @@ struct emails {
|
||||
|
||||
|
||||
static void fill_domain_table(struct __config *cfg){
|
||||
int i;
|
||||
unsigned int i;
|
||||
char buf[SMALLBUFSIZE];
|
||||
struct session_data sdata;
|
||||
|
||||
@ -50,7 +50,7 @@ static void fill_domain_table(struct __config *cfg){
|
||||
|
||||
|
||||
static void restore_domain_table(struct __config *cfg){
|
||||
int i;
|
||||
unsigned int i;
|
||||
char buf[SMALLBUFSIZE];
|
||||
struct session_data sdata;
|
||||
|
||||
@ -71,7 +71,7 @@ static void restore_domain_table(struct __config *cfg){
|
||||
|
||||
|
||||
static void test_mydomains(struct __config *cfg){
|
||||
int i;
|
||||
unsigned int i;
|
||||
struct session_data sdata;
|
||||
struct __data data;
|
||||
struct emails emails[] = {
|
||||
|
@ -25,7 +25,8 @@ struct parser_test {
|
||||
|
||||
|
||||
static void test_parser(struct __config *cfg){
|
||||
int i, j;
|
||||
unsigned int i;
|
||||
int j;
|
||||
struct stat st;
|
||||
struct session_data sdata;
|
||||
struct parser_state state;
|
||||
|
@ -27,7 +27,10 @@ struct str_pair {
|
||||
|
||||
|
||||
static void test_parse_date_header(){
|
||||
int i;
|
||||
unsigned int i;
|
||||
int dst_fix = 0;
|
||||
time_t t = time(NULL);
|
||||
struct tm lt = {0};
|
||||
struct __config cfg;
|
||||
struct date_test date_test[] = {
|
||||
{"Date: Mon, 02 Nov 2015 09:39:31 -0000", 1446457171},
|
||||
@ -49,8 +52,11 @@ static void test_parse_date_header(){
|
||||
setlocale(LC_MESSAGES, cfg.locale);
|
||||
setlocale(LC_CTYPE, cfg.locale);
|
||||
|
||||
localtime_r(&t, <);
|
||||
if(lt.tm_isdst == 1) dst_fix = 3600;
|
||||
|
||||
for(i=0; i<sizeof(date_test)/sizeof(struct date_test); i++){
|
||||
assert(parse_date_header(date_test[i].date_str, &cfg) == date_test[i].timestamp && "test_parse_date_header()");
|
||||
assert(parse_date_header(date_test[i].date_str)-dst_fix == date_test[i].timestamp && "test_parse_date_header()");
|
||||
}
|
||||
|
||||
printf("test_parse_date_header() OK\n");
|
||||
@ -58,7 +64,7 @@ static void test_parse_date_header(){
|
||||
|
||||
|
||||
static void test_extractNameFromHeaderLine(){
|
||||
int i;
|
||||
unsigned int i;
|
||||
char resultbuf[SMALLBUFSIZE];
|
||||
struct name_from_header_test name_from_header_test[] = {
|
||||
{"Content-Type: text/plain; charset=UTF-8", "charset", "UTF-8"},
|
||||
@ -104,7 +110,7 @@ static void test_extractNameFromHeaderLine(){
|
||||
|
||||
|
||||
static void test_fixupEncodedHeaderLine(){
|
||||
int i;
|
||||
unsigned int i;
|
||||
char buf[SMALLBUFSIZE];
|
||||
struct str_pair pair[] = {
|
||||
|
||||
@ -160,7 +166,7 @@ static void test_fixupEncodedHeaderLine(){
|
||||
|
||||
|
||||
static void test_translateLine(){
|
||||
int i;
|
||||
unsigned int i;
|
||||
char buf[SMALLBUFSIZE];
|
||||
struct parser_state state;
|
||||
struct str_pair pair[] = {
|
||||
@ -197,7 +203,7 @@ static void test_translateLine(){
|
||||
|
||||
|
||||
static void test_fixURL(){
|
||||
int i;
|
||||
unsigned int i;
|
||||
char buf[SMALLBUFSIZE];
|
||||
struct str_pair pair[] = {
|
||||
{"http://www.aaa.fu", "__URL__wwwXaaaXfu "},
|
||||
@ -227,7 +233,7 @@ static void test_fixURL(){
|
||||
|
||||
|
||||
static void test_degenerateToken(){
|
||||
int i;
|
||||
unsigned int i;
|
||||
char buf[SMALLBUFSIZE];
|
||||
struct str_pair pair[] = {
|
||||
{"Hello", "Hello"},
|
||||
|
@ -35,7 +35,7 @@ struct rule_query rules[] = {
|
||||
|
||||
|
||||
static void fill_rule_table(struct __config *cfg){
|
||||
int i;
|
||||
unsigned int i;
|
||||
struct session_data sdata;
|
||||
|
||||
if(open_database(&sdata, cfg) == ERR){
|
||||
@ -55,7 +55,7 @@ static void fill_rule_table(struct __config *cfg){
|
||||
|
||||
|
||||
static void restore_rule_table(struct __config *cfg){
|
||||
int i;
|
||||
unsigned int i;
|
||||
char buf[SMALLBUFSIZE];
|
||||
struct session_data sdata;
|
||||
|
||||
@ -77,7 +77,8 @@ static void restore_rule_table(struct __config *cfg){
|
||||
|
||||
|
||||
static void test_archiving_rule(struct __config *cfg){
|
||||
int i, j;
|
||||
unsigned int i;
|
||||
int j;
|
||||
char *rule;
|
||||
struct session_data sdata;
|
||||
struct parser_state state;
|
||||
@ -102,7 +103,7 @@ static void test_archiving_rule(struct __config *cfg){
|
||||
|
||||
initrules(data.archiving_rules);
|
||||
|
||||
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE, cfg);
|
||||
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
|
||||
|
||||
for(i=0; i<sizeof(rule_test)/sizeof(struct rule_test); i++){
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user