--- vchkpw.c.orig	Tue Apr 29 14:24:51 2003
+++ vchkpw.c	Tue Apr 29 14:24:51 2003
@@ -377,7 +377,7 @@
   if ( vpw->pw_dir == NULL || vpw->pw_dir[0]==0 ) {
 
     /* if making a new directory failed log the error and exit */
-    if ( make_user_dir(vpw->pw_name, TheDomain, pw_uid, pw_gid)==NULL){
+    if ( make_user_dir(vpw->pw_name, TheDomain, vpw->pw_name, pw_uid, pw_gid)==NULL){
       snprintf(LogLine, LOG_LINE_SIZE, "%s: dir auto create failed %s@%s:%s", 
         VchkpwLogName, TheUser, TheDomain, IpAddr);
       vlog(VLOG_ERROR_INTERNAL, TheUser, TheDomain, ThePass, 
--- vdelivermail.c.orig	Sat Nov  2 22:34:39 2002
+++ vdelivermail.c	Sat Nov  2 22:35:20 2002
@@ -946,7 +946,7 @@
 
     /* If thier directory path is empty make them a new one */
     if ( vpw->pw_dir == NULL || vpw->pw_dir[0]==0 ) {
-        if ( make_user_dir(vpw->pw_name, TheDomain, 
+        if ( make_user_dir(vpw->pw_name, TheDomain, vpw->pw_name,
                TheDomainUid, TheDomainGid)==NULL){
             printf("Auto creation of maildir failed. vpopmail (#5.9.8)\n");
             vexit(100);
--- vpopmail.c.orig	Tue Apr 29 14:17:56 2003
+++ vpopmail.c	Tue Apr 29 14:18:01 2003
@@ -328,7 +328,7 @@
     }
   }
 
-  if ( (dir=make_user_dir(username, domain, uid, gid)) == NULL ) {
+  if ( (dir=make_user_dir(username, domain, gecos, uid, gid)) == NULL ) {
     if (verrori != 0 ) return(verrori);
     else return(VA_BAD_U_DIR);
   }
@@ -1453,16 +1453,45 @@
     return &pwent;
 }
 
+char *escape_spaces(const char *s)
+{
+  size_t i, len;
+  char *newstr;
+  
+  /* Count the spaces */
+  for (i = len = 0; s[i]; i++, len++)
+    if (s[i] == ' ')
+      len += 2;
+  /* Allocate */
+  newstr = malloc(len + 1);
+  if (newstr == NULL)
+    return (NULL);
+  /* Fill */
+  for (i = len = 0; s[i]; i++)
+    if (s[i] == ' ') {
+      newstr[len++] = '+';
+      newstr[len++] = '2';
+      newstr[len++] = '0';
+    } else {
+      newstr[len++] = s[i];
+    }
+  newstr[len] = '\0';
+  return (newstr);
+}
+
 /*
  * figure out where to put the user and
  * make the directories if needed
  */
-char *make_user_dir(char *username, char *domain, uid_t uid, gid_t gid)
+char *make_user_dir(char *username, char *domain, char *gecos,
+		uid_t uid, gid_t gid)
 {
  char *tmpstr;
  char *tmpbuf;
  char *tmpdir;
  struct vqpasswd *mypw;
+ char *fulladdr, *escaped;
+ FILE *cfg;
 
   verrori = 0;
   tmpbuf = malloc(MAX_BUFF);
@@ -1522,6 +1551,35 @@
     return(NULL);
   }
 
+  if ((cfg = fopen("sqwebmail-config", "wt")) == NULL) {
+    chdir(tmpbuf); free(tmpbuf); free(tmpdir);
+    printf("make_user_dir: error 8\n");
+    return(NULL);
+  }
+  if ((escaped = escape_spaces(username)) == NULL) {
+    fclose(cfg);
+    chdir(tmpbuf); free(tmpbuf); free(tmpdir);
+    printf("make_user_dir: error 9\n");
+    return(NULL);
+  }
+  if ((fulladdr = malloc(strlen(gecos) + strlen(username) + strlen(domain) + 10)) == NULL) {
+    fclose(cfg);
+    chdir(tmpbuf); free(tmpbuf); free(tmpdir);
+    printf("make_user_dir: error 9\n");
+    return(NULL);
+  }
+  sprintf(fulladdr, "\"%s <%s@%s>\"", gecos, username, domain);
+  if ((escaped = escape_spaces(fulladdr)) == NULL) {
+    fclose(cfg);
+    chdir(tmpbuf); free(tmpbuf); free(tmpdir);
+    printf("make_user_dir: error 10\n");
+    return(NULL);
+  }
+  free(fulladdr);
+  fprintf(cfg, "FROM=%s\n", escaped);
+  free(escaped);
+  fclose(cfg);
+  
   chdir("../..");
   r_chown(username, uid, gid);
 
--- vpopmail.h.orig	Tue Apr 29 14:21:06 2003
+++ vpopmail.h	Tue Apr 29 14:21:19 2003
@@ -128,7 +128,7 @@
 int update_file(char *, char *);
 int count_rcpthosts();
 int compile_morercpthosts();
-char *make_user_dir(char *username, char *domain, uid_t uid, gid_t gid);
+char *make_user_dir(char *username, char *domain, char *gecos, uid_t uid, gid_t gid);
 int r_mkdir(char *, uid_t uid, gid_t gid);
 struct vqpasswd *vgetent(FILE *);
 int pw_comp(char *, char *, char *, int);
--- vqmaillocal.c.orig	Tue Apr 29 14:24:51 2003
+++ vqmaillocal.c	Tue Apr 29 14:24:51 2003
@@ -895,7 +895,7 @@
       gid_t pw_gid;
 
 	vget_assign(TheDomain,NULL,0,&pw_uid,&pw_gid);
-        if ( make_user_dir(vpw->pw_name, TheDomain, pw_uid, pw_gid)==NULL){
+        if ( make_user_dir(vpw->pw_name, TheDomain, vpw->pw_name, pw_uid, pw_gid)==NULL){
             printf("Auto creation of maildir failed. vpopmail (#5.9.8)\n");
             vexit(100);
         }
