summaryrefslogtreecommitdiffstats
path: root/imap
diff options
context:
space:
mode:
authorSam Varshavchik2018-09-26 08:21:37 -0400
committerSam Varshavchik2018-09-26 08:21:37 -0400
commita93bf23f84513a7fee6c648266de43dc0f01ad87 (patch)
treead12fe3b8adb1958a2bb6d12a2b979801bfce921 /imap
parent9e7f4cb275f04c59dd187b4a39b00832d2b2817e (diff)
downloadcourier-libs-a93bf23f84513a7fee6c648266de43dc0f01ad87.tar.bz2
Substitute message for non-UTF-8 IMAP clients.
Diffstat (limited to 'imap')
-rw-r--r--imap/ChangeLog5
-rw-r--r--imap/configure.ac2
-rw-r--r--imap/fetch.c36
3 files changed, 41 insertions, 2 deletions
diff --git a/imap/ChangeLog b/imap/ChangeLog
index fcbc247..80d41ed 100644
--- a/imap/ChangeLog
+++ b/imap/ChangeLog
@@ -1,3 +1,8 @@
+2018-09-26 Sam Varshavchik <mrsam@courier-mta.com>
+
+ * Provide an substitute message to IMAP clients that did not enable
+ UTF-8.
+
2018-09-24 Sam Varshavchik <mrsam@courier-mta.com>
* couriertls: additional fixes.
diff --git a/imap/configure.ac b/imap/configure.ac
index 49f909a..3a3a86b 100644
--- a/imap/configure.ac
+++ b/imap/configure.ac
@@ -151,7 +151,7 @@ fi
dnl Checks for library functions.
-AC_CHECK_FUNCS(strerror utime utimes strcasecmp strncasecmp setlocale poll getaddrinfo)
+AC_CHECK_FUNCS(strerror utime utimes strcasecmp strncasecmp setlocale poll getaddrinfo open_memstream)
AC_DEFINE_UNQUOTED(SOCKET_TIMEOUT,60,
[ Read/write timeout ])
diff --git a/imap/fetch.c b/imap/fetch.c
index fd25265..c3998d9 100644
--- a/imap/fetch.c
+++ b/imap/fetch.c
@@ -1,5 +1,5 @@
/*
-** Copyright 1998 - 2010 Double Precision, Inc.
+** Copyright 1998 - 2018 Double Precision, Inc.
** See COPYING for distribution information.
*/
@@ -450,7 +450,41 @@ static int fetchitem(FILE **fp, int *open_err, struct fetchinfo *fi,
if (mimecorrectness && !enabled_utf8 &&
((*mimep)->rfcviolation & RFC2045_ERR8BITHEADER))
+ {
+#if HAVE_OPEN_MEMSTREAM
+ char *ptr;
+ size_t sizeloc;
+ FILE *memfp;
+
+ static const char canned_msg[]=
+ "From: Mail Delivery Subsystem <postmaster@localhost>\n"
+ "Subject: Message unavailable\n"
+ "\n"
+ "This is a Unicode message that cannot be correctly\n"
+ "opened by your E-mail program. Please upgrade to\n"
+ "an E-mail program that supports IMAP with UTF-8.\n";
+
+ if ((memfp=open_memstream(&ptr, &sizeloc)) != 0)
+ {
+ struct rfc2045 *rfcp;
+
+ fprintf(memfp, canned_msg);
+
+ if ((rfcp=rfc2045_alloc()) != NULL)
+ {
+ rfc2045_parse(rfcp, canned_msg,
+ sizeof(canned_msg)-1);
+ (*fetchfunc)(memfp, fi, i, msgnum, rfcp);
+ rfc2045_free(rfcp);
+ }
+ fclose(memfp);
+ free(ptr);
+ }
+
+ /* Still return -1, in order to [ALERT] the client */
+#endif
return -1;
+ }
(*fetchfunc)(*fp, fi, i, msgnum, *mimep);
return (rc);