Patch: Simpler config of servers/folders, "guess" functions
- From: Toralf Lund <toralf kscanners com>
- To: Balsa Mailing List <balsa-list gnome org>
- Subject: Patch: Simpler config of servers/folders, "guess" functions
- Date: Tue, 13 Nov 2001 10:06:06 +0100
This patch is meant to make various "per user" setup tasks simpler. It
introduces new "guess" functions for various parameters, symmetric to
libbalsa_guess_mail_spool(). These functions are called when opening
various configuration dialogues, to fill in default values in some of the
fields.
There used to be some init wizard updates accompanying this, too, but I
think most of them are obsolete now...
--
Toralf Lund <toralf@kscanners.com> +47 66 85 51 22
Kongsberg Scanners AS +47 66 85 51 00 (switchboard)
http://www.kscanners.no/~toralf +47 66 85 51 01 (fax)
Index: libbalsa/libbalsa.c
===================================================================
RCS file: /cvs/gnome/balsa/libbalsa/libbalsa.c,v
retrieving revision 1.32
diff -u -b -r1.32 libbalsa.c
--- libbalsa/libbalsa.c 2001/08/13 13:17:28 1.32
+++ libbalsa/libbalsa.c 2001/11/13 08:59:35
@@ -30,13 +30,22 @@
#include <sys/utsname.h>
#include <stdarg.h>
+#if ENABLE_LDAP
+#include <ldap.h>
+#endif
+
#include "libbalsa.h"
#include "mailbackend.h"
+
#ifdef BALSA_USE_THREADS
static GMutex *mutt_lock;
#endif
+#define POP_SERVER "pop"
+#define IMAP_SERVER "mx"
+#define LDAP_SERVER "ldap"
+
static gchar *Domainname;
void mutt_message(const char *fmt, ...);
@@ -220,6 +229,130 @@
* can't guess it any other way. */
return gnome_util_prepend_user_home("mailbox");
}
+
+/* Some more "guess" functions symmetric to libbalsa_guess_mail_spool()... */
+
+
+static gchar *qualified_hostname(const char *name)
+{
+ gchar *domain=libbalsa_get_domainname();
+
+ if(domain) {
+ gchar *host=g_strdup_printf("%s.%s", name, domain);
+
+ g_free(domain);
+
+ return host;
+ } else
+ return g_strdup(name);
+}
+
+
+gchar *libbalsa_guess_pop_server()
+{
+ return qualified_hostname(POP_SERVER);
+}
+
+gchar *libbalsa_guess_imap_server()
+{
+ return qualified_hostname(IMAP_SERVER);
+}
+
+gchar *libbalsa_guess_ldap_server()
+{
+ return qualified_hostname(LDAP_SERVER);
+}
+
+gchar *libbalsa_guess_imap_inbox()
+{
+ gchar *server = libbalsa_guess_imap_server();
+
+ if(server) {
+ gchar *url = g_strdup_printf("imap://%s/INBOX", server);
+
+ g_free(server);
+
+ return url;
+ }
+
+ return NULL;
+}
+
+gchar *libbalsa_guess_ldap_base()
+{
+ gchar *server = libbalsa_guess_ldap_server();
+ char *domain;
+
+ /* Note: Assumes base dn is "o=<domain name>". Somewhat speculative... */
+ if(server) {
+ gchar *base=NULL, *domain;
+
+ if((domain=strchr(server, '.')))
+ base = g_strdup_printf("o=%s", domain+1);
+
+ g_free(server);
+
+ return base;
+ }
+ return NULL;
+}
+
+gchar *libbalsa_guess_ldap_name()
+{
+ gchar *base = libbalsa_guess_ldap_base();
+
+ if(base) {
+ gchar *name = strchr(base, '=');
+ gchar *dir_name = g_strdup_printf(_("LDAP Directory for %s"),
+ (name?name+1:base));
+ g_free(base);
+
+ return dir_name;
+ }
+
+ return NULL;
+}
+
+gchar *libbalsa_guess_ldif_file()
+{
+ int i;
+ gchar *ldif;
+
+ static const gchar *guesses[] = {
+ "address.ldif",
+ ".address.ldif",
+ "address-book.ldif",
+ ".address-book.ldif",
+ NULL
+ };
+
+ for (i = 0; guesses[i] != NULL; i++) {
+ ldif = gnome_util_prepend_user_home(guesses[i]);
+
+ if (g_file_exists(ldif))
+ return ldif;
+
+ g_free(ldif);
+ }
+ return gnome_util_prepend_user_home(guesses[0]); /* *** Or NULL */
+
+}
+
+gboolean libbalsa_ldap_exists(const gchar *server)
+{
+#if ENABLE_LDAP
+ LDAP *ldap = ldap_open(server, LDAP_PORT);
+
+ if(ldap) {
+ ldap_unbind(ldap);
+
+ return TRUE;
+ }
+#endif /* #if ENABLE_LDAP */
+
+ return FALSE;
+}
+
/*
* This function is hooked into the mutt_error callback
Index: libbalsa/libbalsa.h
===================================================================
RCS file: /cvs/gnome/balsa/libbalsa/libbalsa.h,v
retrieving revision 1.25
diff -u -b -r1.25 libbalsa.h
--- libbalsa/libbalsa.h 2001/10/20 12:14:54 1.25
+++ libbalsa/libbalsa.h 2001/11/13 08:59:35
@@ -77,6 +77,19 @@
gboolean libbalsa_is_sending_mail(void);
void libbalsa_wait_for_sending_thread(gint max_seconds);
+gchar *libbalsa_guess_pop_server(void);
+gchar *libbalsa_guess_imap_server(void);
+gchar *libbalsa_guess_ldap_server(void);
+
+gchar *libbalsa_guess_imap_inbox(void);
+
+gchar *libbalsa_guess_ldap_base(void);
+gchar *libbalsa_guess_ldap_name(void);
+
+gchar *libbalsa_guess_ldif_file(void);
+
+gboolean libbalsa_ldap_exists(const gchar *server);
+
void libbalsa_lock_mutt(void);
void libbalsa_unlock_mutt(void);
Index: src/address-book-config.c
===================================================================
RCS file: /cvs/gnome/balsa/src/address-book-config.c,v
retrieving revision 1.14
diff -u -b -r1.14 address-book-config.c
--- src/address-book-config.c 2001/11/02 15:01:22 1.14
+++ src/address-book-config.c 2001/11/13 08:59:36
@@ -447,6 +447,9 @@
LibBalsaAddressBookLdap* ab;
GnomeDialog* mcw = GNOME_DIALOG(abc->window);
guint keyval;
+ gchar *host = libbalsa_guess_ldap_server();
+ gchar *base = libbalsa_guess_ldap_base();
+ gchar *name = libbalsa_guess_ldap_name();
ab = (LibBalsaAddressBookLdap*)abc->address_book; /* may be NULL */
@@ -454,24 +457,32 @@
create_label(_("_Address Book Name"), table, 0, &keyval);
abc->name_entry = create_entry(mcw, table, NULL, NULL, 0,
- ab ? abc->address_book->name : NULL,
+ ab ? abc->address_book->name : name,
keyval);
create_label(_("_Host Name"), table, 1, &keyval);
abc->ab_specific.ldap.host_name =
create_entry(mcw, table, NULL, NULL, 1,
- ab ? ab->host : NULL, keyval);
+ ab ? ab->host : host, keyval);
create_label(_("_Base Domain Name"), table, 2, &keyval);
abc->ab_specific.ldap.base_dn =
create_entry(mcw, table, NULL, NULL, 2,
- ab ? ab->base_dn : NULL, keyval);
+ ab ? ab->base_dn : base, keyval);
abc->expand_aliases_button =
create_check(mcw, _("_Expand aliases as you type"), table, 3,
ab ? abc->address_book->expand_aliases : TRUE);
gtk_widget_show(table);
+
+ if(base)
+ g_free(base);
+ if(name)
+ g_free(name);
+ if(host)
+ g_free(host);
+
return table;
}
#endif
Index: src/mailbox-conf.c
===================================================================
RCS file: /cvs/gnome/balsa/src/mailbox-conf.c,v
retrieving revision 1.117
diff -u -b -r1.117 mailbox-conf.c
--- src/mailbox-conf.c 2001/11/07 23:34:14 1.117
+++ src/mailbox-conf.c 2001/11/13 08:59:37
@@ -23,6 +23,7 @@
#include <gnome.h>
#include <string.h>
+#include <netdb.h>
#include "balsa-app.h"
#include "balsa-mblist.h"
@@ -33,6 +34,8 @@
#include "libbalsa.h"
+
+
typedef struct _MailboxConfWindow MailboxConfWindow;
struct _MailboxConfWindow {
LibBalsaMailbox *mailbox;
@@ -339,6 +342,8 @@
gtk_window_set_wmclass(GTK_WINDOW(mcw->window),
"mailbox_config_dialog", "Balsa");
+ gnome_dialog_close_hides(mcw->window, TRUE);
+
gnome_dialog_append_button_with_pixmap(mcw->window,
ok_button_name,
ok_pixmap);
@@ -841,13 +846,33 @@
return table;
}
+static const char *qualify_host_name(char *out_name, const char *name)
+{
+ char hostname[512];
+
+ strcpy(out_name, name);
+
+ if(gethostname(hostname, sizeof(hostname)-1)==0) {
+ char *domain;
+ struct hostent *host;
+
+ host=gethostbyname(hostname);
+ if((domain=strchr((host?host->h_name:hostname), '.'))) {
+ strcat(out_name, domain);
+ }
+ }
+ return out_name;
+}
+
static GtkWidget *
create_pop_mailbox_page(MailboxConfWindow *mcw)
{
GtkWidget *table;
guint keyval;
+ gchar *server;
table = gtk_table_new(9, 2, FALSE);
+ server = libbalsa_guess_pop_server();
/* mailbox name */
create_label(_("Mailbox _Name:"), table, 0, &keyval);
@@ -859,7 +884,7 @@
create_label(_("_Server:"), table, 1, &keyval);
mcw->mb_data.pop3.server = create_entry(mcw->window, table,
GTK_SIGNAL_FUNC(check_for_blank_fields),
- mcw, 1, "localhost", keyval);
+ mcw, 1, server, keyval);
/* pop port */
create_label(_("_Port:"), table, 2, &keyval);
@@ -910,6 +935,7 @@
table, 9, FALSE);
gtk_signal_connect(GTK_OBJECT(mcw->mb_data.pop3.use_ssl), "toggled", pop3_use_ssl_cb, mcw);
#endif
+ g_free(server);
return table;
}
@@ -920,6 +946,7 @@
GtkWidget *table;
guint keyval;
GtkWidget *entry;
+ gchar *server=libbalsa_guess_imap_server();
/* GtkWidget *label; */
table = gtk_table_new(7, 2, FALSE);
@@ -935,7 +962,7 @@
mcw->mb_data.imap.server =
create_entry(mcw->window, table,
GTK_SIGNAL_FUNC(check_for_blank_fields),
- mcw, 1, "localhost", keyval);
+ mcw, 1, server, keyval);
/* imap server port number */
create_label(_("_Port:"), table, 2, &keyval);
@@ -993,6 +1020,8 @@
gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 5, 6,
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 10);
+ g_free(server);
+
return table;
}
Index: src/folder-conf.c
===================================================================
RCS file: /cvs/gnome/balsa/src/folder-conf.c,v
retrieving revision 1.23
diff -u -b -r1.23 folder-conf.c
--- src/folder-conf.c 2001/11/09 10:46:39 1.23
+++ src/folder-conf.c 2001/11/13 08:59:37
@@ -153,6 +153,7 @@
FolderDialogData fcw;
guint keyval;
LibBalsaServer * s = mn ? mn->server : NULL;
+ gchar *default_server = libbalsa_guess_imap_server();
fcw.mn = mn;
fcw.dialog = GNOME_DIALOG(gnome_dialog_new(_("Remote IMAP folder"),
@@ -179,7 +180,7 @@
create_label(_("_Server:"), table, 1, &keyval);
fcw.server = create_entry(fcw.dialog, table, validate_folder, &fcw, 1,
- s ? s->host : "localhost",
+ s ? s->host : default_server,
keyval);
create_label(_("_Port:"), table, 2, &keyval);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]