/**
         * Encodes a MIME header.
         *
         * XXX: preferences
         *
         * @param field_name header field name
         * @param field_value header field value
         * @param preferences
         * @return encoded mime header
         */
        public static StringValue encodeMime(Env env,
                                             StringValue name,
                                             StringValue value,
                                             string inCharset,
                                             string outCharset,
                                             string scheme,
                                             string lineBreakChars,
                                             int lineLength)

        {
            Decoder decoder = Decoder.create(inCharset);

            CharSequence nameUnicode = decoder.decode(env, name);

            decoder.reset();
            string valueUnicode = decoder.decode(env, value).ToString();

            StringValue sb = env.createUnicodeBuilder();

            sb.append(UnicodeUtility.encode(env, nameUnicode, outCharset));
            sb.append(':');
            sb.append(' ');

            string word = encodeMimeWord(valueUnicode.ToString(),
                                         outCharset,
                                         scheme,
                                         lineBreakChars,
                                         lineLength);

            sb.append(MimeUtility.fold(sb.length(), word));

            return(sb);
        }