diff --git a/src/config.h b/src/config.h index 6797e5bd..9524b0a9 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "1.2.0-master" -#define BUILD 924 +#define BUILD 925 #define HOSTID "mailarchiver" diff --git a/src/defs.h b/src/defs.h index 62d20209..e66742e8 100644 --- a/src/defs.h +++ b/src/defs.h @@ -283,6 +283,7 @@ struct memcached_server { struct import { char *extra_recipient; + char *move_folder; int status; int total_messages; int processed_messages; @@ -293,6 +294,7 @@ struct import { int download_only; int keep_eml; int timeout; + int cap_uidplus; long total_size; time_t started, updated, finished; }; diff --git a/src/imap.c b/src/imap.c index 22a4001d..47b666ad 100644 --- a/src/imap.c +++ b/src/imap.c @@ -261,13 +261,33 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda read_response(sd, buf, sizeof(buf), seq, data, use_ssl); } + + if(data->import->move_folder && data->import->cap_uidplus == 1 && dryrun == 0){ + + snprintf(tagok, sizeof(tagok)-1, "A%d OK", *seq); + tagoklen = strlen(tagok); + + snprintf(buf, sizeof(buf)-1, "A%d COPY %d %s\r\n", *seq, i, data->import->move_folder); + n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + read_response(sd, buf, sizeof(buf), seq, data, use_ssl); + + if(strncmp(buf, tagok, tagoklen) == 0){ + snprintf(buf, sizeof(buf)-1, "A%d STORE %d +FLAGS.SILENT (\\Deleted)\r\n", *seq, i); + n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); + read_response(sd, buf, sizeof(buf), seq, data, use_ssl); + + } + } + + + if(data->import->download_only == 0) unlink(filename); } } - if(data->import->remove_after_import == 1 && dryrun == 0){ + if((data->import->remove_after_import == 1 || data->import->move_folder) && dryrun == 0){ snprintf(buf, sizeof(buf)-1, "A%d EXPUNGE\r\n", *seq); n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); read_response(sd, buf, sizeof(buf), seq, data, use_ssl); @@ -286,6 +306,7 @@ int connect_to_imap_server(int sd, int *seq, char *username, char *password, int X509* server_cert; char *str; + data->import->cap_uidplus = 0; if(use_ssl == 1){ @@ -325,13 +346,6 @@ int connect_to_imap_server(int sd, int *seq, char *username, char *password, int n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); - /* imap cmd: CAPABILITY */ - - /*snprintf(buf, sizeof(buf)-1, "A%d CAPABILITY\r\n", *seq); - - write1(sd, buf, strlen(buf), use_ssl, data->ssl); - read_response(sd, buf, sizeof(buf), seq, data, use_ssl);*/ - /* imap cmd: LOGIN */ @@ -343,6 +357,22 @@ int connect_to_imap_server(int sd, int *seq, char *username, char *password, int return ERR; } + if(strstr(buf, "UIDPLUS")){ + data->import->cap_uidplus = 1; + } + else { + + /* run the CAPABILITY command if the reply doesn't contain the UIDPLUS capability */ + + snprintf(buf, sizeof(buf)-1, "A%d CAPABILITY\r\n", *seq); + + write1(sd, buf, strlen(buf), use_ssl, data->ssl); + read_response(sd, buf, sizeof(buf), seq, data, use_ssl); + + if(strstr(buf, "UIDPLUS")) data->import->cap_uidplus = 1; + } + + return OK; } diff --git a/src/pilerimport.c b/src/pilerimport.c index 51ca5e7f..fee372f3 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -484,6 +484,7 @@ void usage(){ printf(" -t Timeout in sec for imap/pop3 import\n"); printf(" -x Comma separated list of imap folders to skip. Add the trailing comma!\n"); printf(" -f IMAP folder name to import\n"); + printf(" -g Move email after import to this IMAP folder\n"); printf(" -F Piler folder name to assign to this import\n"); printf(" -b Import only this many emails\n"); printf(" -s Start importing POP3 emails from this position\n"); @@ -517,7 +518,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 = NULL; + import.extra_recipient = import.move_folder = NULL; import.start_position = 1; import.download_only = 0; import.timeout = 30; @@ -554,6 +555,7 @@ int main(int argc, char **argv){ {"quiet", no_argument, 0, 'q' }, {"recursive", required_argument, 0, 'R' }, {"remove-after-import",no_argument, 0, 'r' }, + {"move-folder", required_argument, 0, 'g' }, {"only-download",no_argument, 0, 'o' }, {"gui-import", no_argument, 0, 'G' }, {"dry-run", no_argument, 0, 'D' }, @@ -563,9 +565,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: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: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:GDRroqh?"); + c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:GDRroqh?"); #endif if(c == -1) break; @@ -638,6 +640,10 @@ int main(int argc, char **argv){ data.import->remove_after_import = 1; break; + case 'g' : + data.import->move_folder = optarg; + break; + case 'o' : data.import->download_only = 1; dryrun = 1;