Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RFC 2060's UTF-7 for IMAP

0 views
Skip to first unread message

Edmund GRIMLEY EVANS

unread,
Jun 30, 2000, 3:00:00 AM6/30/00
to

--ALfTUftag+2gvp1h
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

I found Jon Hellan's patch, which he sent to mutt-dev on Guy Falkes'
Day, 1999, and adapted the relevant bits of it for the current CVS
version of Mutt and my utf7.c, which I posted on June 18.

Put utf7.c in imap/ and apply this patch.

It appears to work for opening a folder and copying a message to a new
or existing folder. The list of IMAP folders looked correct, too.

Does Jon Hellan or anyone else want to look at this patch or try it?

It's easiest to test if you can also look at the untranslated file
names on the IMAP server, e.g. from a shell account. If you can't type
any non-ascii characters, try folder names containing '&', and,
British users, don't forget that '£' is a non-ascii character.

Edmund

--ALfTUftag+2gvp1h
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

diff -ru mutt.orig/imap/Makefile.am mutt/imap/Makefile.am
--- mutt.orig/imap/Makefile.am Wed Mar 29 10:08:33 2000
+++ mutt/imap/Makefile.am Thu Jun 29 15:13:28 2000
@@ -19,4 +19,4 @@
noinst_HEADERS = imap_private.h imap_socket.h md5.h message.h $(SSLHEADERS)

libimap_a_SOURCES = auth.c browse.c command.c imap.c imap.h md5c.c message.c \
- socket.c util.c $(GSSSOURCES) $(SSLSOURCES)
+ socket.c util.c utf7.c $(GSSSOURCES) $(SSLSOURCES)
diff -ru mutt.orig/imap/browse.c mutt/imap/browse.c
--- mutt.orig/imap/browse.c Fri Mar 3 10:10:23 2000
+++ mutt/imap/browse.c Thu Jun 29 15:09:50 2000
@@ -123,6 +123,10 @@
if (mx.mbox && mx.mbox[0] != '\0')
{
imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox));
+ imap_munge_mbox_name (buf, sizeof (buf), mbox);
+ imap_unquote_string(buf); /* As kludgy as it gets */
+ mbox[sizeof (mbox) - 1] = '\0';
+ strncpy (mbox, buf, sizeof (mbox) - 1);
n = mutt_strlen (mbox);

dprint (3, (debugfile, "imap_init_browse: mbox: %s\n", mbox));
@@ -143,7 +147,7 @@

