[balsa] Declare LibBalsaServer derivable



commit 74c669c2ba6edb5e6ec42e83eaa88d3752dd6e6c
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Jun 7 20:23:03 2019 -0400

    Declare LibBalsaServer derivable
    
    Use G_DECLARE_DERIVABLE_TYPE to declare LibBalsaServer
    and provide and use the necessary getters and setters.
    
    * libbalsa/folder-scanners.c (libbalsa_scanner_imap_tree):
    * libbalsa/imap-server.c (libbalsa_imap_server_set_username),
    (libbalsa_imap_server_set_host), (libbalsa_imap_server_init),
    (is_info_cb), (lb_imap_server_info_new),
    (libbalsa_imap_server_new_from_config), (handle_connection_error),
    (libbalsa_imap_server_get_handle),
    (libbalsa_imap_server_get_handle_with_user),
    (libbalsa_imap_server_subscriptions):
    * libbalsa/mailbox_imap.c (get_header_cache_path),
    (get_cache_name_pair), (libbalsa_mailbox_imap_reconnect),
    (libbalsa_imap_url), (libbalsa_mailbox_imap_add_messages),
    (libbalsa_mailbox_imap_messages_copy):
    * libbalsa/mailbox_pop3.c (libbalsa_mailbox_pop3_init),
    (libbalsa_mailbox_pop3_startup), (update_msg_list),
    (libbalsa_mailbox_pop3_check):
    * libbalsa/send.c (lbs_check_reachable_cb),
    (lbs_process_queue_init_session):
    * libbalsa/server-config.c (libbalsa_server_cfg_new),
    (libbalsa_server_cfg_assign_server), (server_cfg_security_widget):
    * libbalsa/server.c (libbalsa_server_class_init),
    (libbalsa_server_init), (libbalsa_server_finalize),
    (libbalsa_server_set_password), (lbs_get_password),
    (libbalsa_server_real_set_username),
    (libbalsa_server_real_set_host),
    (libbalsa_server_load_security_config), (store_password_libsecret),
    (load_password_libsecret), (erase_password_libsecret),
    (libbalsa_server_load_config), (libbalsa_server_save_config),
    (libbalsa_server_get_auth), (libbalsa_server_get_cert_pass),
    (libbalsa_server_test_can_reach_full),
    (libbalsa_server_test_can_reach), (libbalsa_server_get_host),
    (libbalsa_server_get_user), (libbalsa_server_get_cert_file),
    (libbalsa_server_get_protocol), (libbalsa_server_get_password),
    (libbalsa_server_get_cert_passphrase),
    (libbalsa_server_get_security),
    (libbalsa_server_get_try_anonymous),
    (libbalsa_server_get_client_cert),
    (libbalsa_server_get_remember_password),
    (libbalsa_server_get_remember_cert_passphrase),
    (libbalsa_server_set_protocol), (libbalsa_server_set_cert_file),
    (libbalsa_server_set_security),
    (libbalsa_server_set_try_anonymous),
    (libbalsa_server_set_remember_password),
    (libbalsa_server_set_client_cert),
    (libbalsa_server_set_remember_cert_passphrase):
    * libbalsa/server.h:
    * libbalsa/smtp-server.c (libbalsa_smtp_server_init),

 ChangeLog                           |  62 ++++
 libbalsa/folder-scanners.c          |   2 +-
 libbalsa/imap-server.c              |  54 ++--
 libbalsa/mailbox_imap.c             |  25 +-
 libbalsa/mailbox_pop3.c             |  30 +-
 libbalsa/send.c                     |  23 +-
 libbalsa/server-config.c            |  72 +++--
 libbalsa/server.c                   | 553 ++++++++++++++++++++++++------------
 libbalsa/server.h                   |  62 ++--
 libbalsa/smtp-server.c              |   4 +-
 libinit_balsa/assistant_page_user.c |   5 +-
 src/balsa-app.c                     |  54 ++--
 src/folder-conf.c                   |   2 +-
 src/mailbox-node.c                  |   8 +-
 src/save-restore.c                  |   6 +-
 15 files changed, 634 insertions(+), 328 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 652d7f3d6..34f356d3a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,65 @@
+2019-06-07  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Use G_DECLARE_DERIVABLE_TYPE to declare LibBalsaServer
+
+       and provide and use the necessary getters and setters.
+
+       * libbalsa/folder-scanners.c (libbalsa_scanner_imap_tree):
+       * libbalsa/imap-server.c (libbalsa_imap_server_set_username),
+       (libbalsa_imap_server_set_host), (libbalsa_imap_server_init),
+       (is_info_cb), (lb_imap_server_info_new),
+       (libbalsa_imap_server_new_from_config), (handle_connection_error),
+       (libbalsa_imap_server_get_handle),
+       (libbalsa_imap_server_get_handle_with_user),
+       (libbalsa_imap_server_subscriptions):
+       * libbalsa/mailbox_imap.c (get_header_cache_path),
+       (get_cache_name_pair), (libbalsa_mailbox_imap_reconnect),
+       (libbalsa_imap_url), (libbalsa_mailbox_imap_add_messages),
+       (libbalsa_mailbox_imap_messages_copy):
+       * libbalsa/mailbox_pop3.c (libbalsa_mailbox_pop3_init),
+       (libbalsa_mailbox_pop3_startup), (update_msg_list),
+       (libbalsa_mailbox_pop3_check):
+       * libbalsa/send.c (lbs_check_reachable_cb),
+       (lbs_process_queue_init_session):
+       * libbalsa/server-config.c (libbalsa_server_cfg_new),
+       (libbalsa_server_cfg_assign_server), (server_cfg_security_widget):
+       * libbalsa/server.c (libbalsa_server_class_init),
+       (libbalsa_server_init), (libbalsa_server_finalize),
+       (libbalsa_server_set_password), (lbs_get_password),
+       (libbalsa_server_real_set_username),
+       (libbalsa_server_real_set_host),
+       (libbalsa_server_load_security_config), (store_password_libsecret),
+       (load_password_libsecret), (erase_password_libsecret),
+       (libbalsa_server_load_config), (libbalsa_server_save_config),
+       (libbalsa_server_get_auth), (libbalsa_server_get_cert_pass),
+       (libbalsa_server_test_can_reach_full),
+       (libbalsa_server_test_can_reach), (libbalsa_server_get_host),
+       (libbalsa_server_get_user), (libbalsa_server_get_cert_file),
+       (libbalsa_server_get_protocol), (libbalsa_server_get_password),
+       (libbalsa_server_get_cert_passphrase),
+       (libbalsa_server_get_security),
+       (libbalsa_server_get_try_anonymous),
+       (libbalsa_server_get_client_cert),
+       (libbalsa_server_get_remember_password),
+       (libbalsa_server_get_remember_cert_passphrase),
+       (libbalsa_server_set_protocol), (libbalsa_server_set_cert_file),
+       (libbalsa_server_set_security),
+       (libbalsa_server_set_try_anonymous),
+       (libbalsa_server_set_remember_password),
+       (libbalsa_server_set_client_cert),
+       (libbalsa_server_set_remember_cert_passphrase):
+       * libbalsa/server.h:
+       * libbalsa/smtp-server.c (libbalsa_smtp_server_init),
+       (libbalsa_smtp_server_new):
+       * libinit_balsa/assistant_page_user.c (create_pop3_mbx),
+       (create_imap_mbx):
+       * src/balsa-app.c (ask_password_real),
+       (balsa_get_short_mailbox_name):
+       * src/folder-conf.c (folder_conf_imap_sub_node):
+       * src/mailbox-node.c (imap_dir_cb),
+       (balsa_mailbox_node_new_from_config), (balsa_mailbox_node_is_imap):
+       * src/save-restore.c (migrate_imap_mailboxes):
+
 2019-06-04  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Remove redundant declarations
