2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include "procheader.h"
40 #include "prefs_common.h"
46 static GHashTable *procmime_get_mime_type_table (void);
48 MimeInfo *procmime_mimeinfo_new(void)
52 mimeinfo = g_new0(MimeInfo, 1);
53 mimeinfo->mime_type = MIME_UNKNOWN;
54 mimeinfo->encoding_type = ENC_UNKNOWN;
59 void procmime_mimeinfo_free(MimeInfo *mimeinfo)
61 if (!mimeinfo) return;
63 g_free(mimeinfo->encoding);
64 g_free(mimeinfo->content_type);
65 g_free(mimeinfo->charset);
66 g_free(mimeinfo->name);
67 g_free(mimeinfo->boundary);
68 g_free(mimeinfo->content_disposition);
69 g_free(mimeinfo->filename);
71 g_free(mimeinfo->plaintextfile);
72 g_free(mimeinfo->sigstatus);
73 g_free(mimeinfo->sigstatus_full);
76 procmime_mimeinfo_free(mimeinfo->sub);
81 void procmime_mimeinfo_free_all(MimeInfo *mimeinfo)
83 while (mimeinfo != NULL) {
86 g_free(mimeinfo->encoding);
87 g_free(mimeinfo->content_type);
88 g_free(mimeinfo->charset);
89 g_free(mimeinfo->name);
90 g_free(mimeinfo->boundary);
91 g_free(mimeinfo->content_disposition);
92 g_free(mimeinfo->filename);
94 g_free(mimeinfo->plaintextfile);
95 g_free(mimeinfo->sigstatus);
96 g_free(mimeinfo->sigstatus_full);
99 procmime_mimeinfo_free_all(mimeinfo->sub);
100 procmime_mimeinfo_free_all(mimeinfo->children);
102 procmime_mimeinfo_free_all(mimeinfo->plaintext);
105 next = mimeinfo->next;
111 MimeInfo *procmime_mimeinfo_insert(MimeInfo *parent, MimeInfo *mimeinfo)
113 MimeInfo *child = parent->children;
116 parent->children = mimeinfo;
118 while (child->next != NULL)
121 child->next = mimeinfo;
124 mimeinfo->parent = parent;
125 mimeinfo->level = parent->level + 1;
130 void procmime_mimeinfo_replace(MimeInfo *old, MimeInfo *new)
132 MimeInfo *parent = old->parent;
136 g_warning("oops: Not top message");
140 g_message("oops: new child should not have a sibling");
144 for (child = parent->children; child && child != old;
148 g_warning("oops: parent can't find it's own child");
151 procmime_mimeinfo_free_all(old);
153 if (child == parent->children) {
154 new->next = parent->children->next;
155 parent->children = new;
157 new->next = child->next;
162 MimeInfo *procmime_mimeinfo_next(MimeInfo *mimeinfo)
164 if (!mimeinfo) return NULL;
166 if (mimeinfo->children)
167 return mimeinfo->children;
169 return mimeinfo->sub;
171 return mimeinfo->next;
173 for (mimeinfo = mimeinfo->parent; mimeinfo != NULL;
174 mimeinfo = mimeinfo->parent) {
176 return mimeinfo->next;
177 if (mimeinfo->main) {
178 mimeinfo = mimeinfo->main;
180 return mimeinfo->next;
187 MimeInfo *procmime_scan_message(MsgInfo *msginfo)
192 g_return_val_if_fail(msginfo != NULL, NULL);
194 if ((fp = procmsg_open_message(msginfo)) == NULL) return NULL;
195 mimeinfo = procmime_scan_mime_header(fp);
198 if (mimeinfo->mime_type != MIME_MULTIPART) {
199 if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
202 if (mimeinfo->mime_type != MIME_TEXT)
203 procmime_scan_multipart_message(mimeinfo, fp);
207 if (prefs_common.auto_check_signatures)
208 rfc2015_check_signature(mimeinfo, fp);
215 void procmime_scan_multipart_message(MimeInfo *mimeinfo, FILE *fp)
219 gint boundary_len = 0;
221 glong fpos, prev_fpos;
224 g_return_if_fail(mimeinfo != NULL);
225 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
227 if (mimeinfo->mime_type == MIME_MULTIPART) {
228 g_return_if_fail(mimeinfo->boundary != NULL);
229 g_return_if_fail(mimeinfo->sub == NULL);
231 g_return_if_fail(fp != NULL);
233 boundary = mimeinfo->boundary;
236 boundary_len = strlen(boundary);
238 /* look for first boundary */
239 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
240 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
244 if ((fpos = ftell(fp)) < 0) {
249 for (npart = 0;; npart++) {
251 gboolean eom = FALSE;
255 partinfo = procmime_scan_mime_header(fp);
256 if (!partinfo) break;
257 procmime_mimeinfo_insert(mimeinfo, partinfo);
259 if (partinfo->mime_type == MIME_MULTIPART) {
260 if (partinfo->level < 8)
261 procmime_scan_multipart_message(partinfo, fp);
262 } else if (partinfo->mime_type == MIME_MESSAGE_RFC822) {
265 partinfo->sub = sub = procmime_scan_mime_header(fp);
267 sub->level = partinfo->level + 1;
268 sub->parent = partinfo->parent;
269 sub->main = partinfo;
271 if (sub->mime_type == MIME_MULTIPART) {
273 procmime_scan_multipart_message
278 /* look for next boundary */
280 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
281 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
282 if (buf[2 + boundary_len] == '-' &&
283 buf[2 + boundary_len + 1] == '-')
289 eom = TRUE; /* broken MIME message */
292 partinfo->size = fpos - prev_fpos - strlen(buf);
296 /*g_message ("** at " __PRETTY_FUNCTION__ ":%d:", __LINE__);*/
299 void procmime_scan_encoding(MimeInfo *mimeinfo, const gchar *encoding)
303 Xstrdup_a(buf, encoding, return);
305 g_free(mimeinfo->encoding);
307 mimeinfo->encoding = g_strdup(g_strstrip(buf));
308 if (!strcasecmp(buf, "7bit"))
309 mimeinfo->encoding_type = ENC_7BIT;
310 else if (!strcasecmp(buf, "8bit"))
311 mimeinfo->encoding_type = ENC_8BIT;
312 else if (!strcasecmp(buf, "quoted-printable"))
313 mimeinfo->encoding_type = ENC_QUOTED_PRINTABLE;
314 else if (!strcasecmp(buf, "base64"))
315 mimeinfo->encoding_type = ENC_BASE64;
316 else if (!strcasecmp(buf, "x-uuencode"))
317 mimeinfo->encoding_type = ENC_X_UUENCODE;
319 mimeinfo->encoding_type = ENC_UNKNOWN;
323 void procmime_scan_content_type(MimeInfo *mimeinfo, const gchar *content_type)
325 gchar *delim, *p, *cnttype;
328 if (conv_get_current_charset() == C_EUC_JP &&
329 strchr(content_type, '\033')) {
331 len = strlen(content_type) * 2 + 1;
332 Xalloca(buf, len, return);
333 conv_jistoeuc(buf, len, content_type);
335 Xstrdup_a(buf, content_type, return);
337 g_free(mimeinfo->content_type);
338 g_free(mimeinfo->charset);
339 g_free(mimeinfo->name);
340 mimeinfo->content_type = NULL;
341 mimeinfo->charset = NULL;
342 mimeinfo->name = NULL;
344 if ((delim = strchr(buf, ';'))) *delim = '\0';
345 mimeinfo->content_type = cnttype = g_strdup(g_strstrip(buf));
347 mimeinfo->mime_type = procmime_scan_mime_type(cnttype);
356 if ((delim = strchr(p, ';'))) *delim = '\0';
358 if (!(eq = strchr(p, '='))) break;
367 extract_quote(value, '"');
369 eliminate_parenthesis(value, '(', ')');
374 if (!strcasecmp(attr, "charset"))
375 mimeinfo->charset = g_strdup(value);
376 else if (!strcasecmp(attr, "name")) {
380 len = strlen(value) + 1;
381 Xalloca(tmp, len, return);
382 conv_unmime_header(tmp, len, value, NULL);
383 mimeinfo->name = g_strdup(tmp);
384 } else if (!strcasecmp(attr, "boundary"))
385 mimeinfo->boundary = g_strdup(value);
392 if (mimeinfo->mime_type == MIME_MULTIPART && !mimeinfo->boundary)
393 mimeinfo->mime_type = MIME_TEXT;
396 void procmime_scan_content_disposition(MimeInfo *mimeinfo,
397 const gchar *content_disposition)
399 gchar *delim, *p, *dispos;
402 if (conv_get_current_charset() == C_EUC_JP &&
403 strchr(content_disposition, '\033')) {
405 len = strlen(content_disposition) * 2 + 1;
406 Xalloca(buf, len, return);
407 conv_jistoeuc(buf, len, content_disposition);
409 Xstrdup_a(buf, content_disposition, return);
411 if ((delim = strchr(buf, ';'))) *delim = '\0';
412 mimeinfo->content_disposition = dispos = g_strdup(g_strstrip(buf));
421 if ((delim = strchr(p, ';'))) *delim = '\0';
423 if (!(eq = strchr(p, '='))) break;
432 extract_quote(value, '"');
434 eliminate_parenthesis(value, '(', ')');
439 if (!strcasecmp(attr, "filename")) {
443 len = strlen(value) + 1;
444 Xalloca(tmp, len, return);
445 conv_unmime_header(tmp, len, value, NULL);
446 g_free(mimeinfo->filename);
447 mimeinfo->filename = g_strdup(tmp);
459 H_CONTENT_TRANSFER_ENCODING = 0,
461 H_CONTENT_DISPOSITION = 2
464 MimeInfo *procmime_scan_mime_header(FILE *fp)
466 static HeaderEntry hentry[] = {{"Content-Transfer-Encoding:",
468 {"Content-Type:", NULL, TRUE},
469 {"Content-Disposition:",
471 {NULL, NULL, FALSE}};
477 g_return_val_if_fail(fp != NULL, NULL);
479 mimeinfo = procmime_mimeinfo_new();
480 mimeinfo->mime_type = MIME_TEXT;
481 mimeinfo->encoding_type = ENC_7BIT;
482 mimeinfo->fpos = ftell(fp);
484 while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
488 if (H_CONTENT_TRANSFER_ENCODING == hnum) {
489 procmime_scan_encoding
490 (mimeinfo, buf + strlen(hp->name));
491 } else if (H_CONTENT_TYPE == hnum) {
492 procmime_scan_content_type
493 (mimeinfo, buf + strlen(hp->name));
494 } else if (H_CONTENT_DISPOSITION == hnum) {
495 procmime_scan_content_disposition
496 (mimeinfo, buf + strlen(hp->name));
500 if (mimeinfo->mime_type == MIME_APPLICATION_OCTET_STREAM &&
503 type = procmime_get_mime_type(mimeinfo->name);
505 mimeinfo->mime_type = procmime_scan_mime_type(type);
508 if (!mimeinfo->content_type)
509 mimeinfo->content_type = g_strdup("text/plain");
514 FILE *procmime_decode_content(FILE *outfp, FILE *infp, MimeInfo *mimeinfo)
517 gchar *boundary = NULL;
518 gint boundary_len = 0;
519 gboolean tmp_file = FALSE;
521 g_return_val_if_fail(infp != NULL, NULL);
522 g_return_val_if_fail(mimeinfo != NULL, NULL);
525 outfp = my_tmpfile();
533 if (mimeinfo->parent && mimeinfo->parent->boundary) {
534 boundary = mimeinfo->parent->boundary;
535 boundary_len = strlen(boundary);
538 if (mimeinfo->encoding_type == ENC_QUOTED_PRINTABLE) {
539 gboolean softline = FALSE;
541 while (fgets(buf, sizeof(buf), infp) != NULL &&
543 !IS_BOUNDARY(buf, boundary, boundary_len))) {
546 softline = DoOneQPLine(&p, FALSE, softline);
547 fwrite(buf, p - (guchar *)buf, 1, outfp);
549 } else if (mimeinfo->encoding_type == ENC_BASE64) {
550 gchar outbuf[BUFFSIZE];
552 Base64Decoder *decoder;
554 decoder = base64_decoder_new();
555 while (fgets(buf, sizeof(buf), infp) != NULL &&
557 !IS_BOUNDARY(buf, boundary, boundary_len))) {
558 len = base64_decoder_decode(decoder, buf, outbuf);
560 g_warning("Bad BASE64 content\n");
563 fwrite(outbuf, sizeof(gchar), len, outfp);
565 base64_decoder_free(decoder);
566 } else if (mimeinfo->encoding_type == ENC_X_UUENCODE) {
567 gchar outbuf[BUFFSIZE];
569 gboolean flag = FALSE;
571 while (fgets(buf, sizeof(buf), infp) != NULL &&
573 !IS_BOUNDARY(buf, boundary, boundary_len))) {
574 if(!flag && strncmp(buf,"begin ", 6)) continue;
577 len = fromuutobits(outbuf, buf);
580 g_warning("Bad UUENCODE content(%d)\n", len);
583 fwrite(outbuf, sizeof(gchar), len, outfp);
588 while (fgets(buf, sizeof(buf), infp) != NULL &&
590 !IS_BOUNDARY(buf, boundary, boundary_len))) {
595 if (tmp_file) rewind(outfp);
599 gint procmime_get_part(const gchar *outfile, const gchar *infile,
605 g_return_val_if_fail(outfile != NULL, -1);
606 g_return_val_if_fail(infile != NULL, -1);
607 g_return_val_if_fail(mimeinfo != NULL, -1);
609 if ((infp = fopen(infile, "r")) == NULL) {
610 FILE_OP_ERROR(infile, "fopen");
613 if (fseek(infp, mimeinfo->fpos, SEEK_SET) < 0) {
614 FILE_OP_ERROR(infile, "fseek");
618 if ((outfp = fopen(outfile, "w")) == NULL) {
619 FILE_OP_ERROR(outfile, "fopen");
624 while (fgets(buf, sizeof(buf), infp) != NULL)
625 if (buf[0] == '\r' || buf[0] == '\n') break;
627 procmime_decode_content(outfp, infp, mimeinfo);
630 if (fclose(outfp) == EOF) {
631 FILE_OP_ERROR(outfile, "fclose");
639 FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
643 gboolean conv_fail = FALSE;
646 g_return_val_if_fail(mimeinfo != NULL, NULL);
647 g_return_val_if_fail(infp != NULL, NULL);
648 g_return_val_if_fail(mimeinfo->mime_type == MIME_TEXT ||
649 mimeinfo->mime_type == MIME_TEXT_HTML, NULL);
651 if (fseek(infp, mimeinfo->fpos, SEEK_SET) < 0) {
656 while (fgets(buf, sizeof(buf), infp) != NULL)
657 if (buf[0] == '\r' || buf[0] == '\n') break;
659 tmpfp = procmime_decode_content(NULL, infp, mimeinfo);
663 if ((outfp = my_tmpfile()) == NULL) {
669 src_codeset = prefs_common.force_charset
670 ? prefs_common.force_charset : mimeinfo->charset;
672 while (fgets(buf, sizeof(buf), tmpfp) != NULL) {
675 str = conv_codeset_strdup(buf, src_codeset, NULL);
684 if (conv_fail) g_warning(_("Code conversion failed.\n"));
692 /* search the first text part of (multipart) MIME message,
693 decode, convert it and output to outfp. */
694 FILE *procmime_get_first_text_content(MsgInfo *msginfo)
696 FILE *infp, *tmpfp, *outfp;
697 MimeInfo *mimeinfo, *partinfo = NULL;
699 gboolean conv_fail = FALSE;
702 g_return_val_if_fail(msginfo != NULL, NULL);
704 mimeinfo = procmime_scan_message(msginfo);
705 if (!mimeinfo) return NULL;
707 if ((infp = procmsg_open_message(msginfo)) == NULL) {
708 procmime_mimeinfo_free_all(mimeinfo);
713 while (partinfo && partinfo->mime_type == MIME_MULTIPART)
714 partinfo = partinfo->children;
716 if (partinfo && partinfo->mime_type == MIME_TEXT) {
717 if (fseek(infp, partinfo->fpos, SEEK_SET) < 0) {
724 procmime_mimeinfo_free_all(mimeinfo);
728 while (fgets(buf, sizeof(buf), infp) != NULL)
729 if (buf[0] == '\r' || buf[0] == '\n') break;
731 tmpfp = procmime_decode_content(NULL, infp, partinfo);
733 procmime_mimeinfo_free_all(mimeinfo);
737 if ((outfp = my_tmpfile()) == NULL) {
740 procmime_mimeinfo_free_all(mimeinfo);
744 src_codeset = prefs_common.force_charset
745 ? prefs_common.force_charset : partinfo->charset;
747 while (fgets(buf, sizeof(buf), tmpfp) != NULL) {
750 str = conv_codeset_strdup(buf, src_codeset, NULL);
759 if (conv_fail) g_warning(_("Code conversion failed.\n"));
762 procmime_mimeinfo_free_all(mimeinfo);
768 gboolean procmime_find_string_part(MimeInfo *mimeinfo, const gchar *filename,
769 const gchar *str, gboolean case_sens)
774 gchar *(* StrFindFunc) (const gchar *haystack, const gchar *needle);
776 g_return_val_if_fail(mimeinfo != NULL, FALSE);
777 g_return_val_if_fail(mimeinfo->mime_type == MIME_TEXT ||
778 mimeinfo->mime_type == MIME_TEXT_HTML, FALSE);
779 g_return_val_if_fail(str != NULL, FALSE);
781 if ((infp = fopen(filename, "r")) == NULL) {
782 FILE_OP_ERROR(filename, "fopen");
786 outfp = procmime_get_text_content(mimeinfo, infp);
793 StrFindFunc = strstr;
795 StrFindFunc = strcasestr;
797 while (fgets(buf, sizeof(buf), outfp) != NULL) {
798 if (StrFindFunc(buf, str) != NULL) {
809 gboolean procmime_find_string(MsgInfo *msginfo, const gchar *str,
815 gboolean found = FALSE;
817 g_return_val_if_fail(msginfo != NULL, NULL);
818 g_return_val_if_fail(str != NULL, NULL);
820 filename = procmsg_get_message_file(msginfo);
821 if (!filename) return FALSE;
822 mimeinfo = procmime_scan_message(msginfo);
824 for (partinfo = mimeinfo; partinfo != NULL;
825 partinfo = procmime_mimeinfo_next(partinfo)) {
826 if (partinfo->mime_type == MIME_TEXT ||
827 partinfo->mime_type == MIME_TEXT_HTML) {
828 if (procmime_find_string_part
829 (partinfo, filename, str, case_sens) == TRUE) {
836 procmime_mimeinfo_free_all(mimeinfo);
842 gchar *procmime_get_tmp_file_name(MimeInfo *mimeinfo)
844 static guint32 id = 0;
849 g_return_val_if_fail(mimeinfo != NULL, NULL);
851 g_snprintf(f_prefix, sizeof(f_prefix), "%08x.", id++);
853 if (MIME_TEXT_HTML == mimeinfo->mime_type)
854 base = "mimetmp.html";
856 base = mimeinfo->filename ? mimeinfo->filename
857 : mimeinfo->name ? mimeinfo->name : "mimetmp";
858 base = g_basename(base);
859 if (*base == '\0') base = "mimetmp";
862 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
863 f_prefix, base, NULL);
868 ContentType procmime_scan_mime_type(const gchar *mime_type)
872 if (!strncasecmp(mime_type, "text/html", 9))
873 type = MIME_TEXT_HTML;
874 else if (!strncasecmp(mime_type, "text/", 5))
876 else if (!strncasecmp(mime_type, "message/rfc822", 14))
877 type = MIME_MESSAGE_RFC822;
878 else if (!strncasecmp(mime_type, "message/", 8))
880 else if (!strncasecmp(mime_type, "application/octet-stream", 24))
881 type = MIME_APPLICATION_OCTET_STREAM;
882 else if (!strncasecmp(mime_type, "application/", 12))
883 type = MIME_APPLICATION;
884 else if (!strncasecmp(mime_type, "multipart/", 10))
885 type = MIME_MULTIPART;
886 else if (!strncasecmp(mime_type, "image/", 6))
888 else if (!strncasecmp(mime_type, "audio/", 6))
890 else if (!strcasecmp(mime_type, "text"))
898 static GList *mime_type_list = NULL;
900 gchar *procmime_get_mime_type(const gchar *filename)
902 static GHashTable *mime_type_table = NULL;
904 const gchar *ext, *p;
906 if (!mime_type_table) {
907 mime_type_table = procmime_get_mime_type_table();
908 if (!mime_type_table) return NULL;
911 filename = g_basename(filename);
912 p = strrchr(filename, '.');
918 mime_type = g_hash_table_lookup(mime_type_table, ext);
922 str = g_strconcat(mime_type->type, "/", mime_type->sub_type,
930 static guint procmime_str_hash(gconstpointer gptr)
932 guint hash_result = 0;
935 for (str = gptr; str && *str; str++) {
936 if (isupper(*str)) hash_result += (*str + ' ');
937 else hash_result += *str;
943 static gint procmime_str_equal(gconstpointer gptr1, gconstpointer gptr2)
945 const char *str1 = gptr1;
946 const char *str2 = gptr2;
948 return !strcasecmp(str1, str2);
951 static GHashTable *procmime_get_mime_type_table(void)
953 GHashTable *table = NULL;
958 if (!mime_type_list) {
959 mime_type_list = procmime_get_mime_type_list();
960 if (!mime_type_list) return NULL;
963 table = g_hash_table_new(procmime_str_hash, procmime_str_equal);
965 for (cur = mime_type_list; cur != NULL; cur = cur->next) {
968 mime_type = (MimeType *)cur->data;
970 if (!mime_type->extension) continue;
972 exts = g_strsplit(mime_type->extension, " ", 16);
973 for (i = 0; exts[i] != NULL; i++)
974 g_hash_table_insert(table, g_strdup(exts[i]),
982 GList *procmime_get_mime_type_list(void)
991 return mime_type_list;
993 if ((fp = fopen("/etc/mime.types", "r")) == NULL) {
994 if ((fp = fopen(SYSCONFDIR "/mime.types", "r")) == NULL) {
995 FILE_OP_ERROR(SYSCONFDIR "/mime.types", "fopen");
1000 while (fgets(buf, sizeof(buf), fp) != NULL) {
1001 p = strchr(buf, '#');
1006 while (*p && !isspace(*p)) p++;
1011 delim = strchr(buf, '/');
1012 if (delim == NULL) continue;
1015 mime_type = g_new(MimeType, 1);
1016 mime_type->type = g_strdup(buf);
1017 mime_type->sub_type = g_strdup(delim + 1);
1019 while (*p && isspace(*p)) p++;
1021 mime_type->extension = g_strdup(p);
1023 mime_type->extension = NULL;
1025 list = g_list_append(list, mime_type);
1031 g_warning("Can't read mime.types\n");
1036 EncodingType procmime_get_encoding_for_charset(const gchar *charset)
1040 else if (!strncasecmp(charset, "ISO-2022-", 9) ||
1041 !strcasecmp(charset, "US-ASCII"))
1045 /* return ENC_BASE64; */
1046 /* return ENC_QUOTED_PRINTABLE; */
1049 const gchar *procmime_get_encoding_str(EncodingType encoding)
1051 static const gchar *encoding_str[] = {
1052 "7bit", "8bit", "quoted-printable", "base64", "x-uuencode",
1056 if (encoding >= ENC_7BIT && encoding <= ENC_UNKNOWN)
1057 return encoding_str[encoding];