diff -u -p -Nr --exclude CVS mailutils-20020409.orig/imap4d/util.c mailutils-20020409/imap4d/util.c
--- mailutils-20020409.orig/imap4d/util.c	2002-03-26 18:24:06.000000000 +0100
+++ mailutils-20020409/imap4d/util.c	2005-05-27 08:13:33.000000000 +0200
@@ -347,16 +347,38 @@ int
 util_finish (struct imap4d_command *command, int rc, const char *format, ...)
 {
   char *buf = NULL;
+  char *tempbuf = NULL;
   int new_state;
   int status;
   va_list ap;
+  size_t size;
 
-  asprintf (&buf, "%s %s%s %s\r\n", command->tag, sc2string (rc),
-	    command->name, format);
+  char *sc = sc2string (rc);
 
   va_start (ap, format);
-  status = vfprintf (ofile, buf, ap);
+  vasprintf (&tempbuf, format, ap);
   va_end (ap);
+
+  if (!tempbuf)
+    imap4d_bye (ERR_NO_MEM);
+
+  size = strlen (command->tag) + 1 +
+    strlen (sc) + strlen (command->name) + 1 +
+    strlen (tempbuf) + 1;
+  buf = malloc (size);
+
+  if (!buf)
+    imap4d_bye (ERR_NO_MEM);
+
+  strcpy (buf, command->tag);
+  strcat (buf, " ");
+  strcat (buf, sc);
+  strcat (buf, command->name);
+  strcat (buf, " ");
+  strcat (buf, tempbuf);
+  free (tempbuf);
+
+  status = fprintf (ofile, "%s", buf);
   free (buf);
   /* Reset the state.  */
   new_state = (rc == RESP_OK) ? command->success : command->failure;
