update copyright year
[claws.git] / src / common / codeconv.h
1 /*
2  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifndef __CODECONV_H__
21 #define __CODECONV_H__
22
23 #ifdef HAVE_CONFIG_H
24 #include "claws-features.h"
25 #endif
26
27 #include <glib.h>
28 #include <iconv.h>
29
30 typedef struct _CodeConverter   CodeConverter;
31
32 typedef enum
33 {
34         C_UNINITIALIZED,
35         C_AUTO,
36         C_US_ASCII,
37         C_UTF_8,
38         C_UTF_7,
39         C_ISO_8859_1,
40         C_ISO_8859_2,
41         C_ISO_8859_3,
42         C_ISO_8859_4,
43         C_ISO_8859_5,
44         C_ISO_8859_6,
45         C_ISO_8859_7,
46         C_ISO_8859_8,
47         C_ISO_8859_9,
48         C_ISO_8859_10,
49         C_ISO_8859_11,
50         C_ISO_8859_13,
51         C_ISO_8859_14,
52         C_ISO_8859_15,
53         C_BALTIC,
54         C_CP1250,
55         C_CP1251,
56         C_CP1252,
57         C_CP1253,
58         C_CP1254,
59         C_CP1255,
60         C_CP1256,
61         C_CP1257,
62         C_CP1258,
63         C_WINDOWS_1250,
64         C_WINDOWS_1251,
65         C_WINDOWS_1252,
66         C_WINDOWS_1253,
67         C_WINDOWS_1254,
68         C_WINDOWS_1255,
69         C_WINDOWS_1256,
70         C_WINDOWS_1257,
71         C_WINDOWS_1258,
72         C_KOI8_R,
73         C_MACCYR,
74         C_KOI8_T,
75         C_KOI8_U,
76         C_ISO_2022_JP,
77         C_ISO_2022_JP_2,
78         C_ISO_2022_JP_3,
79         C_EUC_JP,
80         C_EUC_JP_MS,
81         C_SHIFT_JIS,
82         C_ISO_2022_KR,
83         C_EUC_KR,
84         C_ISO_2022_CN,
85         C_EUC_CN,
86         C_GB18030,
87         C_GB2312,
88         C_GBK,
89         C_EUC_TW,
90         C_BIG5,
91         C_BIG5_HKSCS,
92         C_TIS_620,
93         C_WINDOWS_874,
94         C_GEORGIAN_PS,
95         C_TCVN5712_1
96 } CharSet;
97
98 typedef gint (*CodeConvFunc) (gchar *outbuf, gint outlen, const gchar *inbuf);
99
100 struct _CodeConverter
101 {
102         CodeConvFunc code_conv_func;
103         gchar *charset_str;
104         CharSet charset;
105 };
106
107 #define CS_AUTO                 "AUTO"
108 #define CS_US_ASCII             "US-ASCII"
109 #define CS_ANSI_X3_4_1968       "ANSI_X3.4-1968"
110 #define CS_UTF_8                "UTF-8"
111 #define CS_UTF_7                "UTF-7"
112 #define CS_ISO_8859_1           "ISO-8859-1"
113 #define CS_ISO_8859_2           "ISO-8859-2"
114 #define CS_ISO_8859_3           "ISO-8859-3"
115 #define CS_ISO_8859_4           "ISO-8859-4"
116 #define CS_ISO_8859_5           "ISO-8859-5"
117 #define CS_ISO_8859_6           "ISO-8859-6"
118 #define CS_ISO_8859_7           "ISO-8859-7"
119 #define CS_ISO_8859_8           "ISO-8859-8"
120 #define CS_ISO_8859_8_I "ISO-8859-8-I"
121 #define CS_ISO_8859_9           "ISO-8859-9"
122 #define CS_ISO_8859_10          "ISO-8859-10"
123 #define CS_ISO_8859_11          "ISO-8859-11"
124 #define CS_ISO_8859_13          "ISO-8859-13"
125 #define CS_ISO_8859_14          "ISO-8859-14"
126 #define CS_ISO_8859_15          "ISO-8859-15"
127 #define CS_BALTIC               "BALTIC"
128 #define CS_CP1250               "CP1250"
129 #define CS_CP1251               "CP1251"
130 #define CS_CP1252               "CP1252"
131 #define CS_CP1253               "CP1253"
132 #define CS_CP1254               "CP1254"
133 #define CS_CP1255               "CP1255"
134 #define CS_CP1256               "CP1256"
135 #define CS_CP1257               "CP1257"
136 #define CS_CP1258               "CP1258"
137 #define CS_WINDOWS_1250         "Windows-1250"
138 #define CS_WINDOWS_1251         "Windows-1251"
139 #define CS_WINDOWS_1252         "Windows-1252"
140 #define CS_WINDOWS_1253         "Windows-1253"
141 #define CS_WINDOWS_1254         "Windows-1254"
142 #define CS_WINDOWS_1255         "Windows-1255"
143 #define CS_WINDOWS_1256         "Windows-1256"
144 #define CS_WINDOWS_1257         "Windows-1257"
145 #define CS_WINDOWS_1258         "Windows-1258"
146 #define CS_KOI8_R               "KOI8-R"
147 #define CS_X_MACCYR             "x-mac-cyrillic"
148 #define CS_MACCYR               "Mac-Cyrillic"
149 #define CS_KOI8_T               "KOI8-T"
150 #define CS_KOI8_U               "KOI8-U"
151 #define CS_ISO_2022_JP          "ISO-2022-JP"
152 #define CS_ISO_2022_JP_2        "ISO-2022-JP-2"
153 #define CS_ISO_2022_JP_3        "ISO-2022-JP-3"
154 #define CS_EUC_JP               "EUC-JP"
155 #define CS_EUCJP                "EUCJP"
156 #define CS_EUC_JP_MS            "EUC-JP-MS"
157 #define CS_SHIFT_JIS            "Shift_JIS"
158 #define CS_SHIFT__JIS           "SHIFT-JIS"
159 #define CS_SJIS                 "SJIS"
160 #define CS_X_SJIS               "X-SJIS"
161 #define CS_ISO_2022_KR          "ISO-2022-KR"
162 #define CS_EUC_KR               "EUC-KR"
163 #define CS_ISO_2022_CN          "ISO-2022-CN"
164 #define CS_EUC_CN               "EUC-CN"
165 #define CS_GB18030              "GB18030"
166 #define CS_GB2312               "GB2312"
167 #define CS_GBK                  "GBK"
168 #define CS_X_GBK                "X-GBK"
169 #define CS_EUC_TW               "EUC-TW"
170 #define CS_BIG5                 "Big5"
171 #define CS_BIG5_HKSCS           "BIG5-HKSCS"
172 #define CS_TIS_620              "TIS-620"
173 #define CS_WINDOWS_874          "Windows-874"
174 #define CS_GEORGIAN_PS          "GEORGIAN-PS"
175 #define CS_TCVN5712_1           "TCVN5712-1"
176 #define CS_X_VIET_VPS           "X-VIET-VPS"
177
178 #define C_INTERNAL              C_UTF_8
179 #define CS_INTERNAL             CS_UTF_8
180
181 void conv_utf8todisp    (gchar *outbuf, gint outlen, const gchar *inbuf);
182 void conv_localetodisp  (gchar *outbuf, gint outlen, const gchar *inbuf);
183
184 CodeConverter *conv_code_converter_new  (const gchar    *src_charset);
185 void conv_code_converter_destroy        (CodeConverter  *conv);
186 gint conv_convert                       (CodeConverter  *conv,
187                                          gchar          *outbuf,
188                                          gint            outlen,
189                                          const gchar    *inbuf);
190
191 gchar *conv_codeset_strdup              (const gchar    *inbuf,
192                                          const gchar    *src_code,
193                                          const gchar    *dest_code);
194
195 const gchar *conv_get_charset_str               (CharSet         charset);
196 CharSet conv_get_charset_from_str               (const gchar    *charset);
197 const gchar *conv_get_locale_charset_str        (void);
198 const gchar *conv_get_locale_charset_str_no_utf8(void);
199 const gchar *conv_get_outgoing_charset_str      (void);
200
201 const gchar *conv_get_current_locale            (void);
202
203 gchar *conv_unmime_header               (const gchar    *str,
204                                           const gchar   *default_encoding,
205                                           gboolean       addr_field);
206 void conv_encode_header                 (gchar          *dest,
207                                          gint            len,
208                                          const gchar    *src,
209                                          gint            header_len,
210                                          gboolean        addr_field);
211 void conv_encode_header_full            (gchar          *dest,
212                                          gint            len,
213                                          const gchar    *src,
214                                          gint            header_len,
215                                          gboolean        addr_field,
216                                          const gchar    *out_encoding_);
217
218 gchar *conv_filename_from_utf8          (const gchar    *utf8_file);
219 gchar *conv_filename_to_utf8            (const gchar    *fs_file);
220
221 void codeconv_set_strict                (gboolean        mode);
222 void codeconv_set_allow_jisx0201_kana   (gboolean        allow);
223 void codeconv_set_broken_are_utf8       (gboolean        are);
224
225 #endif /* __CODECONV_H__ */