Diffstat (limited to 'kmicromail/libetpan/maildir/maildir.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libetpan/maildir/maildir.c | 25 |
1 files changed, 18 insertions, 7 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 | |||
@@ -99,43 +99,48 @@ void maildir_free(struct maildir * md) | |||
99 | free(md); | 99 | free(md); |
100 | } | 100 | } |
101 | 101 | ||
102 | #define MAX_TRY_ALLOC 32 | 102 | #define MAX_TRY_ALLOC 32 |
103 | 103 | ||
104 | static char * maildir_get_new_message_filename(struct maildir * md, | 104 | static char * maildir_get_new_message_filename(struct maildir * md, |
105 | char * tmpfile) | 105 | char * tmpfile) |
106 | { | 106 | { |
107 | char filename[PATH_MAX]; | 107 | char filename[PATH_MAX]; |
108 | char basename[PATH_MAX]; | 108 | char basename[PATH_MAX]; |
109 | int k; | 109 | int k; |
110 | time_t now; | 110 | time_t now; |
111 | 111 | struct stat f_stat; | |
112 | now = time(NULL); | 112 | now = time(NULL); |
113 | k = 0; | 113 | k = 0; |
114 | |||
115 | fprintf(stderr,"maildir_get_new_message_filename: %s \n", tmpfile); | ||
114 | while (k < MAX_TRY_ALLOC) { | 116 | while (k < MAX_TRY_ALLOC) { |
115 | snprintf(basename, sizeof(basename), "%lu.%u_%u.%s", | 117 | snprintf(basename, sizeof(basename), "%lu.%u_%u.%s", |
116 | (unsigned long) now, md->mdir_pid, md->mdir_counter, md->mdir_hostname); | 118 | (unsigned long) now, md->mdir_pid, md->mdir_counter, md->mdir_hostname); |
117 | snprintf(filename, sizeof(filename), "%s/tmp/%s", | 119 | snprintf(filename, sizeof(filename), "%s/tmp/%s", |
118 | md->mdir_path, basename); | 120 | md->mdir_path, basename); |
119 | 121 | fprintf(stderr,"filename %s \n", filename); | |
120 | if (link(tmpfile, filename) == 0) { | 122 | // LR changed following lines |
123 | if ( stat( filename, &f_stat ) == -1 ) { | ||
124 | //if (link(tmpfile, filename) == 0) { | ||
121 | char * dup_filename; | 125 | char * dup_filename; |
122 | 126 | ||
123 | dup_filename = strdup(filename); | 127 | dup_filename = strdup(filename); |
124 | if (dup_filename == NULL) { | 128 | if (dup_filename == NULL) { |
125 | unlink(filename); | 129 | //unlink(filename); |
126 | return NULL; | 130 | return NULL; |
127 | } | 131 | } |
128 | 132 | fprintf(stderr,"filename %s %s \n", tmpfile,dup_filename); | |
129 | unlink(tmpfile); | 133 | //unlink(tmpfile); |
134 | rename (tmpfile,dup_filename ); | ||
130 | md->mdir_counter ++; | 135 | md->mdir_counter ++; |
131 | 136 | ||
132 | return dup_filename; | 137 | return dup_filename; |
133 | } | 138 | } |
134 | 139 | ||
135 | md->mdir_counter ++; | 140 | md->mdir_counter ++; |
136 | k ++; | 141 | k ++; |
137 | } | 142 | } |
138 | 143 | ||
139 | return NULL; | 144 | return NULL; |
140 | } | 145 | } |
141 | 146 | ||
@@ -263,24 +268,25 @@ static void maildir_flush(struct maildir * md, int msg_new) | |||
263 | } | 268 | } |
264 | 269 | ||
265 | static int add_message(struct maildir * md, | 270 | static int add_message(struct maildir * md, |
266 | char * filename, int is_new) | 271 | char * filename, int is_new) |
267 | { | 272 | { |
268 | struct maildir_msg * msg; | 273 | struct maildir_msg * msg; |
269 | chashdatum key; | 274 | chashdatum key; |
270 | chashdatum value; | 275 | chashdatum value; |
271 | unsigned int i; | 276 | unsigned int i; |
272 | int res; | 277 | int res; |
273 | int r; | 278 | int r; |
274 | 279 | ||
280 | fprintf(stderr,"add_message filename: %s \n", filename); | ||
275 | msg = msg_new(filename, is_new); | 281 | msg = msg_new(filename, is_new); |
276 | if (msg == NULL) { | 282 | if (msg == NULL) { |
277 | res = MAILDIR_ERROR_MEMORY; | 283 | res = MAILDIR_ERROR_MEMORY; |
278 | goto err; | 284 | goto err; |
279 | } | 285 | } |
280 | 286 | ||
281 | r = carray_add(md->mdir_msg_list, msg, &i); | 287 | r = carray_add(md->mdir_msg_list, msg, &i); |
282 | if (r < 0) { | 288 | if (r < 0) { |
283 | res = MAILDIR_ERROR_MEMORY; | 289 | res = MAILDIR_ERROR_MEMORY; |
284 | goto free_msg; | 290 | goto free_msg; |
285 | } | 291 | } |
286 | 292 | ||
@@ -437,24 +443,25 @@ int maildir_message_add_uid(struct maildir * md, | |||
437 | char path_new[PATH_MAX]; | 443 | char path_new[PATH_MAX]; |
438 | char tmpname[PATH_MAX]; | 444 | char tmpname[PATH_MAX]; |
439 | int fd; | 445 | int fd; |
440 | int r; | 446 | int r; |
441 | char * mapping; | 447 | char * mapping; |
442 | char * delivery_tmp_name; | 448 | char * delivery_tmp_name; |
443 | char * delivery_tmp_basename; | 449 | char * delivery_tmp_basename; |
444 | char delivery_new_name[PATH_MAX]; | 450 | char delivery_new_name[PATH_MAX]; |
445 | char * delivery_new_basename; | 451 | char * delivery_new_basename; |
446 | int res; | 452 | int res; |
447 | struct stat stat_info; | 453 | struct stat stat_info; |
448 | 454 | ||
455 | fprintf(stderr,"maildir_message_add_uid for uid: %s \n", uid); | ||
449 | r = maildir_update(md); | 456 | r = maildir_update(md); |
450 | if (r != MAILDIR_NO_ERROR) { | 457 | if (r != MAILDIR_NO_ERROR) { |
451 | res = r; | 458 | res = r; |
452 | goto err; | 459 | goto err; |
453 | } | 460 | } |
454 | 461 | ||
455 | /* write to tmp/ with a classic temporary file */ | 462 | /* write to tmp/ with a classic temporary file */ |
456 | 463 | ||
457 | snprintf(tmpname, sizeof(tmpname), "%s/tmp/etpan-maildir-XXXXXX", | 464 | snprintf(tmpname, sizeof(tmpname), "%s/tmp/etpan-maildir-XXXXXX", |
458 | md->mdir_path); | 465 | md->mdir_path); |
459 | fd = mkstemp(tmpname); | 466 | fd = mkstemp(tmpname); |
460 | if (fd < 0) { | 467 | if (fd < 0) { |
@@ -549,54 +556,57 @@ int maildir_message_add(struct maildir * md, | |||
549 | { | 556 | { |
550 | return maildir_message_add_uid(md, message, size, | 557 | return maildir_message_add_uid(md, message, size, |
551 | NULL, 0); | 558 | NULL, 0); |
552 | } | 559 | } |
553 | 560 | ||
554 | int maildir_message_add_file_uid(struct maildir * md, int fd, | 561 | int maildir_message_add_file_uid(struct maildir * md, int fd, |
555 | char * uid, size_t max_uid_len) | 562 | char * uid, size_t max_uid_len) |
556 | { | 563 | { |
557 | char * message; | 564 | char * message; |
558 | struct stat buf; | 565 | struct stat buf; |
559 | int r; | 566 | int r; |
560 | 567 | ||
568 | fprintf(stderr,"maildir_message_add_file_uid: %s \n", uid); | ||
561 | if (fstat(fd, &buf) == -1) | 569 | if (fstat(fd, &buf) == -1) |
562 | return MAILDIR_ERROR_FILE; | 570 | return MAILDIR_ERROR_FILE; |
563 | 571 | ||
564 | message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | 572 | message = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
565 | if (message == MAP_FAILED) | 573 | if (message == MAP_FAILED) |
566 | return MAILDIR_ERROR_FILE; | 574 | return MAILDIR_ERROR_FILE; |
567 | 575 | ||
568 | r = maildir_message_add_uid(md, message, buf.st_size, uid, max_uid_len); | 576 | r = maildir_message_add_uid(md, message, buf.st_size, uid, max_uid_len); |
569 | 577 | ||
570 | munmap(message, buf.st_size); | 578 | munmap(message, buf.st_size); |
571 | 579 | ||
572 | return r; | 580 | return r; |
573 | } | 581 | } |
574 | 582 | ||
575 | int maildir_message_add_file(struct maildir * md, int fd) | 583 | int maildir_message_add_file(struct maildir * md, int fd) |
576 | { | 584 | { |
585 | fprintf(stderr,"maildir_message_add_file \n"); | ||
577 | return maildir_message_add_file_uid(md, fd, | 586 | return maildir_message_add_file_uid(md, fd, |
578 | NULL, 0); | 587 | NULL, 0); |
579 | } | 588 | } |
580 | 589 | ||
581 | char * maildir_message_get(struct maildir * md, const char * uid) | 590 | char * maildir_message_get(struct maildir * md, const char * uid) |
582 | { | 591 | { |
583 | chashdatum key; | 592 | chashdatum key; |
584 | chashdatum value; | 593 | chashdatum value; |
585 | char filename[PATH_MAX]; | 594 | char filename[PATH_MAX]; |
586 | char * dup_filename; | 595 | char * dup_filename; |
587 | struct maildir_msg * msg; | 596 | struct maildir_msg * msg; |
588 | char * dir; | 597 | char * dir; |
589 | int r; | 598 | int r; |
590 | 599 | ||
600 | fprintf(stderr,"maildir_message_get for uid: %s \n", uid); | ||
591 | key.data = (void *) uid; | 601 | key.data = (void *) uid; |
592 | key.len = strlen(uid); | 602 | key.len = strlen(uid); |
593 | r = chash_get(md->mdir_msg_hash, &key, &value); | 603 | r = chash_get(md->mdir_msg_hash, &key, &value); |
594 | if (r < 0) | 604 | if (r < 0) |
595 | return NULL; | 605 | return NULL; |
596 | 606 | ||
597 | msg = value.data; | 607 | msg = value.data; |
598 | if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) | 608 | if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) |
599 | dir = "new"; | 609 | dir = "new"; |
600 | else | 610 | else |
601 | dir = "cur"; | 611 | dir = "cur"; |
602 | 612 | ||
@@ -611,24 +621,25 @@ char * maildir_message_get(struct maildir * md, const char * uid) | |||
611 | } | 621 | } |
612 | 622 | ||
613 | int maildir_message_remove(struct maildir * md, const char * uid) | 623 | int maildir_message_remove(struct maildir * md, const char * uid) |
614 | { | 624 | { |
615 | chashdatum key; | 625 | chashdatum key; |
616 | chashdatum value; | 626 | chashdatum value; |
617 | char filename[PATH_MAX]; | 627 | char filename[PATH_MAX]; |
618 | struct maildir_msg * msg; | 628 | struct maildir_msg * msg; |
619 | char * dir; | 629 | char * dir; |
620 | int r; | 630 | int r; |
621 | int res; | 631 | int res; |
622 | 632 | ||
633 | fprintf(stderr,"maildir_message_remove for uid: %s \n", uid); | ||
623 | key.data = (void *) uid; | 634 | key.data = (void *) uid; |
624 | key.len = strlen(uid); | 635 | key.len = strlen(uid); |
625 | r = chash_get(md->mdir_msg_hash, &key, &value); | 636 | r = chash_get(md->mdir_msg_hash, &key, &value); |
626 | if (r < 0) { | 637 | if (r < 0) { |
627 | res = MAILDIR_ERROR_NOT_FOUND; | 638 | res = MAILDIR_ERROR_NOT_FOUND; |
628 | goto err; | 639 | goto err; |
629 | } | 640 | } |
630 | 641 | ||
631 | msg = value.data; | 642 | msg = value.data; |
632 | if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) | 643 | if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) |
633 | dir = "new"; | 644 | dir = "new"; |
634 | else | 645 | else |
@@ -653,25 +664,25 @@ int maildir_message_change_flags(struct maildir * md, | |||
653 | const char * uid, int new_flags) | 664 | const char * uid, int new_flags) |
654 | { | 665 | { |
655 | chashdatum key; | 666 | chashdatum key; |
656 | chashdatum value; | 667 | chashdatum value; |
657 | char filename[PATH_MAX]; | 668 | char filename[PATH_MAX]; |
658 | struct maildir_msg * msg; | 669 | struct maildir_msg * msg; |
659 | char * dir; | 670 | char * dir; |
660 | int r; | 671 | int r; |
661 | char new_filename[PATH_MAX]; | 672 | char new_filename[PATH_MAX]; |
662 | char flag_str[5]; | 673 | char flag_str[5]; |
663 | size_t i; | 674 | size_t i; |
664 | int res; | 675 | int res; |
665 | 676 | fprintf(stderr,"maildir_message_change_flags for uid: %s \n", uid); | |
666 | key.data = (void *) uid; | 677 | key.data = (void *) uid; |
667 | key.len = strlen(uid); | 678 | key.len = strlen(uid); |
668 | r = chash_get(md->mdir_msg_hash, &key, &value); | 679 | r = chash_get(md->mdir_msg_hash, &key, &value); |
669 | if (r < 0) { | 680 | if (r < 0) { |
670 | res = MAILDIR_ERROR_NOT_FOUND; | 681 | res = MAILDIR_ERROR_NOT_FOUND; |
671 | goto err; | 682 | goto err; |
672 | } | 683 | } |
673 | 684 | ||
674 | msg = value.data; | 685 | msg = value.data; |
675 | if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) | 686 | if ((msg->msg_flags & MAILDIR_FLAG_NEW) != 0) |
676 | dir = "new"; | 687 | dir = "new"; |
677 | else | 688 | else |