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)
Timo Sirainen [Mon, 3 Jul 2017 18:08:02 +0000 (21:08 +0300)]
imapc: Prefech - Initialize cached stream only if needed
If the mail is immediately accessed for other purposes (e.g. fetching
message flags), there's no need to go through all the trouble of
initializing the mail stream.
Timo Sirainen [Fri, 30 Jun 2017 10:46:22 +0000 (13:46 +0300)]
lib-storage: Fix ITERINDEX to leave \NoSelect parents after deleting child mailbox
For example if "a/b" was created and deleted, "a" should be left behind.
(Or at least it shouldn't have left "a" to mail root directory and kept it
invisible since it didn't exist in index dir.)
Also add index_mailbox_update_last_temp_file_scan() for easily updating it.
This is reusing an old "sync timestamp" field. Because it was a timestamp,
it doesn't matter if the old data still exists in it. This field could have
been added as an extension, but that's more work and this feature is generic
enough that it should be useful for many of the mail storage backends.
Timo Sirainen [Mon, 26 Jun 2017 16:30:11 +0000 (19:30 +0300)]
lib-storage: Check for storage existence from index dir with ITERINDEX
The root path creation doesn't really even seem to be necessary, because any
mailbox access will automatically mkdir the missing directories anyway.
Although writing other files might not work so well, such as
mail_attribute_dict that points inside the mail directory.
This change simply changes the mailboxes/ directory to be looked up from
index directory instead of the mail root directory. It also mkdirs the
index/mailboxes/ directory afterwards if it didn't exist. So practically
this change shouldn't break anything, since the mailboxes/ directory should
always exist for both root and the indexes.
Timo Sirainen [Mon, 26 Jun 2017 17:10:17 +0000 (20:10 +0300)]
lib-storage: Add mail_location=..:ITERINDEX
This changes mailbox list iteration to work using INDEX directory instead of
the normal mail directory. This can be helpful when the indexes are stored
on a faster storage.
Timo Sirainen [Fri, 30 Jun 2017 10:56:54 +0000 (13:56 +0300)]
lib-storage: Fix mailbox delete to not delete childrens' INDEX or CONTROL dirs
If mail_location had separate INDEX and/or CONTROL set, deleting a mailbox
with children caused the childrens' index and/or control directories to be
deleted (but the mail/ALT directories weren't).
I'm not sure why the _FLAG_MAILBOX_FILES was treated as a special case
earlier. It shouldn't make a difference.
It should return error on unexpected readdir(), closedir() and unlink()
failures. Also fix handling a race condition with another process deleting
the mailbox at the same time.
Timo Sirainen [Tue, 27 Jun 2017 13:37:16 +0000 (16:37 +0300)]
lib-storage: Use mailbox_list_delete_finish_ret() for fs & maildir++ layout
Fixes a problem where e.g. index directory existed but mail root didn't,
and the mailbox couldn't be fully deleted. This was especially a problem
with ITERINDEX enabled.
It means that the user's home directory doesn't exist, which is pretty
unexpected. Home directory is supposed to be created when the storage is
initialized.
Timo Sirainen [Mon, 19 Jun 2017 20:43:17 +0000 (23:43 +0300)]
acl: Add acl_globals_only setting
The local dovecot-acl files aren't even attempted to be looked up if this is
set. This is mainly useful to avoid unnecessary stat()s to dovecot-acl files
that never exist.
Timo Sirainen [Sun, 18 Jun 2017 08:14:05 +0000 (11:14 +0300)]
imap: NOTIFY - Fix crash due to not hooking into commands correctly
The pre/post hooks aren't always called immediately when commands are
created. They're called only after the command input is being read.
Call notify hooks explicitly now immediately when commands are allocated.
Fixes a panic with for example:
a notify set (selected (Messagenew (uid flags) MessageExpunge FlagChange) personal (MessageNew MessageExpunge FlagChange))
b select inbox
c store 1 +flags \deleted
d expunge
e append inbox {10}
Which crashed with:
Panic: file imap-notify.c: line 397 (imap_notify_callback): assertion failed: (client->command_queue_size == 0)
Timo Sirainen [Mon, 12 Jun 2017 19:52:56 +0000 (22:52 +0300)]
*-login: Add client_vfuncs.input_next_cmd()
This allows plugins to hook into all the pre-login commands. For example
with imap-login most of the commands could already be hooked into, except
for ID and AUTHENTICATE because their parameters reading is handled
specially. This allows hooking into them as well.
This is actually internal to all the login binaries, so it wouldn't have to
be in login-common. However, login-common already has all the code to handle
overriding functions nicely and this is a rather useful feature for all the
protocols anyway, so it's easier this way and not too ugly.
Timo Sirainen [Mon, 12 Jun 2017 21:57:08 +0000 (00:57 +0300)]
imapc: Fix prefetching specific headers
FETCH BODY[HEADER.FIELDS ...] shouldn't be used if imapc_features doesn't
include fetch-headers. Also neither this nor BODY[HEADER] should be sent
if we already have header/body stream.
Timo Sirainen [Tue, 13 Jun 2017 19:14:11 +0000 (22:14 +0300)]
lib-index: Fix cache lookups from uncommitted transactions with in-memory indexes
This especially fixes mail_get_header_stream() with imapc and
imapc_features=fetch-headers, because it works by first fetching the
specific headers and putting them to the cache transaction, then later on
relying on index_mail_get_header_stream() to get them from the transaction.
Before this fix they wouldn't be found, which triggered another unnecessary
FETCH BODY.PEEK[HEADER].
Timo Sirainen [Mon, 12 Jun 2017 20:45:05 +0000 (23:45 +0300)]
push-notification: Switch to main ioloop while calling drivers' commit callbacks
There aren't any guarantees what ioloop happens to be active at the time
the commit is called. The active ioloop can also be destroyed early on,
which can cause an I/O leak and crashes later on.