summaryrefslogtreecommitdiffstats
path: root/src/lib-charset/charset-utf8-only.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/lib-charset/charset-utf8-only.c
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib-charset/charset-utf8-only.c')
-rw-r--r--src/lib-charset/charset-utf8-only.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/lib-charset/charset-utf8-only.c b/src/lib-charset/charset-utf8-only.c
new file mode 100644
index 0000000..e8ea810
--- /dev/null
+++ b/src/lib-charset/charset-utf8-only.c
@@ -0,0 +1,51 @@
+/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "charset-utf8-private.h"
+
+struct charset_translation {
+ normalizer_func_t *normalizer;
+};
+
+static int
+utf8only_charset_to_utf8_begin(const char *charset,
+ normalizer_func_t *normalizer,
+ struct charset_translation **t_r)
+{
+ struct charset_translation *t;
+
+ if (!charset_is_utf8(charset)) {
+ /* no support for charsets that need translation */
+ return -1;
+ }
+
+ t = i_new(struct charset_translation, 1);
+ t->normalizer = normalizer;
+ *t_r = t;
+ return 0;
+}
+
+static void utf8only_charset_to_utf8_end(struct charset_translation *t)
+{
+ i_free(t);
+}
+
+static void
+utf8only_charset_to_utf8_reset(struct charset_translation *t ATTR_UNUSED)
+{
+}
+
+static enum charset_result
+utf8only_charset_to_utf8(struct charset_translation *t,
+ const unsigned char *src, size_t *src_size,
+ buffer_t *dest)
+{
+ return charset_utf8_to_utf8(t->normalizer, src, src_size, dest);
+}
+
+const struct charset_utf8_vfuncs charset_utf8only = {
+ .to_utf8_begin = utf8only_charset_to_utf8_begin,
+ .to_utf8_end = utf8only_charset_to_utf8_end,
+ .to_utf8_reset = utf8only_charset_to_utf8_reset,
+ .to_utf8 = utf8only_charset_to_utf8,
+};