if (cur_folder)
{
- imap_unquote_string (cur_folder);
+ imap_unmunge_mbox_name (cur_folder);

if (!noinferiors && cur_folder[0] &&
(n = strlen (mbox)) < LONG_STRING-1)
@@ -295,7 +299,6 @@

if (name)
{
- imap_unquote_string (name);
/* Let a parent folder never be selectable for navigation */
if (isparent)
noselect = 1;
@@ -321,7 +324,7 @@
if (imap_parse_path (state->folder, &mx))
return;

- imap_unquote_string (folder);
+ imap_unmunge_mbox_name (folder);

if (state->entrylen + 1 == state->entrymax)
{
diff -ru mutt.orig/imap/imap.c mutt/imap/imap.c
--- mutt.orig/imap/imap.c Tue Jun 20 13:29:52 2000
+++ mutt/imap/imap.c Thu Jun 29 15:09:50 2000
@@ -46,7 +46,7 @@
{
char buf[LONG_STRING], mbox[LONG_STRING];

- imap_quote_string (mbox, sizeof (mbox), mailbox);
+ imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
snprintf (buf, sizeof (buf), "CREATE %s", mbox);

if (imap_exec (buf, sizeof (buf), CTX_DATA, buf, 0) != 0)
@@ -211,7 +211,7 @@
ctx->subj_hash = hash_create (1031);

mutt_message (_("Reopening mailbox... %s"), CTX_DATA->selected_mailbox);
- imap_quote_string (buf, sizeof (buf), CTX_DATA->selected_mailbox);
+ imap_munge_mbox_name (buf, sizeof (buf), CTX_DATA->selected_mailbox);
imap_make_sequence (seq, sizeof (seq));
snprintf (bufout, sizeof (bufout), "%s STATUS %s (MESSAGES)\r\n", seq, buf);
mutt_socket_write (CTX_DATA->conn, bufout);
@@ -394,7 +394,7 @@
char buf[LONG_STRING];
char mbox[LONG_STRING];

- imap_quote_string (mbox, sizeof(mbox), idata->selected_mailbox);
+ imap_munge_mbox_name (mbox, sizeof(mbox), idata->selected_mailbox);
snprintf (buf, sizeof (buf), "MYRIGHTS %s", mbox);
if (imap_exec (buf, sizeof (buf), idata, buf, 0) != 0)
{
@@ -583,7 +583,7 @@
memset (idata->rights, 0, (RIGHTSMAX+7)/8);

mutt_message (_("Selecting %s..."), idata->selected_mailbox);
- imap_quote_string (buf, sizeof(buf), idata->selected_mailbox);
+ imap_munge_mbox_name (buf, sizeof(buf), idata->selected_mailbox);
imap_make_sequence (seq, sizeof (seq));
snprintf (bufout, sizeof (bufout), "%s %s %s\r\n", seq,
ctx->readonly ? "EXAMINE" : "SELECT", buf);
@@ -782,7 +782,7 @@

imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox));

- imap_quote_string (mbox, sizeof (mbox), mailbox);
+ imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);

if (mutt_bit_isset(idata->capabilities,IMAP4REV1))
{
@@ -1230,7 +1225,7 @@
strcpy (mx.mbox, buf);

imap_make_sequence (seq, sizeof (seq));
- imap_quote_string (mbox, sizeof(mbox), buf);
+ imap_munge_mbox_name (mbox, sizeof(mbox), buf);
strfcpy (mbox_unquoted, buf, sizeof (mbox_unquoted));

/* The draft IMAP implementor's guide warns againts using the STATUS
@@ -1408,7 +1403,7 @@
mutt_message (_("Subscribing to %s..."), buf);
else
mutt_message (_("Unsubscribing to %s..."), buf);
- imap_quote_string (mbox, sizeof(mbox), buf);
+ imap_munge_mbox_name (mbox, sizeof(mbox), buf);

snprintf (buf, sizeof (buf), "%s %s", subscribe ? "SUBSCRIBE" :
"UNSUBSCRIBE", mbox);
@@ -1478,7 +1473,7 @@
if (list_word)
{
/* store unquoted */
- imap_unquote_string (list_word);
+ imap_unmunge_mbox_name (list_word);

/* if the folder isn't selectable, append delimiter to force browse
* to enter it on second tab. */
diff -ru mutt.orig/imap/imap_private.h mutt/imap/imap_private.h
--- mutt.orig/imap/imap_private.h Fri Mar 3 10:10:23 2000
+++ mutt/imap/imap_private.h Thu Jun 29 15:47:39 2000
@@ -196,5 +196,12 @@
char* imap_next_word (char* s);
void imap_quote_string (char* dest, size_t slen, const char* src);
void imap_unquote_string (char* s);
+void imap_munge_mbox_name (char *dest, size_t dlen, const char *src);
+void imap_unmunge_mbox_name (char *s);
int imap_wordcasecmp(const char *a, const char *b);
+
+/* utf8.c */
+void mutt_utf7_encode (char **s);
+void mutt_utf7_decode (char **s);
+
#endif
diff -ru mutt.orig/imap/message.c mutt/imap/message.c
--- mutt.orig/imap/message.c Tue May 9 18:47:58 2000
+++ mutt/imap/message.c Thu Jun 29 15:35:50 2000
@@ -494,7 +494,7 @@

mutt_message _("Sending APPEND command ...");

- imap_quote_string (mbox, sizeof (mbox), mailbox);
+ imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
imap_make_sequence (seq, sizeof (seq));
snprintf (buf, sizeof (buf), "%s APPEND %s {%d}\r\n", seq, mbox, len);

@@ -587,6 +587,7 @@
char buf[HUGE_STRING];
char cmd[LONG_STRING];
char mbox[LONG_STRING];
+ char mmbox[LONG_STRING];
int rc;
int n;
IMAP_MBOX mx;
@@ -626,7 +627,8 @@

/* let's get it on */
strncpy (mbox, cmd, sizeof (mbox));
- snprintf (cmd, sizeof (cmd), "COPY %s \"%s\"", buf, mbox);
+ imap_munge_mbox_name (mmbox, sizeof (mmbox), cmd);
+ snprintf (cmd, sizeof (cmd), "COPY %s %s", buf, mmbox);
rc = imap_exec (buf, sizeof (buf), CTX_DATA, cmd, IMAP_OK_FAIL);
if (rc == -2)
{
diff -ru mutt.orig/imap/util.c mutt/imap/util.c
--- mutt.orig/imap/util.c Wed Apr 26 18:43:00 2000
+++ mutt/imap/util.c Thu Jun 29 15:45:57 2000
@@ -289,6 +289,35 @@
*d = '\0';
}

+/*
+ * Quoting and UTF-7 conversion
+ */
+
+void imap_munge_mbox_name (char *dest, size_t dlen, const char *src)
+{
+ char *buf;
+
+ buf = safe_strdup (src);
+ mutt_utf7_encode (&buf);
+
+ imap_quote_string (dest, dlen, buf);
+
+ free (buf);
+}
+
+void imap_unmunge_mbox_name (char *s)
+{
+ char *buf;
+
+ imap_unquote_string(s);
+
+ buf = safe_strdup (s);
+ mutt_utf7_decode (&buf);
+ strncpy (s, buf, strlen (s));
+
+ free (buf);
+}
+
/* imap_wordcasecmp: find word a in word list b */
int imap_wordcasecmp(const char *a, const char *b)
{

--ALfTUftag+2gvp1h--


0 new messages