diff --git a/src/imap.c b/src/imap.c index 59a7b772..3e343c97 100644 --- a/src/imap.c +++ b/src/imap.c @@ -395,9 +395,9 @@ void send_imap_close(int sd, int *seq, struct __data *data, int use_ssl){ } -int list_folders(int sd, int *seq, int use_ssl, struct __data *data){ +int list_folders(int sd, int *seq, int use_ssl, char *folder_name, struct __data *data){ char *p, *q, *r, *buf, *ruf, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], puf[MAXBUFSIZE]; - char attrs[SMALLBUFSIZE]; + char attrs[SMALLBUFSIZE], folder[SMALLBUFSIZE]; int len=MAXBUFSIZE+3, pos=0, n, rc=ERR, fldrlen=0, result; printf("List of IMAP folders:\n"); @@ -408,8 +408,10 @@ int list_folders(int sd, int *seq, int use_ssl, struct __data *data){ memset(buf, 0, len); snprintf(tag, sizeof(tag)-1, "A%d", *seq); snprintf(tagok, sizeof(tagok)-1, "A%d OK", (*seq)++); - //snprintf(puf, sizeof(puf)-1, "%s LIST \"\" %%\r\n", tag); - snprintf(puf, sizeof(puf)-1, "%s LIST \"\" \"*\"\r\n", tag); + if(folder_name == NULL) + snprintf(puf, sizeof(puf)-1, "%s LIST \"\" \"*\"\r\n", tag); + else + snprintf(puf, sizeof(puf)-1, "%s LIST \"%s\" \"*\"\r\n", tag, folder_name); write1(sd, puf, strlen(puf), use_ssl, data->ssl); @@ -484,24 +486,21 @@ int list_folders(int sd, int *seq, int use_ssl, struct __data *data){ r++; } - if(!strstr(attrs, "\\Noselect")){ - addnode(data->imapfolders, ruf); - } - else printf("skipping "); - - printf("=> '%s' {%d} [%s]\n", ruf, fldrlen, attrs); + snprintf(folder, sizeof(folder)-1, "%s", ruf); free(ruf); fldrlen = 0; } else { - if(!strstr(attrs, "\\Noselect")){ - addnode(data->imapfolders, q); - } - else printf("skipping "); - - printf("=> '%s [%s]'\n", q, attrs); + snprintf(folder, sizeof(folder)-1, "%s", q); } + if(!strstr(attrs, "\\Noselect")){ + addnode(data->imapfolders, folder); + } + else printf("skipping "); + + printf("=> '%s [%s]'\n", folder, attrs); + memset(attrs, 0, sizeof(attrs)); } diff --git a/src/import.h b/src/import.h index 9db5ba10..e52bfa24 100644 --- a/src/import.h +++ b/src/import.h @@ -21,7 +21,7 @@ int connect_to_pop3_server(int sd, char *username, char *password, struct __data int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, int use_ssl, int dryrun, struct __config *cfg); int connect_to_imap_server(int sd, int *seq, char *username, char *password, struct __data *data, int use_ssl); -int list_folders(int sd, int *seq, int use_ssl, struct __data *data); +int list_folders(int sd, int *seq, int use_ssl, char *folder_name, struct __data *data); int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sdata, struct __data *data, int use_ssl, int dryrun, struct __config *cfg); void send_imap_close(int sd, int *seq, struct __data *data, int use_ssl); diff --git a/src/import_imap.c b/src/import_imap.c index 3929f734..ef3b0988 100644 --- a/src/import_imap.c +++ b/src/import_imap.c @@ -64,18 +64,7 @@ int import_from_imap_server(char *server, char *username, char *password, int po } - /* - * if the user gives -f , then don't iterate through the folder list - * rather build the folderlist based on the option, 2014.10.14, SJ - */ - - if(folder_imap){ - addnode(data->imapfolders, folder_imap); - } else { - rc = list_folders(sd, &seq, use_ssl, data); - if(rc == ERR) goto ENDE_IMAP; - } - + if(list_folders(sd, &seq, use_ssl, folder_imap, data) == ERR) goto ENDE_IMAP; for(i=0;iimapfolders[i]; @@ -90,10 +79,6 @@ int import_from_imap_server(char *server, char *username, char *password, int po if(strstr(skiplist, puf)) skipmatch = 1; } - if(folder_imap && strstr(q->str, folder_imap) == NULL){ - skipmatch = 1; - } - if(skipmatch == 1){ if(data->quiet == 0) printf("SKIPPING FOLDER: %s\n", (char *)q->str); }