diff --git a/libbalsa/folder-scanners.c b/libbalsa/folder-scanners.c
index 1788ac6c0..66d7608ff 100644
--- a/libbalsa/folder-scanners.c
+++ b/libbalsa/folder-scanners.c
@@ -505,7 +505,7 @@ libbalsa_scanner_imap_tree(LibBalsaServer  *server,
                g_hash_table_unref(folders);
        } else {
                if (*error == NULL) {
-                       g_set_error(error, LIBBALSA_SCANNER_ERROR, LIBBALSA_SCANNER_ERROR_IMAP, _("Could not 
connect to “%s”"), server->host);
+                       g_set_error(error, LIBBALSA_SCANNER_ERROR, LIBBALSA_SCANNER_ERROR_IMAP, _("Could not 
connect to “%s”"), libbalsa_server_get_host(server));
                }
        }
 
diff --git a/libbalsa/imap-server.c b/libbalsa/imap-server.c
index 216816890..4fd1f38f2 100644
--- a/libbalsa/imap-server.c
+++ b/libbalsa/imap-server.c
@@ -131,16 +131,20 @@ libbalsa_imap_server_get_type(void)
 static void libbalsa_imap_server_set_username(LibBalsaServer * server,
                                               const gchar * name)
 {
-    if(server->host && name) { /* we have been initialized... */
+    const gchar *host;
+
+    host = libbalsa_server_get_host(server);
+
+    if (host != NULL && name != NULL) { /* we have been initialized... */
         LibBalsaImapServer *imap_server = LIBBALSA_IMAP_SERVER(server);
-        
+
         if (imap_server->key == NULL) {
-               imap_server->key = g_strdup_printf("%s@%s", name, server->host);
+            imap_server->key = g_strdup_printf("%s@%s", name, host);
         }
         g_mutex_lock(&imap_servers_lock);
         g_hash_table_steal(imap_servers, imap_server->key);
         g_free(imap_server->key);
-        imap_server->key = g_strdup_printf("%s@%s", name, server->host);
+        imap_server->key = g_strdup_printf("%s@%s", name, host);
         g_hash_table_insert(imap_servers, imap_server->key, imap_server);
         g_mutex_unlock(&imap_servers_lock);
     }
@@ -148,20 +152,24 @@ static void libbalsa_imap_server_set_username(LibBalsaServer * server,
 }
 
 static void
-libbalsa_imap_server_set_host(LibBalsaServer     *server,
-                              const gchar        *host,
-                                                         NetClientCryptMode  security)
+libbalsa_imap_server_set_host(LibBalsaServer    *server,
+                              const gchar       *host,
+                              NetClientCryptMode security)
 {
-    if(server->user && host) { /* we have been initialized... */
+    const gchar *user;
+
+    user = libbalsa_server_get_user(server);
+
+    if (user != NULL && host != NULL) { /* we have been initialized... */
         LibBalsaImapServer *imap_server = LIBBALSA_IMAP_SERVER(server);
 
         if (imap_server->key == NULL) {
-               imap_server->key = g_strdup_printf("%s@%s", server->user, host);
+            imap_server->key = g_strdup_printf("%s@%s", user, host);
         }
         g_mutex_lock(&imap_servers_lock);
         g_hash_table_steal(imap_servers, imap_server->key);
         g_free(imap_server->key);
-        imap_server->key = g_strdup_printf("%s@%s", server->user, host);
+        imap_server->key = g_strdup_printf("%s@%s", user, host);
         g_hash_table_insert(imap_servers, imap_server->key, imap_server);
         g_mutex_unlock(&imap_servers_lock);
     }
@@ -191,7 +199,7 @@ libbalsa_imap_server_class_init(LibBalsaImapServerClass * klass)
 static void
 libbalsa_imap_server_init(LibBalsaImapServer * imap_server)
 {
-    LIBBALSA_SERVER(imap_server)->protocol = "imap";
+    libbalsa_server_set_protocol(LIBBALSA_SERVER(imap_server), "imap");
     imap_server->key = NULL;
     g_mutex_init(&imap_server->lock);
     imap_server->max_connections = MAX_CONNECTIONS_PER_SERVER;
@@ -252,7 +260,7 @@ is_info_cb(ImapMboxHandle *h, ImapResponse rc, const gchar* str, void *arg)
     default:
         return;
     }
-    libbalsa_information(it, fmt, is->host, str);
+    libbalsa_information(it, fmt, libbalsa_server_get_host(is), str);
 }
 
 
@@ -274,8 +282,8 @@ lb_imap_server_info_new(LibBalsaServer *server)
     imap_handle_set_infocb(handle,    is_info_cb, server);
     imap_handle_set_authcb(handle, G_CALLBACK(libbalsa_server_get_auth), server);
     imap_handle_set_certcb(handle, G_CALLBACK(libbalsa_server_check_cert));
-    imap_handle_set_tls_mode(handle, server->security);
-    imap_handle_set_option(handle, IMAP_OPT_ANONYMOUS, server->try_anonymous);
+    imap_handle_set_tls_mode(handle, libbalsa_server_get_security(server));
+    imap_handle_set_option(handle, IMAP_OPT_ANONYMOUS, libbalsa_server_get_try_anonymous(server));
     imap_handle_set_option(handle, IMAP_OPT_CLIENT_SORT, TRUE);
     /* binary fetches change encoding and the checksums, and
        signatures, disable them if we ever consider verifying message
@@ -447,7 +455,7 @@ libbalsa_imap_server_new_from_config(void)
     g_free(user);
     g_free(host);
     server = LIBBALSA_SERVER(imap_server);
-    if (server->host == NULL) {
+    if (libbalsa_server_get_host(server) == NULL) {
         gint conn_limit;
 
         /* common server configs */
@@ -491,7 +499,7 @@ handle_connection_error(int rc, struct handle_info *info,
     case IMAP_CONNECT_FAILED:
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_NETWORK_ERROR,
-                    _("Cannot connect to %s"), server->host);
+                    _("Cannot connect to %s"), libbalsa_server_get_host(server));
         break;
     case IMAP_AUTH_CANCELLED:
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
@@ -561,7 +569,7 @@ libbalsa_imap_server_get_handle(LibBalsaImapServer *imap_server, GError **err)
         if(imap_mbox_is_disconnected(info->handle)) {
             ImapResult rc;
 
-            rc=imap_mbox_handle_connect(info->handle, server->host);
+            rc=imap_mbox_handle_connect(info->handle, libbalsa_server_get_host(server));
             if(rc != IMAP_SUCCESS) {
                 handle_connection_error(rc, info, server, err);
                 g_mutex_unlock(&imap_server->lock);
@@ -650,7 +658,7 @@ libbalsa_imap_server_get_handle_with_user(LibBalsaImapServer *imap_server,
         g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                     LIBBALSA_MAILBOX_TOOMANYOPEN_ERROR,
                     _("Exceeded the number of connections per server %s"),
-                    server->host);
+                    libbalsa_server_get_host(server));
         g_mutex_unlock(&imap_server->lock);
         return NULL;
     }
@@ -658,7 +666,7 @@ libbalsa_imap_server_get_handle_with_user(LibBalsaImapServer *imap_server,
     if (imap_mbox_is_disconnected(info->handle)) {
         ImapResult rc;
 
-        rc=imap_mbox_handle_connect(info->handle, server->host);
+        rc=imap_mbox_handle_connect(info->handle, libbalsa_server_get_host(server));
         if(rc != IMAP_SUCCESS) {
             handle_connection_error(rc, info, server, err);
             g_mutex_unlock(&imap_server->lock);
@@ -909,7 +917,9 @@ libbalsa_imap_server_subscriptions(LibBalsaImapServer  *server,
                                                _("subscribing to “%s” failed"), mailbox);
                                        result = FALSE;
                                } else {
-                                       g_debug("subscribed to %s, '%s'", LIBBALSA_SERVER(server)->host, 
mailbox);
+                                       g_debug("subscribed to %s, '%s'",
+                                                libbalsa_server_get_host(LIBBALSA_SERVER(server)),
+                                                mailbox);
                                }
                        }
                }
@@ -923,7 +933,9 @@ libbalsa_imap_server_subscriptions(LibBalsaImapServer  *server,
                                                _("unsubscribing from “%s” failed"), mailbox);
                                        result = FALSE;
                                } else {
-                                       g_debug("unsubscribed from %s, '%s'", LIBBALSA_SERVER(server)->host, 
mailbox);
+                                       g_debug("unsubscribed from %s, '%s'",
+                                                libbalsa_server_get_host(LIBBALSA_SERVER(server)),
+                                                mailbox);
                                }
                        }
                }
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index d3e050c2b..1203fcb23 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -465,7 +465,8 @@ get_header_cache_path(LibBalsaMailboxImap *mimap)
     LibBalsaServer *s = LIBBALSA_MAILBOX_REMOTE(mimap)->server;
     gchar *cache_dir = get_cache_dir(TRUE); /* FIXME */
     gchar *header_file = g_strdup_printf("%s@%s-%s-%u-headers2",
-                                        s->user, s->host,
+                                        libbalsa_server_get_user(s),
+                                        libbalsa_server_get_host(s),
                                         (mimap->path ? mimap->path : "INBOX"),
                                         mimap->uid_validity);
     gchar *encoded_path = libbalsa_urlencode(header_file);
@@ -490,7 +491,7 @@ get_cache_name_pair(LibBalsaMailboxImap* mailbox, const gchar *type,
 
     res[0] = get_cache_dir(is_persistent);
     fname = g_strdup_printf("%s@%s-%s-%u-%u-%s",
-                            s->user, s->host,
+                            libbalsa_server_get_user(s), libbalsa_server_get_host(s),
                             (mailbox->path ? mailbox->path : "INBOX"),
                             uid_validity, uid, type);
     res[1] = libbalsa_urlencode(fname);
@@ -1732,13 +1733,13 @@ libbalsa_mailbox_imap_reconnect(LibBalsaMailboxImap* mimap)
     if (mimap->handle &&
         imap_mbox_is_disconnected (mimap->handle)) {
         printf("Reconnecting %s (%u)\n",
-               LIBBALSA_MAILBOX_REMOTE_SERVER(mimap)->host,
+               libbalsa_server_get_host(LIBBALSA_MAILBOX_REMOTE_SERVER(mimap)),
                (unsigned)time(NULL));
         if (imap_mbox_handle_reconnect
             (mimap->handle, &(LIBBALSA_MAILBOX(mimap)->readonly))
             == IMAP_SUCCESS)
             printf("Reconnected %s (%u)\n",
-                   LIBBALSA_MAILBOX_REMOTE_SERVER(mimap)->host,
+                   libbalsa_server_get_host(LIBBALSA_MAILBOX_REMOTE_SERVER(mimap)),
                    (unsigned)time(NULL));
     }
 }
@@ -1877,14 +1878,15 @@ libbalsa_imap_delete_folder(LibBalsaMailboxImap *mailbox, GError **err)
 gchar *
 libbalsa_imap_url(LibBalsaServer * server, const gchar * path)
 {
-    gchar *enc = libbalsa_urlencode(server->user);
+    const gchar *user = libbalsa_server_get_user(server);
+    gchar *enc = libbalsa_urlencode(user);
     gchar *url = g_strdup_printf("imap%s://%s@%s/%s",
 #ifdef USE_SSL_TO_SET_IMAPS_IN_URL
                                  server->use_ssl ? "s" : "",
 #else
                                  "",
 #endif
-                                 enc, server->host,
+                                 enc, libbalsa_server_get_host(server),
                                  path ? path : "");
     g_free(enc);
 
@@ -2191,7 +2193,7 @@ get_struct_from_cache(LibBalsaMailbox *mailbox, LibBalsaMessage *message,
     }
     if(flags & LB_FETCH_RFC822_HEADERS) {
         g_assert(message->headers != NULL);
-        message->headers->user_hdrs = 
+        message->headers->user_hdrs =
             libbalsa_message_user_hdrs_from_gmime(message->mime_msg);
         message->has_all_headers = 1;
     }
@@ -2981,8 +2983,8 @@ libbalsa_mailbox_imap_add_messages(LibBalsaMailbox * mailbox,
        struct append_to_cache_data atcd;
        gchar *cache_dir;
 
-       atcd.user = s->user;
-       atcd.host = s->host;
+       atcd.user = libbalsa_server_get_user(s);
+       atcd.host = libbalsa_server_get_host(s);
        atcd.path = mimap->path ? mimap->path : "INBOX";
        atcd.cache_dir = cache_dir = get_cache_dir(is_persistent);
        atcd.curr_name = macd.outfiles;
@@ -3334,7 +3336,7 @@ libbalsa_mailbox_imap_messages_copy(LibBalsaMailbox * mailbox,
                libbalsa_imap_server_has_persistent_cache(is);
            gchar *dir_name = get_cache_dir(is_persistent);
            gchar *src_prefix = g_strdup_printf("%s@%s-%s-%u-",
-                                               s->user, s->host,
+                                               libbalsa_server_get_user(s), libbalsa_server_get_host(s),
                                                (mimap->path 
                                                 ? mimap->path : "INBOX"),
                                                mimap->uid_validity);
@@ -3360,7 +3362,8 @@ libbalsa_mailbox_imap_messages_copy(LibBalsaMailbox * mailbox,
                                g_build_filename(dir_name, filename, NULL);
                            gchar *dst_prefix =
                                g_strdup_printf("%s@%s-%s-%u-%u%s",
-                                               s->user, s->host,
+                                               libbalsa_server_get_user(s),
+                                                libbalsa_server_get_host(s),
                                                (dst_imap->path 
                                                 ? dst_imap->path : "INBOX"),
                                                uid_sequence.uid_validity,
diff --git a/libbalsa/mailbox_pop3.c b/libbalsa/mailbox_pop3.c
index dd6adae69..12270fe2a 100644
--- a/libbalsa/mailbox_pop3.c
+++ b/libbalsa/mailbox_pop3.c
@@ -129,6 +129,7 @@ libbalsa_mailbox_pop3_init(LibBalsaMailboxPop3 * mailbox)
     mailbox->filter_cmd = g_strdup("procmail -f -");
     remote = LIBBALSA_MAILBOX_REMOTE(mailbox);
     remote->server = libbalsa_server_new();
+    libbalsa_server_set_protocol(remote->server, "pop3");
 }
 
 static void
@@ -466,15 +467,19 @@ libbalsa_mailbox_pop3_startup(LibBalsaServer            *server,
                                                          const gchar               *name,
                                                          GList                    **msg_list)
 {
+        NetClientCryptMode security;
+        const gchar *host;
        NetClientPop *pop;
        GError *error = NULL;
        guint allow_auth;
 
        /* create the mailbox connection */
-       if (server->security == NET_CLIENT_CRYPT_ENCRYPTED) {
-               pop = net_client_pop_new(server->host, 995U, server->security, mbox->enable_pipe);
+        security = libbalsa_server_get_security(server);
+        host = libbalsa_server_get_host(server);
+       if (security == NET_CLIENT_CRYPT_ENCRYPTED) {
+               pop = net_client_pop_new(host, 995U, security, mbox->enable_pipe);
        } else {
-               pop = net_client_pop_new(server->host, 110U, server->security, mbox->enable_pipe);
+               pop = net_client_pop_new(host, 110U, security, mbox->enable_pipe);
        }
        if (pop == NULL) {
                return NULL;
@@ -491,10 +496,12 @@ libbalsa_mailbox_pop3_startup(LibBalsaServer            *server,
        net_client_set_timeout(NET_CLIENT(pop), 60U);
 
        /* load client certificate if configured */
-       if (server->client_cert) {
+       if (libbalsa_server_get_client_cert(server)) {
+                const gchar *cert_file = libbalsa_server_get_cert_file(server);
+
                g_signal_connect(G_OBJECT(pop), "cert-pass", G_CALLBACK(libbalsa_server_get_cert_pass), 
server);
-               if (!net_client_set_cert_from_file(NET_CLIENT(pop), server->cert_file, &error)) {
-                       libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Cannot load certificate file %s: 
%s"), server->cert_file,
+               if (!net_client_set_cert_from_file(NET_CLIENT(pop), cert_file, &error)) {
+                       libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Cannot load certificate file %s: 
%s"), cert_file,
                                error->message);
                        /* bad certificate private key password: clear it */
                        if (error->code == NET_CLIENT_ERROR_CERT_KEY_PASS) {
@@ -511,9 +518,9 @@ libbalsa_mailbox_pop3_startup(LibBalsaServer            *server,
        g_signal_connect(G_OBJECT(pop), "auth", G_CALLBACK(libbalsa_server_get_auth), server);
 
        /* connect server */
-       libbalsa_mailbox_progress_notify(LIBBALSA_MAILBOX(mbox), LIBBALSA_NTFY_INIT, INFINITY, _("Connecting 
%s…"), server->host);
+       libbalsa_mailbox_progress_notify(LIBBALSA_MAILBOX(mbox), LIBBALSA_NTFY_INIT, INFINITY, _("Connecting 
%s…"), host);
        if (!net_client_pop_connect(pop, NULL, &error)) {
-               libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("POP3 mailbox %s: cannot connect %s: %s"), 
name, server->host,
+               libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("POP3 mailbox %s: cannot connect %s: %s"), 
name, host,
                        error->message);
                /* authentication failed: clear password */
                if (error->code == NET_CLIENT_ERROR_POP_AUTHFAIL) {
@@ -553,7 +560,8 @@ update_msg_list(struct fetch_data         *fd,
 
        /* load uid's if messages shall be left on the server */
        if (!mbox->delete_from_server) {
-               uid_prefix = g_strconcat(server->user, "@", server->host, NULL);
+               uid_prefix = g_strconcat(libbalsa_server_get_user(server), "@",
+                                         libbalsa_server_get_host(server), NULL);
                prefix_len = strlen(uid_prefix);
                uids = mp_load_uids(uid_prefix);
                *current_uids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
@@ -685,7 +693,9 @@ libbalsa_mailbox_pop3_check(LibBalsaMailbox * mailbox)
 
                /* store uid list */
                if (result && !mbox->delete_from_server) {
-                       gchar *uid_prefix = g_strconcat(server->user, "@", server->host, NULL);
+                       gchar *uid_prefix =
+                            g_strconcat(libbalsa_server_get_user(server), "@",
+                                        libbalsa_server_get_host(server), NULL);
 
                        mp_save_uids(current_uids, uid_prefix, &err);
                        g_free(uid_prefix);
diff --git a/libbalsa/send.c b/libbalsa/send.c
index ba2854e84..f7667522e 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -635,9 +635,9 @@ lbs_check_reachable_cb(GObject  *object,
        } else {
         libbalsa_information(LIBBALSA_INFORMATION_WARNING,
                              _("Cannot reach SMTP server %s (%s), any queued message will remain in %s."),
-                                                        libbalsa_smtp_server_get_name(smtp_server),
-                                                        LIBBALSA_SERVER(smtp_server)->host,
-                                                        send_info->outbox->name);
+                             libbalsa_smtp_server_get_name(smtp_server),
+                             libbalsa_server_get_host(LIBBALSA_SERVER(smtp_server)),
+                             send_info->outbox->name);
        }
 
        if (!thread_started) {
@@ -759,13 +759,17 @@ lbs_process_queue_msg(guint                  msgno,
 static NetClientSmtp *
 lbs_process_queue_init_session(LibBalsaServer* server)
 {
+        NetClientCryptMode security;
+        const gchar *host;
        NetClientSmtp* session;
 
-       if (server->security == NET_CLIENT_CRYPT_ENCRYPTED) {
-               session = net_client_smtp_new(server->host, 465U, server->security);
+        security = libbalsa_server_get_security(server);
+        host = libbalsa_server_get_host(server);
+       if (security == NET_CLIENT_CRYPT_ENCRYPTED) {
+               session = net_client_smtp_new(host, 465U, security);
        } else {
                // FIXME - submission (587) is the standard, but most isp's use 25...
-               session = net_client_smtp_new(server->host, 587U, server->security);
+               session = net_client_smtp_new(host, 587U, security);
        }
 
        /* connect signals */
@@ -773,12 +777,13 @@ lbs_process_queue_init_session(LibBalsaServer* server)
        g_signal_connect(G_OBJECT(session), "auth", G_CALLBACK(libbalsa_server_get_auth), server);
 
        /* load client certificate if configured */
-       if (server->client_cert) {
+       if (libbalsa_server_get_client_cert(server)) {
+                const gchar *cert_file = libbalsa_server_get_cert_file(server);
                GError* error = NULL;
 
                g_signal_connect(G_OBJECT(session), "cert-pass", G_CALLBACK(libbalsa_server_get_cert_pass), 
server);
-               if (!net_client_set_cert_from_file(NET_CLIENT(session), server->cert_file, &error)) {
-                       libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Cannot load certificate file %s: 
%s"), server->cert_file,
+               if (!net_client_set_cert_from_file(NET_CLIENT(session), cert_file, &error)) {
+                       libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Cannot load certificate file %s: 
%s"), cert_file,
                                error->message);
                        /* bad certificate private key password: clear it */
                        if (error->code == NET_CLIENT_ERROR_CERT_KEY_PASS) {
diff --git a/libbalsa/server-config.c b/libbalsa/server-config.c
index 12da41a4f..0530ad5d3 100644
--- a/libbalsa/server-config.c
+++ b/libbalsa/server-config.c
@@ -86,6 +86,8 @@ libbalsa_server_cfg_new(LibBalsaServer *server, const gchar *name)
 {
        LibBalsaServerCfg *server_cfg;
        LibBalsaServerCfgPrivate *priv;
+        const gchar *protocol;
+        const gchar *cert_file;
 
        g_return_val_if_fail(LIBBALSA_IS_SERVER(server), NULL);
 
@@ -102,11 +104,12 @@ libbalsa_server_cfg_new(LibBalsaServer *server, const gchar *name)
 
     /* server descriptive name */
     priv->name = server_cfg_add_entry(priv->basic_grid, priv->basic_rows++, _("_Descriptive Name:"), name,
-       G_CALLBACK(on_server_cfg_changed), server_cfg);
+        G_CALLBACK(on_server_cfg_changed), server_cfg);
 
     /* host and port */
-    priv->host_port = server_cfg_add_entry(priv->basic_grid, priv->basic_rows++, _("_Server:"), server->host,
-       G_CALLBACK(on_server_cfg_changed), server_cfg);
+    priv->host_port = server_cfg_add_entry(priv->basic_grid, priv->basic_rows++, _("_Server:"),
+                                           libbalsa_server_get_host(server),
+                                           G_CALLBACK(on_server_cfg_changed), server_cfg);
 
     /* security settings */
     priv->security = server_cfg_security_widget(server);
@@ -114,22 +117,27 @@ libbalsa_server_cfg_new(LibBalsaServer *server, const gchar *name)
     g_signal_connect(priv->security, "changed", G_CALLBACK(on_server_cfg_changed), server_cfg);
 
     /* check box for authentication or anonymous access - smtp and imap only */
-    if ((strcmp(server->protocol, "smtp") == 0) || (strcmp(server->protocol, "imap") == 0)) {
-       priv->require_auth = server_cfg_add_check(priv->basic_grid, priv->basic_rows++, _("Server requires 
_authentication"),
-               !server->try_anonymous, G_CALLBACK(on_server_cfg_changed), server_cfg);
+    protocol = libbalsa_server_get_protocol(server);
+    if ((strcmp(protocol, "smtp") == 0) || (strcmp(protocol, "imap") == 0)) {
+        priv->require_auth = server_cfg_add_check(priv->basic_grid, priv->basic_rows++,
+                                                  _("Server requires _authentication"),
+                                                  !libbalsa_server_get_try_anonymous(server),
+                                                  G_CALLBACK(on_server_cfg_changed), server_cfg);
     }
 
     /* user name and password */
-    priv->username = server_cfg_add_entry(priv->basic_grid, priv->basic_rows++, _("_User Name:"), 
server->user,
-       G_CALLBACK(on_server_cfg_changed), server_cfg);
+    priv->username = server_cfg_add_entry(priv->basic_grid, priv->basic_rows++, _("_User Name:"),
+                                          libbalsa_server_get_user(server),
+                                          G_CALLBACK(on_server_cfg_changed), server_cfg);
 
-    priv->password = server_cfg_add_entry(priv->basic_grid, priv->basic_rows++, _("_Pass Phrase:"), 
server->passwd,
-       G_CALLBACK(on_server_cfg_changed), server_cfg);
+    priv->password = server_cfg_add_entry(priv->basic_grid, priv->basic_rows++, _("_Pass Phrase:"),
+                                          libbalsa_server_get_password(server),
+        G_CALLBACK(on_server_cfg_changed), server_cfg);
     g_object_set(G_OBJECT(priv->password), "input-purpose", GTK_INPUT_PURPOSE_PASSWORD, NULL);
     gtk_entry_set_visibility(GTK_ENTRY(priv->password), FALSE);
 
     priv->remember_pass = server_cfg_add_check(priv->basic_grid, priv->basic_rows++, 
remember_password_message[0],
-       server->remember_passwd, G_CALLBACK(on_server_cfg_changed), server_cfg);
+        libbalsa_server_get_remember_password(server), G_CALLBACK(on_server_cfg_changed), server_cfg);
 
     /* notebook page with advanced options */
     priv->advanced_grid = libbalsa_create_grid();
@@ -139,22 +147,24 @@ libbalsa_server_cfg_new(LibBalsaServer *server, const gchar *name)
 
     /* client certificate and passphrase */
     priv->require_cert = server_cfg_add_check(priv->advanced_grid, priv->advanced_rows++, _("Server 
_requires client certificate"),
-       server->client_cert, G_CALLBACK(on_server_cfg_changed), server_cfg);
+        libbalsa_server_get_client_cert(server), G_CALLBACK(on_server_cfg_changed), server_cfg);
 
     priv->cert_file = gtk_file_chooser_button_new(_("Choose Client Certificate"), 
GTK_FILE_CHOOSER_ACTION_OPEN);
     server_cfg_add_widget(priv->advanced_grid, priv->advanced_rows++, _("Certificate _File:"), 
priv->cert_file);
-    if (server->cert_file != NULL) {
-       gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(priv->cert_file), server->cert_file);
+
+    cert_file = libbalsa_server_get_cert_file(server);
+    if (cert_file != NULL) {
+        gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(priv->cert_file), cert_file);
     }
     g_signal_connect(priv->cert_file, "file-set", G_CALLBACK(on_server_cfg_changed), server_cfg);
 
        priv->cert_pass = server_cfg_add_entry(priv->advanced_grid, priv->advanced_rows++, _("Certificate 
_Pass Phrase:"),
-               server->cert_passphrase, G_CALLBACK(on_server_cfg_changed), server_cfg);
+               libbalsa_server_get_cert_passphrase(server), G_CALLBACK(on_server_cfg_changed), server_cfg);
     g_object_set(G_OBJECT(priv->cert_pass), "input-purpose", GTK_INPUT_PURPOSE_PASSWORD, NULL);
     gtk_entry_set_visibility(GTK_ENTRY(priv->cert_pass), FALSE);
 
     priv->remember_cert_pass = server_cfg_add_check(priv->advanced_grid, priv->advanced_rows++, 
remember_password_message[1],
-       server->remember_cert_passphrase, G_CALLBACK(on_server_cfg_changed), server_cfg);
+        libbalsa_server_get_remember_cert_passphrase(server), G_CALLBACK(on_server_cfg_changed), server_cfg);
 
     /* initially run the validity check */
     on_server_cfg_changed(NULL, server_cfg);
@@ -266,31 +276,35 @@ void
 libbalsa_server_cfg_assign_server(LibBalsaServerCfg *server_cfg, LibBalsaServer *server)
 {
        LibBalsaServerCfgPrivate *priv;
+        gchar *cert_file;
 
        g_return_if_fail(LIBBALSA_IS_SERVER_CFG(server_cfg) && LIBBALSA_IS_SERVER(server));
 
        priv = server_cfg->priv;
 
        /* host, post and security */
-    server->security = (NetClientCryptMode) (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->security)) + 1);
-    libbalsa_server_set_host(server, gtk_entry_get_text(GTK_ENTRY(priv->host_port)), server->security);
+    libbalsa_server_set_security(server, (NetClientCryptMode) 
(gtk_combo_box_get_active(GTK_COMBO_BOX(priv->security)) + 1));
+    libbalsa_server_set_host(server, gtk_entry_get_text(GTK_ENTRY(priv->host_port)), 
libbalsa_server_get_security(server));
 
     /* authentication stuff */
     if (priv->require_auth != NULL) {
-       server->try_anonymous = !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->require_auth));
+        libbalsa_server_set_try_anonymous(server, 
!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->require_auth)));
     } else {
-       server->try_anonymous = FALSE;
+        libbalsa_server_set_try_anonymous(server, FALSE);
     }
     libbalsa_server_set_username(server, gtk_entry_get_text(GTK_ENTRY(priv->username)));
     libbalsa_server_set_password(server, gtk_entry_get_text(GTK_ENTRY(priv->password)), FALSE);
-    server->remember_passwd = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->remember_pass));
+    libbalsa_server_set_remember_password(server, 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->remember_pass)));
 
     /* client certificate */
-    server->client_cert = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->require_cert));
-    g_free(server->cert_file);
-    server->cert_file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(priv->cert_file));
+    libbalsa_server_set_client_cert(server, 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->require_cert)));
+
+    cert_file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(priv->cert_file));
+    libbalsa_server_set_cert_file(server, cert_file);
+    g_free(cert_file);
+
     libbalsa_server_set_password(server, gtk_entry_get_text(GTK_ENTRY(priv->cert_pass)), TRUE);
-    server->remember_cert_passphrase = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->remember_cert_pass));
+    libbalsa_server_set_remember_cert_passphrase(server, 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->remember_cert_pass)));
 }
 
 
@@ -320,7 +334,7 @@ server_cfg_add_entry(GtkWidget *grid, guint row, const gchar *label, const gchar
         gtk_entry_set_text(GTK_ENTRY(new_entry), value);
     }
     if (callback != NULL) {
-       g_signal_connect(new_entry, "changed", callback, cb_data);
+        g_signal_connect(new_entry, "changed", callback, cb_data);
     }
     return new_entry;
 }
@@ -333,7 +347,7 @@ server_cfg_add_check(GtkWidget *grid, guint row, const gchar *label, gboolean va
 
        new_check = libbalsa_create_grid_check(label, grid, row, value);
     if (callback != NULL) {
-       g_signal_connect(new_check, "toggled", callback, cb_data);
+        g_signal_connect(new_check, "toggled", callback, cb_data);
     }
     return new_check;
 }
@@ -363,7 +377,7 @@ server_cfg_security_widget(LibBalsaServer *server)
     gchar *proto_upper;
     gchar *ssl_label;
 
-    proto_upper = g_ascii_strup(server->protocol, -1);
+    proto_upper = g_ascii_strup(libbalsa_server_get_protocol(server), -1);
     ssl_label = g_strdup_printf(_("%s over SSL (%sS)"), proto_upper, proto_upper);
     g_free(proto_upper);
     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), ssl_label);
@@ -371,7 +385,7 @@ server_cfg_security_widget(LibBalsaServer *server)
     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), _("TLS required"));
     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), _("TLS if possible (not recommended)"));
     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), _("None (not recommended)"));
-    gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), (gint) server->security - 1);
+    gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), (gint) libbalsa_server_get_security(server) - 1);
 
     return combo_box;
 }
