1 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
2 /* Balsa E-Mail Client
3  *
4  * Copyright (C) 1997-2013 Stuart Parmenter and others,
5  *                         See the file AUTHORS for a list.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20  * 02111-1307, USA.
21  */
22 
23 #ifndef __LIBBALSA_MISC_H__
24 #define __LIBBALSA_MISC_H__
25 
26 #ifndef BALSA_VERSION
27 # error "Include config.h before this file."
28 #endif
29 
30 #include <stdio.h>
31 #include <gtk/gtk.h>
32 #include <gmime/gmime.h>
33 
34 #if !USE_GREGEX
35 #  ifdef HAVE_PCRE
36 #    include <pcreposix.h>
37 #  else
38 #    include <sys/types.h>
39 #    include <regex.h>
40 #  endif
41 #endif                          /* USE_GREGEX */
42 
43 typedef enum _LibBalsaCodeset LibBalsaCodeset;
44 
45 enum _LibBalsaCodeset {
46     WEST_EUROPE,        /* iso-8859-1 or windows-1252 */
47     EAST_EUROPE,        /* iso-8859-2 or windows-1250 */
48     SOUTH_EUROPE,       /* iso-8859-3 */
49     NORTH_EUROPE,       /* iso-8859-4 */
50     CYRILLIC,           /* iso-8859-5 or windows-1251 */
51     ARABIC,             /* iso-8859-6 or windows-1256 */
52     GREEK,              /* iso-8859-7 or windows-1253 */
53     HEBREW,             /* iso-8859-8 or windows-1255 */
54     TURKISH,            /* iso-8859-9 or windows-1254 */
55     NORDIC,             /* iso-8859-10 */
56     THAI,               /* iso-8859-11 */
57     BALTIC,             /* iso-8859-13 or windows-1257 */
58     CELTIC,             /* iso-8859-14 */
59     WEST_EUROPE_EURO,   /* iso-8859-15 */
60     RUSSIAN,            /* koi-8r */
61     UKRAINE,            /* koi-8u */
62     JAPAN,              /* iso-2022-jp */
63     KOREA,              /* euc-kr */
64     EAST_EUROPE_WIN,    /* windows-1250 */
65     CYRILLIC_WIN,       /* windows-1251 */
66     GREEK_WIN,          /* windows-1253 */
67     HEBREW_WIN,         /* windows-1255 */
68     ARABIC_WIN,         /* windows-1256 */
69     BALTIC_WIN,         /* windows-1257 */
70     LIBBALSA_NUM_CODESETS
71 };
72 
73 typedef enum _LibBalsaTextAttribute LibBalsaTextAttribute;
74 enum _LibBalsaTextAttribute {
75     LIBBALSA_TEXT_ESC     = 1 << 0,     /* ESC char(s)     */
76     LIBBALSA_TEXT_HI_BIT  = 1 << 1,     /* 8-bit char(s)   */
77     LIBBALSA_TEXT_HI_CTRL = 1 << 2,     /* 0x80 - 0x9f     */
78     LIBBALSA_TEXT_HI_UTF8 = 1 << 3      /* 8-bit utf-8     */
79 };
80 
81 typedef struct _LibBalsaCodesetInfo LibBalsaCodesetInfo;
82 struct _LibBalsaCodesetInfo {
83     const gchar *label;
84     const gchar *std;
85     const gchar *win;
86 };
87 
88 typedef void (*libbalsa_url_cb_t) (GtkTextBuffer *, GtkTextIter *,
89 				   const gchar *, guint, gpointer);
90 typedef struct _LibBalsaUrlInsertInfo LibBalsaUrlInsertInfo;
91 struct _LibBalsaUrlInsertInfo {
92     libbalsa_url_cb_t callback;
93     gpointer callback_data;
94     gboolean buffer_is_flowed;
95     GString *ml_url_buffer;
96 };
97 
98 #define LIBBALSA_ERROR_QUARK (g_quark_from_static_string("libbalsa"))
99 
100 extern LibBalsaCodesetInfo libbalsa_codeset_info[];
101 GtkWidget *libbalsa_charset_button_new(void);
102 LibBalsaTextAttribute libbalsa_text_attr_string(const gchar * string);
103 LibBalsaTextAttribute libbalsa_text_attr_file(const gchar * filename);
104 
105 size_t libbalsa_readfile(FILE * fp, char **buf);
106 size_t libbalsa_readfile_nostat(FILE * fp, char **buf);
107 
108 gchar *libbalsa_get_hostname(void);
109 gchar *libbalsa_get_domainname(void);
110 gchar *libbalsa_urlencode(const gchar* str);
111 gchar *libbalsa_urldecode(const gchar * str);
112 
113 gboolean libbalsa_find_word(const gchar * word, const gchar * str);
114 void libbalsa_wrap_string(gchar * str, int width);
115 GString *libbalsa_process_text_rfc2646(gchar * par, gint width,
116 				       gboolean from_screen,
117 				       gboolean to_screen, gboolean quote,
118 				       gboolean delsp);
119 gchar *libbalsa_wrap_rfc2646(gchar * par, gint width,
120                              gboolean from_screen, gboolean to_screen,
121 			     gboolean delsp);
122 void libbalsa_wrap_view(GtkTextView * view, gint length);
123 void libbalsa_unwrap_buffer(GtkTextBuffer * buffer, GtkTextIter * iter,
124                             gint lines);
125 
126 const char* libbalsa_set_charset(const gchar * charset);
127 const char* libbalsa_set_send_charset(const gchar * charset);
128 
129 gboolean libbalsa_delete_directory_contents(const gchar *path);
130 gchar *libbalsa_truncate_string(const gchar * str, gint length, gint dots);
131 gchar *libbalsa_expand_path(const gchar *path);
132 void libbalsa_contract_path(gchar *path);
133 gboolean libbalsa_mktempdir(gchar ** name);
134 LibBalsaCodeset libbalsa_set_fallback_codeset(LibBalsaCodeset codeset);
135 gboolean libbalsa_utf8_sanitize(gchar ** text, gboolean fallback,
136                                 gchar const **target);
137 gboolean libbalsa_utf8_strstr(const gchar *s1,const gchar *s2);
138 gboolean libbalsa_insert_with_url(GtkTextBuffer * buffer,
139 				  const char *chars,
140 				  guint len,
141 				  GtkTextTag * tag,
142 				  LibBalsaUrlInsertInfo *url_info);
143 #if USE_GREGEX
144 void libbalsa_unwrap_selection(GtkTextBuffer * buffer, GRegex * rex);
145 gboolean libbalsa_match_regex(const gchar * line, GRegex * rex,
146 			      guint * count, guint * index);
147 #else                           /* USE_GREGEX */
148 void libbalsa_unwrap_selection(GtkTextBuffer * buffer, regex_t * rex);
149 gboolean libbalsa_match_regex(const gchar * line, regex_t * rex,
150 			      guint * count, guint * index);
151 #endif                          /* USE_GREGEX */
152 
153 int libbalsa_safe_open (const char *path, int flags, mode_t mode, GError **err);
154 int libbalsa_lock_file (const char *path, int fd, int excl, int dot, int timeout);
155 int libbalsa_unlock_file (const char *path, int fd, int dot);
156 int libbalsa_safe_rename (const char *src, const char *target);
157 #define libbalsa_str_has_prefix(str, prefix) g_str_has_prefix((str), (prefix))
158 
159 gboolean libbalsa_ia_rfc2821_equal(const InternetAddress * a,
160 				   const InternetAddress * b);
161 
162 GtkWidget *libbalsa_create_grid(void);
163 GtkWidget *libbalsa_create_grid_label(const gchar * label, GtkWidget * grid,
164                                       gint row);
165 GtkWidget *libbalsa_create_grid_entry(GtkWidget * grid, GCallback func,
166                                       gpointer data, gint row,
167                                       const gchar * initval,
168                                       GtkWidget * hotlabel);
169 GtkWidget *libbalsa_create_grid_check(const gchar * label, GtkWidget * grid,
170                                       gint row, gboolean initval);
171 GtkSizeGroup *libbalsa_create_size_group(GtkWidget * chooser);
172 
173 void libbalsa_assure_balsa_dir(void);
174 gchar *libbalsa_guess_ldap_base(void);
175 gchar *libbalsa_guess_ldap_name(void);
176 
177 gchar *libbalsa_guess_ldif_file(void);
178 
179 gboolean libbalsa_ldap_exists(const gchar *server);
180 
181 gboolean libbalsa_path_is_below_dir(const gchar * path, const gchar * dir);
182 
183 gchar *libbalsa_size_to_gchar(guint64 length);
184 
185 gchar * libbalsa_text_to_html(const gchar * title, const gchar * body, const gchar * lang);
186 GString * libbalsa_html_encode_hyperlinks(GString * paragraph);
187 
188 #endif				/* __LIBBALSA_MISC_H__ */
189