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_DELETESCRIPT, 78 SIEVE_ERROR, 79 SIEVE_DISCONNECTED, 80 81 N_SIEVE_PHASE 82 } SieveState; 83 84 typedef enum 85 { 86 SIEVE_CODE_NONE, 87 SIEVE_CODE_WARNINGS, 88 SIEVE_CODE_TRYLATER, 89 SIEVE_CODE_UNKNOWN 90 } SieveResponseCode; 91 92 typedef enum { 93 SIEVE_TLS_NO, 94 SIEVE_TLS_MAYBE, 95 SIEVE_TLS_YES 96 } SieveTLSType; 97 98 typedef void (*sieve_session_cb_fn) (SieveSession *session, gpointer data); 99 typedef void (*sieve_session_data_cb_fn) (SieveSession *session, 100 gboolean aborted, gpointer cb_data, gpointer user_data); 101 typedef void (*sieve_session_error_cb_fn) (SieveSession *session, 102 const gchar *msg, gpointer user_data); 103 typedef void (*sieve_session_connected_cb_fn) (SieveSession *session, 104 gboolean connected, gpointer user_data); 105 106 struct SieveSession 107 { 108 Session session; 109 PrefsAccount *account; 110 struct SieveAccountConfig *config; 111 SieveState state; 112 gboolean authenticated; 113 GSList *send_queue; 114 SieveErrorValue error; 115 SieveCommand *current_cmd; 116 guint octets_remaining; 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 SieveSession *session; 143 SieveState next_state; 144 gchar *msg; 145 sieve_session_data_cb_fn cb; 146 gpointer data; 147 }; 148 149 struct SieveScript { 150 gchar *name; 151 gboolean active; 152 }; 153 154 struct SieveResult { 155 gboolean has_status; 156 gboolean success; 157 SieveResponseCode code; 158 gchar *description; 159 gboolean has_octets; 160 guint octets; 161 }; 162 163 void sieve_sessions_close(); 164 165 void sieve_account_prefs_updated(PrefsAccount *account); 166 SieveSession *sieve_session_get_for_account(PrefsAccount *account); 167 void sieve_sessions_discard_callbacks(gpointer user_data); 168 void sieve_session_handle_status(SieveSession *session, 169 sieve_session_error_cb_fn on_error, 170 sieve_session_connected_cb_fn on_connected, 171 gpointer data); 172 void sieve_session_list_scripts(SieveSession *session, 173 sieve_session_data_cb_fn got_script_name_cb, gpointer data); 174 void sieve_session_set_active_script(SieveSession *session, 175 const gchar *filter_name, 176 sieve_session_data_cb_fn cb, gpointer data); 177 void sieve_session_rename_script(SieveSession *session, 178 const gchar *name_old, const char *name_new, 179 sieve_session_data_cb_fn cb, gpointer data); 180 void sieve_session_get_script(SieveSession *session, const gchar *filter_name, 181 sieve_session_data_cb_fn cb, gpointer data); 182 void sieve_session_put_script(SieveSession *session, const gchar *filter_name, 183 gint len, const gchar *script_contents, 184 sieve_session_data_cb_fn cb, gpointer data); 185 void sieve_session_check_script(SieveSession *session, 186 gint len, const gchar *script_contents, 187 sieve_session_data_cb_fn cb, gpointer data); 188 void sieve_session_delete_script(SieveSession *session, 189 const gchar *filter_name, 190 sieve_session_data_cb_fn cb, gpointer data); 191 192 #endif /* MANAGESIEVE_H */ 193