diff --git a/libbalsa/server.c b/libbalsa/server.c
index a5b9f8e09..6d3caf56d 100644
--- a/libbalsa/server.c
+++ b/libbalsa/server.c
@@ -58,20 +58,35 @@ static const SecretSchema cert_pass_schema = {
 };
 #endif                          /* defined(HAVE_LIBSECRET) */
 
-static GObjectClass *parent_class = NULL;
-static void libbalsa_server_class_init(LibBalsaServerClass * klass);
-static void libbalsa_server_init(LibBalsaServer * server);
+typedef struct _LibBalsaServerPrivate LibBalsaServerPrivate;
+
+struct _LibBalsaServerPrivate {
+    const gchar *protocol; /**< type of the server: imap, pop3, or smtp. */
+    gchar *host;
+    gchar *user;
+    gchar *passwd;
+    NetClientCryptMode security;
+    gboolean client_cert;
+    gchar *cert_file;
+    gchar *cert_passphrase;
+    gboolean remember_passwd;
+    gboolean remember_cert_passphrase;
+    gboolean try_anonymous; /* user wants anonymous access */
+};
+
 static void libbalsa_server_finalize(GObject * object);
 
-static void libbalsa_server_real_set_username(LibBalsaServer * server,
-                                             const gchar * username);
-static void libbalsa_server_real_set_host(LibBalsaServer     *server,
-                                                                                 const gchar        *host,
-                                                                                 NetClientCryptMode  
security);
-static gchar *libbalsa_server_get_password(LibBalsaServer *server,
-                                                                                  gchar          
*cert_subject);
+static void libbalsa_server_real_set_username(LibBalsaServer *server,
+                                             const gchar    *username);
+static void libbalsa_server_real_set_host(LibBalsaServer    *server,
+                                          const gchar       *host,
+                                          NetClientCryptMode security);
+static gchar *lbs_get_password(LibBalsaServer *server,
+                                           gchar          *cert_subject);
 static gchar *libbalsa_free_password(gchar *password);
 
