From 12718c4056c30ac2bb1610f6ca62a378718b924c Mon Sep 17 00:00:00 2001 From: Iain Holmes Date: Tue, 4 Sep 2001 20:50:34 +0000 Subject: Get the correct name from the prefs file, or from the passwd file if one does not exist svn path=/trunk/; revision=12597 --- importers/netscape-importer.c | 54 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'importers/netscape-importer.c') diff --git a/importers/netscape-importer.c b/importers/netscape-importer.c index 8c4283dc99..7d1f0d25e7 100644 --- a/importers/netscape-importer.c +++ b/importers/netscape-importer.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -300,9 +302,49 @@ netscape_init_prefs (void) return; } +static char * +get_user_fullname (void) +{ + char *uname, *gecos, *special; + struct passwd *pwd; + + uname = getenv ("USER"); + pwd = getpwnam (uname); + + if (strcmp (pwd->pw_gecos, "") == 0) { + return g_strdup (uname); + } + + special = strchr (pwd->pw_gecos, ','); + if (special == NULL) { + gecos = g_strdup (pwd->pw_gecos); + } else { + gecos = g_strndup (pwd->pw_gecos, special - pwd->pw_gecos); + } + + special = strchr (gecos, '&'); + if (special == NULL) { + return gecos; + } else { + char *capname, *expanded, *noamp; + + capname = g_strdup (uname); + capname[0] = toupper ((int) capname[0]); + noamp = g_strndup (gecos, special - gecos - 1); + expanded = g_strconcat (noamp, capname, NULL); + + g_free (noamp); + g_free (capname); + g_free (gecos); + + return expanded; + } +} + static void netscape_import_accounts (NetscapeImporter *importer) { + char *username; const char *nstr; const char *imap; GNOME_Evolution_MailConfig_Account account; @@ -332,7 +374,13 @@ netscape_import_accounts (NetscapeImporter *importer) /* Create identify structure */ nstr = netscape_get_string ("mail.identity.username"); - id.name = CORBA_string_dup (nstr ? nstr : "John Doe"); + if (nstr != NULL) { + username = g_strdup (nstr); + } else { + username = get_user_fullname (); + } + + id.name = CORBA_string_dup (username); nstr = netscape_get_string ("mail.identity.useremail"); id.address = CORBA_string_dup (nstr ? nstr : ""); nstr = netscape_get_string ("mail.identity.organization"); @@ -364,8 +412,8 @@ netscape_import_accounts (NetscapeImporter *importer) } /* Create account */ - nstr = netscape_get_string ("mail.identity.username"); - account.name = CORBA_string_dup (nstr ? nstr : ""); + account.name = CORBA_string_dup (username); + g_free (username); account.id = id; account.transport = transport; -- cgit v1.2.3