c44a4cb1b8276a0f1d57bd131cc1063935d05438
[claws.git] / src / codeconv.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #ifndef __CODECONV_H__
21 #define __CODECONV_H__
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <glib.h>
28
29 #if HAVE_LIBJCONV
30 #  include <jconv.h>
31 #endif
32
33 typedef struct _CodeConverter   CodeConverter;
34
35 typedef enum
36 {
37         C_AUTO,
38         C_US_ASCII,
39         C_UTF_8,
40         C_ISO_8859_1,
41         C_ISO_8859_2,
42         C_ISO_8859_4,
43         C_ISO_8859_5,
44         C_ISO_8859_7,
45         C_ISO_8859_8,
46         C_ISO_8859_9,
47         C_ISO_8859_13,
48         C_ISO_8859_15,
49         C_BALTIC,
50         C_CP1251,
51         C_WINDOWS_1251,
52         C_KOI8_R,
53         C_KOI8_U,
54         C_ISO_2022_JP,
55         C_ISO_2022_JP_2,
56         C_EUC_JP,
57         C_SHIFT_JIS,
58         C_ISO_2022_KR,
59         C_EUC_KR,
60         C_ISO_2022_CN,
61         C_EUC_CN,
62         C_GB2312,
63         C_EUC_TW,
64         C_BIG5
65 } CharSet;
66
67 typedef void (*CodeConvFunc) (gchar *outbuf, gint outlen, const gchar *inbuf);
68
69 struct _CodeConverter
70 {
71 #if !HAVE_LIBJCONV
72         CodeConvFunc code_conv_func;
73 #endif
74         gchar *charset_str;
75         CharSet charset;
76 };
77
78 #define CS_AUTO                 "AUTO"
79 #define CS_US_ASCII             "US-ASCII"
80 #define CS_UTF_8                "UTF-8"
81 #define CS_ISO_8859_1           "ISO-8859-1"
82 #define CS_ISO_8859_2           "ISO-8859-2"
83 #define CS_ISO_8859_4           "ISO-8859-4"
84 #define CS_ISO_8859_5           "ISO-8859-5"
85 #define CS_ISO_8859_7           "ISO-8859-7"
86 #define CS_ISO_8859_8           "ISO-8859-8"
87 #define CS_ISO_8859_9           "ISO-8859-9"
88 #define CS_ISO_8859_13          "ISO-8859-13"
89 #define CS_ISO_8859_15          "ISO-8859-15"
90 #define CS_BALTIC               "BALTIC"
91 #define CS_CP1251               "CP1251"
92 #define CS_WINDOWS_1251         "Windows-1251"
93 #define CS_KOI8_R               "KOI8-R"
94 #define CS_KOI8_U               "KOI8-U"
95 #define CS_ISO_2022_JP          "ISO-2022-JP"
96 #define CS_ISO_2022_JP_2        "ISO-2022-JP-2"
97 #define CS_EUC_JP               "EUC-JP"
98 #define CS_SHIFT_JIS            "Shift_JIS"
99 #define CS_ISO_2022_KR          "ISO-2022-KR"
100 #define CS_EUC_KR               "EUC-KR"
101 #define CS_ISO_2022_CN          "ISO-2022-CN"
102 #define CS_EUC_CN               "EUC-CN"
103 #define CS_GB2312               "GB2312"
104 #define CS_EUC_TW               "EUC-TW"
105 #define CS_BIG5                 "Big5"
106
107 void conv_jistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf);
108 void conv_euctojis(gchar *outbuf, gint outlen, const gchar *inbuf);
109 void conv_sjistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf);
110 void conv_anytoeuc(gchar *outbuf, gint outlen, const gchar *inbuf);
111 void conv_anytojis(gchar *outbuf, gint outlen, const gchar *inbuf);
112 void conv_unreadable_eucjp(gchar *str);
113 void conv_unreadable_8bit(gchar *str);
114 void conv_unreadable_latin(gchar *str);
115 void conv_mb_alnum(gchar *str);
116
117 void conv_jistodisp  (gchar *outbuf, gint outlen, const gchar *inbuf);
118 void conv_sjistodisp (gchar *outbuf, gint outlen, const gchar *inbuf);
119 void conv_euctodisp  (gchar *outbuf, gint outlen, const gchar *inbuf);
120 void conv_ustodisp   (gchar *outbuf, gint outlen, const gchar *inbuf);
121 void conv_latintodisp(gchar *outbuf, gint outlen, const gchar *inbuf);
122 void conv_noconv     (gchar *outbuf, gint outlen, const gchar *inbuf);
123
124 CodeConverter *conv_code_converter_new  (const gchar    *charset);
125 void conv_code_converter_destroy        (CodeConverter  *conv);
126 gint conv_convert                       (CodeConverter  *conv,
127                                          gchar          *outbuf,
128                                          gint            outlen,
129                                          const gchar    *inbuf);
130
131 gchar *conv_codeset_strdup(const gchar *inbuf,
132                            const gchar *src_codeset,
133                            const gchar *dest_codeset);
134
135 CodeConvFunc conv_get_code_conv_func(const gchar *charset);
136
137 const gchar *conv_get_charset_str               (CharSet         charset);
138 CharSet conv_get_charset_from_str               (const gchar    *charset);
139 CharSet conv_get_current_charset                (void);
140 const gchar *conv_get_current_charset_str       (void);
141 CharSet conv_get_outgoing_charset               (void);
142 const gchar *conv_get_outgoing_charset_str      (void);
143
144 const gchar *conv_get_current_locale            (void);
145
146 void conv_unmime_header_overwrite       (gchar          *str);
147 void conv_unmime_header                 (gchar          *outbuf,
148                                          gint            outlen,
149                                          const gchar    *str,
150                                          const gchar    *charset);
151 void conv_encode_header                 (gchar          *dest,
152                                          gint            len,
153                                          const gchar    *src,
154                                          gint            header_len);
155
156
157 #endif /* __CODECONV_H__ */