+G_DEFINE_TYPE_WITH_PRIVATE(LibBalsaServer, libbalsa_server, G_TYPE_OBJECT)
+
 enum {
     SET_USERNAME,
     SET_HOST,
@@ -82,32 +97,6 @@ enum {
 
 static guint libbalsa_server_signals[LAST_SIGNAL];
 
-GType
-libbalsa_server_get_type(void)
-{
-    static GType server_type = 0;
-
-    if (!server_type) {
-        static const GTypeInfo server_info = {
-            sizeof(LibBalsaServerClass),
-            NULL,               /* base_init */
-            NULL,               /* base_finalize */
-            (GClassInitFunc) libbalsa_server_class_init,
-            NULL,               /* class_finalize */
-            NULL,               /* class_data */
-            sizeof(LibBalsaServer),
-            0,                  /* n_preallocs */
-            (GInstanceInitFunc) libbalsa_server_init
-        };
-
-        server_type =
-            g_type_register_static(G_TYPE_OBJECT, "LibBalsaServer",
-                                   &server_info, 0);
-    }
-
-    return server_type;
-}
-
 static void
 libbalsa_server_class_init(LibBalsaServerClass * klass)
 {
@@ -115,8 +104,6 @@ libbalsa_server_class_init(LibBalsaServerClass * klass)
 
     object_class = G_OBJECT_CLASS(klass);
 
-    parent_class = g_type_class_peek_parent(klass);
-
     object_class->finalize = libbalsa_server_finalize;
 
     libbalsa_server_signals[SET_USERNAME] =
@@ -163,33 +150,30 @@ libbalsa_server_class_init(LibBalsaServerClass * klass)
 static void
 libbalsa_server_init(LibBalsaServer * server)
 {
-    server->protocol = "pop3"; /* Is this a sane default value? */
-    server->host = NULL;
-    server->user = NULL;
-    server->passwd = NULL;
-    server->remember_passwd = TRUE;
-    server->security           = NET_CLIENT_CRYPT_STARTTLS;
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    priv->protocol = NULL;
+    priv->host = NULL;
+    priv->user = NULL;
+    priv->passwd = NULL;
+    priv->remember_passwd = TRUE;
+    priv->security             = NET_CLIENT_CRYPT_STARTTLS;
 }
 
 /* leave object in sane state (NULLified fields) */
 static void
 libbalsa_server_finalize(GObject * object)
 {
-    LibBalsaServer *server;
-
-    g_return_if_fail(LIBBALSA_IS_SERVER(object));
-
-    server = LIBBALSA_SERVER(object);
+    LibBalsaServer *server = LIBBALSA_SERVER(object);
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
 
-    g_free(server->host);   server->host = NULL;
-    g_free(server->user);   server->user = NULL;
-    server->passwd = libbalsa_free_password(server->passwd);
+    g_free(priv->host);
+    g_free(priv->user);
+    g_free(priv->cert_file);
+    priv->passwd = libbalsa_free_password(priv->passwd);
+    priv->cert_passphrase = libbalsa_free_password(priv->cert_passphrase);
 
-    g_free(server->cert_file);
-    server->cert_file = NULL;
-    server->cert_passphrase = libbalsa_free_password(server->cert_passphrase);
-
-    G_OBJECT_CLASS(parent_class)->finalize(object);
+    G_OBJECT_CLASS(libbalsa_server_parent_class)->finalize(object);
 }
 
 LibBalsaServer *
@@ -218,18 +202,19 @@ libbalsa_server_set_password(LibBalsaServer *server,
                              const gchar    *passwd,
                                                         gboolean        for_cert)
 {
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
        gchar **target;
     g_return_if_fail(LIBBALSA_IS_SERVER(server));
 
     if (for_cert) {
-       target = &server->cert_passphrase;
+        target = &priv->cert_passphrase;
     } else {
-       target = &server->passwd;
+        target = &priv->passwd;
     }
 
     *target = libbalsa_free_password(*target);
     if ((passwd != NULL) && (passwd[0] != '\0')) {
-       *target = g_strdup(passwd);
+        *target = g_strdup(passwd);
     }
 }
 
@@ -256,7 +241,7 @@ libbalsa_server_config_changed(LibBalsaServer * server)
 }
 
 static gchar *
-libbalsa_server_get_password(LibBalsaServer *server,
+lbs_get_password(LibBalsaServer *server,
                                                 gchar          *cert_subject)
 {
     gchar *retval = NULL;
@@ -272,57 +257,56 @@ static void
 libbalsa_server_real_set_username(LibBalsaServer * server,
                                  const gchar * username)
 {
-    g_return_if_fail(LIBBALSA_IS_SERVER(server));
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
 
-    g_free(server->user);
-    server->user = g_strdup(username);
+    g_free(priv->user);
+    priv->user = g_strdup(username);
 }
 
 static void
 libbalsa_server_real_set_host(LibBalsaServer * server, const gchar * host,
        NetClientCryptMode  security)
 {
-    g_return_if_fail(LIBBALSA_IS_SERVER(server));
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
 
-    g_free(server->host);
-    server->host = g_strdup(host);
-    server->security = security;
+    g_free(priv->host);
+    priv->host = g_strdup(host);
+    priv->security = security;
 }
 
 void
 libbalsa_server_load_security_config(LibBalsaServer *server)
 {
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
        gboolean not_found;
 
-    g_return_if_fail(LIBBALSA_IS_SERVER(server));
-
-    server->security = libbalsa_conf_get_int_with_default("Security", &not_found);
+    priv->security = libbalsa_conf_get_int_with_default("Security", &not_found);
     if (not_found) {
-       gboolean want_ssl;
-
-       g_debug("server %s@%s: no security config, try to read old settings", server->protocol, server->host);
-       want_ssl = libbalsa_conf_get_bool_with_default("SSL", &not_found);
-       if (want_ssl && !not_found) {
-               server->security = NET_CLIENT_CRYPT_ENCRYPTED;
-       } else {
-               int want_tls;
-
-               want_tls = libbalsa_conf_get_int_with_default("TLSMode", &not_found);
-               if (not_found) {
-                       server->security = NET_CLIENT_CRYPT_STARTTLS;
-               } else {
-                       switch (want_tls) {
-                       case 0:
-                               server->security = NET_CLIENT_CRYPT_NONE;
-                               break;
-                       case 1:
-                               server->security = NET_CLIENT_CRYPT_STARTTLS_OPT;
-                               break;
-                       default:
-                               server->security = NET_CLIENT_CRYPT_STARTTLS;
-                       }
-               }
-       }
+        gboolean want_ssl;
+
+        g_debug("server %s@%s: no security config, try to read old settings", priv->protocol, priv->host);
+        want_ssl = libbalsa_conf_get_bool_with_default("SSL", &not_found);
+        if (want_ssl && !not_found) {
+               priv->security = NET_CLIENT_CRYPT_ENCRYPTED;
+        } else {
+               int want_tls;
+
+               want_tls = libbalsa_conf_get_int_with_default("TLSMode", &not_found);
+               if (not_found) {
+                       priv->security = NET_CLIENT_CRYPT_STARTTLS;
+               } else {
+                       switch (want_tls) {
+                       case 0:
+                               priv->security = NET_CLIENT_CRYPT_NONE;
+                               break;
+                       case 1:
+                               priv->security = NET_CLIENT_CRYPT_STARTTLS_OPT;
+                               break;
+                       default:
+                               priv->security = NET_CLIENT_CRYPT_STARTTLS;
+                       }
+               }
+        }
     }
 
 }
@@ -338,80 +322,83 @@ libbalsa_free_password(gchar *password)
 }
 
 static void
-store_password_libsecret(const LibBalsaServer *server,
+store_password_libsecret(LibBalsaServer *server,
                                         const gchar          *password,
                                                 const SecretSchema   *schema)
 {
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
     GError *err = NULL;
 
     secret_password_store_sync(schema, NULL, _("Balsa passwords"), password, NULL, &err,
-       "protocol", server->protocol,
-               "server",   server->host,
-               "user",     server->user,
+        "protocol", priv->protocol,
+               "server",   priv->host,
+               "user",     priv->user,
                NULL);
     if (err != NULL) {
-       g_info(_("Error storing password for %s@%s:%s: %s"), server->user, server->protocol, server->host, 
err->message);
+        g_info(_("Error storing password for %s@%s:%s: %s"), priv->user, priv->protocol, priv->host, 
err->message);
         g_error_free(err);
     } else {
-       g_debug("stored password for %s@%s:%s in secret service", server->user, server->protocol, 
server->host);
+        g_debug("stored password for %s@%s:%s in secret service", priv->user, priv->protocol, priv->host);
     }
 }
 
 static gchar *
-load_password_libsecret(const LibBalsaServer *server,
+load_password_libsecret(LibBalsaServer *server,
                                            const gchar          *cfg_path,
                                                const SecretSchema   *schema)
 {
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
     GError *err = NULL;
     gchar *password;
 
     password = secret_password_lookup_sync(schema, NULL, &err,
-       "protocol", server->protocol,
-               "server",   server->host,
-               "user",     server->user,
+        "protocol", priv->protocol,
+               "server",   priv->host,
+               "user",     priv->user,
                NULL);
     if (err != NULL) {
-        g_info(_("Error looking up password for %s@%s:%s: %s"), server->user, server->protocol, 
server->host, err->message);
+        g_info(_("Error looking up password for %s@%s:%s: %s"), priv->user, priv->protocol, priv->host, 
err->message);
         g_error_free(err);
 
         /* fall back to the private config file */
         password = libbalsa_conf_private_get_string(cfg_path, TRUE);
         if ((password != NULL) && (password[0] != '\0')) {
-               g_info(_("loaded fallback password from private config file"));
-               /* store a fallback password in the key ring */
-               store_password_libsecret(server, password, schema);
+        g_info(_("loaded fallback password from private config file"));
+        /* store a fallback password in the key ring */
+        store_password_libsecret(server, password, schema);
             /* We could in principle clear the password in the config file here but we do not for the 
backward compatibility.
              * FIXME - Is this really the proper approach, as we leave the obfuscated password in the config 
file, and the user
              * relies on the message that the password is stored in the Secret Service only.  OTOH, there 
are better methods for
              * protecting the user's secrets, like full disk encryption. */
         }
     } else {
-       g_debug("loaded password for %s@%s:%s from secret service", server->user, server->protocol, 
server->host);
+        g_debug("loaded password for %s@%s:%s from secret service", priv->user, priv->protocol, priv->host);
     }
 
     return password;
 }
 
 static void
-erase_password_libsecret(const LibBalsaServer *server,
+erase_password_libsecret(LibBalsaServer *server,
                                                 const SecretSchema   *schema)
 {
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
     GError *err = NULL;
     gboolean removed;
 
     removed = secret_password_clear_sync(schema, NULL, &err,
-       "protocol", server->protocol,
-               "server",   server->host,
-               "user",     server->user,
+        "protocol", priv->protocol,
+               "server",   priv->host,
+               "user",     priv->user,
                NULL);
     if (err != NULL) {
-       g_info("error erasing password for %s@%s:%s from secret service: %s", server->user, server->protocol, 
server->host,
-               err->message);
-       g_error_free(err);
+        g_info("error erasing password for %s@%s:%s from secret service: %s", priv->user, priv->protocol, 
priv->host,
+               err->message);
+        g_error_free(err);
     } else if (removed) {
-       g_debug("erased password for %s@%s:%s from secret service", server->user, server->protocol, 
server->host);
+        g_debug("erased password for %s@%s:%s from secret service", priv->user, priv->protocol, priv->host);
     } else {
-       g_debug("no password erased for %s@%s:%s from secret service", server->user, server->protocol, 
server->host);
+        g_debug("no password erased for %s@%s:%s from secret service", priv->user, priv->protocol, 
priv->host);
     }
 }
 
@@ -436,55 +423,57 @@ libbalsa_free_password(gchar *password)
 void
 libbalsa_server_load_config(LibBalsaServer * server)
 {
-    server->host = libbalsa_conf_get_string("Server");
-    if ((server->host != NULL) && (strrchr(server->host, ':') == NULL)) {
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    priv->host = libbalsa_conf_get_string("Server");
+    if ((priv->host != NULL) && (strrchr(priv->host, ':') == NULL)) {
         gint port;
         gboolean d;
 
         port = libbalsa_conf_get_int_with_default("Port", &d);
         if (!d) {
-            gchar *newhost = g_strdup_printf("%s:%d", server->host, port);
+            gchar *newhost = g_strdup_printf("%s:%d", priv->host, port);
 
-            g_free(server->host);
-            server->host = newhost;
+            g_free(priv->host);
+            priv->host = newhost;
         }
     }
     libbalsa_server_load_security_config(server);
-    server->user = libbalsa_conf_private_get_string("Username", FALSE);
-    if (server->user == NULL) {
-       server->user = g_strdup(g_get_user_name());
+    priv->user = libbalsa_conf_private_get_string("Username", FALSE);
+    if (priv->user == NULL) {
+        priv->user = g_strdup(g_get_user_name());
     }
 
-    server->try_anonymous = libbalsa_conf_get_bool("Anonymous=false");
-    server->remember_passwd = libbalsa_conf_get_bool("RememberPasswd=false");
+    priv->try_anonymous = libbalsa_conf_get_bool("Anonymous=false");
+    priv->remember_passwd = libbalsa_conf_get_bool("RememberPasswd=false");
 
-    server->passwd = libbalsa_free_password(server->passwd);
-    if (server->remember_passwd) {
+    priv->passwd = libbalsa_free_password(priv->passwd);
+    if (priv->remember_passwd) {
 #if defined(HAVE_LIBSECRET)
-       server->passwd = load_password_libsecret(server, "Password", &server_schema);
+        priv->passwd = load_password_libsecret(server, "Password", &server_schema);
 #else
-       server->passwd = libbalsa_conf_private_get_string("Password", TRUE);
+        priv->passwd = libbalsa_conf_private_get_string("Password", TRUE);
 #endif         /* HAVE_LIBSECRET */
-       if ((server->passwd != NULL) && (server->passwd[0] == '\0')) {
-               server->passwd = libbalsa_free_password(server->passwd);
-       }
+        if ((priv->passwd != NULL) && (priv->passwd[0] == '\0')) {
+               priv->passwd = libbalsa_free_password(priv->passwd);
+        }
     }
 
     /* client certificate stuff */
-    server->client_cert = libbalsa_conf_get_bool("NeedClientCert=false");
-    server->cert_file = libbalsa_conf_get_string("UserCertificateFile");
-    server->remember_cert_passphrase = libbalsa_conf_get_bool("RememberCertPasswd=false");
+    priv->client_cert = libbalsa_conf_get_bool("NeedClientCert=false");
+    priv->cert_file = libbalsa_conf_get_string("UserCertificateFile");
+    priv->remember_cert_passphrase = libbalsa_conf_get_bool("RememberCertPasswd=false");
 
-    server->cert_passphrase = libbalsa_free_password(server->cert_passphrase);
-    if (server->client_cert && server->remember_cert_passphrase) {
+    priv->cert_passphrase = libbalsa_free_password(priv->cert_passphrase);
+    if (priv->client_cert && priv->remember_cert_passphrase) {
 #if defined(HAVE_LIBSECRET)
-       server->cert_passphrase = load_password_libsecret(server, "CertificatePassphrase", &cert_pass_schema);
+        priv->cert_passphrase = load_password_libsecret(server, "CertificatePassphrase", &cert_pass_schema);
 #else
-       server->cert_passphrase = libbalsa_conf_private_get_string("CertificatePassphrase", TRUE);
+        priv->cert_passphrase = libbalsa_conf_private_get_string("CertificatePassphrase", TRUE);
 #endif         /* HAVE_LIBSECRET */
-       if ((server->cert_passphrase != NULL) && (server->cert_passphrase[0] == '\0')) {
-               server->cert_passphrase = libbalsa_free_password(server->cert_passphrase);
-       }
+        if ((priv->cert_passphrase != NULL) && (priv->cert_passphrase[0] == '\0')) {
+               priv->cert_passphrase = libbalsa_free_password(priv->cert_passphrase);
+        }
     }
 }
 
@@ -497,46 +486,48 @@ libbalsa_server_load_config(LibBalsaServer * server)
 void
 libbalsa_server_save_config(LibBalsaServer * server)
 {
-    libbalsa_conf_set_string("Server", server->host);
-    libbalsa_conf_private_set_string("Username", server->user, FALSE);
-    libbalsa_conf_set_bool("Anonymous",          server->try_anonymous);
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    libbalsa_conf_set_string("Server", priv->host);
+    libbalsa_conf_private_set_string("Username", priv->user, FALSE);
+    libbalsa_conf_set_bool("Anonymous",          priv->try_anonymous);
 
-    if (server->remember_passwd && (server->passwd != NULL)) {
-       libbalsa_conf_set_bool("RememberPasswd", TRUE);
+    if (priv->remember_passwd && (priv->passwd != NULL)) {
+        libbalsa_conf_set_bool("RememberPasswd", TRUE);
 #if defined(HAVE_LIBSECRET)
-       store_password_libsecret(server, server->passwd, &server_schema);
+        store_password_libsecret(server, priv->passwd, &server_schema);
 #else
-       libbalsa_conf_private_set_string("Password", server->passwd, TRUE);
+        libbalsa_conf_private_set_string("Password", priv->passwd, TRUE);
 #endif
     } else {
-       libbalsa_conf_set_bool("RememberPasswd", FALSE);
+        libbalsa_conf_set_bool("RememberPasswd", FALSE);
 #if defined(HAVE_LIBSECRET)
-       erase_password_libsecret(server, &server_schema);
+        erase_password_libsecret(server, &server_schema);
 #endif         /* HAVE_LIBSECRET */
-       libbalsa_conf_private_set_string("Password", NULL, TRUE);
+        libbalsa_conf_private_set_string("Password", NULL, TRUE);
     }
 
-    libbalsa_conf_set_bool("NeedClientCert", server->client_cert);
-    if (server->cert_file != NULL) {
-       libbalsa_conf_set_string("UserCertificateFile", server->cert_file);
-       if (server->remember_cert_passphrase && (server->cert_passphrase != NULL)) {
-               libbalsa_conf_set_bool("RememberCertPasswd", TRUE);
+    libbalsa_conf_set_bool("NeedClientCert", priv->client_cert);
+    if (priv->cert_file != NULL) {
+        libbalsa_conf_set_string("UserCertificateFile", priv->cert_file);
+        if (priv->remember_cert_passphrase && (priv->cert_passphrase != NULL)) {
+               libbalsa_conf_set_bool("RememberCertPasswd", TRUE);
 #if defined(HAVE_LIBSECRET)
-               store_password_libsecret(server, server->cert_passphrase, &cert_pass_schema);
+               store_password_libsecret(server, priv->cert_passphrase, &cert_pass_schema);
 #else
-               libbalsa_conf_private_set_string("CertificatePassphrase", server->cert_passphrase, TRUE);
+               libbalsa_conf_private_set_string("CertificatePassphrase", priv->cert_passphrase, TRUE);
 #endif
 
-       } else {
-               libbalsa_conf_set_bool("RememberCertPasswd", FALSE);
+        } else {
+               libbalsa_conf_set_bool("RememberCertPasswd", FALSE);
 #if defined(HAVE_LIBSECRET)
-               erase_password_libsecret(server, &cert_pass_schema);
+               erase_password_libsecret(server, &cert_pass_schema);
 #endif         /* HAVE_LIBSECRET */
-               libbalsa_conf_private_set_string("CertificatePassphrase", NULL, TRUE);
-       }
+               libbalsa_conf_private_set_string("CertificatePassphrase", NULL, TRUE);
+        }
     }
 
-    libbalsa_conf_set_int("Security", server->security);
+    libbalsa_conf_set_int("Security", priv->security);
 }
 
 /* Connect the server's "get-password" signal to the callback; if the
@@ -557,22 +548,23 @@ libbalsa_server_connect_signals(LibBalsaServer * server, GCallback cb,
 gchar **
 libbalsa_server_get_auth(NetClient *client,
                                                 gboolean   need_passwd,
-                                        gpointer   user_data)
+                                gpointer   user_data)
 {
     LibBalsaServer *server = LIBBALSA_SERVER(user_data);
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
     gchar **result = NULL;
 
     g_debug("%s: %p %p: encrypted = %d", __func__, client, user_data,
             net_client_is_encrypted(client));
-    if (!server->try_anonymous || (strcmp(server->protocol, "imap") == 0)) {
+    if (!priv->try_anonymous || (strcmp(priv->protocol, "imap") == 0)) {
         result = g_new0(gchar *, 3U);
-        result[0] = g_strdup(server->user);
+        result[0] = g_strdup(priv->user);
         if (need_passwd) {
-               if ((server->passwd != NULL) && (server->passwd[0] != '\0')) {
-                       result[1] = g_strdup(server->passwd);
-               } else {
-                       result[1] = libbalsa_server_get_password(server, NULL);
-               }
+        if ((priv->passwd != NULL) && (priv->passwd[0] != '\0')) {
+               result[1] = g_strdup(priv->passwd);
+        } else {
+               result[1] = lbs_get_password(server, NULL);
+        }
         }
     }
     return result;
@@ -581,7 +573,7 @@ libbalsa_server_get_auth(NetClient *client,
 
 gboolean
 libbalsa_server_check_cert(NetClient           *client,
-                                          GTlsCertificate     *peer_cert,
+                                  GTlsCertificate     *peer_cert,
                                                   GTlsCertificateFlags errors,
                                                   gpointer             user_data)
 {
@@ -595,12 +587,13 @@ libbalsa_server_get_cert_pass(NetClient *client,
                                                          gpointer   user_data)
 {
     LibBalsaServer *server = LIBBALSA_SERVER(user_data);
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
     gchar *result;
 
-    if ((server->cert_passphrase != NULL) && (server->cert_passphrase[0] != '\0')) {
-       result = g_strdup(server->cert_passphrase);
+    if ((priv->cert_passphrase != NULL) && (priv->cert_passphrase[0] != '\0')) {
+        result = g_strdup(priv->cert_passphrase);
     } else {
-       result = libbalsa_server_get_password(server, cert_subject);
+        result = lbs_get_password(server, cert_subject);
     }
        return result;
 }
@@ -634,6 +627,7 @@ libbalsa_server_test_can_reach_full(LibBalsaServer           * server,
                                     gpointer                   cb_data,
                                     GObject                  * source_object)
 {
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
     CanReachInfo *info;
     gchar *host;
     gchar *colon;
@@ -647,10 +641,10 @@ libbalsa_server_test_can_reach_full(LibBalsaServer           * server,
 
     monitor = g_network_monitor_get_default();
 
-    host = g_strdup(server->host);
+    host = g_strdup(priv->host);
     colon = strchr(host, ':');
     if (colon != NULL) {
-       colon[0] = '\0';
+        colon[0] = '\0';
     }
     address = g_network_address_new(host, 0);
     g_free(host);
@@ -666,3 +660,194 @@ libbalsa_server_test_can_reach(LibBalsaServer           * server,
 {
     libbalsa_server_test_can_reach_full(server, cb, cb_data, (GObject *) server);
 }
+
+/*
+ * Getters
+ */
+
+const gchar *
+libbalsa_server_get_host(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), NULL);
+
+    return priv->host;
+}
+
+const gchar *
+libbalsa_server_get_user(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), NULL);
+
+    return priv->user;
+}
+
+const gchar *
+libbalsa_server_get_cert_file(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), NULL);
+
+    return priv->cert_file;
+}
+
+const gchar *
+libbalsa_server_get_protocol(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), NULL);
+
+    return priv->protocol;
+}
+
+const gchar *
+libbalsa_server_get_password(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), NULL);
+
+    return priv->passwd;
+}
+
+const gchar *
+libbalsa_server_get_cert_passphrase(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), NULL);
+
+    return priv->cert_passphrase;
+}
+
+NetClientCryptMode
+libbalsa_server_get_security(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), (NetClientCryptMode) 0);
+
+    return priv->security;
+}
+
+gboolean
+libbalsa_server_get_try_anonymous(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), FALSE);
+
+    return priv->try_anonymous;
+}
+
+gboolean
+libbalsa_server_get_client_cert(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), FALSE);
+
+    return priv->client_cert;
+}
+
+gboolean
+libbalsa_server_get_remember_password(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), FALSE);
+
+    return priv->remember_passwd;
+}
+
+gboolean
+libbalsa_server_get_remember_cert_passphrase(LibBalsaServer *server)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_val_if_fail(LIBBALSA_IS_SERVER(server), FALSE);
+
+    return priv->remember_cert_passphrase;
+}
+
+/*
+ * Setters
+ */
+
+void
+libbalsa_server_set_protocol(LibBalsaServer *server, const gchar *protocol)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_if_fail(LIBBALSA_IS_SERVER(server));
+    g_return_if_fail(priv->protocol == NULL);
+
+    /* We do not allocate a string for the protocol: */
+    priv->protocol = protocol;
+}
+
+void
+libbalsa_server_set_cert_file(LibBalsaServer *server, const gchar *cert_file)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_if_fail(LIBBALSA_IS_SERVER(server));
+
+    g_free(priv->cert_file);
+    priv->cert_file = g_strdup(cert_file);
+}
+
+void
+libbalsa_server_set_security(LibBalsaServer *server, NetClientCryptMode security)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_if_fail(LIBBALSA_IS_SERVER(server));
+
+    priv->security = security;
+}
+
+void
+libbalsa_server_set_try_anonymous(LibBalsaServer *server, gboolean try_anonymous)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_if_fail(LIBBALSA_IS_SERVER(server));
+
+    priv->try_anonymous = try_anonymous;
+}
+
+void
+libbalsa_server_set_remember_password(LibBalsaServer *server, gboolean remember_password)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_if_fail(LIBBALSA_IS_SERVER(server));
+
+    priv->remember_passwd = remember_password;
+}
+
+void
+libbalsa_server_set_client_cert(LibBalsaServer *server, gboolean client_cert)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_if_fail(LIBBALSA_IS_SERVER(server));
+
+    priv->client_cert = client_cert;
+}
+
+void
+libbalsa_server_set_remember_cert_passphrase(LibBalsaServer *server, gboolean remember_cert_passphrase)
+{
+    LibBalsaServerPrivate *priv = libbalsa_server_get_instance_private(server);
+
+    g_return_if_fail(LIBBALSA_IS_SERVER(server));
+
+    priv->remember_cert_passphrase = remember_cert_passphrase;
+}
diff --git a/libbalsa/server.h b/libbalsa/server.h
index 7610e6341..5d5370b80 100644
--- a/libbalsa/server.h
+++ b/libbalsa/server.h
@@ -29,38 +29,13 @@
 #include "libbalsa.h"
 #include "net-client.h"
 
