Timo Sirainen [Tue, 24 Apr 2018 15:01:03 +0000 (18:01 +0300)]
lib-mail: message_part_*_parse_from_header() - Replace NULs with 0x80
This avoids truncation of Content-*, Subject, Message-ID, In-Reply-To and
Date headers in IMAP ENVELOPE, BODY and BODYSTRUCTURE replies. Of course,
NULs in headers are violating RFCs already, so the previous behavior wasn't
really wrong either.
Timo Sirainen [Mon, 23 Apr 2018 10:39:13 +0000 (13:39 +0300)]
lib-storage: Don't add trailing NUL to strings in dovecot.index.cache
They are unnecessary and just unnecessarily consume disk space. The
existing reading code works even if they don't exist, so this change won't
break backwards compatibility.
Timo Sirainen [Sat, 21 Apr 2018 13:07:21 +0000 (16:07 +0300)]
lib-fts: fts-tokenizer-address - Cleanup NUL handling in parent_data
The end result is anyway that the token will be truncated at the first NUL.
This change just makes the code a bit more understandable on where the
truncation will happen.
Timo Sirainen [Sat, 21 Apr 2018 13:11:48 +0000 (16:11 +0300)]
lib: Add str_append_max()
It's otherwise the same as str_append_n(), except it takes const char* as
input instead of const void*. This, as well as its name, should make it
less likely to be used wrong when the input may legitimately have NULs.
The unit test is changed from str_append_n() to str_append_max(), because
str_append_n() will be deprecated.
It's not valid to have "\<CR>" or "\<LF>", so the old behavior isn't really
wrong either. However, rfc822_parse_quoted_string() callers are more likely
to expect that the output won't contain any [CR]LF so this new behavior is
a bit better.
Timo Sirainen [Sat, 21 Apr 2018 09:47:22 +0000 (12:47 +0300)]
lib-mail: Change rfc822_parse_content_param() API to allow NULs in value
This was the only function in rfc822-parser.h that wasn't NUL-safe.
This won't fix anything, but it makes the rfc822-parser.h API fully
consistent with the NUL handling.
Normally rfc2231_parse() should be called instead of calling
rfc822_parse_content_param() directly, so this shouldn't break any plugins.
Timo Sirainen [Sat, 21 Apr 2018 13:03:42 +0000 (16:03 +0300)]
login-common: Consistently truncate client SASL input at first NUL
The input is supposed to be base64-encoded, so there's no need to support
actual NUL characters. The previous code truncated at NULs, but could have
kept appending more data to the value. This could have produced somewhat
random results.
Timo Sirainen [Sat, 21 Apr 2018 12:58:15 +0000 (15:58 +0300)]
lib-master, util: Consistently truncate tabescaped input at the first NUL
The NULs are supposed to come tab-escaped, so there's no need to support
actual NUL characters. The previous code truncated at NULs, but could
have kept appending more data to the value. This could have produced
somewhat random results.
Timo Sirainen [Sat, 21 Apr 2018 12:53:42 +0000 (15:53 +0300)]
config: Consistently truncate value at the first NUL in value input file
When value contained "<file", the file was added as a value. The setting
values don't currently support NULs, so the value gets truncated at the
first NUL. However, the previous code could have appended more data to
the value. This could have produced somewhat confusing results.
Timo Sirainen [Sat, 21 Apr 2018 12:50:08 +0000 (15:50 +0300)]
dict-fs/memcached-ascii/redis: Consistently truncate value at NULs
The dict API currently doesn't support NULs in values, so they have to be
truncated. However, previously they were truncated at NULs, but more data
may have still been appended to the value. This could have produced
somewhat random results.
Timo Sirainen [Sat, 21 Apr 2018 11:31:08 +0000 (14:31 +0300)]
lib-storage: Fix truncating header values at NUL when adding to cache
For example FETCH BODY.PEEK[HEADER.FIELDS (Subject)] could have returned
the NUL on the first fetch when the mail wasn't in dovecot.index.cache,
but the second FETCH would have returned it truncated at the NUL.
Stephan Bosch [Sat, 14 Apr 2018 00:05:51 +0000 (02:05 +0200)]
lib: Implement str_sanitize_utf8().
Unlike str_sanitize(), this function truncates strings based on a UTF8 code point
limit rather than a maximum size in bytes. Also, the Unicode replacement
character is used to mark invalid/control characters and an ellipsis character
is used to indicate the string truncation. For the normal str_sanitize() this is
done using a question mark and triple dots respectively.
Timo Sirainen [Tue, 17 Apr 2018 12:46:41 +0000 (15:46 +0300)]
imapc: Fix expunges+appends in same session with imapc_features=no-msn-updates
Since the EXPUNGEs were ignored, the sequence numbers weren't updated.
When a new mail arrived, the sequence number sent by the remote IMAP server
pointed to existing mails in imapc's mapping. Fix this by changing the
sequence number if the returned UID is >= next_uid.
Timo Sirainen [Fri, 13 Apr 2018 13:14:18 +0000 (16:14 +0300)]
lib-master: If connect() to backend UNIX socket is retried, log a warning
For example if imap-login process needs to retry before it successfully
connects to imap process's socket, a warning is logged. This warning is
important because it means that the imap-login process may have been
sleeping up to 0.5 seconds and causing all the other connections to hang
during it.
It would be better to make this retrying asynchronous, but before spending
time on doing that, lets see if this warning is ever even being logged.
Timo Sirainen [Thu, 12 Apr 2018 11:27:50 +0000 (14:27 +0300)]
lib-smtp: Fix empty address parsing
sret wasn't initialized, which could have randomly caused "Path only
consists of source route" error with empty addresses. Broken by 81c8955e3d1475c6ab1892b1d3edf91126683fda
Stephan Bosch [Sun, 8 Apr 2018 13:53:37 +0000 (15:53 +0200)]
submission: Add workarounds for well-known MAIL and RCPT command syntax deviations.
This adds a new `submission_client_workarounds' setting that works analogous to
the `imap_client_workarounds' setting.
Workarounds:
- whitespace-before-path: Allow one or more spaces or tabs between `MAIL FROM:'
and path and between `RCPT TO:' and path.
- mailbox-for-path: Allow using bare Mailbox syntax (i.e., without <...>)
instead of full path syntax.
Stephan Bosch [Tue, 6 Mar 2018 22:11:32 +0000 (23:11 +0100)]
lib-storage: mail-storage-settings: Pre-parse postmaster_address as an SMTP address.
The pre-parsed address is not currently used anywhere, but this does check that
the postmaster address can successfully be converted to an SMTP address, which
is important for Pigeonhole.
Stephan Bosch [Tue, 6 Mar 2018 20:43:22 +0000 (21:43 +0100)]
lib-smtp: address: Add source syntax check for conversion from RFC5322 addresses.
The message-address parser (for RFC 5322) allows UTF-8 characters in the
localpart, which is not acceptable for SMTP addresses. This change adds a check
that determines whether the source RFC5222 address can be converted into a
SMTP address.