Exemple #1
0
static void
tm_load_model(BalsaToolbarModel * model)
{
    gchar *key;
    guint j;

    key = g_strconcat("toolbar-", balsa_toolbar_names[model->type], NULL);
    libbalsa_conf_push_group(key);
    g_free(key);

    model->style = libbalsa_conf_get_int_with_default("Style=-1", NULL);

    for (j = 0;; j++) {
        BalsaToolbarEntry entry;

        key = g_strdup_printf("Action%d", j);
        entry.action = libbalsa_conf_get_string(key);
        g_free(key);

        if (!entry.action)
            break;

        key = g_strdup_printf("Icon%d", j);
        entry.icon = libbalsa_conf_get_string(key);
        g_free(key);

        g_array_append_val(model->current, entry);
    }

    libbalsa_conf_pop_group();
}
Exemple #2
0
LibBalsaImapServer*
libbalsa_imap_server_new_from_config(void)
{
    LibBalsaServer tmp_server;
    LibBalsaImapServer *imap_server;
    LibBalsaServer *server;
    gboolean d, d1;
    gint tls_mode, conn_limit;

    tmp_server.host = libbalsa_conf_get_string("Server");
    if(strrchr(tmp_server.host, ':') == NULL) {
        gint port;
        port = libbalsa_conf_get_int_with_default("Port", &d);
        if (!d) {
            gchar *newhost = g_strdup_printf("%s:%d", tmp_server.host, port);
            g_free(tmp_server.host);
            tmp_server.host = newhost;
        }
    }       
    tmp_server.user = libbalsa_conf_private_get_string("Username");
    if (!tmp_server.user)
        tmp_server.user = g_strdup(getenv("USER"));

    imap_server = get_or_create(tmp_server.user, tmp_server.host);
    server = LIBBALSA_SERVER(imap_server);
    if (server->user) {
        g_free(tmp_server.user);
        g_free(tmp_server.host);
    } else {
        server->user = tmp_server.user;
        server->host = tmp_server.host;
    }
    d1 = libbalsa_conf_get_bool_with_default("Anonymous", &d);
    if(!d) server->try_anonymous = !!d1;
    server->use_ssl |= libbalsa_conf_get_bool("SSL=false");
    tls_mode = libbalsa_conf_get_int_with_default("TLSMode", &d);
    if(!d) server->tls_mode = tls_mode;
    conn_limit = libbalsa_conf_get_int_with_default("ConnectionLimit", &d);
    if(!d) imap_server->max_connections = conn_limit;
    d1 = libbalsa_conf_get_bool_with_default("PersistentCache", &d);
    if(!d) imap_server->persistent_cache = !!d1;
    d1 = libbalsa_conf_get_bool_with_default("HasFetchBug", &d);
    if(!d) imap_server->has_fetch_bug = !!d1;
    d1 = libbalsa_conf_get_bool_with_default("UseStatus", &d);
    if(!d) imap_server->use_status = !!d1;
    d1 = libbalsa_conf_get_bool_with_default("UseIdle", &d);
    if(!d) imap_server->use_idle = !!d1;
    if (!server->passwd) {
        server->remember_passwd = libbalsa_conf_get_bool("RememberPasswd=false");
        if(server->remember_passwd) {
#if defined(HAVE_LIBSECRET)
            GError *err = NULL;

            server->passwd =
                secret_password_lookup_sync(LIBBALSA_SERVER_SECRET_SCHEMA,
                                            NULL, &err,
                                            "protocol", server->protocol,
                                            "server",   server->host,
                                            "user",     server->user,
                                            NULL);
            if (err) {
                libbalsa_free_password(server->passwd);
                server->passwd = NULL;
                printf(_("Error looking up password for %s@%s: %s\n"),
                       server->user, server->host, err->message);
                printf(_("Falling back\n"));
                g_clear_error(&err);
                server->passwd =
                    libbalsa_conf_private_get_string("Password");
                if (server->passwd != NULL) {
                    gchar *buff = libbalsa_rot(server->passwd);
                    libbalsa_free_password(server->passwd);
                    server->passwd = buff;
                    secret_password_store_sync
                        (LIBBALSA_SERVER_SECRET_SCHEMA, NULL,
                         _("Balsa passwords"), server->passwd, NULL, &err,
                         "protocol", server->protocol,
                         "server",   server->host,
                         "user",     server->user,
                         NULL);
                    /* We could in principle clear the password in the
                     * config file here but we do not for the backward
                     * compatibility. */
                    if (err) {
                        printf(_("Error storing password for %s@%s: %s\n"),
                               server->user, server->host, err->message);
                        g_error_free(err);
                    }
                }
            }
#elif defined (HAVE_GNOME_KEYRING)
	    GnomeKeyringResult r;
	    server->passwd = NULL;
	    r = gnome_keyring_find_password_sync(LIBBALSA_SERVER_KEYRING_SCHEMA,
						 &server->passwd,
						 "protocol", server->protocol,
						 "server", server->host,
						 "user", server->user,
						 NULL);
	    if(r != GNOME_KEYRING_RESULT_OK) {
		gnome_keyring_free_password(server->passwd);
		server->passwd = NULL;
		printf("Keyring has no password for %s@%s\n",
		       server->user, server->host);
		server->passwd = libbalsa_conf_private_get_string("Password");
		if (server->passwd != NULL) {
		    gchar *buff = libbalsa_rot(server->passwd);
		    libbalsa_free_password(server->passwd);
		    server->passwd = buff;
	            gnome_keyring_store_password_sync
                        (LIBBALSA_SERVER_KEYRING_SCHEMA, NULL,
                         _("Balsa passwords"), server->passwd,
                         "protocol", server->protocol,
                         "server", server->host,
                         "user", server->user,
                         NULL);
		    /* We could in principle clear the password in the
		       config file here but we do not for the backward
		       compatibility. */
		}
	    }
#else
            server->passwd = libbalsa_conf_private_get_string("Password");
	    if (server->passwd != NULL) {
		gchar *buff = libbalsa_rot(server->passwd);
		libbalsa_free_password(server->passwd);
		server->passwd = buff;
	    }
#endif                          /* defined(HAVE_LIBSECRET) */
	}
        if(server->passwd && server->passwd[0] == '\0') {
            libbalsa_free_password(server->passwd);
            server->passwd = NULL;
        }
    }
    return imap_server;
}