-#define LIBBALSA_TYPE_SERVER \
-    (libbalsa_server_get_type())
-#define LIBBALSA_SERVER(obj) \
-    (G_TYPE_CHECK_INSTANCE_CAST (obj, LIBBALSA_TYPE_SERVER, LibBalsaServer))
-#define LIBBALSA_SERVER_CLASS(klass) \
-    (G_TYPE_CHECK_CLASS_CAST (klass, LIBBALSA_TYPE_SERVER, \
-                              LibBalsaServerClass))
-#define LIBBALSA_IS_SERVER(obj) \
-    (G_TYPE_CHECK_INSTANCE_TYPE (obj, LIBBALSA_TYPE_SERVER))
-#define LIBBALSA_IS_SERVER_CLASS(klass) \
-    (G_TYPE_CHECK_CLASS_TYPE (klass, LIBBALSA_TYPE_SERVER))
-
-GType libbalsa_server_get_type(void);
-
-typedef struct _LibBalsaServerClass LibBalsaServerClass;
-
-
-struct _LibBalsaServer {
-    GObject object;
-    const gchar *protocol; /**< type of the server: imap, pop3, or smtp. */
-
-    gchar *host;
-    gchar *user;
-    gchar *passwd;
-    NetClientCryptMode security;
-    gboolean client_cert;
-    gchar *cert_file;
-    gchar *cert_passphrase;
-    gboolean remember_passwd;
-    gboolean remember_cert_passphrase;
-    gboolean try_anonymous; /* user wants anonymous access */
-};
+#define LIBBALSA_TYPE_SERVER (libbalsa_server_get_type())
+
+G_DECLARE_DERIVABLE_TYPE(LibBalsaServer,
+                         libbalsa_server,
+                         LIBBALSA,
+                         SERVER,
+                         GObject)
 
 struct _LibBalsaServerClass {
     GObjectClass parent_class;
@@ -115,4 +90,27 @@ void libbalsa_server_test_can_reach_full(LibBalsaServer           * server,
                                          gpointer                   cb_data,
                                          GObject                  * source_object);
 
+/* Getters */
+const gchar * libbalsa_server_get_host(LibBalsaServer *server);
+const gchar * libbalsa_server_get_user(LibBalsaServer *server);
+const gchar * libbalsa_server_get_cert_file(LibBalsaServer *server);
+const gchar * libbalsa_server_get_protocol(LibBalsaServer *server);
+const gchar * libbalsa_server_get_password(LibBalsaServer *server);
+const gchar * libbalsa_server_get_cert_passphrase(LibBalsaServer *server);
+NetClientCryptMode libbalsa_server_get_security(LibBalsaServer *server);
+gboolean libbalsa_server_get_try_anonymous(LibBalsaServer *server);
+gboolean libbalsa_server_get_client_cert(LibBalsaServer *server);
+gboolean libbalsa_server_get_remember_password(LibBalsaServer *server);
+gboolean libbalsa_server_get_remember_cert_passphrase(LibBalsaServer *server);
+
+/* Setters */
+void libbalsa_server_set_protocol(LibBalsaServer *server, const gchar *protocol);
+void libbalsa_server_set_cert_file(LibBalsaServer *server, const gchar *cert_file);
+void libbalsa_server_set_security(LibBalsaServer *server, NetClientCryptMode security);
+void libbalsa_server_set_try_anonymous(LibBalsaServer *server, gboolean try_anonymous);
+void libbalsa_server_set_remember_password(LibBalsaServer *server, gboolean remember_password);
+void libbalsa_server_set_client_cert(LibBalsaServer *server, gboolean client_cert);
+void libbalsa_server_set_remember_cert_passphrase(LibBalsaServer *server,
+                                                  gboolean remember_cert_passphrase);
+
 #endif                         /* __LIBBALSA_SERVER_H__ */
diff --git a/libbalsa/smtp-server.c b/libbalsa/smtp-server.c
index 592caa8de..9ee78d124 100644
--- a/libbalsa/smtp-server.c
+++ b/libbalsa/smtp-server.c
@@ -87,7 +87,7 @@ libbalsa_smtp_server_class_init(LibBalsaSmtpServerClass * klass)
 static void
 libbalsa_smtp_server_init(LibBalsaSmtpServer * smtp_server)
 {
-    LIBBALSA_SERVER(smtp_server)->protocol = "smtp";
+    libbalsa_server_set_protocol(LIBBALSA_SERVER(smtp_server), "smtp");
 }
 
 /* Class boilerplate */
@@ -137,7 +137,7 @@ libbalsa_smtp_server_new(void)
     smtp_server = g_object_new(LIBBALSA_TYPE_SMTP_SERVER, NULL);
 
     /* Change the default. */
-    LIBBALSA_SERVER(smtp_server)->remember_passwd = TRUE;
+    libbalsa_server_set_remember_password(LIBBALSA_SERVER(smtp_server), TRUE);
 
     return smtp_server;
 }
