From cras@procontrol.fi  Wed Oct 23 03:00:31 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 03:00:31 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id AE44C2382D
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 03:00:31 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.336,1.337
Message-Id: <20021023000031.AE44C2382D@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 03:00:31 +0300 (EEST)
X-archive-position: 1
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv465

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.336
retrieving revision 1.337
diff -u -d -r1.336 -r1.337
--- ChangeLog	22 Oct 2002 23:45:28 -0000	1.336
+++ ChangeLog	23 Oct 2002 00:00:29 -0000	1.337
@@ -1,3 +1,7 @@
+2002-10-22 23:45  Timo Sirainen <tss@iki.fi>
+
+	* TODO: useless test commit
+
 2002-10-22 23:35  Timo Sirainen <tss@iki.fi>
 
 	* TODO: updated


From cras@procontrol.fi  Wed Oct 23 16:16:53 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 16:16:53 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 4527F2382C
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 16:16:53 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib compat.c,1.4,1.5 strfuncs.c,1.14,1.15
Message-Id: <20021023131653.4527F2382C@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 16:16:53 +0300 (EEST)
X-archive-position: 2
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv14470

Modified Files:
	compat.c strfuncs.c 
Log Message:
Check vsnprintf() return values more carefully, thanks to Thomas Wouters
<thomas@xs4all.net> for noticing.



Index: compat.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/compat.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- compat.c	13 Oct 2002 23:49:11 -0000	1.4
+++ compat.c	23 Oct 2002 13:16:50 -0000	1.5
@@ -104,7 +104,11 @@
 	char buf[1024];
 
 #ifdef HAVE_VSNPRINTF
-	vsnprintf(buf, sizeof(buf), format, args);
+	int ret;
+
+	ret = vsnprintf(buf, sizeof(buf), format, args);
+	if (ret < 0 || (size_t)ret >= sizeof(buf))
+		buf[sizeof(buf)-1] = '\0';
 	str = buf;
 #else
         va_list args2;

Index: strfuncs.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/strfuncs.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- strfuncs.c	20 Oct 2002 03:19:10 -0000	1.14
+++ strfuncs.c	23 Oct 2002 13:16:50 -0000	1.15
@@ -401,7 +401,7 @@
 	va_end(args);
 	t_pop();
 
-	if (ret < 0) {
+	if (ret < 0 || (size_t)ret >= max_chars) {
 		str[max_chars-1] = '\0';
 		ret = strlen(str);
 	}


From cras@procontrol.fi  Wed Oct 23 16:19:58 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 16:19:58 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 479502382C
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 16:19:58 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib strfuncs.c,1.15,1.16
Message-Id: <20021023131958.479502382C@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 16:19:58 +0300 (EEST)
X-archive-position: 3
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv14726

Modified Files:
	strfuncs.c 
Log Message:
Assert i_snprintf() string lengths to INT_MAX instead of SSIZE_T_MAX since
*printf()s returns int, not ssize_t..



Index: strfuncs.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/strfuncs.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- strfuncs.c	23 Oct 2002 13:16:50 -0000	1.15
+++ strfuncs.c	23 Oct 2002 13:19:56 -0000	1.16
@@ -392,7 +392,7 @@
 	int ret;
 
 	i_assert(str != NULL);
-	i_assert(max_chars < SSIZE_T_MAX);
+	i_assert(max_chars < INT_MAX);
 	i_assert(format != NULL);
 
 	t_push();
@@ -413,7 +413,7 @@
         int len;
 
 	i_assert(str != NULL);
-	i_assert(max_chars < SSIZE_T_MAX);
+	i_assert(max_chars < INT_MAX);
 	i_assert(format != NULL);
 
 	t_push();


From cras@procontrol.fi  Wed Oct 23 16:30:31 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 16:30:31 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id CDC6D2382C
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 16:30:31 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.337,1.338
Message-Id: <20021023133031.CDC6D2382C@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 16:30:31 +0300 (EEST)
X-archive-position: 4
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv14991

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.337
retrieving revision 1.338
diff -u -d -r1.337 -r1.338
--- ChangeLog	23 Oct 2002 00:00:29 -0000	1.337
+++ ChangeLog	23 Oct 2002 13:30:29 -0000	1.338
@@ -1,3 +1,14 @@
+2002-10-23 13:19  Timo Sirainen <tss@iki.fi>
+
+	* src/lib/strfuncs.c: Assert i_snprintf() string lengths to INT_MAX
+	instead of SSIZE_T_MAX since *printf()s returns int, not ssize_t..
+
+2002-10-23 13:16  Timo Sirainen <tss@iki.fi>
+
+	* src/lib/: compat.c, strfuncs.c: Check vsnprintf() return values
+	more carefully, thanks to Thomas Wouters <thomas@xs4all.net> for
+	noticing.
+
 2002-10-22 23:45  Timo Sirainen <tss@iki.fi>
 
 	* TODO: useless test commit


From tss@iki.fi  Wed Oct 23 16:31:58 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 16:31:58 +0300 (EEST)
Return-Path: <tss@iki.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from hurina (ip213-185-36-189.laajakaista.mtv3.fi [213.185.36.189])
	by danu.procontrol.fi (Postfix) with ESMTP id 92B3F2382C
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 16:31:58 +0300 (EEST)
Received: by hurina (Postfix, from userid 1000)
	id 0E0A05E01F42; Wed, 23 Oct 2002 16:31:58 +0300 (EEST)
Subject: [dovecot-cvs] Re: dovecot ChangeLog,1.337,1.338
From: Timo Sirainen <tss@iki.fi>
To: dovecot-cvs@procontrol.fi
In-Reply-To: <20021023133031.CDC6D2382C@danu.procontrol.fi>
References: <20021023133031.CDC6D2382C@danu.procontrol.fi>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Organization: 
Message-Id: <1035379917.28683.18.camel@hurina>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.1.1.99 (Preview Release)
Date: 23 Oct 2002 16:31:57 +0300
X-archive-position: 5
X-Approved-By: tss@iki.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: tss@iki.fi
Precedence: bulk
X-list: dovecot-cvs

On Wed, 2002-10-23 at 16:30, cras@procontrol.fi wrote:
> Update of /home/cvs/dovecot
> In directory danu:/tmp/cvs-serv14991
> 
> Modified Files:
> 	ChangeLog 
> Log Message:
> ChangeLog

..why is it doing these too.. even "dovecot/ChangeLog echo >/dev/null"
didn't seem to help..



From tss@iki.fi  Wed Oct 23 16:33:55 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 16:33:55 +0300 (EEST)
Return-Path: <tss@iki.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from hurina (ip213-185-36-189.laajakaista.mtv3.fi [213.185.36.189])
	by danu.procontrol.fi (Postfix) with ESMTP id 90C4F2382C
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 16:33:55 +0300 (EEST)
Received: by hurina (Postfix, from userid 1000)
	id 6254D5E01F42; Wed, 23 Oct 2002 16:33:55 +0300 (EEST)
Subject: [dovecot-cvs] Re: dovecot ChangeLog,1.337,1.338
From: Timo Sirainen <tss@iki.fi>
To: dovecot-cvs@procontrol.fi
In-Reply-To: <1035379917.28683.18.camel@hurina>
References: <20021023133031.CDC6D2382C@danu.procontrol.fi>
	 <1035379917.28683.18.camel@hurina>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Organization: 
Message-Id: <1035380035.28683.20.camel@hurina>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.1.1.99 (Preview Release)
Date: 23 Oct 2002 16:33:55 +0300
X-archive-position: 6
X-Approved-By: tss@iki.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: tss@iki.fi
Precedence: bulk
X-list: dovecot-cvs

On Wed, 2002-10-23 at 16:31, Timo Sirainen wrote:
> ..why is it doing these too.. even "dovecot/ChangeLog echo >/dev/null"
> didn't seem to help..

Of course it might have helped if I had committed that change :) Well,
maybe now (and why did that last message come twice..)


From cras@procontrol.fi  Wed Oct 23 20:02:44 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 20:02:44 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 97AAA2382D
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 20:02:44 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index/mbox mbox-rewrite.c,1.29,1.30
Message-Id: <20021023170244.97AAA2382D@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 20:02:44 +0300 (EEST)
X-archive-position: 7
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index/mbox
In directory danu:/tmp/cvs-serv19820

Modified Files:
	mbox-rewrite.c 
Log Message:
input buffer limit wasn't reset in error conditions.



Index: mbox-rewrite.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-rewrite.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- mbox-rewrite.c	19 Oct 2002 16:40:17 -0000	1.29
+++ mbox-rewrite.c	23 Oct 2002 17:02:42 -0000	1.30
@@ -53,6 +53,7 @@
 		      uoff_t end_offset)
 {
 	uoff_t old_limit;
+	int failed;
 
 	i_assert(inbuf->v_offset <= end_offset);
 
@@ -61,16 +62,18 @@
 	if (o_buffer_send_ibuffer(outbuf, inbuf) < 0) {
 		index_set_error(index, "Error rewriting mbox file %s: %s",
 				index->mbox_path, strerror(outbuf->buf_errno));
+		failed = TRUE;
 	} else if (inbuf->v_offset < end_offset) {
 		/* fsck should have noticed it.. */
 		index_set_error(index, "Error rewriting mbox file %s: "
 				"Unexpected end of file", index->mbox_path);
+		failed = TRUE;
 	} else {
-		return TRUE;
+		failed = FALSE;
 	}
 
 	i_buffer_set_read_limit(inbuf, old_limit);
-	return FALSE;
+	return !failed;
 }
 
 static int mbox_write_ximapbase(MboxRewriteContext *ctx)
@@ -526,8 +529,11 @@
 		failed = TRUE;
 	}
 
-	/* always end with a \n */
-	(void)o_buffer_send(outbuf, "\n", 1);
+	if (!failed) {
+		/* always end with a \n */
+		(void)o_buffer_send(outbuf, "\n", 1);
+	}
+
 	if (outbuf->closed) {
 		errno = outbuf->buf_errno;
 		mbox_set_syscall_error(index, "write()");


From cras@procontrol.fi  Wed Oct 23 20:03:41 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 20:03:41 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 954D32382D
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 20:03:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index mail-modifylog.c,1.28,1.29 mail-modifylog.h,1.4,1.5
Message-Id: <20021023170341.954D32382D@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 20:03:41 +0300 (EEST)
X-archive-position: 8
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv19843/lib-index

Modified Files:
	mail-modifylog.c mail-modifylog.h 
Log Message:
Modify log was pretty much broken whenever it was switched.



Index: mail-modifylog.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- mail-modifylog.c	21 Oct 2002 01:56:20 -0000	1.28
+++ mail-modifylog.c	23 Oct 2002 17:03:39 -0000	1.29
@@ -9,21 +9,30 @@
 #include "mail-index-util.h"
 #include "mail-modifylog.h"
 
+#include <stddef.h>
 #include <stdlib.h>
 #include <fcntl.h>
 
 /* Maximum size for modify log (isn't exact) */
 #define MAX_MODIFYLOG_SIZE (4096*8)
 
+/* How large chunks to use to grow log file */
[...1503 lines suppressed...]
 	}
+
+	return expunges;
+}
+
+unsigned int mail_modifylog_get_expunge_count(MailModifyLog *log)
+{
+	unsigned int expunges;
+
+	i_assert(log->index->lock_type != MAIL_LOCK_UNLOCK);
+
+	if (!mmap_update_both(log))
+		return 0;
+
+	expunges = modifylog_file_get_expunge_count(log->tail);
+	if (log->tail != log->head)
+		expunges += modifylog_file_get_expunge_count(log->head);
 
 	return expunges;
 }

Index: mail-modifylog.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mail-modifylog.h	19 Oct 2002 23:09:56 -0000	1.4
+++ mail-modifylog.h	23 Oct 2002 17:03:39 -0000	1.5
@@ -28,7 +28,7 @@
 
 /* for mail_modifylog_*_get_expunges() */
 struct _ModifyLogExpunge {
-	unsigned int uid1, uid2;
+	unsigned int uid1, uid2; /* NOTE: may be outside wanted range */
 	unsigned int seq_count;
 };
 
@@ -52,9 +52,13 @@
 /* Must be called when exclusive lock is dropped from index. */
 void mail_modifylog_notify_lock_drop(MailModifyLog *log);
 
-/* Returns the nonsynced log entries. count is set to number of log records. */
-ModifyLogRecord *mail_modifylog_get_nonsynced(MailModifyLog *log,
-					      unsigned int *count);
+/* Updates arr and count parameters to list nonsynced log entries.
+   Returns TRUE if successful. */
+int mail_modifylog_get_nonsynced(MailModifyLog *log,
+				 const ModifyLogRecord **arr1,
+				 unsigned int *count1,
+				 const ModifyLogRecord **arr2,
+				 unsigned int *count2);
 
 /* Marks the modify log as being synced with in-memory state. */
 int mail_modifylog_mark_synced(MailModifyLog *log);
@@ -63,16 +67,26 @@
    expunged messages before the range. Returns 0,0 terminated list of
    expunged UIDs, or NULL if error occured.
 
-   Note that the first and last returned records may contain more than the
-   wanted sequences, and expunges_before doesn't include those unwanted
-   expunges in the first record. */
+   Note that returned UID range may not be exact for first returned
+   expunge record. For example fetching range 9:10 may return
+   expunges_before=8, {uid1=1, uid2=9, seq_count=1} if only message 10
+   exists.
+
+   Also the last expunge record's both uid and seq_count ranges may go
+   past last_seq */
 const ModifyLogExpunge *
 mail_modifylog_seq_get_expunges(MailModifyLog *log,
 				unsigned int first_seq,
 				unsigned int last_seq,
 				unsigned int *expunges_before);
 
