aboutsummaryrefslogtreecommitdiffstats
path: root/importers
diff options
context:
space:
mode:
authorIain Holmes <iain@src.gnome.org>2001-09-05 04:50:34 +0800
committerIain Holmes <iain@src.gnome.org>2001-09-05 04:50:34 +0800
commit12718c4056c30ac2bb1610f6ca62a378718b924c (patch)
treece5c72a91fa3ea8cb816e7373bd385758f3a386e /importers
parent98b0ce35e99ae6d6c0fffc791a98424ee9f40aca (diff)
downloadgsoc2013-evolution-12718c4056c30ac2bb1610f6ca62a378718b924c.tar.gz
gsoc2013-evolution-12718c4056c30ac2bb1610f6ca62a378718b924c.tar.zst
gsoc2013-evolution-12718c4056c30ac2bb1610f6ca62a378718b924c.zip
Get the correct name from the prefs file, or from the passwd file if one does
not exist svn path=/trunk/; revision=12597
Diffstat (limited to 'importers')
-rw-r--r--importers/ChangeLog8
-rw-r--r--importers/netscape-importer.c54
2 files changed, 59 insertions, 3 deletions
diff --git a/importers/ChangeLog b/importers/ChangeLog
index f138273071..97175314fd 100644
--- a/importers/ChangeLog
+++ b/importers/ChangeLog
@@ -1,3 +1,11 @@
+2001-09-04 Iain Holmes <iain@ximian.com>
+
+ * netscape-importer.c (netscape_import_accounts): If there is no
+ username defined in the netscape file, work it out from the passwd
+ file.
+ (get_user_fullname): Work out the username from the passwd file,
+ striping all the extra stuff and expanding the &
+
2001-08-31 Iain Holmes <iain@ximian.com>
* elm-importer.c (create_importer_gui): Add a messagebox.
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 <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <pwd.h>
+#include <ctype.h>
#include <unistd.h>
#include <dirent.h>
@@ -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;