diff -ur courier-imap-4.0.2.orig/imap/imapd.c courier-imap-4.0.2/imap/imapd.c --- courier-imap-4.0.2.orig/imap/imapd.c 2004-11-14 08:24:48.000000000 +0900 +++ courier-imap-4.0.2/imap/imapd.c 2005-04-19 16:40:16.342868926 +0900 @@ -6284,11 +6284,44 @@ #if 0 imapscanpath=getimapscanpath(argv[0]); #endif + + /* automake maildir */ + struct stat mbuf, sbuf; + char *maildir = malloc(strlen(p) + sizeof("/tmp")); + if (stat(p, &mbuf) != 0 || + stat(strcat(strcpy(maildir, p), "/tmp"), &mbuf) != 0 || + stat(strcat(strcpy(maildir, p), "/new"), &mbuf) != 0 || + stat(strcat(strcpy(maildir, p), "/cur"), &mbuf) != 0) { + /* + * if Maildir or Maildir/tmp or Maildir/new or Maildir/cur doesn't exist, + * try to make + */ + if (maildir_make(p, 0700, 0700, 0) == 0) { + fprintf(stderr, "INFO: MAILDIRMAKE, user=%s, dir=%s\n", + getenv("AUTHENTICATED"), + p); + fflush(stderr); + } + } + /* automake maildir end */ + if (chdir(p)) { fprintf(stderr, "chdir %s: %s\n", p, strerror(errno)); write_error_exit(p); } + + /* automake maildirsize */ + char *maildirsize = malloc(strlen(p) + sizeof("/maildirsize")); + strcat(strcpy(maildirsize, p), "/maildirsize"); + if (getenv("MAILDIRQUOTA") != NULL && stat(maildirsize, &sbuf) != 0) { + /* If quota is not null and maildirsize does not exist, make */ + char *mquota = malloc(sizeof(getenv("MAILDIRQUOTA"))); + strcpy(mquota, getenv("MAILDIRQUOTA")); + maildir_quota_set(p, mquota); + } + /* automake maildirsize end */ + maildir_loginexec(); if (auth_getoptionenvint("disableshared")) diff -ur courier-imap-4.0.2.orig/imap/imaplogin.c courier-imap-4.0.2/imap/imaplogin.c --- courier-imap-4.0.2.orig/imap/imaplogin.c 2005-02-20 13:49:06.000000000 +0900 +++ courier-imap-4.0.2/imap/imaplogin.c 2005-04-19 16:38:26.546845507 +0900 @@ -243,6 +243,16 @@ strcat(strcpy(p, "AUTHENTICATED="), ainfo->address); putenv(p); + /* putenv MAILDIRQUOTA */ + p=malloc(sizeof("MAILDIRQUOTA=")+ + strlen(ainfo->quota)); + if (p && strlen(ainfo->quota) > 0) + { + strcat(strcpy(p, "MAILDIRQUOTA="), + ainfo->quota); + putenv(p); + } + /* putenv MAILDIRQUOTA end */ alarm(0); execl(imapd, imapd, ainfo->maildir ? @@ -461,9 +471,7 @@ writes("* OK [CAPABILITY "); imapcapability(); - writes("] Courier-IMAP ready. " - "Copyright 1998-2005 Double Precision, Inc. " - "See COPYING for distribution information.\r\n"); + writes("] IMAP ready.\r\n"); fprintf(stderr, "DEBUG: Connection, ip=[%s]\n", ip); writeflush(); main_argc=argc; diff -ur courier-imap-4.0.2.orig/imap/pop3dserver.c courier-imap-4.0.2/imap/pop3dserver.c --- courier-imap-4.0.2.orig/imap/pop3dserver.c 2005-03-01 12:13:53.000000000 +0900 +++ courier-imap-4.0.2/imap/pop3dserver.c 2005-04-19 16:40:41.793850936 +0900 @@ -1009,6 +1009,26 @@ if (!p) p="./Maildir"; + /* automake maildir */ + struct stat mbuf, sbuf; + char *maildir = malloc(strlen(p) + sizeof("/tmp")); + if (stat(p, &mbuf) != 0 || + stat(strcat(strcpy(maildir, p), "/tmp"), &mbuf) != 0 || + stat(strcat(strcpy(maildir, p), "/new"), &mbuf) != 0 || + stat(strcat(strcpy(maildir, p), "/cur"), &mbuf) != 0) { + /* + * if Maildir or Maildir/tmp or Maildir/new or Maildir/cur doesn't exist, + * try to make + */ + if (maildir_make(p, 0700, 0700, 0) == 0) { + fprintf(stderr, "INFO: MAILDIRMAKE, user=%s, dir=%s\n", + authaddr, + p); + fflush(stderr); + } + } + /* automake maildir end */ + if (chdir(p)) { fprintf(stderr, "chdir %s: %s\n", p, strerror(errno)); @@ -1016,7 +1036,18 @@ fflush(stdout); exit(1); } - + + /* automake maildirsize */ + char *maildirsize = malloc(strlen(p) + sizeof("/maildirsize")); + strcat(strcpy(maildirsize, p), "/maildirsize"); + if (getenv("MAILDIRQUOTA") != NULL && stat(maildirsize, &sbuf) != 0) { + /* If quota is not null and maildirsize does not exist, make */ + char *mquota = malloc(sizeof(getenv("MAILDIRQUOTA"))); + strcpy(mquota, getenv("MAILDIRQUOTA")); + maildir_quota_set(p, mquota); + } + /* automake maildirsize end */ + maildir_loginexec(); if (auth_getoptionenvint("disablepop3")) diff -ur courier-imap-4.0.2.orig/imap/pop3login.c courier-imap-4.0.2/imap/pop3login.c --- courier-imap-4.0.2.orig/imap/pop3login.c 2005-02-20 13:49:06.000000000 +0900 +++ courier-imap-4.0.2/imap/pop3login.c 2005-04-19 16:38:26.552599547 +0900 @@ -224,7 +224,16 @@ strcat(strcpy(p, "AUTHENTICATED="), ainfo->address); putenv(p); - + /* putenv MAILDIRQUOTA */ + p=malloc(sizeof("MAILDIRQUOTA=")+ + strlen(ainfo->quota)); + if (p && strlen(ainfo->quota) > 0) + { + strcat(strcpy(p, "MAILDIRQUOTA="), + ainfo->quota); + putenv(p); + } + /* putenv MAILDIRQUOTA end */ alarm(0); execl(pop3d, pop3d, ainfo->maildir ? diff -ur courier-imap-4.0.2.orig/maildir/maildirmake2.c courier-imap-4.0.2/maildir/maildirmake2.c --- courier-imap-4.0.2.orig/maildir/maildirmake2.c 2004-03-12 21:05:54.000000000 +0900 +++ courier-imap-4.0.2/maildir/maildirmake2.c 2005-04-19 16:38:26.554926392 +0900 @@ -44,16 +44,29 @@ if (!q) return -1; - if (mkdir(maildir, perm) < 0 || - chmod(maildir, perm) < 0 || - mkdir(strcat(strcpy(q, maildir), "/tmp"), subdirperm) < 0 || - chmod(q, subdirperm) < 0 || - mkdir(strcat(strcpy(q, maildir), "/new"), subdirperm) < 0 || - chmod(q, subdirperm) < 0 || - mkdir(strcat(strcpy(q, maildir), "/cur"), subdirperm) < 0 || - chmod(q, subdirperm) < 0 || - (folder && (fd=open(strcat(strcpy(q, maildir), "/maildirfolder"), - O_CREAT|O_WRONLY, 0600)) < 0)) + pmkdir(maildir, perm); + if (chmod(maildir, perm) < 0) { + free(q); + return -1; + } + mkdir(strcat(strcpy(q, maildir), "/tmp"), subdirperm); + if (chmod(q, subdirperm) < 0) { + free(q); + return -1; + } + mkdir(strcat(strcpy(q, maildir), "/new"), subdirperm); + if (chmod(q, subdirperm) < 0) { + free(q); + return -1; + } + mkdir(strcat(strcpy(q, maildir), "/cur"), subdirperm); + if (chmod(q, subdirperm) < 0) { + free(q); + return -1; + } + + if (folder && (fd=open(strcat(strcpy(q, maildir), "/maildirfolder"), + O_CREAT|O_WRONLY, 0600)) < 0) { free(q); return -1; @@ -131,3 +144,29 @@ } while (n); return rmdir(maildir) < 0 && errno != ENOENT ? -1:0; } + +/* mkdir(2) wrapper to make parent directory */ +int pmkdir(const char *pathname, mode_t mode) +{ + int first, last, retval=0; + char *p; + p = (char *)pathname; + if (p[0] == '/') + ++p; + for (first = 1, last = 0; !last ; ++p) { + if (p[0] == '\0') + last = 1; + else if (p[0] != '/') + continue; + *p = '\0'; + if (!last && p[1] == '\0') + last = 1; + if (first) { + first = 0; + } + retval = mkdir(pathname, mode); + if (!last) + *p = '/'; + } + return (retval); +} diff -ur courier-imap-4.0.2.orig/maildir/maildirmisc.h courier-imap-4.0.2/maildir/maildirmisc.h --- courier-imap-4.0.2.orig/maildir/maildirmisc.h 2004-02-17 09:58:13.000000000 +0900 +++ courier-imap-4.0.2/maildir/maildirmisc.h 2005-04-19 16:38:26.556610255 +0900 @@ -41,6 +41,8 @@ #define PUBLIC "public" /* SMAP */ +extern int pmkdir(const char *pathname, mode_t mode); + int maildir_make(const char *maildir, int perm, int subdirperm, int folder);