mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 07:40:12 +01:00
folder import fixes
Change-Id: I25e5353420ae402a0905dcd885c69742fa7f7513 Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
parent
397904fde7
commit
8b0995a556
2
configure
vendored
2
configure
vendored
@ -4866,7 +4866,7 @@ echo; echo
|
||||
|
||||
CFLAGS="$static -O2 -Wall -g"
|
||||
LIBS="$antispam_libs $sunos_libs "
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o import_gui.o imap.o pop3.o extract.o folder_extra.o mydomains.o $objs"
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o import_gui.o imap.o pop3.o extract.o folder.o mydomains.o $objs"
|
||||
|
||||
ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile unit_tests/Makefile contrib/imap/Makefile"
|
||||
|
||||
|
@ -544,7 +544,7 @@ echo; echo
|
||||
|
||||
CFLAGS="$static -O2 -Wall -g"
|
||||
LIBS="$antispam_libs $sunos_libs "
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o import_gui.o imap.o pop3.o extract.o folder_extra.o mydomains.o $objs"
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o import_gui.o imap.o pop3.o extract.o folder.o mydomains.o $objs"
|
||||
|
||||
AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile unit_tests/Makefile contrib/imap/Makefile])
|
||||
AC_OUTPUT
|
||||
|
@ -71,7 +71,7 @@ backlog=20
|
||||
|
||||
workdir=/var/piler/tmp
|
||||
|
||||
; whether to enable writing folder_message table (1) or not (0)
|
||||
; whether the daemon is enabled writing folder_message table (1) or not (0)
|
||||
enable_folders=0
|
||||
|
||||
; discard a message if it's shorter than this value (in bytes)
|
||||
|
@ -84,6 +84,7 @@
|
||||
#define SQL_RETENTION_RULE_TABLE "retention_rule"
|
||||
#define SQL_FOLDER_RULE_TABLE "folder_rule"
|
||||
#define SQL_FOLDER_EXTRA_TABLE "folder_extra"
|
||||
#define SQL_FOLDER_EMAIL_TABLE "folder_email"
|
||||
#define SQL_COUNTER_TABLE "counter"
|
||||
#define SQL_OPTION_TABLE "option"
|
||||
#define SQL_DOMAIN_TABLE "domain"
|
||||
@ -106,6 +107,7 @@
|
||||
#define SQL_PREPARED_STMT_QUERY_ATTACHMENT "SELECT `attachment_id`, `ptr` FROM " SQL_ATTACHMENT_TABLE " WHERE piler_id=? ORDER BY attachment_id ASC"
|
||||
#define SQL_PREPARED_STMT_GET_FOLDER_ID "SELECT `id` FROM " SQL_FOLDER_TABLE " WHERE `name`=? AND `parent_id`=?"
|
||||
#define SQL_PREPARED_STMT_GET_FOLDER_EXTRA_ID "SELECT `id` FROM " SQL_FOLDER_EXTRA_TABLE " WHERE `name`=? AND `uid`=?"
|
||||
#define SQL_PREPARED_STMT_GET_FOLDER_UID_BY_EMAIL "SELECT `uid` FROM " SQL_FOLDER_EMAIL_TABLE " WHERE `email`=?"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE "INSERT INTO `" SQL_FOLDER_TABLE "` (`name`, `parent_id`) VALUES(?,?)"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_EXTRA_TABLE "INSERT INTO `" SQL_FOLDER_EXTRA_TABLE "` (`name`, `uid`) VALUES(?,?)"
|
||||
#define SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE "UPDATE " SQL_METADATA_TABLE " SET reference=? WHERE message_id=? AND reference=''"
|
||||
|
@ -286,6 +286,7 @@ struct memcached_server {
|
||||
struct import {
|
||||
char *extra_recipient;
|
||||
char *move_folder;
|
||||
char *email;
|
||||
int status;
|
||||
int total_messages;
|
||||
int processed_messages;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* folder_extra.c, SJ
|
||||
* folder.c, SJ
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -18,6 +18,33 @@
|
||||
#include <piler.h>
|
||||
|
||||
|
||||
void get_folder_uid_by_email(struct session_data *sdata, struct __data *data){
|
||||
int uid = 0;
|
||||
|
||||
data->import->uid = uid;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_folder_id), SQL_PREPARED_STMT_GET_FOLDER_UID_BY_EMAIL) == ERR) return;
|
||||
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = data->import->email; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
|
||||
if(p_exec_query(sdata, data->stmt_get_folder_id, data) == OK){
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = (char *)&uid; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(unsigned long); data->pos++;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
printf("uid=%d\n", uid);
|
||||
|
||||
close_prepared_statement(data->stmt_get_folder_id);
|
||||
|
||||
data->import->uid = uid;
|
||||
}
|
||||
|
||||
|
||||
int get_folder_extra_id(struct session_data *sdata, struct __data *data, char *foldername){
|
||||
int id=ERR_FOLDER;
|
||||
|
@ -98,8 +98,8 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
||||
rc = process_message(sdata, &state, data, cfg);
|
||||
|
||||
/*
|
||||
* if pilerimport was invoked with --uid, and this is a duplicate,
|
||||
* then add it to the folder_extra table
|
||||
* if pilerimport was invoked with --email (then queried the matching uid!),
|
||||
* and this is a duplicate, then add it to the folder_extra table
|
||||
*/
|
||||
|
||||
if(rc == ERR_EXISTS && data->import->uid > 0){
|
||||
|
@ -59,6 +59,7 @@ int file_from_archive_to_network(char *filename, int sd, int tls_enable, struct
|
||||
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);
|
||||
|
||||
void get_folder_uid_by_email(struct session_data *sdata, struct __data *data);
|
||||
int get_folder_extra_id(struct session_data *sdata, struct __data *data, char *foldername);
|
||||
int add_new_folder_extra(struct session_data *sdata, struct __data *data, char *foldername);
|
||||
|
||||
|
@ -50,7 +50,7 @@ void usage(){
|
||||
printf(" -f <imap folder> IMAP folder name to import\n");
|
||||
printf(" -g <imap folder> Move email after import to this IMAP folder\n");
|
||||
printf(" -F <folder> Piler folder name to assign to this import\n");
|
||||
printf(" --uid <uidr> UID to assign to this import\n");
|
||||
printf(" --email <email@address> Email address to assign to this import\n");
|
||||
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");
|
||||
@ -90,6 +90,7 @@ int main(int argc, char **argv){
|
||||
import.download_only = 0;
|
||||
import.timeout = 30;
|
||||
import.uid = 0;
|
||||
import.email = NULL;
|
||||
|
||||
data.import = &import;
|
||||
|
||||
@ -116,7 +117,7 @@ int main(int argc, char **argv){
|
||||
{"skiplist", required_argument, 0, 'x' },
|
||||
{"folder", required_argument, 0, 'F' },
|
||||
{"folder_imap", required_argument, 0, 'f' },
|
||||
{"uid", required_argument, 0, 'U' },
|
||||
{"email", required_argument, 0, 'E' },
|
||||
{"add-recipient",required_argument, 0, 'a' },
|
||||
{"batch-limit", required_argument, 0, 'b' },
|
||||
{"timeout", required_argument, 0, 't' },
|
||||
@ -135,9 +136,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:U:GDRrozqh?", 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:E: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:U:GDRrozqh?");
|
||||
c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:E:GDRrozqh?");
|
||||
#endif
|
||||
|
||||
if(c == -1) break;
|
||||
@ -182,8 +183,8 @@ int main(int argc, char **argv){
|
||||
username = optarg;
|
||||
break;
|
||||
|
||||
case 'U' :
|
||||
data.import->uid = atoi(optarg);
|
||||
case 'E' :
|
||||
data.import->email = optarg;
|
||||
break;
|
||||
|
||||
case 'p' :
|
||||
@ -305,7 +306,12 @@ int main(int argc, char **argv){
|
||||
#endif
|
||||
|
||||
if(folder){
|
||||
if(data.import->uid > 0){
|
||||
|
||||
cfg.enable_folders = 1;
|
||||
|
||||
if(data.import->email){
|
||||
get_folder_uid_by_email(&sdata, &data);
|
||||
|
||||
data.folder = get_folder_extra_id(&sdata, &data, folder);
|
||||
|
||||
if(data.folder == ERR_FOLDER){
|
||||
|
@ -279,15 +279,15 @@ create table if not exists `folder` (
|
||||
) Engine=InnoDB;
|
||||
|
||||
|
||||
create table if not exists `folder_user` (
|
||||
`id` bigint unsigned not null,
|
||||
`uid` int unsigned not null,
|
||||
key `folder_user_idx` (`id`),
|
||||
key `folder_user_idx2` (`uid`)
|
||||
create table if not exists `folder_email` (
|
||||
`uid` int unsigned not null auto_increment,
|
||||
`email` char(128) not null unique,
|
||||
key `folder_user_idx` (`uid`)
|
||||
key `folder_user_idx2` (`email`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
||||
create table if not exists `folder_extra` (
|
||||
create table if not exists `folder_user` (
|
||||
`id` int unsigned not null auto_increment,
|
||||
`uid` int unsigned not null,
|
||||
`name` char(64) not null,
|
||||
@ -301,7 +301,7 @@ create table if not exists `folder_message` (
|
||||
`folder_id` bigint not null,
|
||||
`message_id` bigint not null,
|
||||
`uid` int not null,
|
||||
unique(`folder_id`, `message_id`, `uid`),
|
||||
unique(`message_id`, `uid`),
|
||||
key (`id`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user