summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kmicromail/libetpan/mh/mailmh.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/kmicromail/libetpan/mh/mailmh.c b/kmicromail/libetpan/mh/mailmh.c
index 5e2b4cc..1087ce1 100644
--- a/kmicromail/libetpan/mh/mailmh.c
+++ b/kmicromail/libetpan/mh/mailmh.c
@@ -274,256 +274,261 @@ struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root,
else {
key.data = pathname;
key.len = strlen(pathname);
r = chash_get(root->fl_subfolders_hash, &key, &data);
if (r < 0)
return NULL;
return data.data;
}
}
int mailmh_folder_update(struct mailmh_folder * folder)
{
DIR * d;
struct dirent * ent;
struct stat buf;
char * mh_seq;
char filename[PATH_MAX];
int res;
int r;
uint32_t max_index;
#if 0
int add_folder;
#endif
unsigned int i;
if (stat(folder->fl_filename, &buf) == -1) {
res = MAILMH_ERROR_FOLDER;
goto err;
}
if (folder->fl_mtime == buf.st_mtime) {
res = MAILMH_NO_ERROR;
goto err;
}
folder->fl_mtime = buf.st_mtime;
d = opendir(folder->fl_filename);
if (d == NULL) {
res = MAILMH_ERROR_FOLDER;
goto err;
}
max_index = 0;
#if 0
if (folder->fl_subfolders_tab->len == 0)
add_folder = 1;
else
add_folder = 0;
#endif
/* clear the message list */
for(i = 0 ; i < carray_count(folder->fl_msgs_tab) ; i ++) {
struct mailmh_msg_info * msg_info;
chashdatum key;
msg_info = carray_get(folder->fl_msgs_tab, i);
if (msg_info == NULL)
continue;
#if 0
cinthash_remove(folder->fl_msgs_hash, msg_info->msg_index);
#endif
key.data = &msg_info->msg_index;
key.len = sizeof(msg_info->msg_index);
chash_delete(folder->fl_msgs_hash, &key, NULL);
mailmh_msg_info_free(msg_info);
}
carray_set_size(folder->fl_msgs_tab, 0);
do {
uint32_t index;
ent = readdir(d);
if (ent != NULL) {
snprintf(filename, PATH_MAX,
"%s%c%s", folder->fl_filename, MAIL_DIR_SEPARATOR, ent->d_name);
if (stat(filename, &buf) == -1)
continue;
if (S_ISREG(buf.st_mode)) {
index = strtoul(ent->d_name, NULL, 10);
if (index != 0) {
struct mailmh_msg_info * msg_info;
unsigned int array_index;
chashdatum key;
chashdatum data;
msg_info = mailmh_msg_info_new(index, buf.st_size, buf.st_mtime);
if (msg_info == NULL) {
res = MAILMH_ERROR_MEMORY;
goto closedir;
}
r = carray_add(folder->fl_msgs_tab, msg_info, &array_index);
if (r < 0) {
mailmh_msg_info_free(msg_info);
res = MAILMH_ERROR_MEMORY;
goto closedir;
}
msg_info->msg_array_index = array_index;
if (index > max_index)
max_index = index;
#if 0
r = cinthash_add(folder->fl_msgs_hash, msg_info->msg_index, msg_info);
#endif
key.data = &msg_info->msg_index;
key.len = sizeof(msg_info->msg_index);
data.data = msg_info;
data.len = 0;
r = chash_set(folder->fl_msgs_hash, &key, &data, NULL);
if (r < 0) {
carray_delete_fast(folder->fl_msgs_tab, msg_info->msg_array_index);
mailmh_msg_info_free(msg_info);
res = MAILMH_ERROR_MEMORY;
goto closedir;
}
+ //LR memory leak? added next line
+ //mailmh_msg_info_free(msg_info);
+ //it seems so that it should be freed later,
+ // but it is not in every case
+ //PENDING fixme in ompi somewhere
}
}
else if (S_ISDIR(buf.st_mode)) {
struct mailmh_folder * subfolder;
unsigned int array_index;
chashdatum key;
chashdatum data;
if (ent->d_name[0] == '.') {
if (ent->d_name[1] == 0)
continue;
if ((ent->d_name[1] == '.') && (ent->d_name[2] == 0))
continue;
}
key.data = ent->d_name;
key.len = strlen(ent->d_name);
r = chash_get(folder->fl_subfolders_hash, &key, &data);
if (r < 0) {
subfolder = mailmh_folder_new(folder, ent->d_name);
if (subfolder == NULL) {
res = MAILMH_ERROR_MEMORY;
goto closedir;
}
r = carray_add(folder->fl_subfolders_tab, subfolder, &array_index);
if (r < 0) {
mailmh_folder_free(subfolder);
res = MAILMH_ERROR_MEMORY;
goto closedir;
}
subfolder->fl_array_index = array_index;
key.data = subfolder->fl_filename;
key.len = strlen(subfolder->fl_filename);
data.data = subfolder;
data.len = 0;
r = chash_set(folder->fl_subfolders_hash, &key, &data, NULL);
if (r < 0) {
carray_delete_fast(folder->fl_subfolders_tab, subfolder->fl_array_index);
mailmh_folder_free(subfolder);
res = MAILMH_ERROR_MEMORY;
goto closedir;
}
}
}
}
}
while (ent != NULL);
folder->fl_max_index = max_index;
mh_seq = malloc(strlen(folder->fl_filename) + 2 + sizeof(".mh_sequences"));
if (mh_seq == NULL) {
res = MAILMH_ERROR_MEMORY;
goto closedir;
}
strcpy(mh_seq, folder->fl_filename);
strcat(mh_seq, MAIL_DIR_SEPARATOR_S);
strcat(mh_seq, ".mh_sequences");
if (stat(mh_seq, &buf) == -1) {
int fd;
fd = creat(mh_seq, S_IRUSR | S_IWUSR);
if (fd != -1)
close(fd);
}
free(mh_seq);
closedir(d);
return MAILMH_NO_ERROR;
closedir:
closedir(d);
err:
return res;
}
int mailmh_folder_add_subfolder(struct mailmh_folder * parent,
const char * name)
{
char * foldername;
int r;
struct mailmh_folder * folder;
unsigned int array_index;
chashdatum key;
chashdatum data;
foldername = malloc(strlen(parent->fl_filename) + strlen(name) + 2);
if (foldername == NULL)
return MAILMH_ERROR_MEMORY;
strcpy(foldername, parent->fl_filename);
strcat(foldername, MAIL_DIR_SEPARATOR_S);
strcat(foldername, name);
r = mkdir(foldername, 0700);
free(foldername);
if (r < 0)
return MAILMH_ERROR_FOLDER;
folder = mailmh_folder_new(parent, name);
if (folder == NULL)
return MAILMH_ERROR_MEMORY;
r = carray_add(parent->fl_subfolders_tab, folder, &array_index);
if (r < 0) {
mailmh_folder_free(folder);
return MAILMH_ERROR_MEMORY;
}
folder->fl_array_index = array_index;
key.data = folder->fl_filename;
key.len = strlen(folder->fl_filename);
data.data = folder;
data.len = 0;
r = chash_set(parent->fl_subfolders_hash, &key, &data, NULL);
if (r < 0) {
carray_delete_fast(folder->fl_subfolders_tab, folder->fl_array_index);
mailmh_folder_free(folder);
return MAILMH_ERROR_MEMORY;
}
return MAILMH_NO_ERROR;
}