mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 01:31:58 +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 VERSION "1.2.0"
|
||||
|
||||
#define BUILD 954
|
||||
#define VERSION "1.3.0"
|
||||
#define BUILD 955
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
|
@ -284,6 +284,7 @@ struct memcached_server {
|
||||
struct import {
|
||||
char *extra_recipient;
|
||||
char *move_folder;
|
||||
char *failed_folder;
|
||||
int status;
|
||||
int total_messages;
|
||||
int processed_messages;
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
int import_message(char *filename, struct session_data *sdata, struct __data *data, struct __config *cfg){
|
||||
int rc=ERR;
|
||||
char *rule;
|
||||
char *rule, newpath[SMALLBUFSIZE];
|
||||
struct stat st;
|
||||
struct parser_state state;
|
||||
struct counters counters;
|
||||
@ -126,6 +126,11 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -609,11 +609,14 @@ void *get_in_addr(struct sockaddr *sa){
|
||||
}
|
||||
|
||||
|
||||
int can_i_write_current_directory(){
|
||||
int can_i_write_directory(char *dir){
|
||||
int fd;
|
||||
char filename[SMALLBUFSIZE];
|
||||
|
||||
snprintf(filename, sizeof(filename)-1, "__piler_%d", getpid());
|
||||
if(dir)
|
||||
snprintf(filename, sizeof(filename)-1, "%s/__piler_%d", dir, getpid());
|
||||
else
|
||||
snprintf(filename, sizeof(filename)-1, "__piler_%d", getpid());
|
||||
|
||||
fd = open(filename, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP);
|
||||
if(fd == -1){
|
||||
|
@ -44,7 +44,7 @@ void strtolower(char *s);
|
||||
|
||||
void *get_in_addr(struct sockaddr *sa);
|
||||
|
||||
int can_i_write_current_directory();
|
||||
int can_i_write_directory(char *dir);
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
char *strcasestr(const char *s, const char *find);
|
||||
|
@ -560,7 +560,7 @@ int main(int argc, char **argv){
|
||||
|
||||
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);
|
||||
|
||||
|
@ -53,6 +53,7 @@ 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(" -j <failed folder> Move failed to import emails to this folder\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");
|
||||
@ -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.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.download_only = 0;
|
||||
import.timeout = 30;
|
||||
@ -120,6 +121,7 @@ int main(int argc, char **argv){
|
||||
{"quiet", no_argument, 0, 'q' },
|
||||
{"recursive", required_argument, 0, 'R' },
|
||||
{"remove-after-import",no_argument, 0, 'r' },
|
||||
{"failed-folder", required_argument, 0, 'j' },
|
||||
{"move-folder", required_argument, 0, 'g' },
|
||||
{"only-download",no_argument, 0, 'o' },
|
||||
{"gui-import", no_argument, 0, 'G' },
|
||||
@ -130,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:j:GDRroqh?", 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:j:GDRroqh?");
|
||||
#endif
|
||||
|
||||
if(c == -1) break;
|
||||
@ -209,6 +211,10 @@ int main(int argc, char **argv){
|
||||
data.import->move_folder = optarg;
|
||||
break;
|
||||
|
||||
case 'j' :
|
||||
data.import->failed_folder = optarg;
|
||||
break;
|
||||
|
||||
case 'o' :
|
||||
data.import->download_only = 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(!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);
|
||||
|
||||
|
@ -211,7 +211,7 @@ int main(int argc, char **argv){
|
||||
|
||||
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);
|
||||
|
||||
|
@ -32,7 +32,7 @@ int main(int argc, char **argv){
|
||||
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){
|
||||
fprintf(stderr, "%s is not found\n", argv[1]);
|
||||
|
Loading…
Reference in New Issue
Block a user