message-header-hash.c revision b696d1d6df36a78441175535f5049eb29d5beb93
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen/* Copyright (c) 2013-2017 Dovecot authors, see the included COPYING file */
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainenvoid message_header_hash_more(struct message_header_hash_context *ctx,
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen const struct hash_method *method, void *context,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen unsigned int version,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen i_assert(version >= 1 && version <= MESSAGE_HEADER_HASH_MAX_VERSION);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* - Dovecot IMAP replaces NULs with 0x80 character.
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen - Dovecot POP3 with outlook-no-nuls workaround replaces NULs
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen with 0x80 character.
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen - Zimbra replaces 8bit chars with '?' in header fetches,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen but not body fetches.
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainen - Yahoo replaces 8bit chars with '?' in partial header
68b5e132f1f8bb2528482310daffcc06c2f019d3Timo Sirainen fetches, but not POP3 TOP. UTF-8 character sequence writes only a
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen So we'll just replace all control and 8bit chars with '?' and
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen remove any repeated '?', which hopefully will satisfy everybody.
dc53fff3700362b544dcba166ff81420db227a60Timo Sirainen - Zimbra removes trailing spaces and tabs from IMAP BODY[HEADER],
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen but not IMAP BODY[] or POP3 TOP. Just strip away all spaces with
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen version 3 and tabs also with version 4.
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen switch (data[i]) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* strip away spaces */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* strip away tabs */
57b819d3aa978b88ef478e4f2397c32db231ebb7Timo Sirainen if (data[i] < 0x20 || data[i] >= 0x7f || data[i] == '?') {
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainen /* remove repeated '?' */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen if (start < i || !ctx->prev_was_questionmark) {