mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-26 08:40:12 +01:00
Resolved issue #791
Change-Id: Ie9477db7e13490e1b19594a8d9f8e56d215c8f1d Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
parent
850a84c260
commit
b8cfd4ffcb
@ -11,9 +11,8 @@
|
|||||||
|
|
||||||
#define PROGNAME "piler"
|
#define PROGNAME "piler"
|
||||||
|
|
||||||
#define VERSION "1.2.0"
|
#define VERSION "1.3.0"
|
||||||
|
#define BUILD 955
|
||||||
#define BUILD 954
|
|
||||||
|
|
||||||
#define HOSTID "mailarchiver"
|
#define HOSTID "mailarchiver"
|
||||||
|
|
||||||
|
@ -284,6 +284,7 @@ struct memcached_server {
|
|||||||
struct import {
|
struct import {
|
||||||
char *extra_recipient;
|
char *extra_recipient;
|
||||||
char *move_folder;
|
char *move_folder;
|
||||||
|
char *failed_folder;
|
||||||
int status;
|
int status;
|
||||||
int total_messages;
|
int total_messages;
|
||||||
int processed_messages;
|
int processed_messages;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
int import_message(char *filename, struct session_data *sdata, struct __data *data, struct __config *cfg){
|
int import_message(char *filename, struct session_data *sdata, struct __data *data, struct __config *cfg){
|
||||||
int rc=ERR;
|
int rc=ERR;
|
||||||
char *rule;
|
char *rule, newpath[SMALLBUFSIZE];
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct parser_state state;
|
struct parser_state state;
|
||||||
struct counters counters;
|
struct counters counters;
|
||||||
@ -126,6 +126,11 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(rc != OK && data->import->failed_folder){
|
||||||
|
snprintf(newpath, sizeof(newpath)-2, "%s/%s", data->import->failed_folder, filename);
|
||||||
|
rename(filename, newpath);
|
||||||
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,10 +609,13 @@ void *get_in_addr(struct sockaddr *sa){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int can_i_write_current_directory(){
|
int can_i_write_directory(char *dir){
|
||||||
int fd;
|
int fd;
|
||||||
char filename[SMALLBUFSIZE];
|
char filename[SMALLBUFSIZE];
|
||||||
|
|
||||||
|
if(dir)
|
||||||
|
snprintf(filename, sizeof(filename)-1, "%s/__piler_%d", dir, getpid());
|
||||||
|
else
|
||||||
snprintf(filename, sizeof(filename)-1, "__piler_%d", getpid());
|
snprintf(filename, sizeof(filename)-1, "__piler_%d", getpid());
|
||||||
|
|
||||||
fd = open(filename, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP);
|
fd = open(filename, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP);
|
||||||
|
@ -44,7 +44,7 @@ void strtolower(char *s);
|
|||||||
|
|
||||||
void *get_in_addr(struct sockaddr *sa);
|
void *get_in_addr(struct sockaddr *sa);
|
||||||
|
|
||||||
int can_i_write_current_directory();
|
int can_i_write_directory(char *dir);
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
char *strcasestr(const char *s, const char *find);
|
char *strcasestr(const char *s, const char *find);
|
||||||
|
@ -560,7 +560,7 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
regfree(®exp);
|
regfree(®exp);
|
||||||
|
|
||||||
if(!can_i_write_current_directory()) __fatal("cannot write current directory!");
|
if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!");
|
||||||
|
|
||||||
(void) openlog("pilerexport", LOG_PID, LOG_MAIL);
|
(void) openlog("pilerexport", LOG_PID, LOG_MAIL);
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ void usage(){
|
|||||||
printf(" -R Assign IMAP folder names as Piler folder names\n");
|
printf(" -R Assign IMAP folder names as Piler folder names\n");
|
||||||
printf(" -b <batch limit> Import only this many emails\n");
|
printf(" -b <batch limit> Import only this many emails\n");
|
||||||
printf(" -s <start position> Start importing POP3 emails from this position\n");
|
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(" -a <recipient> Add recipient to the To:/Cc: list\n");
|
||||||
printf(" -D Dry-run, do not import anything\n");
|
printf(" -D Dry-run, do not import anything\n");
|
||||||
printf(" -o Only download emails for POP3/IMAP import\n");
|
printf(" -o Only download emails for POP3/IMAP import\n");
|
||||||
@ -83,7 +84,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.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 = 0;
|
||||||
import.extra_recipient = import.move_folder = NULL;
|
import.extra_recipient = import.move_folder = import.failed_folder = NULL;
|
||||||
import.start_position = 1;
|
import.start_position = 1;
|
||||||
import.download_only = 0;
|
import.download_only = 0;
|
||||||
import.timeout = 30;
|
import.timeout = 30;
|
||||||
@ -120,6 +121,7 @@ int main(int argc, char **argv){
|
|||||||
{"quiet", no_argument, 0, 'q' },
|
{"quiet", no_argument, 0, 'q' },
|
||||||
{"recursive", required_argument, 0, 'R' },
|
{"recursive", required_argument, 0, 'R' },
|
||||||
{"remove-after-import",no_argument, 0, 'r' },
|
{"remove-after-import",no_argument, 0, 'r' },
|
||||||
|
{"failed-folder", required_argument, 0, 'j' },
|
||||||
{"move-folder", required_argument, 0, 'g' },
|
{"move-folder", required_argument, 0, 'g' },
|
||||||
{"only-download",no_argument, 0, 'o' },
|
{"only-download",no_argument, 0, 'o' },
|
||||||
{"gui-import", no_argument, 0, 'G' },
|
{"gui-import", no_argument, 0, 'G' },
|
||||||
@ -130,9 +132,9 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
int option_index = 0;
|
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:j:GDRroqh?", long_options, &option_index);
|
||||||
#else
|
#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:j:GDRroqh?");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(c == -1) break;
|
if(c == -1) break;
|
||||||
@ -209,6 +211,10 @@ int main(int argc, char **argv){
|
|||||||
data.import->move_folder = optarg;
|
data.import->move_folder = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'j' :
|
||||||
|
data.import->failed_folder = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'o' :
|
case 'o' :
|
||||||
data.import->download_only = 1;
|
data.import->download_only = 1;
|
||||||
dryrun = 1;
|
dryrun = 1;
|
||||||
@ -262,7 +268,12 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
if(!mbox[0] && !mboxdir && !emlfile && !directory && !imapserver && !pop3server && import_from_gui == 0) usage();
|
if(!mbox[0] && !mboxdir && !emlfile && !directory && !imapserver && !pop3server && import_from_gui == 0) usage();
|
||||||
|
|
||||||
if(!can_i_write_current_directory()) __fatal("cannot write current directory!");
|
if(data.import->failed_folder && !can_i_write_directory(data.import->failed_folder)){
|
||||||
|
printf("cannot write failed directory '%s'\n", data.import->failed_folder);
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!");
|
||||||
|
|
||||||
cfg = read_config(configfile);
|
cfg = read_config(configfile);
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
if(all == 0 && (from_id <= 0 || to_id <= 0) ) usage();
|
if(all == 0 && (from_id <= 0 || to_id <= 0) ) usage();
|
||||||
|
|
||||||
if(!can_i_write_current_directory()) __fatal("cannot write current directory!");
|
if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!");
|
||||||
|
|
||||||
(void) openlog("reindex", LOG_PID, LOG_MAIL);
|
(void) openlog("reindex", LOG_PID, LOG_MAIL);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ int main(int argc, char **argv){
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!can_i_write_current_directory()) __fatal("cannot write current directory!");
|
if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!");
|
||||||
|
|
||||||
if(stat(argv[1], &st) != 0){
|
if(stat(argv[1], &st) != 0){
|
||||||
fprintf(stderr, "%s is not found\n", argv[1]);
|
fprintf(stderr, "%s is not found\n", argv[1]);
|
||||||
|
Loading…
Reference in New Issue
Block a user