Hi again,

I had some troubles simplifying the UTF-7 transcoding in an elegant way
and without code duplication. 
But I think there is an easier solution to the problem, which involves
fewer hoops and less code.

The [RFC 6855][1] specifies the UTF8=ACCEPT and UTF8=ONLY IMAP server
capabilities, which are the same (except one is mandatory). The only
thing the client has to do is issue an "ENABLE UTF8=ACCEPT" command to
activate the use of the extension.
I tested that with the patch below, and it seems to work.
As far as I can tell, the extension allow to use UTF8 in quoted strings,
no particular gotchas in the syntax (section 3 of the RFC) but as I'm
not overly familiar with IMAP, I might have missed some.

The patch below is just enough to make it work (on my setup) ; I was not
sure where exactly I should insert the IMAP command execution, since it
seems there is several execution paths in the imap_open_store_*, and I'm
not sure I understand it right.
Where do you think the code should go ?

Additional things to think about :
- I don't know how widely that extension is implemented. I can say gmail
  imap does it, since it is what I use, but other IMAP servers might not
  provide this extension. So it might be less useful than the previous
  approach (transcoding from UTF7 IMAP).
- It might not be necessary to check for UTF8=ACCEPT in the capabilities
  before sending the ENABLE command. If I read [RFC 5161][2] (specifying
  the ENABLE extension for IMAP) correctly, the server is supposed to
  ignore unknowns extension, so checking for ENABLE might be enough
  (section 3.1).

[1]: https://tools.ietf.org/html/rfc6855
[2]: https://tools.ietf.org/html/rfc5161

Max Gautier

---
 src/drv_imap.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/drv_imap.c b/src/drv_imap.c
index 7bc88f6..88b2dbe 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -216,7 +216,9 @@ enum CAPABILITY {
        LITERALPLUS,
        MOVE,
        NAMESPACE,
-       COMPRESS_DEFLATE
+       COMPRESS_DEFLATE,
+       UTF8_ACCEPT,
+       UTF8_ONLY
 };
 
 static const char *cap_list[] = {
@@ -231,7 +233,9 @@ static const char *cap_list[] = {
        "LITERAL+",
        "MOVE",
        "NAMESPACE",
-       "COMPRESS=DEFLATE"
+       "COMPRESS=DEFLATE",
+       "UTF8=ACCEPT",
+       "UTF8=ONLY"
 };
 
 #define RESP_OK       0
@@ -2231,9 +2235,16 @@ imap_open_store_authenticate2_p2( imap_store_t *ctx, 
imap_cmd_t *cmd ATTR_UNUSED
                imap_open_store_compress( ctx );
 }
 
+static void
+imap_handle_simple_cmd( imap_store_t *ctx ATTR_UNUSED,
+               imap_cmd_t *cmd ATTR_UNUSED,
+               int response ATTR_UNUSED) {
+}
 static void
 imap_open_store_compress( imap_store_t *ctx )
 {
+       if (CAP(UTF8_ACCEPT) || CAP(UTF8_ONLY))
+               imap_exec(ctx, 0, imap_handle_simple_cmd, "ENABLE UTF8=ACCEPT");
 #ifdef HAVE_LIBZ
        if (CAP(COMPRESS_DEFLATE)) {
                imap_exec( ctx, 0, imap_open_store_compress_p2, "COMPRESS 
DEFLATE" );
-- 
2.26.2



_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to