mirror of
https://bitbucket.org/jsuto/piler.git
synced 2025-06-13 12:07:03 +02:00
@ -107,6 +107,7 @@
|
||||
#define SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE "UPDATE " SQL_METADATA_TABLE " SET reference=? WHERE message_id=? AND reference=''"
|
||||
#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(?,?)"
|
||||
#define SQL_PREPARED_STMT_UPDATE_IMPORT_TABLE "UPDATE " SQL_IMPORT_TABLE " SET status=?, imported=? WHERE id=?"
|
||||
|
||||
/* Error codes */
|
||||
|
||||
|
@ -304,6 +304,7 @@ struct import {
|
||||
int tot_msgs;
|
||||
int port;
|
||||
int seq;
|
||||
int table_id;
|
||||
char *server;
|
||||
char *username;
|
||||
char *password;
|
||||
|
20
src/import.c
20
src/import.c
@ -144,6 +144,26 @@ int import_message(struct session_data *sdata, struct data *data, struct config
|
||||
}
|
||||
|
||||
|
||||
int update_import_table(struct session_data *sdata, struct data *data) {
|
||||
int ret=ERR, status=2;
|
||||
struct sql sql;
|
||||
|
||||
if(prepare_sql_statement(sdata, &sql, SQL_PREPARED_STMT_UPDATE_IMPORT_TABLE) == ERR) return ret;
|
||||
|
||||
p_bind_init(&sql);
|
||||
|
||||
sql.sql[sql.pos] = (char *)&(status); sql.type[sql.pos] = TYPE_LONG; sql.pos++;
|
||||
sql.sql[sql.pos] = (char *)&(data->import->tot_msgs); sql.type[sql.pos] = TYPE_LONG; sql.pos++;
|
||||
sql.sql[sql.pos] = (char *)&(data->import->table_id); sql.type[sql.pos] = TYPE_LONG; sql.pos++;
|
||||
|
||||
if(p_exec_stmt(sdata, &sql) == OK) ret = OK;
|
||||
|
||||
close_prepared_statement(&sql);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int get_folder_id(struct session_data *sdata, char *foldername, int parent_id){
|
||||
int id=ERR_FOLDER;
|
||||
struct sql sql;
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
int import_message(struct session_data *sdata, struct data *data, struct config *cfg);
|
||||
int update_import_table(struct session_data *sdata, struct data *data);
|
||||
|
||||
int import_from_maildir(struct session_data *sdata, struct data *data, char *directory, struct config *cfg);
|
||||
int import_from_mailbox(char *mailbox, struct session_data *sdata, struct data *data, struct config *cfg);
|
||||
|
@ -103,5 +103,9 @@ int import_from_maildir(struct session_data *sdata, struct data *data, char *dir
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
if(data->import->table_id > 0){
|
||||
update_import_table(sdata, data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ void usage(){
|
||||
printf(" -s <start position> Start importing POP3 emails from this position\n");
|
||||
printf(" -j <failed folder> Move failed to import emails to this folder\n");
|
||||
printf(" -a <recipient> Add recipient to the To:/Cc: list\n");
|
||||
printf(" -T <id> Update import table at id=<id>\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");
|
||||
@ -96,6 +97,7 @@ int main(int argc, char **argv){
|
||||
memset(import.filename, 0, SMALLBUFSIZE);
|
||||
import.mboxdir = NULL;
|
||||
import.tot_msgs = 0;
|
||||
import.table_id = 0;
|
||||
import.folder = NULL;
|
||||
|
||||
data.import = &import;
|
||||
@ -132,6 +134,7 @@ int main(int argc, char **argv){
|
||||
{"batch-limit", required_argument, 0, 'b' },
|
||||
{"timeout", required_argument, 0, 't' },
|
||||
{"start-position",required_argument, 0, 's' },
|
||||
{"table-id", required_argument, 0, 'T' },
|
||||
{"quiet", no_argument, 0, 'q' },
|
||||
{"recursive", required_argument, 0, 'R' },
|
||||
{"remove-after-import",no_argument, 0, 'r' },
|
||||
@ -145,9 +148,9 @@ int main(int argc, char **argv){
|
||||
|
||||
int option_index = 0;
|
||||
|
||||
int c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:DRroqh?", long_options, &option_index);
|
||||
int c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:T:DRroqh?", long_options, &option_index);
|
||||
#else
|
||||
int c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:DRroqh?");
|
||||
int c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:T:DRroqh?");
|
||||
#endif
|
||||
|
||||
if(c == -1) break;
|
||||
@ -257,6 +260,15 @@ int main(int argc, char **argv){
|
||||
data.import->extra_recipient = puf;
|
||||
break;
|
||||
|
||||
case 'T' :
|
||||
if(atoi(optarg) < 1){
|
||||
printf("invalid import table id: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
data.import->table_id = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'D' :
|
||||
data.import->dryrun = 1;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user