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_H__
24 #define __LIBBALSA_H__
25 
26 #ifndef BALSA_VERSION
27 # error "Include config.h before this file."
28 #endif
29 
30 typedef struct _LibBalsaCondition LibBalsaCondition;
31 typedef struct _LibBalsaIdentity LibBalsaIdentity;
32 typedef struct _LibBalsaMailbox LibBalsaMailbox;
33 typedef struct _LibBalsaMailboxRemote LibBalsaMailboxRemote;
34 typedef struct _LibBalsaMailboxSearchIter LibBalsaMailboxSearchIter;
35 typedef struct _LibBalsaMessage LibBalsaMessage;
36 typedef struct _LibBalsaMessageHeaders LibBalsaMessageHeaders;
37 typedef struct _LibBalsaMessageBody LibBalsaMessageBody;
38 typedef struct _LibBalsaServer LibBalsaServer;
39 #if ENABLE_ESMTP
40 typedef struct _LibBalsaSmtpServer LibBalsaSmtpServer;
41 #endif                          /* ENABLE_ESMTP */
42 typedef struct _LibbalsaVfs LibbalsaVfs;
43 
44 
45 #include "message.h"
46 #include "body.h"
47 #include "files.h"
48 #include "mime.h"
49 
50 #include "information.h"
51 
52 #include "address-book.h"
53 #include "address-book-vcard.h"
54 #include "address-book-ldif.h"
55 #include "address-book-extern.h"
56 
57 #if ENABLE_LDAP
58 #include "address-book-ldap.h"
59 #endif
60 #if HAVE_SQLITE
61 #include "address-book-gpe.h"
62 #endif
63 #if HAVE_RUBRICA
64 #include "address-book-rubrica.h"
65 #endif
66 
67 #include "mailbox.h"
68 #include "mailbox_local.h"
69 #include "mailbox_remote.h"
70 #include "mailbox_pop3.h"
71 #include "mailbox_imap.h"
72 #include "mailbox_mbox.h"
73 #include "mailbox_mh.h"
74 #include "mailbox_maildir.h"
75 
76 #define ELEMENTS(x) (sizeof (x) / sizeof (x[0]))
77 
78 /*
79  * Error domains for GError:
80  */
81 GQuark libbalsa_scanner_error_quark(void);
82 #define LIBBALSA_SCANNER_ERROR libbalsa_scanner_error_quark()
83 GQuark libbalsa_mailbox_error_quark(void);
84 #define LIBBALSA_MAILBOX_ERROR libbalsa_mailbox_error_quark()
85 
86 /*
87  * Error codes for GError:
88  */
89 enum {
90     LIBBALSA_SCANNER_ERROR_IMAP,
91     LIBBALSA_MAILBOX_APPEND_ERROR,
92     LIBBALSA_MAILBOX_AUTH_ERROR, /* retryable */
93     LIBBALSA_MAILBOX_AUTH_CANCELLED, /* do not try again */
94     LIBBALSA_MAILBOX_COPY_ERROR,
95     LIBBALSA_MAILBOX_RENAME_ERROR,
96     LIBBALSA_MAILBOX_CREATE_ERROR,
97     LIBBALSA_MAILBOX_DELETE_ERROR,
98     LIBBALSA_MAILBOX_NETWORK_ERROR,
99     LIBBALSA_MAILBOX_OPEN_ERROR,
100     LIBBALSA_MAILBOX_TOOMANYOPEN_ERROR,
101     LIBBALSA_MAILBOX_ACCESS_ERROR,
102     LIBBALSA_MAILBOX_DUPLICATES_ERROR,
103     LIBBALSA_MAILBOX_TEMPDIR_ERROR
104 };
105 
106 
107 /*
108  * Initialize the library
109  */
110 void libbalsa_init(LibBalsaInformationFunc information_callback);
111 void libbalsa_set_spool(const gchar * spool);
112 
113 void libbalsa_show_message_source(LibBalsaMessage * msg,
114                                   const gchar * font,
115                                   gboolean *escape_specials,
116                                   gint * width, gint * height);
117 gchar *libbalsa_rot(const gchar * pass);
118 
119 gchar *libbalsa_guess_email_address(void);
120 gchar *libbalsa_guess_mail_spool(void);
121 gboolean libbalsa_is_sending_mail(void);
122 void libbalsa_wait_for_sending_thread(gint max_seconds);
123 
124 gchar *libbalsa_guess_pop_server(void);
125 gchar *libbalsa_guess_imap_server(void);
126 gchar *libbalsa_guess_ldap_server(void);
127 
128 gchar *libbalsa_guess_imap_inbox(void);
129 
130 
131 gchar* libbalsa_date_to_utf8(const time_t *date, const gchar *date_string);
132 LibBalsaMessageStatus libbalsa_get_icon_from_flags(LibBalsaMessageFlag flags);
133 
134 #ifdef USE_TLS
135 #include <openssl/ssl.h>
136 gboolean libbalsa_is_cert_known(X509* cert, long vfy_result);
137 void libbalsa_certs_destroy(void);
138 #endif
139 
140 gboolean libbalsa_abort_on_timeout(const char *host);
141 
142 #ifdef BALSA_USE_THREADS
143 #include <pthread.h>
144 pthread_t libbalsa_get_main_thread(void);
145 gboolean libbalsa_am_i_subthread(void);
146 #else
147 #define libbalsa_am_i_subthread() FALSE
148 #endif /* BALSA_USE_THREADS */
149 #if defined(BALSA_DEBUG_THREADS)
150 #define gdk_threads_enter()                       \
151     do if (libbalsa_am_i_subthread())             \
152         g_warning("%s: sub-thread!\n", __func__); \
153     while (0)
154 #else
155 #define gdk_threads_enter()
156 #endif
157 #define gdk_threads_leave()
158 void libbalsa_message(const char *fmt, ...)
159 #ifdef __GNUC__
160     __attribute__ ((format (printf, 1, 2)))
161 #endif
162 ;
163 gchar * libbalsa_rot(const gchar * pass);
164 
165 typedef enum {
166     LIBBALSA_PROGRESS_NO = 0,
167     LIBBALSA_PROGRESS_YES
168 } LibBalsaProgress;
169 #define LIBBALSA_PROGRESS_INIT LIBBALSA_PROGRESS_NO
170 /* We will not use the progress bar if the number of increments is less
171  * than LIBBALSA_PROGRESS_MIN_COUNT, and we will not update the fraction
172  * if the time since the last update is less than
173  * LIBBALSA_PROGRESS_MIN_UPDATE_SECS seconds or if the fraction has
174  * increased by less than LIBBALSA_PROGRESS_MIN_UPDATE_STEP. */
175 #define LIBBALSA_PROGRESS_MIN_COUNT        400
176 #define LIBBALSA_PROGRESS_MIN_UPDATE_USECS 50000
177 #define LIBBALSA_PROGRESS_MIN_UPDATE_STEP  0.05
178 
179 extern void (*libbalsa_progress_set_text) (LibBalsaProgress * progress,
180                                            const gchar * text,
181                                            guint total);
182 extern void (*libbalsa_progress_set_fraction) (LibBalsaProgress * progress,
183                                                gdouble fraction);
184 extern void (*libbalsa_progress_set_activity) (gboolean set,
185                                                const gchar * text);
186 
187 /*
188  * Face and X-Face header support.
189  */
190 gchar *libbalsa_get_header_from_path(const gchar * header,
191                                      const gchar * path, gsize * size,
192                                      GError ** err);
193 GtkWidget *libbalsa_get_image_from_face_header(const gchar * content,
194                                                GError ** err);
195 #if HAVE_COMPFACE
196 GtkWidget *libbalsa_get_image_from_x_face_header(const gchar * content,
197                                                  GError ** err);
198 #endif                          /* HAVE_COMPFACE */
199 
200 GQuark libbalsa_image_error_quark(void);
201 #define LIBBALSA_IMAGE_ERROR libbalsa_image_error_quark()
202 enum LibBalsaImageError {
203     LIBBALSA_IMAGE_ERROR_NO_DATA
204 #if HAVE_COMPFACE
205         ,
206     LIBBALSA_IMAGE_ERROR_FORMAT,
207     LIBBALSA_IMAGE_ERROR_BUFFER,
208     LIBBALSA_IMAGE_ERROR_BAD_DATA
209 #endif                          /* HAVE_COMPFACE */
210 };
211 
212 #if HAVE_GTKSOURCEVIEW
213 GtkWidget *libbalsa_source_view_new(gboolean highlight_phrases);
214 #endif                          /* HAVE_GTKSOURCEVIEW */
215 
216 #endif                          /* __LIBBALSA_H__ */
217