author | zautrix <zautrix> | 2004-12-04 04:53:22 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-12-04 04:53:22 (UTC) |
commit | 7828f46413766ee5db72dc9bd457eac0868f0646 (patch) (side-by-side diff) | |
tree | d3da09120bdef2b498f836c5b1b97a5b2aa2da99 /kmicromail | |
parent | 967f7c879d06961dd7a25d019380c521f7a84792 (diff) | |
download | kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.zip kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.tar.gz kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.tar.bz2 |
fixed some bugs
-rw-r--r-- | kmicromail/libetpan/maildir/maildir.c | 25 | ||||
-rw-r--r-- | kmicromail/libetpan/mh/mailmh.c | 12 |
2 files changed, 26 insertions, 11 deletions
diff --git a/kmicromail/libetpan/maildir/maildir.c b/kmicromail/libetpan/maildir/maildir.c index 0e038b1..1ef0b7a 100644 --- a/kmicromail/libetpan/maildir/maildir.c +++ b/kmicromail/libetpan/maildir/maildir.c @@ -95,51 +95,56 @@ 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; - + struct stat f_stat; now = time(NULL); k = 0; + + fprintf(stderr,"maildir_get_new_message_filename: %s \n", tmpfile); 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); - - if (link(tmpfile, filename) == 0) { + fprintf(stderr,"filename %s \n", filename); + // LR changed following lines + if ( stat( filename, &f_stat ) == -1 ) { + //if (link(tmpfile, filename) == 0) { char * dup_filename; dup_filename = strdup(filename); if (dup_filename == NULL) { - unlink(filename); + //unlink(filename); return NULL; } - - unlink(tmpfile); + fprintf(stderr,"filename %s %s \n", tmpfile,dup_filename); + //unlink(tmpfile); + rename (tmpfile,dup_filename ); md->mdir_counter ++; return dup_filename; } md->mdir_counter ++; k ++; } return NULL; } static void msg_free(struct maildir_msg * msg) { free(msg->msg_uid); @@ -259,32 +264,33 @@ static void maildir_flush(struct maildir * md, int msg_new) else { i ++; } } } static int add_message(struct maildir * md, char * filename, int is_new) { struct maildir_msg * msg; chashdatum key; chashdatum value; unsigned int i; int res; int r; + fprintf(stderr,"add_message filename: %s \n", filename); msg = msg_new(filename, is_new); if (msg == NULL) { res = MAILDIR_ERROR_MEMORY; goto err; } r = carray_add(md->mdir_msg_list, msg, &i); if (r < 0) { res = MAILDIR_ERROR_MEMORY; goto free_msg; } key.data = msg->msg_uid; key.len = strlen(msg->msg_uid); value.data = msg; value.len = 0; @@ -433,32 +439,33 @@ static char * libetpan_basename(char * filename) int maildir_message_add_uid(struct maildir * md, const char * message, size_t size, char * uid, size_t max_uid_len) { char path_new[PATH_MAX]; char tmpname[PATH_MAX]; int fd; int r; char * mapping; char * delivery_tmp_name; char * delivery_tmp_basename; char delivery_new_name[PATH_MAX]; char * delivery_new_basename; int res; struct stat stat_info; + fprintf(stderr,"maildir_message_add_uid for uid: %s \n", uid); r = maildir_update(md); if (r != MAILDIR_NO_ERROR) { res = r; goto err; } /* write to tmp/ with a classic temporary file */ snprintf(tmpname, sizeof(tmpname), "%s/tmp/etpan-maildir-XXXXXX", md->mdir_path); fd = mkstemp(tmpname); if (fd < 0) { res = MAILDIR_ERROR_FILE; goto err; } @@ -545,94 +552,98 @@ int maildir_message_add_uid(struct maildir * md, } int maildir_message_add(struct maildir * md, const char * message, size_t size) { return maildir_message_add_uid(md, message, size, NULL, 0); } int maildir_message_add_file_uid(struct maildir * md, int fd, char * uid, size_t max_uid_len) { char * message; struct stat buf; int r; + fprintf(stderr,"maildir_message_add_file_uid: %s \n", uid); if (fstat(fd, &buf) == -1) return MAILDIR_ERROR_FILE; message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (message == MAP_FAILED) return MAILDIR_ERROR_FILE; r = maildir_message_add_uid(md, message, buf.st_size, uid, max_uid_len); munmap(message, buf.st_size); return r; } int maildir_message_add_file(struct maildir * md, int fd) { + fprintf(stderr,"maildir_message_add_file \n"); return maildir_message_add_file_uid(md, fd, NULL, 0); } char * maildir_message_get(struct maildir * md, const char * uid) { chashdatum key; chashdatum value; char filename[PATH_MAX]; char * dup_filename; struct maildir_msg * msg; char * dir; int r; + fprintf(stderr,"maildir_message_get for uid: %s \n", uid); key.data = (void *) uid; key.len = strlen(uid); r = chash_get(md->mdir_msg_hash, &key, &value); if (r < 0) return NULL; msg = value.data; if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) dir = "new"; else dir = "cur"; snprintf(filename, sizeof(filename), "%s/%s/%s", md->mdir_path, dir, msg->msg_filename); dup_filename = strdup(filename); if (dup_filename == NULL) return NULL; return dup_filename; } int maildir_message_remove(struct maildir * md, const char * uid) { chashdatum key; chashdatum value; char filename[PATH_MAX]; struct maildir_msg * msg; char * dir; int r; int res; + fprintf(stderr,"maildir_message_remove for uid: %s \n", uid); key.data = (void *) uid; key.len = strlen(uid); r = chash_get(md->mdir_msg_hash, &key, &value); if (r < 0) { res = MAILDIR_ERROR_NOT_FOUND; goto err; } msg = value.data; if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) dir = "new"; else dir = "cur"; snprintf(filename, sizeof(filename), "%s/%s/%s", md->mdir_path, dir, msg->msg_filename); @@ -649,33 +660,33 @@ int maildir_message_remove(struct maildir * md, const char * uid) return res; } int maildir_message_change_flags(struct maildir * md, const char * uid, int new_flags) { chashdatum key; chashdatum value; char filename[PATH_MAX]; struct maildir_msg * msg; char * dir; int r; char new_filename[PATH_MAX]; char flag_str[5]; size_t i; int res; - + fprintf(stderr,"maildir_message_change_flags for uid: %s \n", uid); key.data = (void *) uid; key.len = strlen(uid); r = chash_get(md->mdir_msg_hash, &key, &value); if (r < 0) { res = MAILDIR_ERROR_NOT_FOUND; goto err; } msg = value.data; if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) dir = "new"; else dir = "cur"; snprintf(filename, sizeof(filename), "%s/%s/%s", md->mdir_path, dir, msg->msg_filename); diff --git a/kmicromail/libetpan/mh/mailmh.c b/kmicromail/libetpan/mh/mailmh.c index 119f217..5e2b4cc 100644 --- a/kmicromail/libetpan/mh/mailmh.c +++ b/kmicromail/libetpan/mh/mailmh.c @@ -594,50 +594,54 @@ int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder, } return MAILMH_NO_ERROR; } #define MAX_TRY_ALLOC 32 /* initial file MUST be in the same directory */ static int mailmh_folder_alloc_msg(struct mailmh_folder * folder, char * filename, uint32_t * result) { uint32_t max; uint32_t k; char * new_filename; size_t len; + struct stat f_stat; len = strlen(folder->fl_filename) + 20; new_filename = malloc(len); if (new_filename == NULL) return MAILMH_ERROR_MEMORY; max = folder->fl_max_index + 1; + //fprintf(stderr,"mailmh_folder_alloc_msg filename: %s \n", filename); k = 0; while (k < MAX_TRY_ALLOC) { snprintf(new_filename, len, "%s%c%lu", folder->fl_filename, MAIL_DIR_SEPARATOR, (unsigned long) (max + k)); - - if (link(filename, new_filename) == 0) { + //fprintf(stderr,"mailmh_folder_alloc_msg new_filename: %s \n", new_filename); + if ( stat( new_filename, &f_stat ) == -1 ) { + // if (link(filename, new_filename) == 0) { int r; - + //fprintf(stderr,"filename found \n"); + //unlink(filename); + rename (filename,new_filename ); free(new_filename); - unlink(filename); if (k > MAX_TRY_ALLOC / 2) { r = mailmh_folder_update(folder); /* ignore errors */ } * result = max + k; folder->fl_max_index = max + k; return MAILMH_NO_ERROR; } else if (errno == EXDEV) { free(filename); return MAILMH_ERROR_FOLDER; } |