Some consumers of lib.h are in C++ and therefore they try to compile
byteorder.h as C++ code. C++ compilers don't like the implicit void *
-> struct anything * conversion, so we squelch those by adding explicit
casts.
Timo Sirainen [Tue, 25 Jul 2017 17:53:18 +0000 (20:53 +0300)]
lib-storage: Hide and rmdir \NoSelect leaf mailboxes with NO-NOSELECT
If the leaf is successfully rmdir()ed, rmdir() also its parents.
This doesn't work perfectly with if there are multiple levels of \NoSelect
mailboxes. For example with "a/b/c" the listing will already have returned
"a" and "a/b" before it reaches the "a/b/c" code, which will rmdir all of
them, but it's a bit too late at that point. It's too much work to fix
though, and the situation will be fixed on the next list anyway.
This controls whether to update INBOX's STATUS information in the mailbox
list index. It can be useful especially if LISTINDEX points to a tmpfs,
but perhaps also in other situations.
I considered adding a more generic setting to exclude other mailboxes, but
the namespace prefixes and hierarchy separators get a bit complicated with
shared mailboxes. It's probably also not very useful to change this for
anything but the INBOX.
Timo Sirainen [Fri, 21 Jul 2017 16:52:23 +0000 (19:52 +0300)]
virtual: Make sure index is rewritten when new mailboxes are added
Otherwise multiple bbox->sync_mailbox_idx point to 0 and they keep overwriting
each others in the header. This causes the header to be constantly updated with
wrong contents.
Timo Sirainen [Wed, 19 Jul 2017 10:43:09 +0000 (13:43 +0300)]
lib-index: Fix next_uid lookup in open transaction that has appended mails
The appended mails were used for returning an updated
mail_index_header.next_uid, but only if the mails were assigned UIDs in
mail_index_append(). It should have updated the next_uid also after
mail_index_append_finish_uids() was used to assign the UIDs.
This fixes setting first_recent_uid correctly for virtual mailboxes when the
sync finds new mails. Avoids multiple sessions from getting \Recent flags
for the same mails.
Aki Tuomi [Thu, 20 Jul 2017 08:01:37 +0000 (11:01 +0300)]
virtual: Do not remove mailbox notify if the mailbox is closed
The backend mailbox close/open status is not related to
the notify API usage. The notify is removed in
virtual_mailbox_close_internal instead when we are
actually deinitializing.
Timo Sirainen [Tue, 18 Jul 2017 11:42:23 +0000 (14:42 +0300)]
lib-index: Fix mail_index_get_modification_time() to work when index isn't open.
index->filepath may be NULL after a failed index open, and it's a bit unsafe
to trust that index->log->filepath isn't NULL either. So just build the full
path from elements that are definitely non-NULL.
Also stat() only dovecot.index.log, because it's always supposed to exist.
If it doesn't, something's broken and stat()ing dovecot.index doesn't make
much sense.
This commit removes mail_transaction_log_get_mtime(), which is no longer
needed.
Timo Sirainen [Tue, 18 Jul 2017 09:39:44 +0000 (12:39 +0300)]
lib-storage: Don't allow removing \Recent flags with mail_update_flags()
Reverts an ancient commit 7deb24e7453249d09741641bff0f269f68165033. I don't
know why it was added in the first place. Normally \Recent flags are
removed during sync with MAIL_INDEX_SYNC_FLAG_DROP_RECENT. This should be
enough, especially since it's not even possible to remove a single \Recent
flag - only update the first_recent_uid.
The code was also wrong: It was dropping \Recent flags even when
modify_type/flags combination didn't ask for it. Even if this was fixed,
there would still be race conditions with multiple processes since this
update is done without locking.
Fixes:
Error: Recent flags state corrupted for mailbox
Timo Sirainen [Mon, 17 Jul 2017 11:22:35 +0000 (14:22 +0300)]
lib-sql: Add API support for asynchronously iterating over rows.
sql_query() can already do an async lookup, but the full result needs
to be available immediately. This can be inefficient for large results.
Add a new SQL_RESULT_NEXT_MORE return value and sql_result_more() for
asynchronously requesting more results.
This changes the API a bit, but isn't done by default by any drivers yet.
Also callers that can't handle this are hopefully checking for "ret < 0",
which allows them to handle such an async-more request as an error
instead.
sql_result_next_row() will be changed to return enum in a separate commit to
keep backwards compatibility in v2.2.x.
Aki Tuomi [Wed, 28 Jun 2017 10:45:19 +0000 (13:45 +0300)]
virtual: Fix keywords handling
Keywords are per-mail object, and should be treated as one. The old
code left pointer to keywords dandling which lead into double-free.
Now the ctx->data is treated in similar way as other backends.
Aki Tuomi [Thu, 18 May 2017 11:59:51 +0000 (14:59 +0300)]
virtual: Match any metadata condition
The old code ignored succesful earlier matches for
patterns, and stopped looking on first non-matching
metadata pattern. Now it breaks on error or on first
matching pattern.
Timo Sirainen [Thu, 13 Jul 2017 23:11:56 +0000 (02:11 +0300)]
lib-storage: When index dir rmdir() fails with ENOTEMPTY, retry it for 1 second
This helps to avoid leaving those index directories lying around with NFS.
Hopefully within the 1 second any existing processes that have been keeping those
files open have finished their task. Especially IMAP IDLE will take 0.5 seconds
to start syncing indexes and realize that they're deleted.
Timo Sirainen [Thu, 13 Jul 2017 22:54:31 +0000 (01:54 +0300)]
lib-index: If refreshing finds dovecot.index.log gone, assume the mailbox was deleted
Don't try to recreate the log file again. It can just cause further problems.
A way to reproduce this problem with NFS when INDEX dir is specified:
* create mailbox foo, select foo, IDLE
* delete mailbox foo
--> foo's index is recreated back by IDLEing process
Timo Sirainen [Wed, 12 Jul 2017 23:56:33 +0000 (02:56 +0300)]
quota: When setting auto_updating to transaction, skip invisible quota roots
Skip the quota root also if the mailbox matches "ignore" quota_rule.
This is only an optimization fix so that unnecessary work isn't done for
quota roots that aren't actually used.
Aki Tuomi [Tue, 11 Jul 2017 07:45:16 +0000 (10:45 +0300)]
lib-storage: Remove user namespaces on hook error
If there is a hook error during namespaces added
remove the namespaces from user. This avoids attempts
to use the namespaces later on without proper initialization.
Make sure the directory isn't created if the mail root directory no longer
exists. This might happen during mailbox deletion when another process is
opening the mailbox at the same time.
Timo Sirainen [Tue, 11 Jul 2017 12:35:16 +0000 (15:35 +0300)]
lib-index: Track .log.2 rotation time in index header
This avoids unnecessarily stat()ing the file. Also it's a bit better
since it's tracking the actual rotation time, not the mtime of what the
.log file happened to have at the time of rotation.
The initial rotation timestamp is written only to the dovecot.index header
without going through dovecot.index.log. This works, because the
dovecot.index is written practically always after a log rotation. For the
rare cases when it doesn't happen, the dovecot.index.log.2 just gets
deleted later after the next log rotation.
Timo Sirainen [Tue, 11 Jul 2017 12:33:56 +0000 (15:33 +0300)]
lib-index: Check .log.2 rotation only when syncing
Instead of also whenever appending transactions to .log file. This
shouldn't change the behavior much, and it's needed for the following
change to work correctly.
Timo Sirainen [Mon, 10 Jul 2017 13:11:48 +0000 (16:11 +0300)]
lib-storage: Fix mailbox_update() to always update mailbox list index.
It previously was updating it only if the list index for the mailbox was
already fully up-to-date. But that doesn't really matter, because
mailbox_update() is supposed to be changing the values regardless.
This fixes mailbox_update() to always work with LAYOUT=index. It also
fixes mailbox_update() for INBOX to update UIDVALIDITY/GUID.
Timo Sirainen [Thu, 6 Jul 2017 14:45:02 +0000 (17:45 +0300)]
lib-storage: Set mailbox list index to be refreshed after changes, not before
Mailbox deletion and rename set the refresh-flag before the change was done.
This was unnecessary if the change didn't happen. Also there was a race
condition that another process could have done the refresh before the
change was even done.
Timo Sirainen [Mon, 10 Jul 2017 11:37:04 +0000 (14:37 +0300)]
lib-storage: Try to avoid opening mailbox list index on mailbox access
Perform the STATUS (and other relevant) updates only if syncing or
transaction commits changed anything. This could be optimized further to
check even more strongly whether the seen changes could cause changes to
the list index, but it's probably not worth the effort.
Timo Sirainen [Thu, 20 Oct 2016 14:45:44 +0000 (17:45 +0300)]
global: Replaced t_strsplit_tab() calls with t_strsplit_tabescaped()
This is useful especially in auth code to support LFs in extra fields.
Other pieces of code were also tab-escaping strings, but never unescaping
them. Usually it didn't matter, because nobody would use the escaped
characters. Still, the code wasn't exactly behaving correctly.
One downside to this change is that it's now possible to pass through TABs,
CRs and LFs through the various protocols. In theory this shouldn't cause
any problems, but combined with other bugs this could trigger some security
problems.
Timo Sirainen [Mon, 2 May 2016 21:25:43 +0000 (00:25 +0300)]
lib-storage: Another fix to mail storage initialization.
Allow mail_namespaces_init_location() to add the namespace directly to user,
since that's what the current callers always want. But compared to the
original code we're now calling mail_namespaces_init_finish() rather than
doing the same things ourself.
Timo Sirainen [Mon, 2 May 2016 14:00:22 +0000 (17:00 +0300)]
lib-storage: Changed mail storage initialization.
Most importantly require mail_namespaces_init_finish() after
mail_storage_create(). This was needed so that
mail_namespaces_created/added hook would always have the ns->list set, which
is required for several of the hooks to work (e.g. mailbox list index)