Add ManageSieve plugin
[claws.git] / src / plugins / managesieve / managesieve.h
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2015 the Claws Mail team
4  * Copyright (C) 2014-2015 Charles Lehner
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  * 
19  */
20
21 #ifndef MANAGESIEVE_H
22 #define MANAGESIEVE_H
23
24 #include "prefs_account.h"
25 #include "socket.h"
26 #include "session.h"
27
28 #define SIEVE_SESSION(obj)      ((SieveSession *)obj)
29 #define SIEVE_PORT 4190
30
31 typedef struct SieveSession SieveSession;
32 typedef struct SieveCommand SieveCommand;
33 typedef struct SieveScript SieveScript;
34 typedef struct SieveResult SieveResult;
35
36 typedef enum
37 {
38         SE_OK                   = 0,
39         SE_ERROR                        = 128,
40         SE_UNRECOVERABLE        = 129,
41         SE_AUTHFAIL             = 130
42 } SieveErrorValue;
43
44 typedef enum
45 {
46         SIEVEAUTH_NONE          = 0,
47         SIEVEAUTH_REUSE         = 1,
48         SIEVEAUTH_CUSTOM        = 2
49 } SieveAuth;
50
51 typedef enum
52 {
53         SIEVEAUTH_AUTO                  = 0,
54         SIEVEAUTH_PLAIN                 = 1 << 0,
55         SIEVEAUTH_LOGIN                 = 1 << 1,
56         SIEVEAUTH_CRAM_MD5              = 1 << 2,
57 } SieveAuthType;
58
59 typedef enum
60 {
61         SIEVE_CAPABILITIES,
62         SIEVE_READY,
63         SIEVE_LISTSCRIPTS,
64         SIEVE_STARTTLS,
65         SIEVE_NOOP,
66         SIEVE_RETRY_AUTH,
67         SIEVE_AUTH,
68         SIEVE_AUTH_PLAIN,
69         SIEVE_AUTH_LOGIN_USER,
70         SIEVE_AUTH_LOGIN_PASS,
71         SIEVE_AUTH_CRAM_MD5,
72         SIEVE_RENAMESCRIPT,
73         SIEVE_SETACTIVE,
74         SIEVE_GETSCRIPT,
75         SIEVE_GETSCRIPT_DATA,
76         SIEVE_PUTSCRIPT,
77         SIEVE_PUTSCRIPT_DATA,
78         SIEVE_DELETESCRIPT,
79         SIEVE_ERROR,
80         SIEVE_DISCONNECTED,
81
82         N_SIEVE_PHASE
83 } SieveState;
84
85 typedef enum
86 {
87         SIEVE_CODE_NONE,
88         SIEVE_CODE_WARNINGS,
89         SIEVE_CODE_TRYLATER,
90         SIEVE_CODE_UNKNOWN
91 } SieveResponseCode;
92
93 typedef enum {
94         SIEVE_TLS_NO,
95         SIEVE_TLS_MAYBE,
96         SIEVE_TLS_YES
97 } SieveTLSType;
98
99 typedef void (*sieve_session_cb_fn) (SieveSession *session, gpointer data);
100 typedef void (*sieve_session_data_cb_fn) (SieveSession *session,
101                 gpointer cb_data, gpointer user_data);
102 typedef void (*sieve_session_error_cb_fn) (SieveSession *session,
103                 const gchar *msg, gpointer user_data);
104 typedef void (*sieve_session_connected_cb_fn) (SieveSession *session,
105                 gboolean connected, gpointer user_data);
106
107 struct SieveSession
108 {
109         Session session;
110         PrefsAccount *account;
111         struct SieveAccountConfig *config;
112         SieveState state;
113         gboolean authenticated;
114         GSList *send_queue;
115         SieveErrorValue error;
116         SieveCommand *current_cmd;
117
118         gboolean use_auth;
119         SieveAuthType avail_auth_type;
120         SieveAuthType forced_auth_type;
121         SieveAuthType auth_type;
122
123         gchar *host;
124         gushort port;
125         gchar *user;
126         gchar *pass;
127
128 #ifdef USE_GNUTLS
129         gboolean tls_init_done;
130 #endif
131
132         struct {
133                 gboolean starttls;
134         } capability;
135
136         sieve_session_error_cb_fn on_error;
137         sieve_session_connected_cb_fn on_connected;
138         gpointer cb_data;
139 };
140
141 struct SieveCommand {
142         SieveState next_state;
143         gchar *msg;
144         sieve_session_data_cb_fn cb;
145         gpointer data;
146 };
147
148 struct SieveScript {
149         gchar *name;
150         gboolean active;
151 };
152
153 struct SieveResult {
154         gboolean has_status;
155         gboolean success;
156         SieveResponseCode code;
157         gchar *description;
158         gboolean has_octets;
159         guint octets;
160 };
161
162 void sieve_sessions_close();
163
164 void sieve_account_prefs_updated(PrefsAccount *account);
165 SieveSession *sieve_session_get_for_account(PrefsAccount *account);
166 void sieve_sessions_discard_callbacks(gpointer user_data);
167 void sieve_session_handle_status(SieveSession *session,
168                 sieve_session_error_cb_fn on_error,
169                 sieve_session_connected_cb_fn on_connected,
170                 gpointer data);
171 void sieve_session_list_scripts(SieveSession *session,
172                 sieve_session_data_cb_fn got_script_name_cb, gpointer data);
173 void sieve_session_add_script(SieveSession *session, const gchar *filter_name,
174                 sieve_session_data_cb_fn cb, gpointer data);
175 void sieve_session_set_active_script(SieveSession *session,
176                 const gchar *filter_name,
177                 sieve_session_data_cb_fn cb, gpointer data);
178 void sieve_session_rename_script(SieveSession *session,
179                 const gchar *name_old, const char *name_new,
180                 sieve_session_data_cb_fn cb, gpointer data);
181 void sieve_session_get_script(SieveSession *session, const gchar *filter_name,
182                 sieve_session_data_cb_fn cb, gpointer data);
183 void sieve_session_put_script(SieveSession *session, const gchar *filter_name,
184                 gint len, const gchar *script_contents,
185                 sieve_session_data_cb_fn cb, gpointer data);
186 void sieve_session_check_script(SieveSession *session,
187                 gint len, const gchar *script_contents,
188                 sieve_session_data_cb_fn cb, gpointer data);
189 void sieve_session_delete_script(SieveSession *session,
190                 const gchar *filter_name,
191                 sieve_session_data_cb_fn cb, gpointer data);
192
193 #endif /* MANAGESIEVE_H */