-/* Like above, but for given UID range. */
+/* Like above, but for given UID range. expunges_before is treated a bit
+   differently however. It specifies the number of messages deleted before
+   the first returned expunge-record, which may partially be before our
+   wanted range. For example fetching range 9:10 may return
+   expunges_before=0, {uid1=1, uid2=9, seq_count=9} if only message 10
+   exists. This is because we have no idea how many messages there are
+   between UIDs since they're not guaranteed to be contiguous. */
 const ModifyLogExpunge *
 mail_modifylog_uid_get_expunges(MailModifyLog *log,
 				unsigned int first_uid,


From cras@procontrol.fi  Wed Oct 23 20:03:41 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 20:03:41 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id A561923837
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 20:03:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-storage/index index-messageset.c,1.6,1.7 index-sync.c,1.14,1.15
Message-Id: <20021023170341.A561923837@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 20:03:41 +0300 (EEST)
X-archive-position: 9
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-storage/index
In directory danu:/tmp/cvs-serv19843/lib-storage/index

Modified Files:
	index-messageset.c index-sync.c 
Log Message:
Modify log was pretty much broken whenever it was switched.



Index: index-messageset.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-messageset.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- index-messageset.c	19 Oct 2002 23:09:56 -0000	1.6
+++ index-messageset.c	23 Oct 2002 17:03:39 -0000	1.7
@@ -46,6 +46,9 @@
 	   can be used to calculate the current real sequence position */
 	expunges = mail_modifylog_seq_get_expunges(index->modifylog, seq, seq2,
 						   &expunges_before);
+	if (expunges == NULL)
+		return -1;
+
 	i_assert(expunges_before < seq);
 	expunges_found = expunges->uid1 != 0;
 
@@ -196,6 +199,9 @@
 	/* get list of expunged messages in our range. */
 	expunges = mail_modifylog_uid_get_expunges(index->modifylog, uid, uid2,
 						   &expunges_before);
+	if (expunges == NULL)
+		return -1;
+
 	expunges_found = expunges->uid1 != 0;
 
 	rec = index->lookup_uid_range(index, uid, uid2, &idx_seq);

Index: index-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-sync.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- index-sync.c	19 Oct 2002 23:33:56 -0000	1.14
+++ index-sync.c	23 Oct 2002 17:03:39 -0000	1.15
@@ -67,18 +67,18 @@
 
 int index_storage_sync_modifylog(IndexMailbox *ibox, int hide_deleted)
 {
-	const ModifyLogRecord *log;
+	const ModifyLogRecord *log1, *log2, *log, *first_flag_log;
 	MailIndexRecord *rec;
 	MailFlags flags;
         MailboxSyncCallbacks *sc;
 	void *sc_context;
 	const char **custom_flags;
-	unsigned int count, seq, seq_count, i, messages;
+	unsigned int count1, count2, total_count, seq, seq_count, i, messages;
 	unsigned int first_flag_change, first_flag_messages_count;
 
 	/* show the log */
-	log = mail_modifylog_get_nonsynced(ibox->index->modifylog, &count);
-	if (log == NULL)
+	if (!mail_modifylog_get_nonsynced(ibox->index->modifylog,
+					  &log1, &count1, &log2, &count2))
 		return mail_storage_set_index_error(ibox);
 
 	sc = &ibox->sync_callbacks;
@@ -86,28 +86,35 @@
 
 	/* first show expunges. this makes it easier to deal with sequence
 	   numbers. */
+	total_count = count1 + count2;
 	messages = ibox->synced_messages_count;
-	first_flag_change = count;
+	first_flag_change = total_count;
+	first_flag_log = NULL;
         first_flag_messages_count = 0;
-	for (i = 0; i < count; i++) {
-		if (log[i].seq1 > messages) {
+
+	for (i = 0, log = log1; i < total_count; i++, log++) {
+		if (i == count1)
+			log = log2;
+
+		if (log->seq1 > messages) {
 			/* client doesn't know about this message yet */
 			continue;
 		}
 
-		switch (log[i].type) {
+		switch (log->type) {
 		case RECORD_TYPE_EXPUNGE:
-			seq_count = (log[i].seq2 - log[i].seq1) + 1;
+			seq_count = (log->seq2 - log->seq1) + 1;
 			messages -= seq_count;
 
 			for (; seq_count > 0; seq_count--) {
-				sc->expunge(&ibox->box, log[i].seq1,
+				sc->expunge(&ibox->box, log->seq1,
 					    sc_context);
 			}
 			break;
 		case RECORD_TYPE_FLAGS_CHANGED:
-			if (first_flag_change == count) {
+			if (first_flag_change == total_count) {
 				first_flag_change = i;
+				first_flag_log = log;
 				first_flag_messages_count = messages;
 			}
 			break;
@@ -120,21 +127,26 @@
 	/* now show the flags */
 	messages = first_flag_messages_count;
 	custom_flags = mail_custom_flags_list_get(ibox->index->custom_flags);
-	for (i = first_flag_change; i < count; i++) {
-		if (log[i].seq1 > messages) {
+
+	log = first_flag_log;
+	for (i = first_flag_change; i < total_count; i++, log++) {
+		if (i == count1)
+			log = log2;
+
+		if (log->seq1 > messages) {
 			/* client doesn't know about this message yet */
 			continue;
 		}
 
-		switch (log[i].type) {
+		switch (log->type) {
 		case RECORD_TYPE_EXPUNGE:
-			messages -= (log[i].seq2 - log[i].seq1) + 1;
+			messages -= (log->seq2 - log->seq1) + 1;
 			break;
 		case RECORD_TYPE_FLAGS_CHANGED:
 			rec = ibox->index->lookup_uid_range(ibox->index,
-							    log[i].uid1,
-							    log[i].uid2, &seq);
-			while (rec != NULL && rec->uid <= log[i].uid2) {
+							    log->uid1,
+							    log->uid2, &seq);
+			while (rec != NULL && rec->uid <= log->uid2) {
 				flags = rec->msg_flags;
 				if (rec->uid >= ibox->index->first_recent_uid)
 					flags |= MAIL_RECENT;


From cras@procontrol.fi  Wed Oct 23 20:15:29 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 20:15:29 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id B462F2382D
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 20:15:29 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.338,1.339
Message-Id: <20021023171529.B462F2382D@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 20:15:29 +0300 (EEST)
X-archive-position: 10
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv20187

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.338
retrieving revision 1.339
diff -u -d -r1.338 -r1.339
--- ChangeLog	23 Oct 2002 13:30:29 -0000	1.338
+++ ChangeLog	23 Oct 2002 17:15:27 -0000	1.339
@@ -1,3 +1,15 @@
+2002-10-23 17:03  Timo Sirainen <tss@iki.fi>
+
+	* src/: lib-index/mail-modifylog.c, lib-index/mail-modifylog.h,
+	lib-storage/index/index-messageset.c,
+	lib-storage/index/index-sync.c: Modify log was pretty much broken
+	whenever it was switched.
+
+2002-10-23 17:02  Timo Sirainen <tss@iki.fi>
+
+	* src/lib-index/mbox/mbox-rewrite.c: input buffer limit wasn't
+	reset in error conditions.
+
 2002-10-23 13:19  Timo Sirainen <tss@iki.fi>
 
 	* src/lib/strfuncs.c: Assert i_snprintf() string lengths to INT_MAX


From cras@procontrol.fi  Wed Oct 23 20:15:38 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 20:15:38 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 5CFAC2382D
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 20:15:38 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index mail-modifylog.c,1.29,1.30
Message-Id: <20021023171538.5CFAC2382D@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 20:15:38 +0300 (EEST)
X-archive-position: 11
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv20110/lib-index

Modified Files:
	mail-modifylog.c 
Log Message:
if we're only process accessing modify log when it gets full, we can just
truncate it instead of switching.



Index: mail-modifylog.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- mail-modifylog.c	23 Oct 2002 17:03:39 -0000	1.29
+++ mail-modifylog.c	23 Oct 2002 17:15:36 -0000	1.30
@@ -853,20 +853,26 @@
 	return TRUE;
 }
 
-static void mail_modifylog_try_truncate(ModifyLogFile *file)
+static int mail_modifylog_try_truncate(ModifyLogFile *file)
 {
 	if (modifylog_have_other_users(file->log, TRUE) != 0)
-		return;
+		return FALSE;
 
+	file->header->sync_id = 0;
 	file->header->used_file_size = sizeof(ModifyLogHeader);
 
 	if (msync(file->mmap_base, sizeof(ModifyLogHeader), MS_SYNC) < 0) {
 		modifylog_set_syscall_error(file, "msync()");
-		return;
+		return FALSE;
 	}
 
+	file->synced_id = 0;
+	file->synced_position = sizeof(ModifyLogHeader);
+
 	if (file_set_size(file->fd, MODIFY_LOG_INITIAL_SIZE) < 0)
 		modifylog_set_syscall_error(file, "file_set_size()");
+
+	return TRUE;
 }
 
 /* switches to active modify log, updating our sync mark to end of it */
@@ -874,7 +880,7 @@
 {
 	ModifyLogFile *file;
 
-	mail_modifylog_try_truncate(log->tail);
+	(void)mail_modifylog_try_truncate(log->tail);
 
 	file = log->tail == &log->file1 ? &log->file2 : &log->file1;
 	if (file->fd == -1) {
@@ -897,6 +903,12 @@
 
 	if (log->head->anon_mmap)
 		return TRUE;
+
+	if (mail_modifylog_try_truncate(log->tail)) {
+		/* no need to switch, we're the only user and we just
+		   truncated it  */
+		return TRUE;
+	}
 
 	file = log->head == &log->file1 ? &log->file2 : &log->file1;
 	if (modifylog_reuse_or_create_file(file) != 1) {


From cras@procontrol.fi  Wed Oct 23 20:30:29 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 20:30:29 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 8321B2382C
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 20:30:29 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.339,1.340
Message-Id: <20021023173029.8321B2382C@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 20:30:29 +0300 (EEST)
X-archive-position: 12
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv20523

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.339
retrieving revision 1.340
diff -u -d -r1.339 -r1.340
--- ChangeLog	23 Oct 2002 17:15:27 -0000	1.339
+++ ChangeLog	23 Oct 2002 17:30:27 -0000	1.340
@@ -1,3 +1,9 @@
+2002-10-23 17:15  Timo Sirainen <tss@iki.fi>
+
+	* src/lib-index/mail-modifylog.c: if we're only process accessing
+	modify log when it gets full, we can just truncate it instead of
+	switching.
+
 2002-10-23 17:03  Timo Sirainen <tss@iki.fi>
 
 	* src/: lib-index/mail-modifylog.c, lib-index/mail-modifylog.h,


From cras@procontrol.fi  Wed Oct 23 22:13:41 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 22:13:41 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 8295E2382D
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 22:13:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index mail-custom-flags.h,1.4,1.5
Message-Id: <20021023191341.8295E2382D@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 22:13:41 +0300 (EEST)
X-archive-position: 13
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv22259

Modified Files:
	mail-custom-flags.h 
Log Message:
comment update



Index: mail-custom-flags.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-custom-flags.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mail-custom-flags.h	19 Oct 2002 16:40:17 -0000	1.4
+++ mail-custom-flags.h	23 Oct 2002 19:13:39 -0000	1.5
@@ -1,6 +1,8 @@
 #ifndef __MAIL_CUSTOM_FLAGS_H
 #define __MAIL_CUSTOM_FLAGS_H
 
+/* NOTE: Contains it's own locking, unrelated to index locks. */
+
 #include "mail-index.h"
 
 #define CUSTOM_FLAGS_FILE_NAME ".customflags"


From cras@procontrol.fi  Wed Oct 23 22:15:29 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 22:15:29 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id AF25C2382D
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 22:15:29 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.340,1.341
Message-Id: <20021023191529.AF25C2382D@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 22:15:29 +0300 (EEST)
X-archive-position: 14
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv22437

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.340
retrieving revision 1.341
diff -u -d -r1.340 -r1.341
--- ChangeLog	23 Oct 2002 17:30:27 -0000	1.340
+++ ChangeLog	23 Oct 2002 19:15:27 -0000	1.341
@@ -1,3 +1,7 @@
+2002-10-23 19:13  Timo Sirainen <tss@iki.fi>
+
+	* src/lib-index/mail-custom-flags.h: comment update
+
 2002-10-23 17:15  Timo Sirainen <tss@iki.fi>
 
 	* src/lib-index/mail-modifylog.c: if we're only process accessing


From cras@procontrol.fi  Wed Oct 23 22:49:25 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 22:49:25 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 583992382C
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 22:49:25 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index mail-index-compress.c,1.15,1.16 mail-index-data.c,1.25,1.26 mail-index-data.h,1.9,1.10 mail-index-update.c,1.24,1.25 mail-index.c,1.60,1.61 mail-index.h,1.44,1.45 mail-modifylog.c,1.30,1.31 mail-modifylog.h,1.5,1.6 Message-Id: <20021023194925.583992382C@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 22:49:25 +0300 (EEST)
X-archive-position: 15
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv22997/lib-index

Modified Files:
	mail-index-compress.c mail-index-data.c mail-index-data.h 
	mail-index-update.c mail-index.c mail-index.h mail-modifylog.c 
	mail-modifylog.h mail-tree-redblack.c mail-tree.c mail-tree.h 
Log Message:
Use fdatasync() instead of fsync() where possible. msync() all files first,
then fsync them instead of msync+fsync+msync+fsync+.. data file now keeps
track of when it's been changed, tree file didn't do mmap updates, plus
other related cleanups.



Index: mail-index-compress.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-compress.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- mail-index-compress.c	8 Oct 2002 23:26:08 -0000	1.15
+++ mail-index-compress.c	23 Oct 2002 19:49:23 -0000	1.16
@@ -18,7 +18,7 @@
 
 	if (index->mmap_full_length <= INDEX_FILE_MIN_SIZE)
 		return TRUE;
-	    
+
 	/* really truncate the file only when it's almost empty */
 	empty_space = index->mmap_full_length - index->mmap_used_length;
 	truncate_threshold =
@@ -46,6 +46,7 @@
 {
 	MailIndexRecord *rec, *hole_rec, *end_rec;
 	unsigned int idx;
+	int tree_fd;
 
 	if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE))
 		return FALSE;
@@ -62,7 +63,7 @@
 	/* if we get interrupted, the whole index is probably corrupted.
 	   so keep rebuild-flag on while doing this */
 	index->header->flags |= MAIL_INDEX_FLAG_REBUILD;
-	if (!mail_index_fmsync(index, sizeof(MailIndexHeader)))
+	if (!mail_index_fmdatasync(index, sizeof(MailIndexHeader)))
 		return FALSE;
 
 	/* first actually compress the data */
@@ -96,7 +97,16 @@
 	index->header->first_hole_records = 0;
 
 	/* make sure the whole file is synced before removing rebuild-flag */
-	if (!mail_index_fmsync(index, index->mmap_used_length))
+	if (!mail_tree_sync_file(index->tree, &tree_fd))
+		return FALSE;
+
+	if (fdatasync(tree_fd) < 0) {
+		index_file_set_syscall_error(index, index->tree->filepath,
+					     "fdatasync()");
+		return FALSE;
+	}
+
+	if (!mail_index_fmdatasync(index, index->mmap_used_length))
 		return FALSE;
 
 	index->header->flags &= ~(MAIL_INDEX_FLAG_COMPRESS |
@@ -130,7 +140,7 @@
 	/* now we'll begin the actual moving. keep rebuild-flag on
 	   while doing it. */
 	index->header->flags |= MAIL_INDEX_FLAG_REBUILD;
-	if (!mail_index_fmsync(index, sizeof(MailIndexHeader)))
+	if (!mail_index_fmdatasync(index, sizeof(MailIndexHeader)))
 		return FALSE;
 
 	offset = sizeof(data_hdr);
@@ -195,8 +205,15 @@
 
 	failed = !mail_index_copy_data(index, fd, temppath);
 
-	if (close(fd) < 0)
+	if (close(fd) < 0) {
 		index_file_set_syscall_error(index, temppath, "close()");
+		failed = TRUE;
+	}
+
+	if (fdatasync(fd) < 0) {
+		index_file_set_syscall_error(index, temppath, "fdatasync()");
+		failed = TRUE;
+	}
 
 	if (!failed) {
 		/* now, rename the temp file to new data file. but before that
@@ -226,7 +243,7 @@
 	}
 
 	/* make sure the whole file is synced before removing rebuild-flag */
-	if (!mail_index_fmsync(index, index->mmap_used_length))
+	if (!mail_index_fmdatasync(index, index->mmap_used_length))
 		return FALSE;
 
 	index->header->flags &= ~(MAIL_INDEX_FLAG_COMPRESS_DATA |

Index: mail-index-data.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-data.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mail-index-data.c	17 Oct 2002 18:11:05 -0000	1.25
+++ mail-index-data.c	23 Oct 2002 19:49:23 -0000	1.26
@@ -40,6 +40,8 @@
 
 	unsigned int anon_mmap:1;
 	unsigned int dirty_mmap:1;
+	unsigned int modified:1;
+	unsigned int fsynced:1;
 };
 
 int index_data_set_corrupted(MailIndexData *data, const char *fmt, ...)
@@ -146,9 +148,11 @@
 	i_assert(!data->anon_mmap);
 
 	if (data->mmap_base != NULL) {
-		if (data->mmap_used_length > 0 &&
+		if (data->modified &&
 		    msync(data->mmap_base, data->mmap_used_length, MS_SYNC) < 0)
 			return index_data_set_syscall_error(data, "msync()");
+		data->modified = FALSE;
+		data->fsynced = FALSE;
 
 		if (munmap(data->mmap_base, data->mmap_full_length) < 0)
 			index_data_set_syscall_error(data, "munmap()");
@@ -359,6 +363,8 @@
 		return index_data_set_syscall_error(data, "write_full()");
 	}
 
+	data->modified = FALSE;
+	data->fsynced = FALSE;
 	return mmap_update(data, 0, 0);
 }
 
@@ -371,9 +377,15 @@
 	if (msync(data->mmap_base, sizeof(MailIndexDataHeader), MS_SYNC) < 0)
 		return index_data_set_syscall_error(data, "msync()");
 
+	data->fsynced = FALSE;
 	return TRUE;
 }
 
+void mail_index_data_mark_modified(MailIndexData *data)
+{
+	data->modified = TRUE;
+}
+
 static int mail_index_data_grow(MailIndexData *data, size_t size)
 {
 	void *base;
@@ -443,6 +455,7 @@
 	memcpy((char *) data->mmap_base + offset, buffer, size);
 	data->header->used_file_size += size;
 
+        data->modified = TRUE;
 	return offset;
 }
 
@@ -462,20 +475,28 @@
 		if (data->header->deleted_space >= max_del_space)
 			data->index->set_flags |= MAIL_INDEX_FLAG_COMPRESS_DATA;
 	}
+
+        data->modified = TRUE;
 	return TRUE;
 }
 
-int mail_index_data_sync_file(MailIndexData *data)
+int mail_index_data_sync_file(MailIndexData *data, int *fsync_fd)
 {
+	*fsync_fd = -1;
+
 	if (data->anon_mmap)
 		return TRUE;
 
-	if (data->mmap_base != NULL && data->mmap_used_length > 0) {
+	if (data->modified) {
 		if (msync(data->mmap_base, data->mmap_used_length, MS_SYNC) < 0)
 			return index_data_set_syscall_error(data, "msync()");
 
-		if (fsync(data->fd) < 0)
-			return index_data_set_syscall_error(data, "fsync()");
+		data->fsynced = FALSE;
+	}
+
+	if (!data->fsynced) {
+		data->fsynced = TRUE;
+		*fsync_fd = data->fd;
 	}
 
 	return TRUE;

Index: mail-index-data.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-data.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mail-index-data.h	16 Oct 2002 22:54:18 -0000	1.9
+++ mail-index-data.h	23 Oct 2002 19:49:23 -0000	1.10
@@ -14,6 +14,9 @@
    re-open it. */
 int mail_index_data_mark_deleted(MailIndexData *data);
 
+/* Mark the file as being modified */
+void mail_index_data_mark_modified(MailIndexData *data);
+
 /* Append new data at the end of the file. Returns the position in file
    where the data begins, or 0 if error occured. */
 uoff_t mail_index_data_append(MailIndexData *data, const void *buffer,
@@ -23,7 +26,7 @@
 int mail_index_data_add_deleted_space(MailIndexData *data, size_t data_size);
 
 /* Synchronize the data into disk */
-int mail_index_data_sync_file(MailIndexData *data);
+int mail_index_data_sync_file(MailIndexData *data, int *fsync_fd);
 
 /* Looks up a field from data file. If field is 0, returns the first field
    found. Returns NULL if not found or if error occured. */

Index: mail-index-update.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-update.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- mail-index-update.c	20 Oct 2002 01:12:27 -0000	1.24
+++ mail-index-update.c	23 Oct 2002 19:49:23 -0000	1.25
@@ -231,6 +231,8 @@
 		rec = mail_index_data_next(update->index->data,
 					   update->rec, rec);
 	}
+
+        mail_index_data_mark_modified(update->index->data);
 }
 
 int mail_index_update_end(MailIndexUpdate *update)

Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- mail-index.c	20 Oct 2002 02:35:51 -0000	1.60
+++ mail-index.c	23 Oct 2002 19:49:23 -0000	1.61
@@ -177,12 +177,16 @@
 static int mail_index_sync_file(MailIndex *index)
 {
 	struct utimbuf ut;
-	int failed;
+	unsigned int i;
+	int failed, fsync_fds[3];
 
 	if (index->anon_mmap)
 		return TRUE;
 
-	if (!mail_index_data_sync_file(index->data))
+	for (i = 0; i < sizeof(fsync_fds)/sizeof(fsync_fds[0]); i++)
+		fsync_fds[i] = -1;
+
+	if (!mail_index_data_sync_file(index->data, &fsync_fds[0]))
 		return FALSE;
 
 	if (msync(index->mmap_base, index->mmap_used_length, MS_SYNC) < 0)
@@ -191,12 +195,12 @@
 	failed = FALSE;
 
 	if (index->tree != NULL) {
-		if (!mail_tree_sync_file(index->tree))
+		if (!mail_tree_sync_file(index->tree, &fsync_fds[1]))
 			failed = TRUE;
 	}
 
 	if (index->modifylog != NULL) {
-		if (!mail_modifylog_sync_file(index->modifylog))
+		if (!mail_modifylog_sync_file(index->modifylog, &fsync_fds[2]))
 			failed = TRUE;
 	}
 
@@ -206,20 +210,25 @@
 	if (utime(index->filepath, &ut) < 0)
 		return index_set_syscall_error(index, "utime()");
 
+	for (i = 0; i < sizeof(fsync_fds)/sizeof(fsync_fds[0]); i++) {
+		if (fsync_fds[i] != -1 && fdatasync(fsync_fds[i]) < 0)
+			index_set_error(index, "fdatasync(%d) failed: %m", i);
+	}
+
 	if (fsync(index->fd) < 0)
 		return index_set_syscall_error(index, "fsync()");
 
 	return !failed;
 }
 
-int mail_index_fmsync(MailIndex *index, size_t size)
+int mail_index_fmdatasync(MailIndex *index, size_t size)
 {
 	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
 	if (!index->anon_mmap) {
 		if (msync(index->mmap_base, size, MS_SYNC) < 0)
 			return index_set_syscall_error(index, "msync()");
-		if (fsync(index->fd) < 0)
+		if (fdatasync(index->fd) < 0)
 			return index_set_syscall_error(index, "fsync()");
 	}
 
@@ -370,7 +379,7 @@
 		   when the lock is released, the FSCK flag will also be
 		   removed. */
 		index->header->flags |= MAIL_INDEX_FLAG_FSCK;
-		if (!mail_index_fmsync(index, sizeof(MailIndexHeader))) {
+		if (!mail_index_fmdatasync(index, sizeof(MailIndexHeader))) {
 			(void)mail_index_set_lock(index, MAIL_LOCK_UNLOCK);
 			return FALSE;
 		}

Index: mail-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- mail-index.h	20 Oct 2002 02:35:51 -0000	1.44
+++ mail-index.h	23 Oct 2002 19:49:23 -0000	1.45
@@ -395,7 +395,7 @@
 int mail_index_mmap_update(MailIndex *index);
 void mail_index_init_header(MailIndex *index, MailIndexHeader *hdr);
 void mail_index_close(MailIndex *index);
-int mail_index_fmsync(MailIndex *index, size_t size);
+int mail_index_fmdatasync(MailIndex *index, size_t size);
 int mail_index_verify_hole_range(MailIndex *index);
 void mail_index_mark_flag_changes(MailIndex *index, MailIndexRecord *rec,
 				  MailFlags old_flags, MailFlags new_flags);

Index: mail-modifylog.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- mail-modifylog.c	23 Oct 2002 17:15:36 -0000	1.30
+++ mail-modifylog.c	23 Oct 2002 19:49:23 -0000	1.31
@@ -178,6 +178,7 @@
 		if (file->modified &&
 		    msync(file->mmap_base, file->mmap_used_length, MS_SYNC) < 0)
 			return modifylog_set_syscall_error(file, "msync()");
+		file->modified = FALSE;
 
 		if (munmap(file->mmap_base, file->mmap_full_length) < 0)
 			modifylog_set_syscall_error(file, "munmap()");
@@ -578,22 +579,21 @@
 	i_free(log);
 }
 
-int mail_modifylog_sync_file(MailModifyLog *log)
+int mail_modifylog_sync_file(MailModifyLog *log, int *fsync_fd)
 {
 	ModifyLogFile *file = log->head;
 
+	*fsync_fd = -1;
+
 	if (!file->modified || file->anon_mmap)
 		return TRUE;
 
-	if (file->mmap_base != NULL) {
-		if (msync(file->mmap_base, file->mmap_used_length,
-			  MS_SYNC) < 0)
-			return modifylog_set_syscall_error(file, "msync()");
-	}
+	i_assert(file->mmap_base != NULL);
 
-	if (fsync(file->fd) < 0)
-		return modifylog_set_syscall_error(file, "fsync()");
+	if (msync(file->mmap_base, file->mmap_used_length, MS_SYNC) < 0)
+		return modifylog_set_syscall_error(file, "msync()");
 
+	*fsync_fd = file->fd;
 	file->modified = FALSE;
 	return TRUE;
 }

Index: mail-modifylog.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mail-modifylog.h	23 Oct 2002 17:03:39 -0000	1.5
+++ mail-modifylog.h	23 Oct 2002 19:49:23 -0000	1.6
@@ -47,7 +47,7 @@
 			     unsigned int uid, int external_change);
 
 /* Synchronize the data into disk */
-int mail_modifylog_sync_file(MailModifyLog *log);
+int mail_modifylog_sync_file(MailModifyLog *log, int *fsync_fd);
 
 /* Must be called when exclusive lock is dropped from index. */
 void mail_modifylog_notify_lock_drop(MailModifyLog *log);

Index: mail-tree-redblack.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree-redblack.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- mail-tree-redblack.c	19 Oct 2002 23:09:56 -0000	1.13
+++ mail-tree-redblack.c	23 Oct 2002 19:49:23 -0000	1.14
@@ -630,6 +630,9 @@
 	i_assert(first_uid <= last_uid);
 	i_assert(tree->index->lock_type != MAIL_LOCK_UNLOCK);
 
+	if (!_mail_tree_mmap_update(tree, FALSE))
+		return (unsigned int)-1;
+
 	rb_check(tree);
 
 	if (seq_r != NULL)
@@ -684,6 +687,9 @@
 	i_assert(seq != 0);
 	i_assert(tree->index->lock_type != MAIL_LOCK_UNLOCK);
 
+	if (!_mail_tree_mmap_update(tree, FALSE))
+		return (unsigned int)-1;
+
 	rb_check(tree);
 
 	x = tree->header->root;
@@ -716,6 +722,9 @@
 	i_assert(uid != 0);
 	i_assert(tree->index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
+	if (!_mail_tree_mmap_update(tree, FALSE))
+		return FALSE;
+
 	tree->modified = TRUE;
 
 	/* we'll always insert to right side of the tree */
@@ -770,6 +779,9 @@
 	i_assert(uid != 0);
 	i_assert(tree->index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
+	if (!_mail_tree_mmap_update(tree, FALSE))
+		return FALSE;
+
 	rb_check(tree);
 
 	tree->modified = TRUE;
@@ -799,6 +811,9 @@
 
 	i_assert(uid != 0);
 	i_assert(tree->index->lock_type == MAIL_LOCK_EXCLUSIVE);
+
+	if (!_mail_tree_mmap_update(tree, FALSE))
+		return;
 
 	tree->modified = TRUE;
 

Index: mail-tree.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mail-tree.c	20 Oct 2002 01:34:15 -0000	1.4
+++ mail-tree.c	23 Oct 2002 19:49:23 -0000	1.5
@@ -43,7 +43,7 @@
 	return FALSE;
 }
 
-static int mmap_update(MailTree *tree, int forced)
+int _mail_tree_mmap_update(MailTree *tree, int forced)
 {
 	if (!forced && tree->header != NULL &&
 	    tree->mmap_full_length >= tree->header->used_file_size) {
@@ -58,6 +58,7 @@
 		if (tree->modified &&
 		    msync(tree->mmap_base, tree->mmap_used_length, MS_SYNC) < 0)
 			return tree_set_syscall_error(tree, "msync()");
+		tree->modified = FALSE;
 
 		if (munmap(tree->mmap_base, tree->mmap_full_length) < 0)
 			tree_set_syscall_error(tree, "munmap()");
@@ -199,7 +200,7 @@
 		return FALSE;
 
 	do {
-		if (!mmap_update(tree, TRUE))
+		if (!_mail_tree_mmap_update(tree, TRUE))
 			break;
 
 		if (tree->mmap_full_length == 0) {
@@ -271,7 +272,7 @@
 		return FALSE;
 
 	if (!mail_tree_init(tree) ||
-	    !mmap_update(tree, TRUE) ||
+	    !_mail_tree_mmap_update(tree, TRUE) ||
 	    !mmap_verify(tree)) {
 		tree->index->header->flags |= MAIL_INDEX_FLAG_REBUILD_TREE;
 		return FALSE;
@@ -292,19 +293,19 @@
 	return TRUE;
 }
 
-int mail_tree_sync_file(MailTree *tree)
+int mail_tree_sync_file(MailTree *tree, int *fsync_fd)
 {
+	*fsync_fd = -1;
+
 	if (!tree->modified || tree->anon_mmap)
 		return TRUE;
 
-	if (tree->mmap_base != NULL) {
-		if (msync(tree->mmap_base, tree->mmap_used_length, MS_SYNC) < 0)
-			return tree_set_syscall_error(tree, "msync()");
-	}
+	i_assert(tree->mmap_base != NULL);
 
-	if (fsync(tree->fd) < 0)
-		return tree_set_syscall_error(tree, "fsync()");
+	if (msync(tree->mmap_base, tree->mmap_used_length, MS_SYNC) < 0)
+		return tree_set_syscall_error(tree, "msync()");
 
+	*fsync_fd = tree->fd;
 	tree->modified = FALSE;
 	return TRUE;
 }
@@ -343,7 +344,7 @@
 		return tree_set_syscall_error(tree, "file_set_size()");
 	}
 
-	if (!mmap_update(tree, TRUE) || !mmap_verify(tree))
+	if (!_mail_tree_mmap_update(tree, TRUE) || !mmap_verify(tree))
 		return FALSE;
 
 	return TRUE;

Index: mail-tree.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mail-tree.h	8 Oct 2002 23:26:08 -0000	1.2
+++ mail-tree.h	23 Oct 2002 19:49:23 -0000	1.3
@@ -51,7 +51,7 @@
 void mail_tree_free(MailTree *tree);
 
 int mail_tree_rebuild(MailTree *tree);
-int mail_tree_sync_file(MailTree *tree);
+int mail_tree_sync_file(MailTree *tree, int *fsync_fd);
 
 /* Find first existing UID in range. Returns (unsigned int)-1 if not found. */
 unsigned int mail_tree_lookup_uid_range(MailTree *tree, unsigned int *seq_r,
@@ -72,6 +72,7 @@
 
 /* private: */
 int _mail_tree_set_corrupted(MailTree *tree, const char *fmt, ...);
+int _mail_tree_mmap_update(MailTree *tree, int forced);
 int _mail_tree_grow(MailTree *tree);
 
 #endif


From cras@procontrol.fi  Wed Oct 23 22:55:16 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 22:55:16 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 13C952382C
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 22:55:16 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index mail-index.c,1.61,1.62
Message-Id: <20021023195516.13C952382C@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 22:55:16 +0300 (EEST)
X-archive-position: 16
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv23084

Modified Files:
	mail-index.c 
Log Message:
minor fixes



Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- mail-index.c	23 Oct 2002 19:49:23 -0000	1.61
+++ mail-index.c	23 Oct 2002 19:55:13 -0000	1.62
@@ -212,7 +212,7 @@
 
 	for (i = 0; i < sizeof(fsync_fds)/sizeof(fsync_fds[0]); i++) {
 		if (fsync_fds[i] != -1 && fdatasync(fsync_fds[i]) < 0)
-			index_set_error(index, "fdatasync(%d) failed: %m", i);
+			index_set_error(index, "fdatasync(%u) failed: %m", i);
 	}
 
 	if (fsync(index->fd) < 0)
@@ -229,7 +229,7 @@
 		if (msync(index->mmap_base, size, MS_SYNC) < 0)
 			return index_set_syscall_error(index, "msync()");
 		if (fdatasync(index->fd) < 0)
-			return index_set_syscall_error(index, "fsync()");
+			return index_set_syscall_error(index, "fdatasync()");
 	}
 
 	return TRUE;


From cras@procontrol.fi  Wed Oct 23 23:00:31 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 23:00:31 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id A62102382C
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 23:00:31 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.341,1.342
Message-Id: <20021023200031.A62102382C@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 23:00:31 +0300 (EEST)
X-archive-position: 17
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv23260

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.341
retrieving revision 1.342
diff -u -d -r1.341 -r1.342
--- ChangeLog	23 Oct 2002 19:15:27 -0000	1.341
+++ ChangeLog	23 Oct 2002 20:00:29 -0000	1.342
@@ -1,3 +1,18 @@
+2002-10-23 19:55  Timo Sirainen <tss@iki.fi>
+
+	* src/lib-index/mail-index.c: minor fixes
+
+2002-10-23 19:49  Timo Sirainen <tss@iki.fi>
+
+	* src/lib-index/: mail-index-compress.c, mail-index-data.c,
+	mail-index-data.h, mail-index-update.c, mail-index.c, mail-index.h,
+	mail-modifylog.c, mail-modifylog.h, mail-tree-redblack.c,
+	mail-tree.c, mail-tree.h: Use fdatasync() instead of fsync() where
+	possible. msync() all files first, then fsync them instead of
+	msync+fsync+msync+fsync+.. data file now keeps track of when it's
+	been changed, tree file didn't do mmap updates, plus other related
+	cleanups.
+
 2002-10-23 19:13  Timo Sirainen <tss@iki.fi>
 
 	* src/lib-index/mail-custom-flags.h: comment update


From cras@procontrol.fi  Wed Oct 23 23:41:38 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 23:41:38 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id F210423837
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 23:41:37 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-storage/subscription-file subscription-file.c,1.7,1.8
Message-Id: <20021023204138.F210423837@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 23:41:38 +0300 (EEST)
X-archive-position: 18
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-storage/subscription-file
In directory danu:/tmp/cvs-serv24024/lib-storage/subscription-file

Modified Files:
	subscription-file.c 
Log Message:
file_wait_lock() now takes timeout-parameter so one badly behaving process
won't start creating tons of lock-waiting processes.



Index: subscription-file.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/subscription-file/subscription-file.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- subscription-file.c	21 Oct 2002 15:01:56 -0000	1.7
+++ subscription-file.c	23 Oct 2002 20:41:35 -0000	1.8
@@ -42,7 +42,8 @@
 		return -1;
 	}
 
-	if (file_wait_lock(fd, update ? F_WRLCK : F_RDLCK) < 0) {
+	if (file_wait_lock(fd, update ? F_WRLCK : F_RDLCK,
+			   DEFAULT_LOCK_TIMEOUT) <= 0) {
 		subsfile_set_syscall_error(storage, "file_wait_lock()", *path);
 		(void)close(fd);
 		return -1;


From cras@procontrol.fi  Wed Oct 23 23:41:38 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 23:41:38 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id EE0E62382D
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 23:41:37 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib file-lock.c,1.1,1.2 file-lock.h,1.1,1.2 lib-signals.c,1.2,1.3
Message-Id: <20021023204137.EE0E62382D@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 23:41:37 +0300 (EEST)
X-archive-position: 19
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv24024/lib

Modified Files:
	file-lock.c file-lock.h lib-signals.c 
Log Message:
file_wait_lock() now takes timeout-parameter so one badly behaving process
won't start creating tons of lock-waiting processes.



Index: file-lock.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/file-lock.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- file-lock.c	14 Sep 2002 11:09:42 -0000	1.1
+++ file-lock.c	23 Oct 2002 20:41:35 -0000	1.2
@@ -26,6 +26,19 @@
 #include "lib.h"
 #include "file-lock.h"
 
+#include <signal.h>
+
+static int got_alarm = FALSE;
+
+static void sig_alarm(int signo __attr_unused__)
+{
+	got_alarm = TRUE;
+
+	/* we need fcntl() to stop with EINTR */
+	if (raise(SIGHUP) < 0)
+		i_fatal("kill(): %m");
+}
+
 static int file_lock(int fd, int wait_lock, int lock_type)
 {
 	struct flock fl;
@@ -41,6 +54,11 @@
 
 		if (errno != EINTR)
 			return -1;
+
+		if (got_alarm) {
+			errno = EAGAIN;
+			return 0;
+		}
 	}
 
 	return 1;
@@ -48,10 +66,56 @@
 
 int file_try_lock(int fd, int lock_type)
 {
+        got_alarm = FALSE;
 	return file_lock(fd, FALSE, lock_type);
 }
 
-int file_wait_lock(int fd, int lock_type)
+int file_wait_lock(int fd, int lock_type, unsigned int timeout __attr_unused__)
 {
-	return file_lock(fd, TRUE, lock_type);
+#ifdef HAVE_SIGACTION
+	struct sigaction act;
+#endif
+	int ret;
+
+	got_alarm = FALSE;
+
+	if (timeout > 0 && lock_type != F_UNLCK) {
+#ifdef HAVE_SIGACTION
+		if (sigemptyset(&act.sa_mask) < 0)
+			i_fatal("sigemptyset(): %m");
+		act.sa_flags = 0;
+		act.sa_handler = sig_alarm;
+
+		while (sigaction(SIGALRM, &act, NULL) < 0) {
+			if (errno != EINTR)
+				i_fatal("sigaction(): %m");
+		}
+#else
+		/* at least Linux blocks raise(SIGHUP) inside SIGALRM
+		   handler if it's added with signal().. sigaction() should
+		   be pretty much everywhere though, so this code is pretty
+		   useless. */
+#warning file_wait_lock() timeouting may not work
+		signal(SIGALRM, sig_alarm);
+#endif
+
+		alarm(timeout);
+	}
+
+	ret = file_lock(fd, TRUE, lock_type);
+
+	if (timeout > 0 && lock_type != F_UNLCK) {
+		alarm(0);
+
+#ifdef HAVE_SIGACTION
+		act.sa_handler = SIG_DFL;
+		while (sigaction(SIGALRM, &act, NULL) < 0) {
+			if (errno != EINTR)
+				i_fatal("sigaction(): %m");
+		}
+#else
+		signal(SIGALRM, SIG_IGN);
+#endif
+	}
+	return ret;
 }

Index: file-lock.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/file-lock.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- file-lock.h	14 Sep 2002 11:09:42 -0000	1.1
+++ file-lock.h	23 Oct 2002 20:41:35 -0000	1.2
@@ -4,11 +4,15 @@
 #include <unistd.h>
 #include <fcntl.h>
 
+#define DEFAULT_LOCK_TIMEOUT 120
+
 /* Lock whole file descriptor. Returns 1 if successful, 0 if lock failed,
    or -1 if error. lock_type is F_WRLCK, F_RDLCK or F_UNLCK. */
 int file_try_lock(int fd, int lock_type);
 
-/* Lock whole file descriptor. Returns 1 if successful, or -1 if error. */
-int file_wait_lock(int fd, int lock_type);
+/* Lock whole file descriptor. Returns 1 if successful, 0 if timeout or
+   -1 if error. When returning 0, errno is also set to EAGAIN.
+   NOTE: timeout uses SIGALRM and resets it at the end. */
+int file_wait_lock(int fd, int lock_type, unsigned int timeout);
 
 #endif

Index: lib-signals.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/lib-signals.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- lib-signals.c	24 Sep 2002 13:53:43 -0000	1.2
+++ lib-signals.c	23 Oct 2002 20:41:35 -0000	1.3
@@ -67,10 +67,14 @@
 	   isn't ignored, or your handler doesn't kill the program,
 	   sigaction() should be used. */
 #ifdef HAVE_SIGACTION
-	sigemptyset(&act.sa_mask);
+	if (sigemptyset(&act.sa_mask) < 0)
+		i_fatal("sigemptyset(): %m");
 	act.sa_flags = 0;
 	act.sa_handler = sig_hup;
-	sigaction(SIGHUP, &act, NULL);
+	while (sigaction(SIGHUP, &act, NULL) < 0) {
+		if (errno != EINTR)
+			i_fatal("sigaction(): %m");
+	}
 #else
         signal(SIGHUP, sig_hup);
 #endif


From cras@procontrol.fi  Wed Oct 23 23:41:38 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 23:41:38 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 1E7D92385F
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 23:41:38 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index mail-custom-flags.c,1.11,1.12 mail-index-open.c,1.11,1.12 mail-index.c,1.62,1.63 mail-modifylog.c,1.31,1.32
Message-Id: <20021023204138.1E7D92385F@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 23:41:38 +0300 (EEST)
X-archive-position: 20
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv24024/lib-index

Modified Files:
	mail-custom-flags.c mail-index-open.c mail-index.c 
	mail-modifylog.c 
Log Message:
file_wait_lock() now takes timeout-parameter so one badly behaving process
won't start creating tons of lock-waiting processes.



Index: mail-custom-flags.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-custom-flags.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- mail-custom-flags.c	19 Oct 2002 16:40:17 -0000	1.11
+++ mail-custom-flags.c	23 Oct 2002 20:41:35 -0000	1.12
@@ -195,7 +195,7 @@
 	if (mcf->lock_type == type)
 		return TRUE;
 
-	if (file_wait_lock(mcf->fd, type) < 0)
+	if (file_wait_lock(mcf->fd, type, DEFAULT_LOCK_TIMEOUT) <= 0)
 		return index_cf_set_syscall_error(mcf, "file_wait_lock()");
 
 	mcf->lock_type = type;

Index: mail-index-open.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-open.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- mail-index-open.c	20 Oct 2002 02:35:51 -0000	1.11
+++ mail-index-open.c	23 Oct 2002 20:41:35 -0000	1.12
@@ -254,7 +254,7 @@
 		return index_file_set_syscall_error(index, path, "open()");
 
 	/* if index is being created, we'll wait here until it's finished */
-	if (file_wait_lock(fd, F_RDLCK) < 0) {
+	if (file_wait_lock(fd, F_RDLCK, DEFAULT_LOCK_TIMEOUT) <= 0) {
 		index_file_set_syscall_error(index, path, "file_wait_lock()");
 		(void)close(fd);
 		return FALSE;
@@ -267,7 +267,7 @@
 		return FALSE;
 	}
 
-	if (file_wait_lock(fd, F_UNLCK) < 0) {
+	if (file_wait_lock(fd, F_UNLCK, 0) <= 0) {
 		index_file_set_syscall_error(index, path, "file_wait_lock()");
 		(void)close(fd);
 		return FALSE;
@@ -305,7 +305,7 @@
 		return FALSE;
 	}
 
-	if (file_wait_lock(fd, F_WRLCK) < 0) {
+	if (file_wait_lock(fd, F_WRLCK, DEFAULT_LOCK_TIMEOUT) <= 0) {
 		index_file_set_syscall_error(index, path, "file_wait_lock()");
 		return FALSE;
 	}

Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- mail-index.c	23 Oct 2002 19:55:13 -0000	1.62
+++ mail-index.c	23 Oct 2002 20:41:35 -0000	1.63
@@ -275,7 +275,7 @@
 
 	/* use our own locking here so we don't mess up with any other
 	   index states, like inconsistency. */
-	if (file_wait_lock(index->fd, F_WRLCK) < 0)
+	if (file_wait_lock(index->fd, F_WRLCK, DEFAULT_LOCK_TIMEOUT) <= 0)
 		return index_set_syscall_error(index, "file_wait_lock()");
 
 	mail_index_update_header_changes(index);
@@ -284,7 +284,7 @@
 	if (failed)
 		index_set_syscall_error(index, "msync()");
 
-	if (file_wait_lock(index->fd, F_UNLCK) < 0)
+	if (file_wait_lock(index->fd, F_UNLCK, 0) <= 0)
 		return index_set_syscall_error(index, "file_wait_lock()");
 
 	return !failed;
@@ -294,7 +294,7 @@
 {
 	MailLockType old_lock_type;
 
-	if (file_wait_lock(index->fd, F_UNLCK) < 0)
+	if (file_wait_lock(index->fd, F_UNLCK, 0) <= 0)
 		return index_set_syscall_error(index, "file_wait_lock()");
 
 	old_lock_type = index->lock_type;
@@ -328,7 +328,8 @@
 		return FALSE;
 	}
 
-	if (file_wait_lock(index->fd, MAIL_LOCK_TO_FLOCK(lock_type)) < 0)
+	if (file_wait_lock(index->fd, MAIL_LOCK_TO_FLOCK(lock_type),
+			   DEFAULT_LOCK_TIMEOUT) <= 0)
 		return index_set_syscall_error(index, "file_wait_lock()");
 	index->lock_type = lock_type;
 
@@ -355,7 +356,8 @@
 			if (!mail_index_lock_remove(index))
 				return FALSE;
 
-			if (file_wait_lock(index->fd, MAIL_LOCK_EXCLUSIVE) < 0)
+			if (file_wait_lock(index->fd, MAIL_LOCK_EXCLUSIVE,
+					   DEFAULT_LOCK_TIMEOUT) <= 0)
 				return index_set_syscall_error(index,
 							"file_wait_lock()");
 			index->lock_type = MAIL_LOCK_EXCLUSIVE;

Index: mail-modifylog.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- mail-modifylog.c	23 Oct 2002 19:49:23 -0000	1.31
+++ mail-modifylog.c	23 Oct 2002 20:41:35 -0000	1.32
@@ -413,7 +413,7 @@
 		return -1;
 	}
 
-	if (file_wait_lock(fd, F_RDLCK) < 0) {
+	if (file_wait_lock(fd, F_RDLCK, DEFAULT_LOCK_TIMEOUT) <= 0) {
 		modifylog_set_syscall_error(file, "file_wait_lock()");
 		(void)close(fd);
 		return -1;


From cras@procontrol.fi  Wed Oct 23 23:45:30 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Wed, 23 Oct 2002 23:45:30 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id ACF882382D
	for <dovecot-cvs@procontrol.fi>; Wed, 23 Oct 2002 23:45:30 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.342,1.343
Message-Id: <20021023204530.ACF882382D@danu.procontrol.fi>
Date: Wed, 23 Oct 2002 23:45:30 +0300 (EEST)
X-archive-position: 21
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv24266

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.342
retrieving revision 1.343
diff -u -d -r1.342 -r1.343
--- ChangeLog	23 Oct 2002 20:00:29 -0000	1.342
+++ ChangeLog	23 Oct 2002 20:45:28 -0000	1.343
@@ -1,3 +1,12 @@
+2002-10-23 20:41  Timo Sirainen <tss@iki.fi>
+
+	* src/: lib/file-lock.c, lib/file-lock.h, lib/lib-signals.c,
+	lib-index/mail-custom-flags.c, lib-index/mail-index-open.c,
+	lib-index/mail-index.c, lib-index/mail-modifylog.c,
+	lib-storage/subscription-file/subscription-file.c: file_wait_lock()
+	now takes timeout-parameter so one badly behaving process won't
+	start creating tons of lock-waiting processes.
+
 2002-10-23 19:55  Timo Sirainen <tss@iki.fi>
 
 	* src/lib-index/mail-index.c: minor fixes


From cras@procontrol.fi  Thu Oct 24 00:07:39 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 00:07:39 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 9B80D2382D
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 00:07:39 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index/maildir maildir-index.c,1.11,1.12
Message-Id: <20021023210739.9B80D2382D@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 00:07:39 +0300 (EEST)
X-archive-position: 22
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index/maildir
In directory danu:/tmp/cvs-serv24586/lib-index/maildir

Modified Files:
	maildir-index.c 
Log Message:
Ignore and leave maildir flags after ',' character (eg. file:2,S,U123).



Index: maildir-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-index.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- maildir-index.c	20 Oct 2002 01:12:27 -0000	1.11
+++ maildir-index.c	23 Oct 2002 21:07:37 -0000	1.12
@@ -19,7 +19,7 @@
 		return default_flags;
 
 	flags = 0;
-	for (info += 3; *info != '\0'; info++) {
+	for (info += 3; *info != '\0' && *info != ','; info++) {
 		switch (*info) {
 		case 'R': /* replied */
 			flags |= MAIL_ANSWERED;
@@ -83,7 +83,7 @@
 		       (*oldflags >= 'a' && *oldflags <= 'z'))
 			oldflags++;
 
-		nextflag = *oldflags == '\0' ? 256 :
+		nextflag = *oldflags == '\0' || *oldflags == ',' ? 256 :
 			(unsigned char) *oldflags;
 
 		if ((flags & MAIL_DRAFT) && nextflag > 'D') {
@@ -115,10 +115,16 @@
 			flags &= ~MAIL_CUSTOM_FLAGS_MASK;
 		}
 
-		if (*oldflags == '\0')
+		if (*oldflags == '\0' || *oldflags == ',')
 			break;
 
 		*p++ = *oldflags++;
+	}
+
+	if (*oldflags == ',') {
+		/* another flagset, we don't know about these, just keep them */
+		while (*oldflags != '\0')
+			*p++ = *oldflags++;
 	}
 
 	*p = '\0';


From cras@procontrol.fi  Thu Oct 24 00:15:30 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 00:15:30 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 93B922382D
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 00:15:30 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.343,1.344
Message-Id: <20021023211530.93B922382D@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 00:15:30 +0300 (EEST)
X-archive-position: 23
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv24847

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.343
retrieving revision 1.344
diff -u -d -r1.343 -r1.344
--- ChangeLog	23 Oct 2002 20:45:28 -0000	1.343
+++ ChangeLog	23 Oct 2002 21:15:28 -0000	1.344
@@ -1,3 +1,8 @@
+2002-10-23 21:07  Timo Sirainen <tss@iki.fi>
+
+	* src/lib-index/maildir/maildir-index.c: Ignore and leave maildir
+	flags after ',' character (eg. file:2,S,U123).
+
 2002-10-23 20:41  Timo Sirainen <tss@iki.fi>
 
 	* src/: lib/file-lock.c, lib/file-lock.h, lib/lib-signals.c,


From cras@procontrol.fi  Thu Oct 24 03:15:41 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 2F9B823837
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib utc-mktime.c,NONE,1.1 utc-mktime.h,NONE,1.1 utc-offset.c,NONE,1.1 utc-offset.h,NONE,1.1 Makefile.am,1.8,1.9 ioloop.c,1.5,1.6 ioloop.h,1.3,1.4 gmtoff.c,1.1.1.1,NONE gmtoff.h,1.1.1.1,NONE
Message-Id: <20021024001541.2F9B823837@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
X-archive-position: 24
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv28234/lib

Modified Files:
	Makefile.am ioloop.c ioloop.h 
Added Files:
	utc-mktime.c utc-mktime.h utc-offset.c utc-offset.h 
Removed Files:
	gmtoff.c gmtoff.h 
Log Message:
Fixes to timezone handling which were handling quite badly. added
ioloop_timezone which gets updated with ioloop_time. Changed some GMT
references to UTC. Timezone offsets are in minutes now everywhere instead of
seconds. Fixes for unsigned time_t.



--- NEW FILE: utc-mktime.c ---
/* mkgmtime.c - make time corresponding to a GMT timeval struct
 $Id: utc-mktime.c,v 1.1 2002/10/24 00:15:38 cras Exp $
 
 * Copyright (c) 1998-2000 Carnegie Mellon University.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The name "Carnegie Mellon University" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For permission or any other legal
 *    details, please contact  
 *      Office of Technology Transfer
 *      Carnegie Mellon University
 *      5000 Forbes Avenue
 *      Pittsburgh, PA  15213-3890
 *      (412) 268-4387, fax: (412) 268-7395
 *      tech-transfer@andrew.cmu.edu
 *
 * 4. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by Computing Services
 *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
 *
 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 *
 */
/*
 * Copyright (c) 1987, 1989, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * Arthur David Olson of the National Cancer Institute.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
** Adapted from code provided by Robert Elz, who writes:
**	The "best" way to do mktime I think is based on an idea of Bob
**	Kridle's (so its said...) from a long time ago. (mtxinu!kridle now).
**	It does a binary search of the time_t space.  Since time_t's are
**	just 32 bits, its a max of 32 iterations (even at 64 bits it
**	would still be very reasonable).
*/

#include "utc-mktime.h"

static int tmcomp(register const struct tm * const atmp,
		  register const struct tm * const btmp)
{
	register int	result;

	if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
		(result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
		(result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
		(result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
		(result = (atmp->tm_min - btmp->tm_min)) == 0)
			result = atmp->tm_sec - btmp->tm_sec;
	return result;
}

time_t utc_mktime(struct tm *tm)
{
	register int			dir;
	register int			bits;
	register int			saved_seconds;
	time_t				t;
	struct tm			yourtm, *mytm;

	yourtm = *tm;
	saved_seconds = yourtm.tm_sec;
	yourtm.tm_sec = 0;
	/*
	** Calculate the number of magnitude bits in a time_t
	** (this works regardless of whether time_t is
	** signed or unsigned, though lint complains if unsigned).
	*/
	for (bits = 0, t = 1; t > 0; ++bits, t <<= 1)
		;
	/*
	** If time_t is signed, then 0 is the median value,
	** if time_t is unsigned, then 1 << bits is median.
	*/
	t = (t < 0) ? 0 : ((time_t) 1 << bits);
	for ( ; ; ) {
		mytm = gmtime(&t);
		dir = tmcomp(mytm, &yourtm);
		if (dir != 0) {
			if (bits-- < 0)
				return (time_t)-1;
			if (bits < 0)
				--t;
			else if (dir > 0)
				t -= (time_t) 1 << bits;
			else	t += (time_t) 1 << bits;
			continue;
		}
		break;
	}
	t += saved_seconds;
	return t;
}

--- NEW FILE: utc-mktime.h ---
#ifndef __UTC_MKTIME_H
#define __UTC_MKTIME_H

#include <time.h>

/* Like mktime(), but assume that tm is in UTC. Unlike mktime(), values in
   tm fields must be in valid range. */
time_t utc_mktime(struct tm *tm);

#endif

--- NEW FILE: utc-offset.c ---
/*
 compat.c : Compatibility functions for OSes not having them

    Copyright (c) 2002 Timo Sirainen

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "lib.h"
#include "utc-offset.h"

#include <sys/time.h>

int utc_offset(struct tm *tm, time_t t __attr_unused__)
{
#ifdef HAVE_TM_GMTOFF
	return (int) (tm->tm_gmtoff/60);
#else
	struct tm ltm, gtm;
	int offset;

	/* gmtime() overwrites tm, so we need to copy it elsewhere */
	ltm = *tm;
	tm = gmtime(&t);
	gtm = *tm;

	/* max offset of 24 hours */
	if (ltm.tm_yday < gtm.tm_yday)
		offset = -24 * 60;
	else if (ltm.tm_yday > gtm.tm_yday)
		offset = 24 * 60;
	else
		offset = 0;

	offset += (ltm.tm_hour - gtm.tm_hour) * 60;
	offset += (ltm.tm_min - gtm.tm_min);

	/* restore overwritten tm */
	*tm = ltm;
	return offset;
#endif
}

--- NEW FILE: utc-offset.h ---
#ifndef __UTC_OFFSET_H
#define __UTC_OFFSET_H

#include <time.h>

/* Returns given time's offset to UTC in minutes. */
int utc_offset(struct tm *tm, time_t t);

#endif

Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Makefile.am	13 Oct 2002 23:49:11 -0000	1.8
+++ Makefile.am	24 Oct 2002 00:15:38 -0000	1.9
@@ -18,7 +18,6 @@
 	fdpass.c \
 	file-lock.c \
 	file-set-size.c \
-	gmtoff.c \
 	hash.c \
 	hex-binary.c \
 	hostpid.c \
@@ -50,6 +49,8 @@
 	temp-string.c \
 	unlink-directory.c \
 	unlink-lockfiles.c \
+	utc-offset.c \
+	utc-mktime.c \
 	write-full.c
 
 noinst_HEADERS = \
@@ -60,7 +61,6 @@
 	fdpass.h \
 	file-lock.h \
 	file-set-size.h \
-	gmtoff.h \
 	hash.h \
 	hex-binary.h \
 	hostpid.h \
@@ -87,6 +87,8 @@
 	temp-string.h \
 	unlink-directory.h \
 	unlink-lockfiles.h \
+	utc-offset.h \
+	utc-mktime.h \
 	write-full.h
 
 EXTRA_DIST = \

Index: ioloop.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ioloop.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ioloop.c	10 Oct 2002 02:01:34 -0000	1.5
+++ ioloop.c	24 Oct 2002 00:15:38 -0000	1.6
@@ -37,6 +37,7 @@
 
 time_t ioloop_time = 0;
 struct timeval ioloop_timeval;
+struct timezone ioloop_timezone;
 
 static IOLoop current_ioloop = NULL;
 
@@ -253,7 +254,7 @@
 	struct timeval tv;
         int t_id;
 
-	gettimeofday(&ioloop_timeval, NULL);
+	gettimeofday(&ioloop_timeval, &ioloop_timezone);
 	ioloop_time = ioloop_timeval.tv_sec;
 
 	if (ioloop->timeouts == NULL || !ioloop->timeouts->run_now)
@@ -306,7 +307,7 @@
 	IOLoop ioloop;
 
 	/* initialize time */
-	gettimeofday(&ioloop_timeval, NULL);
+	gettimeofday(&ioloop_timeval, &ioloop_timezone);
 	ioloop_time = ioloop_timeval.tv_sec;
 
         ioloop = p_new(pool, struct _IOLoop, 1);

Index: ioloop.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ioloop.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ioloop.h	8 Oct 2002 23:26:08 -0000	1.3
+++ ioloop.h	24 Oct 2002 00:15:38 -0000	1.4
@@ -17,6 +17,7 @@
    Can be used instead of time(NULL). */
 extern time_t ioloop_time;
 extern struct timeval ioloop_timeval;
+extern struct timezone ioloop_timezone;
 
 /* I/O listeners - you can create different handlers for IO_READ and IO_WRITE,
    but make sure you don't create multiple handlers of same type, it's not

--- gmtoff.c DELETED ---

--- gmtoff.h DELETED ---


From cras@procontrol.fi  Thu Oct 24 03:15:41 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 208822382C
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/imap cmd-append.c,1.12,1.13
Message-Id: <20021024001541.208822382C@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
X-archive-position: 25
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/imap
In directory danu:/tmp/cvs-serv28234/imap

Modified Files:
	cmd-append.c 
Log Message:
Fixes to timezone handling which were handling quite badly. added
ioloop_timezone which gets updated with ioloop_time. Changed some GMT
references to UTC. Timezone offsets are in minutes now everywhere instead of
seconds. Fixes for unsigned time_t.



Index: cmd-append.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-append.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- cmd-append.c	19 Oct 2002 14:51:59 -0000	1.12
+++ cmd-append.c	24 Oct 2002 00:15:38 -0000	1.13
@@ -7,6 +7,8 @@
 #include "imap-parser.h"
 #include "imap-date.h"
 
+#include <sys/time.h>
+
 /* Returns -1 = error, 0 = need more data, 1 = successful. flags and
    internal_date may be NULL as a result, but mailbox and msg_size are always
    set when successful. */
@@ -78,7 +80,7 @@
 	const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT];
 	const char *mailbox, *internal_date_str;
 	uoff_t msg_size;
-	int failed;
+	int failed, timezone_offset;
 
 	/* <mailbox> [<flags>] [<internal date>] <message literal> */
 	switch (validate_args(client, &mailbox, &flags_list,
@@ -106,7 +108,9 @@
 	if (internal_date_str == NULL) {
 		/* no time given, default to now. */
 		internal_date = ioloop_time;
-	} else if (!imap_parse_datetime(internal_date_str, &internal_date)) {
+                timezone_offset = ioloop_timezone.tz_minuteswest;
+	} else if (!imap_parse_datetime(internal_date_str, &internal_date,
+					&timezone_offset)) {
 		client_send_tagline(client, "BAD Invalid internal date.");
 		return TRUE;
 	}
@@ -126,7 +130,8 @@
 	o_buffer_flush(client->outbuf);
 
 	/* save the mail */
-	failed = !box->save(box, flags, custom_flags, internal_date,
+	failed = !box->save(box, flags, custom_flags,
+			    internal_date, timezone_offset,
 			    client->inbuf, msg_size);
 	box->close(box);
 


From cras@procontrol.fi  Thu Oct 24 03:15:41 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 3E52D2385D
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-imap imap-date.c,1.2,1.3 imap-date.h,1.1,1.2
Message-Id: <20021024001541.3E52D2385D@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
X-archive-position: 26
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-imap
In directory danu:/tmp/cvs-serv28234/lib-imap

Modified Files:
	imap-date.c imap-date.h 
Log Message:
Fixes to timezone handling which were handling quite badly. added
ioloop_timezone which gets updated with ioloop_time. Changed some GMT
references to UTC. Timezone offsets are in minutes now everywhere instead of
seconds. Fixes for unsigned time_t.



Index: imap-date.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-date.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imap-date.c	2 Sep 2002 19:14:17 -0000	1.2
+++ imap-date.c	24 Oct 2002 00:15:38 -0000	1.3
@@ -1,7 +1,8 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "lib.h"
-#include "gmtoff.h"
+#include "utc-offset.h"
+#include "utc-mktime.h"
 
 #include <ctype.h>
 
@@ -20,7 +21,7 @@
 	    !i_isdigit(str[3]) || !i_isdigit(str[4]))
 		return 0;
 
-	offset = (str[1]-'0') * 1000 + (str[2]-'0') * 100 +
+	offset = (str[1]-'0') * 10*60 + (str[2]-'0') * 60 +
 		(str[3]-'0') * 10 + (str[4]-'0');
 	return *str == '+' ? offset : -offset;
 }
@@ -79,7 +80,7 @@
 
 int imap_parse_date(const char *str, time_t *time)
 {
-	struct tm tm;
+	struct tm tm, *tml;
 
 	str = imap_parse_date_internal(str, &tm);
 	if (str == NULL)
@@ -87,13 +88,18 @@
 
 	tm.tm_isdst = -1;
 	*time = mktime(&tm);
-	return *time >= 0;
+	if (*time == (time_t)-1)
+		return FALSE;
+
+	/* get it to UTC */
+	tml = localtime(time);
+        *time -= utc_offset(tml, *time);
+	return TRUE;
 }
 
-int imap_parse_datetime(const char *str, time_t *time)
+int imap_parse_datetime(const char *str, time_t *time, int *timezone_offset)
 {
 	struct tm tm;
-	int zone_offset;
 
 	str = imap_parse_date_internal(str, &tm);
 	if (str == NULL)
@@ -122,44 +128,49 @@
 	str += 3;
 
 	/* timezone */
-	zone_offset = parse_timezone(str);
+	*timezone_offset = parse_timezone(str);
 
 	tm.tm_isdst = -1;
-	*time = mktime(&tm);
-	if (*time < 0)
+	*time = utc_mktime(&tm);
+	if (*time == (time_t)-1)
 		return FALSE;
 
-	*time -= zone_offset * 60;
+	*time -= *timezone_offset * 60;
 	return TRUE;
 }
 
-const char *imap_to_datetime(time_t time)
+const char *imap_to_datetime_internal(struct tm *tm, int timezone_offset)
 {
-	struct tm *tm;
-	int offset, negative;
+	int negative;
 
-	tm = localtime(&time);
-	offset = gmtoff(tm, time);
-	if (offset >= 0)
+	if (timezone_offset >= 0)
 		negative = 0;
 	else {
 		negative = 1;
-		offset = -offset;
+		timezone_offset = -timezone_offset;
 	}
-	offset /= 60;
 
 	return t_strdup_printf("%02d-%s-%04d %02d:%02d:%02d %c%02d%02d",
 			       tm->tm_mday, month_names[tm->tm_mon],
 			       tm->tm_year+1900,
 			       tm->tm_hour, tm->tm_min, tm->tm_sec,
-			       negative ? '-' : '+', offset / 60, offset % 60);
+			       negative ? '-' : '+',
+			       timezone_offset / 60, timezone_offset % 60);
 }
 
-const char *imap_to_date(time_t time)
+const char *imap_to_datetime_offset(time_t time, int timezone_offset)
+{
+	struct tm *tm;
+
+	time += timezone_offset;
+	tm = gmtime(&time);
+	return imap_to_datetime_internal(tm, timezone_offset);
+}
+
+const char *imap_to_datetime(time_t time)
 {
 	struct tm *tm;
 
 	tm = localtime(&time);
-	return t_strdup_printf("%d-%s-%04d", tm->tm_mday,
-			       month_names[tm->tm_mon], tm->tm_year+1900);
+	return imap_to_datetime_internal(tm, utc_offset(tm, time));
 }

Index: imap-date.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-date.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- imap-date.h	2 Sep 2002 19:08:47 -0000	1.1
+++ imap-date.h	24 Oct 2002 00:15:38 -0000	1.2
@@ -1,10 +1,15 @@
 #ifndef __IMAP_DATE_H
 #define __IMAP_DATE_H
 
+/* Parses IMAP date/time string. time_t is filled with UTC date.
+   timezone_offset is filled with parsed timezone. If no timezone is given,
+   local timezone is assumed. */
 int imap_parse_date(const char *str, time_t *time);
-int imap_parse_datetime(const char *str, time_t *time);
+int imap_parse_datetime(const char *str, time_t *time, int *timezone_offset);
 
+/* Returns given UTC time in given timezone. */
+const char *imap_to_datetime_offset(time_t time, int timezone_offset);
+/* Returns given UTC time in local timezone. */
 const char *imap_to_datetime(time_t time);
-const char *imap_to_date(time_t time);
 
 #endif


From cras@procontrol.fi  Thu Oct 24 03:15:41 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 458862385F
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-mail rfc822-date.c,1.6,1.7 rfc822-date.h,1.2,1.3
Message-Id: <20021024001541.458862385F@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
X-archive-position: 27
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-mail
In directory danu:/tmp/cvs-serv28234/lib-mail

Modified Files:
	rfc822-date.c rfc822-date.h 
Log Message:
Fixes to timezone handling which were handling quite badly. added
ioloop_timezone which gets updated with ioloop_time. Changed some GMT
references to UTC. Timezone offsets are in minutes now everywhere instead of
seconds. Fixes for unsigned time_t.



Index: rfc822-date.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/rfc822-date.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- rfc822-date.c	11 Oct 2002 22:33:54 -0000	1.6
+++ rfc822-date.c	24 Oct 2002 00:15:39 -0000	1.7
@@ -1,7 +1,8 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "lib.h"
-#include "gmtoff.h"
+#include "utc-offset.h"
+#include "utc-mktime.h"
 #include "rfc822-date.h"
 #include "rfc822-tokenize.h"
 
@@ -196,14 +197,15 @@
 	/* timezone */
 	if (tok == NULL || tok->token != 'A')
 		return FALSE;
-
 	*timezone_offset = parse_timezone(tok->ptr, tok->len);
 
 	tm.tm_isdst = -1;
-	*time = mktime(&tm);
-	if (*time < 0)
+	*time = utc_mktime(&tm);
+	if (*time == (time_t)-1)
 		return FALSE;
 
+	*time -= *timezone_offset;
+
 	return TRUE;
 }
 
@@ -213,14 +215,13 @@
 	int offset, negative;
 
 	tm = localtime(&time);
-	offset = gmtoff(tm, time);
+	offset = utc_offset(tm, time);
 	if (offset >= 0)
 		negative = 0;
 	else {
 		negative = 1;
 		offset = -offset;
 	}
-	offset /= 60;
 
 	return t_strdup_printf("%s, %02d %s %04d %02d:%02d:%02d %c%02d%02d",
 			       weekday_names[tm->tm_wday],

Index: rfc822-date.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/rfc822-date.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rfc822-date.h	11 Oct 2002 22:33:54 -0000	1.2
+++ rfc822-date.h	24 Oct 2002 00:15:39 -0000	1.3
@@ -1,9 +1,8 @@
 #ifndef __RFC822_DATE
 #define __RFC822_DATE
 
-/* Parses RFC822 date/time string. time_t is filled with the date without
-   any timezone changes. timezone_offset is filled with the timezone's
-   difference to UTC in minutes. */
+/* Parses RFC822 date/time string. timezone_offset is filled with the
+   timezone's difference to UTC in minutes. */
 int rfc822_parse_date(const char *str, time_t *time, int *timezone_offset);
 
 /* Create RFC822 date/time string from given time in local timezone. */


From cras@procontrol.fi  Thu Oct 24 03:15:41 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 4DC2423860
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index/mbox mbox-append.c,1.29,1.30 mbox-from.c,1.5,1.6 mbox-index.c,1.37,1.38
Message-Id: <20021024001541.4DC2423860@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
X-archive-position: 29
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index/mbox
In directory danu:/tmp/cvs-serv28234/lib-index/mbox

Modified Files:
	mbox-append.c mbox-from.c mbox-index.c 
Log Message:
Fixes to timezone handling which were handling quite badly. added
ioloop_timezone which gets updated with ioloop_time. Changed some GMT
references to UTC. Timezone offsets are in minutes now everywhere instead of
seconds. Fixes for unsigned time_t.



Index: mbox-append.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-append.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- mbox-append.c	13 Oct 2002 23:49:11 -0000	1.29
+++ mbox-append.c	24 Oct 2002 00:15:39 -0000	1.30
@@ -60,7 +60,7 @@
 
 	/* parse the From-line */
 	internal_date = mbox_from_parse_date((char *) data, size);
-	if (internal_date <= 0)
+	if (internal_date == (time_t)-1)
 		internal_date = ioloop_time;
 
 	i_buffer_skip(inbuf, pos+1);

Index: mbox-from.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-from.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mbox-from.c	24 Sep 2002 16:17:39 -0000	1.5
+++ mbox-from.c	24 Oct 2002 00:15:39 -0000	1.6
@@ -26,7 +26,7 @@
 
 	/* From <sender> <date> <moreinfo> */
 	if (strncmp(msg, "From ", 5) != 0)
-		return 0;
+		return (time_t)-1;
 
 	msg_end = msg + size;
 
@@ -38,7 +38,7 @@
 	/* next 24 chars are the date in asctime() format,
 	   eg. "Thu Nov 29 22:33:52 2001" */
 	if (msg+24 > msg_end)
-		return 0;
+		return (time_t)-1;
 
 	memset(&tm, 0, sizeof(tm));
 
@@ -54,43 +54,43 @@
 	}
 
 	if (i == 12 || msg[3] != ' ')
-		return 0;
+		return (time_t)-1;
 	msg += 4;
 
 	/* day */
 	if (msg[0] == ' ') {
 		if (!i_isdigit(msg[1]) || msg[2] != ' ')
-			return 0;
+			return (time_t)-1;
 		tm.tm_mday = msg[1]-'0';
 	} else {
 		if (!i_isdigit(msg[0]) || !i_isdigit(msg[1]) || msg[2] != ' ')
-			return 0;
+			return (time_t)-1;
 		tm.tm_mday = (msg[0]-'0') * 10 + (msg[1]-'0');
 	}
 	msg += 3;
 
 	/* hour */
 	if (!i_isdigit(msg[0]) || !i_isdigit(msg[1]) || msg[2] != ':')
-		return 0;
+		return (time_t)-1;
 	tm.tm_hour = (msg[0]-'0') * 10 + (msg[1]-'0');
 	msg += 3;
 
 	/* minute */
 	if (!i_isdigit(msg[0]) || !i_isdigit(msg[1]) || msg[2] != ':')
-		return 0;
+		return (time_t)-1;
 	tm.tm_min = (msg[0]-'0') * 10 + (msg[1]-'0');
 	msg += 3;
 
 	/* second */
 	if (!i_isdigit(msg[0]) || !i_isdigit(msg[1]) || msg[2] != ' ')
-		return 0;
+		return (time_t)-1;
 	tm.tm_sec = (msg[0]-'0') * 10 + (msg[1]-'0');
 	msg += 3;
 
 	/* year */
 	if (!i_isdigit(msg[0]) || !i_isdigit(msg[1]) ||
 	    !i_isdigit(msg[2]) || !i_isdigit(msg[3]))
-		return 0;
+		return (time_t)-1;
 	tm.tm_year = (msg[0]-'0') * 1000 + (msg[1]-'0') * 100 +
 		(msg[2]-'0') * 10 + (msg[3]-'0') - 1900;
 

Index: mbox-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-index.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- mbox-index.c	21 Oct 2002 00:09:29 -0000	1.37
+++ mbox-index.c	24 Oct 2002 00:15:39 -0000	1.38
@@ -395,7 +395,7 @@
 				msg += startpos;
 				i -= startpos;
 				return mbox_from_parse_date((char *) msg,
-							    size) != 0;
+							    size) != (time_t)-1;
 			}
 		}
 	}


From cras@procontrol.fi  Thu Oct 24 03:15:41 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 51D6623861
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-storage mail-storage.h,1.16,1.17
Message-Id: <20021024001541.51D6623861@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
X-archive-position: 28
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-storage
In directory danu:/tmp/cvs-serv28234/lib-storage

Modified Files:
	mail-storage.h 
Log Message:
Fixes to timezone handling which were handling quite badly. added
ioloop_timezone which gets updated with ioloop_time. Changed some GMT
references to UTC. Timezone offsets are in minutes now everywhere instead of
seconds. Fixes for unsigned time_t.



Index: mail-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/mail-storage.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- mail-storage.h	19 Oct 2002 23:09:56 -0000	1.16
+++ mail-storage.h	24 Oct 2002 00:15:39 -0000	1.17
@@ -158,9 +158,12 @@
 	int (*search)(Mailbox *box, MailSearchArg *args,
 		      OBuffer *outbuf, int uid_result);
 
-	/* Save a new mail into mailbox. */
+	/* Save a new mail into mailbox. timezone_offset specifies the
+	   timezone in minutes which internal_date was originally given
+	   with. */
 	int (*save)(Mailbox *box, MailFlags flags, const char *custom_flags[],
-		    time_t internal_date, IBuffer *data, uoff_t data_size);
+		    time_t internal_date, int timezone_offset,
+		    IBuffer *data, uoff_t data_size);
 
 	/* Returns TRUE if mailbox is now in inconsistent state, meaning that
 	   the message IDs etc. may have changed - only way to recover this


From cras@procontrol.fi  Thu Oct 24 03:15:42 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:15:42 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 6079523862
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-storage/index index-copy.c,1.16,1.17
Message-Id: <20021024001541.6079523862@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
X-archive-position: 31
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-storage/index
In directory danu:/tmp/cvs-serv28234/lib-storage/index

Modified Files:
	index-copy.c 
Log Message:
Fixes to timezone handling which were handling quite badly. added
ioloop_timezone which gets updated with ioloop_time. Changed some GMT
references to UTC. Timezone offsets are in minutes now everywhere instead of
seconds. Fixes for unsigned time_t.



Index: index-copy.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-copy.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- index-copy.c	20 Oct 2002 00:17:21 -0000	1.16
+++ index-copy.c	24 Oct 2002 00:15:39 -0000	1.17
@@ -27,7 +27,7 @@
 
 	/* save it in destination mailbox */
 	failed = !ctx->dest->save(ctx->dest, rec->msg_flags,
-				  ctx->custom_flags, rec->internal_date,
+				  ctx->custom_flags, rec->internal_date, 0,
 				  inbuf, inbuf->v_size);
 
 	i_buffer_unref(inbuf);


From cras@procontrol.fi  Thu Oct 24 03:15:42 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:15:42 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 7AA63238BF
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-save.c,1.8,1.9 maildir-storage.h,1.6,1.7
Message-Id: <20021024001541.7AA63238BF@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
X-archive-position: 30
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-storage/index/maildir
In directory danu:/tmp/cvs-serv28234/lib-storage/index/maildir

Modified Files:
	maildir-save.c maildir-storage.h 
Log Message:
Fixes to timezone handling which were handling quite badly. added
ioloop_timezone which gets updated with ioloop_time. Changed some GMT
references to UTC. Timezone offsets are in minutes now everywhere instead of
seconds. Fixes for unsigned time_t.



Index: maildir-save.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-save.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- maildir-save.c	21 Oct 2002 00:24:54 -0000	1.8
+++ maildir-save.c	24 Oct 2002 00:15:39 -0000	1.9
@@ -78,6 +78,7 @@
 
 int maildir_storage_save(Mailbox *box, MailFlags flags,
 			 const char *custom_flags[], time_t internal_date,
+			 int timezone_offset __attr_unused__,
 			 IBuffer *data, uoff_t data_size)
 {
         IndexMailbox *ibox = (IndexMailbox *) box;
@@ -110,7 +111,11 @@
 	/* set the internal_date by modifying mtime */
 	buf.actime = ioloop_time;
 	buf.modtime = internal_date;
-	(void)utime(tmp_path, &buf);
+	if (utime(tmp_path, &buf) < 0) {
+		/* just warn, don't bother actually failing */
+		mail_storage_set_critical(box->storage, "utime() failed for "
+					  "%s: %m", tmp_path);
+	}
 
 	/* move the file into new/ directory - syncing will pick it
 	   up from there */

Index: maildir-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- maildir-storage.h	21 Oct 2002 00:24:54 -0000	1.6
+++ maildir-storage.h	24 Oct 2002 00:15:39 -0000	1.7
@@ -6,7 +6,8 @@
 int maildir_storage_copy(Mailbox *box, Mailbox *destbox,
 			 const char *messageset, int uidset);
 int maildir_storage_save(Mailbox *box, MailFlags flags,
-			 const char *custom_flags[], time_t internal_date,
+			 const char *custom_flags[],
+			 time_t internal_date, int timezone_offset,
 			 IBuffer *data, uoff_t data_size);
 
 int maildir_find_mailboxes(MailStorage *storage, const char *mask,


From cras@procontrol.fi  Thu Oct 24 03:15:42 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:15:42 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 8D860238C2
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-save.c,1.18,1.19 mbox-storage.h,1.5,1.6
Message-Id: <20021024001541.8D860238C2@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:15:41 +0300 (EEST)
X-archive-position: 32
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-storage/index/mbox
In directory danu:/tmp/cvs-serv28234/lib-storage/index/mbox

Modified Files:
	mbox-save.c mbox-storage.h 
Log Message:
Fixes to timezone handling which were handling quite badly. added
ioloop_timezone which gets updated with ioloop_time. Changed some GMT
references to UTC. Timezone offsets are in minutes now everywhere instead of
seconds. Fixes for unsigned time_t.



Index: mbox-save.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-save.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- mbox-save.c	21 Oct 2002 00:09:29 -0000	1.18
+++ mbox-save.c	24 Oct 2002 00:15:39 -0000	1.19
@@ -87,6 +87,7 @@
 
 	sender = t_strconcat(storage->user, "@", my_hostdomain, NULL);
 
+	/* save in local timezone, no matter what it was given with */
 	line = mbox_from_create(sender, internal_date);
 	len = strlen(line);
 
@@ -148,7 +149,8 @@
 }
 
 int mbox_storage_save(Mailbox *box, MailFlags flags, const char *custom_flags[],
-		      time_t internal_date, IBuffer *data, uoff_t data_size)
+		      time_t internal_date, int timezone_offset __attr_unused__,
+		      IBuffer *data, uoff_t data_size)
 {
 	IndexMailbox *ibox = (IndexMailbox *) box;
 	MailFlags real_flags;

Index: mbox-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mbox-storage.h	19 Oct 2002 14:51:59 -0000	1.5
+++ mbox-storage.h	24 Oct 2002 00:15:39 -0000	1.6
@@ -6,7 +6,8 @@
 int mbox_storage_copy(Mailbox *box, Mailbox *destbox,
 		      const char *messageset, int uidset);
 int mbox_storage_save(Mailbox *box, MailFlags flags, const char *custom_flags[],
-		      time_t internal_date, IBuffer *data, uoff_t data_size);
+		      time_t internal_date, int timezone_offset,
+		      IBuffer *data, uoff_t data_size);
 
 int mbox_find_mailboxes(MailStorage *storage, const char *mask,
 			MailboxFunc func, void *context);


From cras@procontrol.fi  Thu Oct 24 03:17:30 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:17:30 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id DA0F12382D
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:17:30 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib utc-mktime.c,1.1,1.2 utc-offset.c,1.1,1.2
Message-Id: <20021024001730.DA0F12382D@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:17:30 +0300 (EEST)
X-archive-position: 33
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv28571

Modified Files:
	utc-mktime.c utc-offset.c 
Log Message:
comment cleanups



Index: utc-mktime.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/utc-mktime.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- utc-mktime.c	24 Oct 2002 00:15:38 -0000	1.1
+++ utc-mktime.c	24 Oct 2002 00:17:28 -0000	1.2
@@ -1,6 +1,4 @@
-/* mkgmtime.c - make time corresponding to a GMT timeval struct
- $Id$
- 
+/*
  * Copyright (c) 1998-2000 Carnegie Mellon University.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Index: utc-offset.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/utc-offset.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- utc-offset.c	24 Oct 2002 00:15:38 -0000	1.1
+++ utc-offset.c	24 Oct 2002 00:17:28 -0000	1.2
@@ -1,6 +1,4 @@
 /*
- compat.c : Compatibility functions for OSes not having them
-
     Copyright (c) 2002 Timo Sirainen
 
     Permission is hereby granted, free of charge, to any person obtaining


From cras@procontrol.fi  Thu Oct 24 03:30:31 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:30:31 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id E60FA2382D
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:30:31 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.344,1.345
Message-Id: <20021024003031.E60FA2382D@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:30:31 +0300 (EEST)
X-archive-position: 34
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv28821

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.344
retrieving revision 1.345
diff -u -d -r1.344 -r1.345
--- ChangeLog	23 Oct 2002 21:15:28 -0000	1.344
+++ ChangeLog	24 Oct 2002 00:30:29 -0000	1.345
@@ -1,3 +1,26 @@
+2002-10-24 00:17  Timo Sirainen <tss@iki.fi>
+
+	* src/lib/: utc-mktime.c, utc-offset.c: comment cleanups
+
+2002-10-24 00:15  Timo Sirainen <tss@iki.fi>
+
+	* src/: imap/cmd-append.c, lib/Makefile.am, lib/gmtoff.c,
+	lib/gmtoff.h, lib/ioloop.c, lib/ioloop.h, lib/utc-mktime.c,
+	lib/utc-mktime.h, lib/utc-offset.c, lib/utc-offset.h,
+	lib-imap/imap-date.c, lib-imap/imap-date.h,
+	lib-index/mbox/mbox-append.c, lib-index/mbox/mbox-from.c,
+	lib-index/mbox/mbox-index.c, lib-mail/rfc822-date.c,
+	lib-mail/rfc822-date.h, lib-storage/mail-storage.h,
+	lib-storage/index/index-copy.c,
+	lib-storage/index/maildir/maildir-save.c,
+	lib-storage/index/maildir/maildir-storage.h,
+	lib-storage/index/mbox/mbox-save.c,
+	lib-storage/index/mbox/mbox-storage.h: Fixes to timezone handling
+	which were handling quite badly. added ioloop_timezone which gets
+	updated with ioloop_time. Changed some GMT references to UTC.
+	Timezone offsets are in minutes now everywhere instead of seconds.
+	Fixes for unsigned time_t.
+
 2002-10-23 21:07  Timo Sirainen <tss@iki.fi>
 
 	* src/lib-index/maildir/maildir-index.c: Ignore and leave maildir


From cras@procontrol.fi  Thu Oct 24 03:34:22 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:34:22 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 3E7982382D
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:34:22 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot configure.in,1.34,1.35 acconfig.h,1.7,1.8
Message-Id: <20021024003422.3E7982382D@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:34:22 +0300 (EEST)
X-archive-position: 35
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv28902

Modified Files:
	configure.in acconfig.h 
Log Message:
Check fdatasync() from -lrt if it's not in libc (solaris). Also fallback to
fsync() entirely if fdatasync() doesn't exist.



Index: configure.in
===================================================================
RCS file: /home/cvs/dovecot/configure.in,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- configure.in	20 Oct 2002 03:15:16 -0000	1.34
+++ configure.in	24 Oct 2002 00:34:20 -0000	1.35
@@ -109,6 +109,15 @@
 	])
 ])
 
+AC_CHECK_FUNC(fdatasync, [
+	AC_DEFINE([HAVE_FDATASYNC])
+], [
+	AC_CHECK_LIB(rt, fdatasync, [
+		AC_DEFINE([HAVE_FDATASYNC])
+		LIBS="$LIBS -lrt"
+	])
+])
+
 dnl * after -lsocket and -lnsl tests, inet_aton() may be in them
 AC_CHECK_FUNCS(fcntl flock inet_aton sigaction getpagesize madvise setreuid)
 AC_CHECK_FUNCS(strcasecmp stricmp vsnprintf memmove vsyslog writev)

Index: acconfig.h
===================================================================
RCS file: /home/cvs/dovecot/acconfig.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- acconfig.h	14 Oct 2002 00:27:42 -0000	1.7
+++ acconfig.h	24 Oct 2002 00:34:20 -0000	1.8
@@ -52,3 +52,6 @@
 
 /* Define if you have Linux-compatible mremap() */
 #undef HAVE_LINUX_MREMAP
+
+/* Define if you have fdatasync() */
+#undef HAVE_FDATASYNC


From cras@procontrol.fi  Thu Oct 24 03:34:22 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:34:22 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 495FA23837
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:34:22 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib compat.h,1.6,1.7
Message-Id: <20021024003422.495FA23837@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:34:22 +0300 (EEST)
X-archive-position: 36
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv28902/src/lib

Modified Files:
	compat.h 
Log Message:
Check fdatasync() from -lrt if it's not in libc (solaris). Also fallback to
fsync() entirely if fdatasync() doesn't exist.



Index: compat.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/compat.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- compat.h	13 Oct 2002 23:49:11 -0000	1.6
+++ compat.h	24 Oct 2002 00:34:20 -0000	1.7
@@ -62,6 +62,10 @@
 int my_getpagesize(void);
 #endif
 
+#ifndef HAVE_FDATASYNC
+#  define fdatasync fsync
+#endif
+
 #ifndef HAVE_STRUCT_IOVEC
 struct iovec {
 	void *iov_base;


From cras@procontrol.fi  Thu Oct 24 03:45:31 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 03:45:31 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id A3ACB2382D
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 03:45:31 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot ChangeLog,1.345,1.346
Message-Id: <20021024004531.A3ACB2382D@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 03:45:31 +0300 (EEST)
X-archive-position: 37
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot
In directory danu:/tmp/cvs-serv29193

Modified Files:
	ChangeLog 
Log Message:
ChangeLog


Index: ChangeLog
===================================================================
RCS file: /home/cvs/dovecot/ChangeLog,v
retrieving revision 1.345
retrieving revision 1.346
diff -u -d -r1.345 -r1.346
--- ChangeLog	24 Oct 2002 00:30:29 -0000	1.345
+++ ChangeLog	24 Oct 2002 00:45:29 -0000	1.346
@@ -1,3 +1,9 @@
+2002-10-24 00:34  Timo Sirainen <tss@iki.fi>
+
+	* acconfig.h, configure.in, src/lib/compat.h: Check fdatasync()
+	from -lrt if it's not in libc (solaris). Also fallback to fsync()
+	entirely if fdatasync() doesn't exist.
+
 2002-10-24 00:17  Timo Sirainen <tss@iki.fi>
 
 	* src/lib/: utc-mktime.c, utc-offset.c: comment cleanups


From cras@procontrol.fi  Thu Oct 24 04:48:00 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 04:48:00 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id B5F462382C
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 04:48:00 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index mail-index-compress.c,1.16,1.17
Message-Id: <20021024014800.B5F462382C@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 04:48:00 +0300 (EEST)
X-archive-position: 38
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv30455

Modified Files:
	mail-index-compress.c 
Log Message:
Make sure we never truncate ourself smaller than INDEX_FILE_MIN_SIZE.



Index: mail-index-compress.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-compress.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- mail-index-compress.c	23 Oct 2002 19:49:23 -0000	1.16
+++ mail-index-compress.c	24 Oct 2002 01:47:58 -0000	1.17
@@ -33,6 +33,9 @@
 			(index->mmap_full_length - sizeof(MailIndexHeader)) %
 			sizeof(MailIndexRecord);
 
+		if (index->mmap_full_length < INDEX_FILE_MIN_SIZE)
+                        index->mmap_full_length = INDEX_FILE_MIN_SIZE;
+
 		if (ftruncate(index->fd, (off_t)index->mmap_full_length) < 0)
 			return index_set_syscall_error(index, "ftruncate()");
 


From cras@procontrol.fi  Thu Oct 24 04:48:35 2002
Received: with ECARTIS (v1.0.0; list dovecot-cvs); Thu, 24 Oct 2002 04:48:35 +0300 (EEST)
Return-Path: <cras@procontrol.fi>
Delivered-To: dovecot-cvs@procontrol.fi
Received: from danu.procontrol.fi (localhost [127.0.0.1])
	by danu.procontrol.fi (Postfix) with ESMTP id 96FE12382C
	for <dovecot-cvs@procontrol.fi>; Thu, 24 Oct 2002 04:48:35 +0300 (EEST)
From: cras@procontrol.fi
To: dovecot-cvs@procontrol.fi
Subject: [dovecot-cvs] dovecot/src/lib-index mail-tree-redblack.c,1.14,1.15 mail-tree.c,1.5,1.6 mail-tree.h,1.3,1.4
Message-Id: <20021024014835.96FE12382C@danu.procontrol.fi>
Date: Thu, 24 Oct 2002 04:48:35 +0300 (EEST)
X-archive-position: 39
X-Approved-By: cras@procontrol.fi
X-ecartis-version: Ecartis v1.0.0
Sender: dovecot-cvs-bounce@procontrol.fi
Errors-to: dovecot-cvs-bounce@procontrol.fi
X-original-sender: cras@procontrol.fi
Precedence: bulk
Reply-to: dovecot@procontrol.fi
X-list: dovecot-cvs

Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv30483/lib-index

Modified Files:
	mail-tree-redblack.c mail-tree.c mail-tree.h 
Log Message:
Instead of keeping "unused nodes" list in tree file, just move the last node 
over the deleted one. This way we're also able to truncate the file when
needed.



Index: mail-tree-redblack.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree-redblack.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mail-tree-redblack.c	23 Oct 2002 19:49:23 -0000	1.14
+++ mail-tree-redblack.c	24 Oct 2002 01:48:33 -0000	1.15
@@ -18,7 +18,10 @@
    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
+*/
+
+/* NOTE: currently this code doesn't do any bounds checkings. I'm not sure
+   if I should even bother, the code would just get uglier and slower. */
 
 #include "lib.h"
 #include "mail-index.h"
@@ -60,14 +63,6 @@
         MailTreeNode *node = tree->node_base;
 	unsigned int x;
 
-	if (tree->header->unused_root != RBNULL) {
-		/* use the nodes in the middle of the file */
-		x = tree->header->unused_root;
-		tree->header->unused_root = node[x].up;
-		return x;
-	}
-
-	/* use nodes at the end of file */
 	if (tree->mmap_used_length == tree->mmap_full_length) {
 		if (!_mail_tree_grow(tree))
 			return RBNULL;
@@ -77,20 +72,65 @@
 	i_assert(tree->mmap_used_length + sizeof(MailTreeNode) <=
 		 tree->mmap_full_length);
 
+	x = (tree->mmap_used_length - sizeof(MailTreeHeader)) /
+		sizeof(MailTreeNode);
+
 	tree->header->used_file_size += sizeof(MailTreeNode);
 	tree->mmap_used_length += sizeof(MailTreeNode);
 
-	return (tree->mmap_used_length - sizeof(MailTreeHeader)) /
-		sizeof(MailTreeNode) - 1;
+	memset(&node[x], 0, sizeof(MailTreeNode));
+	return x;
+}
+
+static void
+rb_move(MailTree *tree, unsigned int src, unsigned int dest)
+{
+	MailTreeNode *node = tree->node_base;
+
+	/* update parent */
+	if (node[src].up != RBNULL) {
+		if (node[node[src].up].left == src)
+			node[node[src].up].left = dest;
+		else if (node[node[src].up].right == src)
+			node[node[src].up].right = dest;
+	}
+
+	/* update children */
+	if (node[src].left != RBNULL)
+		node[node[src].left].up = dest;
+	if (node[src].right != RBNULL)
+		node[node[src].right].up = dest;
+
+	/* update root */
+	if (tree->header->root == src)
+		tree->header->root = dest;
+
+	memcpy(&node[dest], &node[src], sizeof(MailTreeNode));
+	memset(&node[src], 0, sizeof(MailTreeNode));
 }
 
 static void
 rb_free(MailTree *tree, unsigned int x)
 {
-        MailTreeNode *node = tree->node_base;
+	unsigned int last;
 
-	node[x].up = tree->header->unused_root;
-	tree->header->unused_root = x;
+	i_assert(tree->mmap_used_length >=
+		 sizeof(MailTreeHeader) + sizeof(MailTreeNode));
+
+	/* get index to last used record */
+	last = (tree->mmap_used_length - sizeof(MailTreeHeader)) /
+		sizeof(MailTreeNode) - 1;
+
+	if (last != x) {
+		/* move it over the one we want free'd */
+		rb_move(tree, last, x);
+	}
+
+	/* mark the moved node unused */
+	tree->mmap_used_length -= sizeof(MailTreeNode);
+	tree->header->used_file_size -= sizeof(MailTreeNode);
+
+	_mail_tree_truncate(tree);
 }
 
 /*

Index: mail-tree.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mail-tree.c	23 Oct 2002 19:49:23 -0000	1.5
+++ mail-tree.c	24 Oct 2002 01:48:33 -0000	1.6
@@ -11,8 +11,9 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-#define MAIL_TREE_INITIAL_SIZE \
-	(sizeof(MailTreeHeader) + sizeof(MailTreeNode) * 64)
+#define MAIL_TREE_MIN_SIZE \
+	(sizeof(MailTreeHeader) + \
+	 INDEX_MIN_RECORDS_COUNT * sizeof(MailTreeNode))
 
 static int tree_set_syscall_error(MailTree *tree, const char *function)
 {
@@ -46,8 +47,14 @@
 int _mail_tree_mmap_update(MailTree *tree, int forced)
 {
 	if (!forced && tree->header != NULL &&
-	    tree->mmap_full_length >= tree->header->used_file_size) {
+	    tree->sync_id == tree->header->sync_id) {
+		/* make sure file size hasn't changed */
 		tree->mmap_used_length = tree->header->used_file_size;
+		if (tree->mmap_used_length > tree->mmap_full_length) {
+			i_panic("Tree file size was grown without "
+				"updating sync_id");
+		}
+
 		return TRUE;
 	}
 
@@ -56,7 +63,7 @@
 	if (tree->mmap_base != NULL) {
 		/* make sure we're synced before munmap() */
 		if (tree->modified &&
-		    msync(tree->mmap_base, tree->mmap_used_length, MS_SYNC) < 0)
+		    msync(tree->mmap_base, tree->mmap_highwater, MS_SYNC) < 0)
 			return tree_set_syscall_error(tree, "msync()");
 		tree->modified = FALSE;
 
@@ -121,7 +128,9 @@
 	tree->header = tree->mmap_base;
 	tree->node_base = (MailTreeNode *) ((char *) tree->mmap_base +
 					    sizeof(MailTreeHeader));
+	tree->sync_id = hdr->sync_id;
 	tree->mmap_used_length = hdr->used_file_size;
+	tree->mmap_highwater = tree->mmap_used_length;
 	return TRUE;
 }
 
@@ -254,7 +263,7 @@
 		return tree_set_syscall_error(tree, "write_full()");
 	}
 
-	if (file_set_size(tree->fd, MAIL_TREE_INITIAL_SIZE) < 0) {
+	if (file_set_size(tree->fd, MAIL_TREE_MIN_SIZE) < 0) {
 		if (errno == ENOSPC)
 			tree->index->nodiskspace = TRUE;
 
@@ -302,11 +311,13 @@
 
 	i_assert(tree->mmap_base != NULL);
 
-	if (msync(tree->mmap_base, tree->mmap_used_length, MS_SYNC) < 0)
+	if (msync(tree->mmap_base, tree->mmap_highwater, MS_SYNC) < 0)
 		return tree_set_syscall_error(tree, "msync()");
 
-	*fsync_fd = tree->fd;
+	tree->mmap_highwater = tree->mmap_used_length;
 	tree->modified = FALSE;
+
+	*fsync_fd = tree->fd;
 	return TRUE;
 }
 
@@ -344,8 +355,47 @@
 		return tree_set_syscall_error(tree, "file_set_size()");
 	}
 
+	/* file size changed, let others know about 