String handling: refactor the expanding-string routines and users to use a descriptor...
[exim.git] / src / src / imap_utf7.c
index 0c3d5a20dc125e55f9e1994d96ff86ad67c3cf8c..323225c231a06972832ca3858bc4431a5257f69a 100644 (file)
@@ -8,10 +8,9 @@ imap_utf7_encode(uschar *string, const uschar *charset, uschar sep,
 {
 static uschar encode_base64[64] =
   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
-int ptr = 0;
-int size = 0;
 size_t slen;
-uschar *sptr, *yield = NULL;
+uschar *sptr;
+gstring * yield = NULL;
 int i = 0, j;  /* compiler quietening */
 uschar c = 0;  /* compiler quietening */
 BOOL base64mode = FALSE;
@@ -170,7 +169,7 @@ while (slen > 0)
 
     if (outptr > outbuf + sizeof(outbuf) - 3)
       {
-      yield = string_catn(yield, &size, &ptr, outbuf, outptr - outbuf);
+      yield = string_catn(yield, outbuf, outptr - outbuf);
       outptr = outbuf;
       }
 
@@ -196,12 +195,12 @@ if (base64mode)
 iconv_close(icd);
 #endif
 
-yield = string_catn(yield, &size, &ptr, outbuf, outptr - outbuf);
-if (yield[ptr-1] == '.')
-  ptr--;
-yield[ptr] = '\0';
+yield = string_catn(yield, outbuf, outptr - outbuf);
 
-return yield;
+if (yield->s[yield->ptr-1] == '.')
+  yield->ptr--;
+
+return string_from_gstring(yield);
 }
 
 #endif /* whole file */