mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 04:21:59 +01:00
imap fixes
This commit is contained in:
parent
850445a324
commit
537641afd9
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#define VERSION "0.1.25-rc3"
|
#define VERSION "0.1.25-rc3"
|
||||||
|
|
||||||
#define BUILD 880
|
#define BUILD 881
|
||||||
|
|
||||||
#define HOSTID "mailarchiver"
|
#define HOSTID "mailarchiver"
|
||||||
|
|
||||||
|
28
src/imap.c
28
src/imap.c
@ -87,7 +87,7 @@ END:
|
|||||||
|
|
||||||
|
|
||||||
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){
|
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){
|
||||||
int rc=ERR, i, n, messages=0, len, readlen, fd, nreads, readpos, finished, msglen, msg_written_len, tagoklen, tagbadlen;
|
int rc=ERR, i, n, messages=0, len, readlen, fd, nreads, readpos, finished, msglen, msg_written_len, tagoklen, tagbadlen, result;
|
||||||
char *p, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], tagbad[SMALLBUFSIZE], buf[MAXBUFSIZE], puf[MAXBUFSIZE], filename[SMALLBUFSIZE];
|
char *p, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], tagbad[SMALLBUFSIZE], buf[MAXBUFSIZE], puf[MAXBUFSIZE], filename[SMALLBUFSIZE];
|
||||||
|
|
||||||
/* imap cmd: SELECT */
|
/* imap cmd: SELECT */
|
||||||
@ -159,9 +159,12 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
|
|||||||
do {
|
do {
|
||||||
nreads++;
|
nreads++;
|
||||||
memset(puf, 0, sizeof(puf));
|
memset(puf, 0, sizeof(puf));
|
||||||
p = split(p, '\n', puf, sizeof(puf)-1);
|
p = split(p, '\n', puf, sizeof(puf)-1, &result);
|
||||||
len = strlen(puf);
|
len = strlen(puf);
|
||||||
|
|
||||||
|
if(result == 1){
|
||||||
|
// process a complete line
|
||||||
|
|
||||||
if(nreads == 1){
|
if(nreads == 1){
|
||||||
|
|
||||||
if(strcasestr(puf, " FETCH ")){
|
if(strcasestr(puf, " FETCH ")){
|
||||||
@ -171,7 +174,6 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
|
|||||||
finished = 1;
|
finished = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,15 +183,14 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
|
|||||||
unlink(filename);
|
unlink(filename);
|
||||||
return ERR;
|
return ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(len > 0){
|
if(len > 0 && msg_written_len < msglen){
|
||||||
if(msg_written_len < msglen){
|
|
||||||
write(fd, puf, len);
|
write(fd, puf, len);
|
||||||
write(fd, "\n", 1);
|
write(fd, "\n", 1);
|
||||||
msg_written_len += len + 1;
|
msg_written_len += len + 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(strncmp(puf, tagok, tagoklen) == 0){
|
if(strncmp(puf, tagok, tagoklen) == 0){
|
||||||
finished = 1;
|
finished = 1;
|
||||||
@ -202,8 +203,19 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// prepend the last incomplete line back to 'buf'
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf)-2, "%s", puf);
|
||||||
|
readpos = len;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
} while(p);
|
} while(p);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
readpos += n;
|
readpos += n;
|
||||||
@ -342,7 +354,7 @@ void close_connection(int sd, 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, struct __data *data){
|
||||||
char *p, *q, *r, *buf, *ruf, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], puf[MAXBUFSIZE];
|
char *p, *q, *r, *buf, *ruf, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], puf[MAXBUFSIZE];
|
||||||
int len=MAXBUFSIZE+3, pos=0, n, rc=ERR, fldrlen=0;
|
int len=MAXBUFSIZE+3, pos=0, n, rc=ERR, fldrlen=0, result;
|
||||||
|
|
||||||
printf("List of IMAP folders:\n");
|
printf("List of IMAP folders:\n");
|
||||||
|
|
||||||
@ -382,7 +394,7 @@ int list_folders(int sd, int *seq, int use_ssl, struct __data *data){
|
|||||||
p = buf;
|
p = buf;
|
||||||
do {
|
do {
|
||||||
memset(puf, 0, sizeof(puf));
|
memset(puf, 0, sizeof(puf));
|
||||||
p = split(p, '\n', puf, sizeof(puf)-1);
|
p = split(p, '\n', puf, sizeof(puf)-1, &result);
|
||||||
trimBuffer(puf);
|
trimBuffer(puf);
|
||||||
|
|
||||||
if(strncmp(puf, "* LIST ", 7) == 0 || fldrlen){
|
if(strncmp(puf, "* LIST ", 7) == 0 || fldrlen){
|
||||||
|
@ -146,7 +146,7 @@ int update_metadata_reference(struct session_data *sdata, struct _state *state,
|
|||||||
|
|
||||||
|
|
||||||
int store_meta_data(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg){
|
int store_meta_data(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg){
|
||||||
int rc, ret=ERR;
|
int rc, ret=ERR, result;
|
||||||
char *subj, *p, s[MAXBUFSIZE], s2[SMALLBUFSIZE], vcode[2*DIGEST_LENGTH+1], ref[2*DIGEST_LENGTH+1];
|
char *subj, *p, s[MAXBUFSIZE], s2[SMALLBUFSIZE], vcode[2*DIGEST_LENGTH+1], ref[2*DIGEST_LENGTH+1];
|
||||||
uint64 id=0;
|
uint64 id=0;
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ int store_meta_data(struct session_data *sdata, struct _state *state, struct __d
|
|||||||
p = state->b_from;
|
p = state->b_from;
|
||||||
do {
|
do {
|
||||||
memset(s2, 0, sizeof(s2));
|
memset(s2, 0, sizeof(s2));
|
||||||
p = split(p, ' ', s2, sizeof(s2)-1);
|
p = split(p, ' ', s2, sizeof(s2)-1, &result);
|
||||||
|
|
||||||
if(s2[0] == '\0') continue;
|
if(s2[0] == '\0') continue;
|
||||||
|
|
||||||
|
28
src/misc.c
28
src/misc.c
@ -112,23 +112,27 @@ void replaceCharacterInBuffer(char *p, char from, char to){
|
|||||||
* split a string by a character as delimiter
|
* split a string by a character as delimiter
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *split(char *row, int ch, char *s, int size){
|
char *split(char *str, int ch, char *buf, int buflen, int *result){
|
||||||
char *r;
|
char *p;
|
||||||
|
|
||||||
if(row == NULL || s == NULL)
|
*result = 0;
|
||||||
return NULL;
|
|
||||||
|
|
||||||
r = strchr(row, ch);
|
if(str == NULL || buf == NULL || buflen < 2) return NULL;
|
||||||
if(r) *r = '\0';
|
|
||||||
|
|
||||||
snprintf(s, size, "%s", row);
|
p = strchr(str, ch);
|
||||||
|
if(p){
|
||||||
if(r){
|
*p = '\0';
|
||||||
*r = ch;
|
|
||||||
r++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
snprintf(buf, buflen, "%s", str);
|
||||||
|
|
||||||
|
if(p){
|
||||||
|
*p = ch;
|
||||||
|
*result = 1;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ long tvdiff(struct timeval a, struct timeval b);
|
|||||||
int searchStringInBuffer(char *s, int len1, char *what, int len2);
|
int searchStringInBuffer(char *s, int len1, char *what, int len2);
|
||||||
int countCharacterInBuffer(char *p, char c);
|
int countCharacterInBuffer(char *p, char c);
|
||||||
void replaceCharacterInBuffer(char *p, char from, char to);
|
void replaceCharacterInBuffer(char *p, char from, char to);
|
||||||
char *split(char *row, int ch, char *s, int size);
|
char *split(char *str, int ch, char *buf, int buflen, int *result);
|
||||||
char *split_str(char *row, char *what, char *s, int size);
|
char *split_str(char *row, char *what, char *s, int size);
|
||||||
int trimBuffer(char *s);
|
int trimBuffer(char *s);
|
||||||
int extractEmail(char *rawmail, char *email);
|
int extractEmail(char *rawmail, char *email);
|
||||||
|
@ -173,7 +173,7 @@ void storno_attachment(struct _state *state){
|
|||||||
int parse_line(char *buf, struct _state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __data *data, struct __config *cfg){
|
int parse_line(char *buf, struct _state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __data *data, struct __config *cfg){
|
||||||
char *p, *q, puf[SMALLBUFSIZE];
|
char *p, *q, puf[SMALLBUFSIZE];
|
||||||
unsigned char b64buffer[MAXBUFSIZE];
|
unsigned char b64buffer[MAXBUFSIZE];
|
||||||
int n64, len, writelen, boundary_line=0;
|
int n64, len, writelen, boundary_line=0, result;
|
||||||
|
|
||||||
if(cfg->debug == 1) printf("line: %s", buf);
|
if(cfg->debug == 1) printf("line: %s", buf);
|
||||||
|
|
||||||
@ -635,7 +635,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
memset(puf, 0, sizeof(puf));
|
memset(puf, 0, sizeof(puf));
|
||||||
p = split(p, ' ', puf, sizeof(puf)-1);
|
p = split(p, ' ', puf, sizeof(puf)-1, &result);
|
||||||
|
|
||||||
if(puf[0] == '\0') continue;
|
if(puf[0] == '\0') continue;
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ ENDE:
|
|||||||
|
|
||||||
int remove_message_frame_files(char *s, char *update_meta_sql, struct session_data *sdata, struct __config *cfg){
|
int remove_message_frame_files(char *s, char *update_meta_sql, struct session_data *sdata, struct __config *cfg){
|
||||||
char *p, puf[SMALLBUFSIZE], filename[SMALLBUFSIZE];
|
char *p, puf[SMALLBUFSIZE], filename[SMALLBUFSIZE];
|
||||||
int n=0;
|
int n=0, result;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
p = s;
|
p = s;
|
||||||
do {
|
do {
|
||||||
p = split(p, ' ', puf, sizeof(puf)-1);
|
p = split(p, ' ', puf, sizeof(puf)-1, &result);
|
||||||
|
|
||||||
if(strlen(puf) == RND_STR_LEN){
|
if(strlen(puf) == RND_STR_LEN){
|
||||||
snprintf(filename, sizeof(filename)-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.m", cfg->queuedir, cfg->server_id, puf[8], puf[9], puf[10], puf[RND_STR_LEN-4], puf[RND_STR_LEN-3], puf[RND_STR_LEN-2], puf[RND_STR_LEN-1], puf);
|
snprintf(filename, sizeof(filename)-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.m", cfg->queuedir, cfg->server_id, puf[8], puf[9], puf[10], puf[RND_STR_LEN-4], puf[RND_STR_LEN-3], puf[RND_STR_LEN-2], puf[RND_STR_LEN-1], puf);
|
||||||
|
Loading…
Reference in New Issue
Block a user