# HG changeset patch # User Timo Sirainen # Date 1032227471 -10800 # Node ID 757c32a1920ddb4e04afb2158d077d4d421ede9c # Parent d0ba9a65891ce8c662c0c8116c9d13cea83793b8 expunging last message from mbox duplicated the whole file. appending mail to mbox works now too. diff -r d0ba9a65891c -r 757c32a1920d src/lib-index/mbox/mbox-from.c --- a/src/lib-index/mbox/mbox-from.c Tue Sep 17 04:49:45 2002 +0300 +++ b/src/lib-index/mbox/mbox-from.c Tue Sep 17 04:51:11 2002 +0300 @@ -1,6 +1,7 @@ /* Copyright (C) 2002 Timo Sirainen */ #include "lib.h" +#include "temp-string.h" #include "mbox-index.h" #include @@ -93,55 +94,54 @@ const char *mbox_from_create(const char *sender, time_t time) { + TempString *str; struct tm *tm; - char *ret, *p; - size_t len; int year; - len = strlen(sender); - ret = t_malloc(len + 24 + 1); - memcpy(ret, sender, len); + str = t_string_new(256); + t_string_append(str, "From "); + t_string_append(str, sender); + t_string_append(str, " "); /* we could use simply asctime(), but i18n etc. may break it. Example: "Thu Nov 29 22:33:52 2001" */ tm = localtime(&time); - p = ret + len; /* week day */ - strcpy(p, weekdays[tm->tm_wday]); p += 3; - *p++ = ' '; + t_string_append(str, weekdays[tm->tm_wday]); + t_string_append_c(str, ' '); /* month */ - strcpy(p, months[tm->tm_mon]); p += 3; - *p++ = ' '; + t_string_append(str, months[tm->tm_mon]); + t_string_append_c(str, ' '); /* day */ - *p++ = (tm->tm_mday / 10) + '0'; - *p++ = (tm->tm_mday % 10) + '0'; - *p++ = ' '; + t_string_append_c(str, (tm->tm_mday / 10) + '0'); + t_string_append_c(str, (tm->tm_mday % 10) + '0'); + t_string_append_c(str, ' '); /* hour */ - *p++ = (tm->tm_hour / 10) + '0'; - *p++ = (tm->tm_hour % 10) + '0'; - *p++ = ':'; + t_string_append_c(str, (tm->tm_hour / 10) + '0'); + t_string_append_c(str, (tm->tm_hour % 10) + '0'); + t_string_append_c(str, ':'); /* minute */ - *p++ = (tm->tm_min / 10) + '0'; - *p++ = (tm->tm_min % 10) + '0'; - *p++ = ':'; + t_string_append_c(str, (tm->tm_min / 10) + '0'); + t_string_append_c(str, (tm->tm_min % 10) + '0'); + t_string_append_c(str, ':'); /* second */ - *p++ = (tm->tm_sec / 10) + '0'; - *p++ = (tm->tm_sec % 10) + '0'; - *p++ = ' '; + t_string_append_c(str, (tm->tm_sec / 10) + '0'); + t_string_append_c(str, (tm->tm_sec % 10) + '0'); + t_string_append_c(str, ' '); /* year */ year = tm->tm_year + 1900; - *p++ = (year / 1000) + '0'; - *p++ = ((year / 100) % 10) + '0'; - *p++ = ((year / 10) % 10) + '0'; - *p++ = (year % 10) + '0'; + t_string_append_c(str, (year / 1000) + '0'); + t_string_append_c(str, ((year / 100) % 10) + '0'); + t_string_append_c(str, ((year / 10) % 10) + '0'); + t_string_append_c(str, (year % 10) + '0'); - *p++ = '\0'; - return ret; + t_string_append_c(str, '\n'); + return str->str; } diff -r d0ba9a65891c -r 757c32a1920d src/lib-storage/index/mbox/mbox-expunge.c --- a/src/lib-storage/index/mbox/mbox-expunge.c Tue Sep 17 04:49:45 2002 +0300 +++ b/src/lib-storage/index/mbox/mbox-expunge.c Tue Sep 17 04:51:11 2002 +0300 @@ -89,6 +89,8 @@ seq++; } + io_buffer_skip(inbuf, end_offset - inbuf->offset); + /* copy the rest as well, should be only \n but someone might as well just appended more data.. */ copy_size = inbuf->size - inbuf->offset; diff -r d0ba9a65891c -r 757c32a1920d src/lib-storage/index/mbox/mbox-save.c --- a/src/lib-storage/index/mbox/mbox-save.c Tue Sep 17 04:49:45 2002 +0300 +++ b/src/lib-storage/index/mbox/mbox-save.c Tue Sep 17 04:51:11 2002 +0300 @@ -34,14 +34,14 @@ return TRUE; do { - if (lseek(fd, 0, pos-1) < 0) + if (lseek(fd, pos-1, SEEK_SET) < 0) break; if (read(fd, &ch, 1) != 1) break; if (ch != '\n') { - if (write_full(fd, &ch, 1) < 0) + if (write_full(fd, "\n", 1) < 0) break; } @@ -52,6 +52,16 @@ return FALSE; } +static int mbox_append_lf(MailStorage *storage, int fd, const char *mbox_path) +{ + if (write_full(fd, "\n", 1) < 0) { + set_error(storage, mbox_path); + return FALSE; + } + + return TRUE; +} + static int write_from_line(MailStorage *storage, int fd, const char *mbox_path, time_t internal_date) { @@ -131,7 +141,8 @@ !write_from_line(box->storage, fd, mbox_path, internal_date) || !index_storage_save_into_fd(box->storage, fd, mbox_path, - data, data_size)) { + data, data_size) || + !mbox_append_lf(box->storage, fd, mbox_path)) { /* failed, truncate file back to original size */ (void)ftruncate(fd, pos); failed = TRUE;