summaryrefslogtreecommitdiffabout
path: root/kmicromail/libetpan/mh/mailmh.c
Side-by-side diff
Diffstat (limited to 'kmicromail/libetpan/mh/mailmh.c') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/mh/mailmh.c12
1 files changed, 8 insertions, 4 deletions
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
@@ -562,114 +562,118 @@ int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder,
struct mailmh_folder * parent;
char * new_foldername;
parent = src_folder->fl_parent;
if (parent == NULL)
return MAILMH_ERROR_RENAME;
new_foldername = malloc(strlen(dst_folder->fl_filename) + 2 + strlen(new_name));
if (new_foldername == NULL)
return MAILMH_ERROR_MEMORY;
strcpy(new_foldername, dst_folder->fl_filename);
strcat(new_foldername, MAIL_DIR_SEPARATOR_S);
strcat(new_foldername, new_name);
r = rename(src_folder->fl_filename, new_foldername);
free(new_foldername);
if (r < 0)
return MAILMH_ERROR_RENAME;
r = mailmh_folder_remove_subfolder(src_folder);
if (r != MAILMH_NO_ERROR)
return r;
folder = mailmh_folder_new(dst_folder, new_name);
if (folder == NULL)
return MAILMH_ERROR_MEMORY;
r = carray_add(parent->fl_subfolders_tab, folder, NULL);
if (r < 0) {
mailmh_folder_free(folder);
return MAILMH_ERROR_MEMORY;
}
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;
}
k ++;
}
free(new_filename);
return MAILMH_ERROR_FOLDER;
}
int mailmh_folder_get_message_filename(struct mailmh_folder * folder,
uint32_t index, char ** result)
{
char * filename;
int len;
#if 0
r = mailmh_folder_update(folder);
if (r != MAILMH_NO_ERROR)
return r;
#endif
len = strlen(folder->fl_filename) + 20;
filename = malloc(len);
if (filename == NULL)
return MAILMH_ERROR_MEMORY;
snprintf(filename, len, "%s%c%lu", folder->fl_filename, MAIL_DIR_SEPARATOR,
(unsigned long) index);
* result = filename;
return MAILMH_NO_ERROR;;
}