This easy to correct errors is unfortunately still exists.
I once hung my solution, but I can only test on a system.


# dovecot --version
2.2.16.rc1
# doveadm -f table mailbox status "messages guid" -u flor_hardy "*"
mailbox   messages guid
Trash     0        60a619171f66fd54035800004b126f5b
Entwürfe 0        62a619171f66fd54035800004b126f5b
INBOX     0        61a619171f66fd54035800004b126f5b

diff -Nubr src.org/doveadm/doveadm-print-table.c src/doveadm/doveadm-print-table.c
--- src.org/doveadm/doveadm-print-table.c	2015-01-29 17:01:15.000000000 +0100
+++ src/doveadm/doveadm-print-table.c	2015-03-09 11:53:34.041973877 +0100
@@ -46,6 +46,22 @@
 	thdr->flags = hdr->flags;
 }
 
+static size_t utf8len(const char *s)
+{
+  size_t len = 0;
+  while(*s)
+    len += (*(s++)&0xC0)!=0x80;
+  return len;
+}
+
+static size_t utf8correction(const char *s)
+{
+  size_t len = 0;
+  while(*s)
+    len += (*(s++)&0xC0)==0x80;
+  return len;
+}
+
 static void doveadm_calc_header_length(void)
 {
 	struct doveadm_print_table_header *headers;
@@ -64,7 +80,7 @@
 	for (line = 0; line < line_count; line++) {
 		for (i = 0; i < hdr_count; i++) {
 			value = values[line*hdr_count + i];
-			len = value == NULL ? 0 : strlen(value);
+			len = value == NULL ? 0 : utf8len(value);
 			if (headers[i].min_length > len)
 				headers[i].min_length = len;
 			if (headers[i].max_length < len) {
@@ -123,9 +139,9 @@
 	hdr = array_idx(&ctx->headers, ctx->hdr_idx);
 
 	if ((hdr->flags & DOVEADM_PRINT_HEADER_FLAG_RIGHT_JUSTIFY) == 0)
-		printf("%-*s", (int)hdr->length, value);
+		printf("%-*s", (int)(hdr->length+utf8correction(value)), value);
 	else
-		printf("%*s", (int)hdr->length, value);
+		printf("%*s", (int)(hdr->length+utf8correction(value)), value);
 
 	if (++ctx->hdr_idx == array_count(&ctx->headers)) {
 		ctx->hdr_idx = 0;
--- Begin Message --- In calculating the column width multi-byte characters (eg umlauts, utf8) not properly analyzed:

Username mailbox        messages guid
sh_berger     Spam           0 a7b32818c14e5b54bf5500006ad9a53c
sh_berger     Entwürfe      0 a4b32818c14e5b54bf5500006ad9a53c
sh_berger     Papierkorb     0 a6b32818c14e5b54bf5500006ad9a53c

--- End Message ---

Reply via email to