summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libetpan/src/data-types/mailstream_helper.c11
-rw-r--r--libetpan/src/driver/implementation/pop3/pop3driver.c8
-rw-r--r--libetpan/src/low-level/imap/mailimap_parser.c22
-rw-r--r--libetpan/src/low-level/maildir/maildir.c17
-rw-r--r--libetpan/src/low-level/mh/mailmh.c3
-rw-r--r--libetpan/src/low-level/pop3/mailpop3.c7
6 files changed, 59 insertions, 9 deletions
diff --git a/libetpan/src/data-types/mailstream_helper.c b/libetpan/src/data-types/mailstream_helper.c
index 2f0b9ae..f0ddf51 100644
--- a/libetpan/src/data-types/mailstream_helper.c
+++ b/libetpan/src/data-types/mailstream_helper.c
@@ -77,50 +77,57 @@ char * mailstream_read_line_append(mailstream * stream, MMAPString * line)
if (stream == NULL)
return NULL;
do {
if (stream->read_buffer_len > 0) {
size_t i;
i = 0;
while (i < stream->read_buffer_len) {
if (stream->read_buffer[i] == '\n')
return mailstream_read_len_append(stream, line, i + 1);
i++;
}
if (mailstream_read_len_append(stream, line,
stream->read_buffer_len) == NULL)
return NULL;
}
else {
ssize_t r;
r = mailstream_feed_read_buffer(stream);
if (r == -1)
return NULL;
- if (r == 0)
- break;
+ if (r == 0) {
+ // LR
+ // this avoids a memory access violation later when trying
+ // to remove_trailing_eol from a null string
+ if ( line->len == 0 )
+ return NULL;
+ else
+ break;
+ }
}
}
while (1);
return line->str;
}
char * mailstream_read_line_remove_eol(mailstream * stream, MMAPString * line)
{
if (!mailstream_read_line(stream, line))
return NULL;
remove_trailing_eol(line);
return line->str;
}
int mailstream_is_end_multiline(const char * line)
{
if (line[0] != '.')
return FALSE;
if (line[1] != 0)
return FALSE;
return TRUE;
diff --git a/libetpan/src/driver/implementation/pop3/pop3driver.c b/libetpan/src/driver/implementation/pop3/pop3driver.c
index ea69923..6cc6a9a 100644
--- a/libetpan/src/driver/implementation/pop3/pop3driver.c
+++ b/libetpan/src/driver/implementation/pop3/pop3driver.c
@@ -228,71 +228,77 @@ static int pop3driver_parameters(mailsession * session,
{
struct pop3_session_state_data * data;
data = get_data(session);
switch (id) {
case POP3DRIVER_SET_AUTH_TYPE:
{
int * param;
param = value;
data->pop3_auth_type = * param;
return MAIL_NO_ERROR;
}
}
return MAIL_ERROR_INVAL;
}
static int pop3driver_login(mailsession * session,
char * userid, char * password)
{
int r;
+ //LR
+ int ret;
carray * msg_tab;
struct pop3_session_state_data * data;
data = get_data(session);
switch (data->pop3_auth_type) {
case POP3DRIVER_AUTH_TYPE_TRY_APOP:
r = mailpop3_login_apop(get_pop3_session(session), userid, password);
if (r != MAILPOP3_NO_ERROR)
r = mailpop3_login(get_pop3_session(session), userid, password);
break;
case POP3DRIVER_AUTH_TYPE_APOP:
r = mailpop3_login_apop(get_pop3_session(session), userid, password);
break;
default:
case POP3DRIVER_AUTH_TYPE_PLAIN:
r = mailpop3_login(get_pop3_session(session), userid, password);
break;
}
- mailpop3_list(get_pop3_session(session), &msg_tab);
+ // LR 2 lines
+ ret = pop3driver_pop3_error_to_mail_error(r);
+ if ( ret == MAIL_NO_ERROR )
+ mailpop3_list(get_pop3_session(session), &msg_tab);
+ // LR
return pop3driver_pop3_error_to_mail_error(r);
}
static int pop3driver_logout(mailsession * session)
{
int r;
r = mailpop3_quit(get_pop3_session(session));
return pop3driver_pop3_error_to_mail_error(r);
}
static int pop3driver_noop(mailsession * session)
{
int r;
r = mailpop3_noop(get_pop3_session(session));
return pop3driver_pop3_error_to_mail_error(r);
}
static int pop3driver_status_folder(mailsession * session, char * mb,
uint32_t * result_messages,
diff --git a/libetpan/src/low-level/imap/mailimap_parser.c b/libetpan/src/low-level/imap/mailimap_parser.c
index ab4db67..071891c 100644
--- a/libetpan/src/low-level/imap/mailimap_parser.c
+++ b/libetpan/src/low-level/imap/mailimap_parser.c
@@ -2378,50 +2378,68 @@ mailimap_body_fld_enc_parse(mailstream * fd, MMAPString * buffer,
struct mailimap_body_fld_enc ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
int type;
char * value;
struct mailimap_body_fld_enc * body_fld_enc;
int r;
int res;
cur_token = * index;
r = mailimap_body_fld_known_enc_parse(fd, buffer, &cur_token,
&type, progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR) {
value = NULL;
}
else if (r == MAILIMAP_ERROR_PARSE) {
type = MAILIMAP_BODY_FLD_ENC_OTHER;
r = mailimap_string_parse(fd, buffer, &cur_token, &value, NULL,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
- res = r;
- goto err;
+ // LR start
+ // accept NIL and set type to utf8
+ int ret = r;
+ r = mailimap_char_parse(fd, buffer, &cur_token, 'N');
+ if (r == MAILIMAP_NO_ERROR) {
+ r = mailimap_char_parse(fd, buffer, &cur_token, 'I');
+ if (r == MAILIMAP_NO_ERROR) {
+ r = mailimap_char_parse(fd, buffer, &cur_token, 'L');
+ if (r == MAILIMAP_NO_ERROR) {
+ type = 4;
+ ret = MAILIMAP_NO_ERROR;
+ value = NULL;
+ }
+ }
+ }
+ if ( ret != MAILIMAP_NO_ERROR ) {
+ res = ret;
+ goto err;
+ }
+ // LR end
}
}
else {
res = r;
goto err;
}
body_fld_enc = mailimap_body_fld_enc_new(type, value);
if (body_fld_enc == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto value_free;
}
* result = body_fld_enc;
* index = cur_token;
return MAILIMAP_NO_ERROR;
value_free:
if (value)
mailimap_string_free(value);
err:
return res;
}
diff --git a/libetpan/src/low-level/maildir/maildir.c b/libetpan/src/low-level/maildir/maildir.c
index 98b9f87..e81625d 100644
--- a/libetpan/src/low-level/maildir/maildir.c
+++ b/libetpan/src/low-level/maildir/maildir.c
@@ -89,86 +89,99 @@ struct maildir * maildir_new(const char * path)
err:
return NULL;
}
static void maildir_flush(struct maildir * md, int msg_new);
void maildir_free(struct maildir * md)
{
maildir_flush(md, 0);
maildir_flush(md, 1);
chash_free(md->mdir_msg_hash);
carray_free(md->mdir_msg_list);
free(md);
}
#define MAX_TRY_ALLOC 32
static char * maildir_get_new_message_filename(struct maildir * md,
char * tmpfile)
{
char filename[PATH_MAX];
char basename[PATH_MAX];
int k;
time_t now;
+ //LR
+ struct stat f_stat;
int got_file;
int r;
got_file = 0;
now = time(NULL);
k = 0;
while (k < MAX_TRY_ALLOC) {
snprintf(basename, sizeof(basename), "%lu.%u_%u.%s",
(unsigned long) now, md->mdir_pid, md->mdir_counter, md->mdir_hostname);
snprintf(filename, sizeof(filename), "%s/tmp/%s",
md->mdir_path, basename);
-
+
+ // LR changed following lines
+ if ( stat( filename, &f_stat ) == -1 ) {
+ char * dup_filename;
+
+ dup_filename = strdup(filename);
+ if (dup_filename == NULL) {
+ //unlink(filename);
+ return NULL;
+ }
+ rename (tmpfile,dup_filename );
+#if 0
if (link(tmpfile, filename) == 0) {
got_file = 1;
unlink(tmpfile);
}
else if (errno == EXDEV) {
unlink(tmpfile);
return NULL;
}
else if (errno == EPERM) {
r = rename(tmpfile, filename);
if (r < 0) {
unlink(tmpfile);
return NULL;
}
got_file = 1;
}
if (got_file) {
char * dup_filename;
dup_filename = strdup(filename);
if (dup_filename == NULL) {
unlink(filename);
return NULL;
}
-
+#endif
md->mdir_counter ++;
return dup_filename;
}
md->mdir_counter ++;
k ++;
}
return NULL;
}
static void msg_free(struct maildir_msg * msg)
{
free(msg->msg_uid);
free(msg->msg_filename);
free(msg);
}
/*
msg_new()
filename is given without path
diff --git a/libetpan/src/low-level/mh/mailmh.c b/libetpan/src/low-level/mh/mailmh.c
index 42cab9d..f8c694d 100644
--- a/libetpan/src/low-level/mh/mailmh.c
+++ b/libetpan/src/low-level/mh/mailmh.c
@@ -899,48 +899,51 @@ int mailmh_folder_remove_message(struct mailmh_folder * folder,
res = r;
goto err;
}
if (unlink(filename) == -1) {
res = MAILMH_ERROR_FILE;
goto free;
}
key.data = &index;
key.len = sizeof(index);
r = chash_get(folder->fl_msgs_hash, &key, &data);
#if 0
msg_info = cinthash_find(folder->fl_msgs_hash, index);
#endif
if (r == 0) {
msg_info = data.data;
carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index);
#if 0
cinthash_remove(folder->fl_msgs_hash, index);
#endif
chash_delete(folder->fl_msgs_hash, &key, NULL);
}
+ // LR memory leak fixed
+ mailmh_msg_info_free( msg_info );
+ free(filename);
return MAILMH_NO_ERROR;
free:
free(filename);
err:
return res;
}
int mailmh_folder_move_message(struct mailmh_folder * dest_folder,
struct mailmh_folder * src_folder,
uint32_t index)
{
int fd;
char * filename;
int r;
#if 0
r = mailmh_folder_update(dest_folder);
if (r != MAILMH_NO_ERROR)
return r;
r = mailmh_folder_update(src_folder);
if (r != MAILMH_NO_ERROR)
diff --git a/libetpan/src/low-level/pop3/mailpop3.c b/libetpan/src/low-level/pop3/mailpop3.c
index 6f77a3a..bca62d5 100644
--- a/libetpan/src/low-level/pop3/mailpop3.c
+++ b/libetpan/src/low-level/pop3/mailpop3.c
@@ -487,50 +487,53 @@ int mailpop3_user(mailpop3 * f, const char * user)
return MAILPOP3_NO_ERROR;
}
int mailpop3_pass(mailpop3 * f, const char * password)
{
char command[POP3_STRING_SIZE];
int r;
char * response;
if (f->pop3_state != POP3_STATE_AUTHORIZATION)
return MAILPOP3_ERROR_BAD_STATE;
/* send password command */
snprintf(command, POP3_STRING_SIZE, "PASS %s\r\n", password);
r = send_command(f, command);
if (r == -1)
return MAILPOP3_ERROR_STREAM;
response = read_line(f);
if (response == NULL)
return MAILPOP3_ERROR_STREAM;
r = parse_response(f, response);
- if (r != RESPONSE_OK)
- return MAILPOP3_ERROR_BAD_PASSWORD;
+ if (r != RESPONSE_OK) {
+ // LR
+ fprintf(stderr,"POP3 login error. Response from server:\n%s\n",response );
+ return MAILPOP3_ERROR_BAD_PASSWORD;
+ }
f->pop3_state = POP3_STATE_TRANSACTION;
return MAILPOP3_NO_ERROR;
}
static int read_list(mailpop3 * f, carray ** result);
static int read_uidl(mailpop3 * f, carray * msg_tab);
static int mailpop3_do_uidl(mailpop3 * f, carray * msg_tab)
{
char command[POP3_STRING_SIZE];
int r;
char * response;
if (f->pop3_state != POP3_STATE_TRANSACTION)
return MAILPOP3_ERROR_BAD_STATE;
/* send list command */