diff --git a/libinit_balsa/assistant_page_user.c b/libinit_balsa/assistant_page_user.c
index 741f76de0..0bd26f321 100644
--- a/libinit_balsa/assistant_page_user.c
+++ b/libinit_balsa/assistant_page_user.c
@@ -204,8 +204,7 @@ create_pop3_mbx(const gchar *name, const gchar* host, gint security,
     libbalsa_server_set_username(server, login);
     libbalsa_server_set_password(server, passwd, FALSE);
     libbalsa_server_set_host(server, host, security);
-    server->security        = security;
-    server->remember_passwd = remember;
+    libbalsa_server_set_remember_password(server, remember);
     mbx->name               = g_strdup(name && *name ? name : host);
     pop->check              = TRUE;
     pop->disable_apop       = FALSE;
@@ -227,7 +226,7 @@ create_imap_mbx(const gchar *name, const gchar* host, NetClientCryptMode securit
     libbalsa_server_set_username(server, login);
     libbalsa_server_set_password(server, passwd, FALSE);
     libbalsa_server_set_host(server, host, security);
-    server->remember_passwd = remember;
+    libbalsa_server_set_remember_password(server, remember);
     mbnode = balsa_mailbox_node_new_imap_folder(server, NULL);
     mbnode->name = g_strdup(name && *name ? name : host);
 
diff --git a/src/balsa-app.c b/src/balsa-app.c
index a91a537a0..fa12a159a 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -64,18 +64,26 @@ ask_password_real(LibBalsaServer *server, const gchar *cert_subject)
 #endif                          /* defined(HAVE_LIBSECRET) */
        GcrPromptDialog *dialog;
        gchar *prompt;
-       gboolean *remember;
+       gboolean remember;
        gchar *passwd;
+        const gchar *user;
+        const gchar *host;
+        const gchar *protocol;
 
     g_return_val_if_fail(server != NULL, NULL);
 
+    user = libbalsa_server_get_user(server);
+    host = libbalsa_server_get_host(server);
+    protocol = libbalsa_server_get_protocol(server);
     if (cert_subject != NULL) {
        prompt = g_strdup_printf(_("Password to unlock the user certificate\n%s\nfor %s@%s (%s)"),
-               cert_subject, server->user, server->host, server->protocol);
-       remember = &server->remember_cert_passphrase;
+               cert_subject,
+                user, host, protocol);
+       remember = libbalsa_server_get_remember_cert_passphrase(server);
     } else {
-       prompt = g_strdup_printf(_("Password for %s@%s (%s)"), server->user, server->host, server->protocol);
-       remember = &server->remember_passwd;
+       prompt = g_strdup_printf(_("Password for %s@%s (%s)"),
+                user, host, protocol);
+       remember = libbalsa_server_get_remember_password(server);
     }
        dialog = g_object_new(GCR_TYPE_PROMPT_DIALOG,
                                                  "use-header-bar", libbalsa_use_headerbar(),
@@ -85,7 +93,7 @@ ask_password_real(LibBalsaServer *server, const gchar *cert_subject)
                                                  "choice-label", remember_password_message,
                                                  "cancel-label", _("_Cancel"),
                                                  "continue-label", _("_OK"),
-                                                 "choice-chosen", *remember,
+                                                 "choice-chosen", remember,
                                                  "destroy-with-parent", TRUE,
                                                  "transient-for", GTK_WINDOW(balsa_app.main_window),
                                                  "modal", TRUE,
@@ -95,10 +103,14 @@ ask_password_real(LibBalsaServer *server, const gchar *cert_subject)
        if (passwd != NULL) {
                gboolean old_remember;
 
-               old_remember = *remember;
-               *remember = gcr_prompt_get_choice_chosen(GCR_PROMPT(dialog));
+               old_remember = remember;
+               remember = gcr_prompt_get_choice_chosen(GCR_PROMPT(dialog));
+                if (cert_subject != NULL)
+                    libbalsa_server_set_remember_cert_passphrase(server, remember);
+                else
+                    libbalsa_server_set_remember_password(server, remember);
                libbalsa_server_set_password(server, passwd, cert_subject != NULL);
-               if (*remember || old_remember) {
+               if (remember || old_remember) {
                        libbalsa_server_config_changed(server);
                }
        }
@@ -124,7 +136,7 @@ ask_password_real(LibBalsaServer * server, const gchar *cert_subject)
     GtkWidget *rememb_check;
     gchar *prompt;
     gchar *passwd;
-       gboolean *remember;
+       gboolean remember;
 #if defined(HAVE_LIBSECRET)
     static const gchar *remember_password_message =
         N_("_Remember password in Secret Service");
@@ -136,11 +148,11 @@ ask_password_real(LibBalsaServer * server, const gchar *cert_subject)
     g_return_val_if_fail(server != NULL, NULL);
     if (cert_subject != NULL) {
        prompt = g_strdup_printf(_("Password to unlock the user certificate\n%s\nfor %s@%s (%s)"),
-               cert_subject, server->user, server->host, server->protocol);
-       remember = &server->remember_cert_passphrase;
+               cert_subject, libbalsa_server_get_user(server), libbalsa_server_get_host(server), 
libbalsa_server_get_protocol(server));
+       remember = libbalsa_server_get_remember_cert_passphrase(server);
     } else {
-       prompt = g_strdup_printf(_("Password for %s@%s (%s)"), server->user, server->host, server->protocol);
-               remember = &server->remember_passwd;
+       prompt = g_strdup_printf(_("Password for %s@%s (%s)"), libbalsa_server_get_user(server), 
libbalsa_server_get_host(server), libbalsa_server_get_protocol(server));
+               remember = libbalsa_server_get_remember_password(server);
     }
 
     dialog = gtk_dialog_new_with_buttons(_("Password needed"),
@@ -170,7 +182,7 @@ ask_password_real(LibBalsaServer * server, const gchar *cert_subject)
     gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
     gtk_widget_grab_focus(entry);
 
-    rememb_check = libbalsa_create_grid_check(remember_password_message, grid, 2, *remember);
+    rememb_check = libbalsa_create_grid_check(remember_password_message, grid, 2, remember);
 
     gtk_widget_show_all(grid);
     gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
@@ -178,11 +190,15 @@ ask_password_real(LibBalsaServer * server, const gchar *cert_subject)
     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
                gboolean old_remember;
 
-               old_remember = *remember;
+               old_remember = remember;
                passwd = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
-               *remember = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rememb_check));
+               remember = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rememb_check));
+                if (cert_subject != NULL)
+                    libbalsa_server_set_remember_cert_passphrase(server, remember);
+                else
+                    libbalsa_server_set_remember_password(server, remember);
                libbalsa_server_set_password(server, passwd, cert_subject != NULL);
