mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 07:10:12 +01:00
pilerimport may move imported messages to new folder
This commit is contained in:
parent
a3340e1291
commit
e3b95b1e99
@ -14,7 +14,7 @@
|
||||
|
||||
#define VERSION "1.2.0-master"
|
||||
|
||||
#define BUILD 924
|
||||
#define BUILD 925
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
46
src/imap.c
46
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;
|
||||
}
|
||||
|
||||
|
@ -484,6 +484,7 @@ void usage(){
|
||||
printf(" -t <timeout> Timeout in sec for imap/pop3 import\n");
|
||||
printf(" -x <folder1,folder2,....folderN,> Comma separated list of imap folders to skip. Add the trailing comma!\n");
|
||||
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(" -b <batch limit> Import only this many emails\n");
|
||||
printf(" -s <start position> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user