-               if (*remember || old_remember) {
+               if (remember || old_remember) {
                        libbalsa_server_config_changed(server);
                }
     } else {
@@ -738,7 +754,7 @@ balsa_get_short_mailbox_name(const gchar *url)
 
     if ((mbnode = balsa_find_url(url)) && mbnode->mailbox) {
         if (mbnode->server) {
-            return g_strconcat(mbnode->server->host, ":",
+            return g_strconcat(libbalsa_server_get_host(mbnode->server), ":",
                                mbnode->mailbox->name, NULL);
         } else {
             return g_strdup(mbnode->mailbox->name);
diff --git a/src/folder-conf.c b/src/folder-conf.c
index 45b4dd412..7d6f3ce98 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -849,7 +849,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
     (void) libbalsa_create_grid_label(_("Host:"), grid, row);
     sdd->host_label =
         gtk_label_new(sdd->mbnode && sdd->mbnode->server
-                      ? sdd->mbnode->server->host : "");
+                      ? libbalsa_server_get_host(sdd->mbnode->server) : "");
     gtk_widget_set_halign(sdd->host_label, GTK_ALIGN_START);
     gtk_widget_set_hexpand(sdd->host_label, TRUE);
     gtk_grid_attach(GTK_GRID(grid), sdd->host_label, 1, row, 1, 1);
diff --git a/src/mailbox-node.c b/src/mailbox-node.c
index 528c23335..df81991a8 100644
--- a/src/mailbox-node.c
+++ b/src/mailbox-node.c
@@ -510,7 +510,7 @@ imap_dir_cb(BalsaMailboxNode* mb)
                              ? _("Scanning of %s failed: %s\n"
                                  "Check network connectivity.")
                              : _("Scanning of %s failed: %s"),
-                             mb->server->host,
+                             libbalsa_server_get_host(mb->server),
                              error->message);
         g_error_free(error);
         imap_scan_destroy_tree(&imap_tree);
@@ -602,8 +602,8 @@ balsa_mailbox_node_new_from_config(const gchar* group)
 
     folder->server = LIBBALSA_SERVER(libbalsa_imap_server_new_from_config());
 
-       g_debug("Server loaded, host: %s, security %d.", folder->server->host,
-               folder->server->security);
+       g_debug("Server loaded, host: %s, security %d.", libbalsa_server_get_host(folder->server),
+               libbalsa_server_get_security(folder->server));
     g_signal_connect_swapped(G_OBJECT(folder->server), "config-changed", 
                              G_CALLBACK(config_folder_update), folder);
     g_signal_connect(G_OBJECT(folder), "show-prop-dialog", 
@@ -1011,7 +1011,7 @@ balsa_mailbox_node_is_imap(const BalsaMailboxNode *mbnode)
 {
        return (mbnode != NULL) &&
                (mbnode->server != NULL) &&
-               (strcmp(mbnode->server->protocol, "imap") == 0);
+               (strcmp(libbalsa_server_get_protocol(mbnode->server), "imap") == 0);
 }
 
 GtkWidget *
diff --git a/src/save-restore.c b/src/save-restore.c
index 20e9972df..f9b3b96f0 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -121,11 +121,13 @@ migrate_imap_mailboxes(const gchar *key, const gchar *value, gpointer data)
                libbalsa_conf_pop_group();
                mbnode = balsa_mailbox_node_new_from_config(key);
            if (mbnode != NULL) {
+                LibBalsaServer *server = mbnode->server;
                gchar *folder_key;
                gchar *oldname;
 
                /* do not add the same folder multiple times */
-               folder_key = g_strconcat(mbnode->server->user, "@", mbnode->server->host, NULL);
+               folder_key = g_strconcat(libbalsa_server_get_user(server), "@",
+                                         libbalsa_server_get_host(server), NULL);
                oldname = g_strdup(mbnode->name);
                if (g_hash_table_contains(migrated, folder_key)) {
                        g_object_unref(mbnode);
@@ -133,7 +135,7 @@ migrate_imap_mailboxes(const gchar *key, const gchar *value, gpointer data)
                } else {
                        g_hash_table_add(migrated, folder_key);
                        g_free(mbnode->name);
-                       mbnode->name = g_strdup(mbnode->server->host);
+                       mbnode->name = g_strdup(libbalsa_server_get_host(server));
                        balsa_mblist_mailbox_node_append(NULL, mbnode);
 
                        g_free(mbnode->config_prefix);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]