diff -r -u3 imap-4.5_orig2/src/osdep/unix/maildir.c imap-4.5_rename/src/osdep/unix/maildir.c --- imap-4.5_orig2/src/osdep/unix/maildir.c Sat Jun 26 23:53:59 1999 +++ imap-4.5_rename/src/osdep/unix/maildir.c Sun Jun 27 01:22:21 1999 @@ -1180,6 +1180,7 @@ long maildir_rename (MAILSTREAM *stream,char *old,char *new) { char tmp[MAILTMPLEN],tmpnew[MAILTMPLEN]; + int i; /* old mailbox name must be valid */ if (!maildir_isvalid (old,NIL)) { @@ -1195,8 +1196,26 @@ return NIL; } + /* get the filesnames to rename */ + maildir_file (tmp,old); + i = strlen(tmp); + if ( i > 4 && tmp[i-4] == '/' && tmp[i-3] == 'c' && tmp[i-2] == 'u' && tmp[i-1] == 'r' ) + tmp[i-4] = 0; + + maildir_file (tmpnew,new); + i = strlen(tmpnew); + if ( i > 4 && tmpnew[i-4] == '/' && tmpnew[i-3] == 'c' && tmpnew[i-2] == 'u' && tmpnew[i-1] == 'r' ) + tmpnew[i-4] = 0; + + /* new filename must not exist */ + if (access (tmpnew,F_OK) == 0) { + sprintf (tmp,"Can't rename to mailbox %s: destination already exists as a non-mailbox",new); + mm_log (tmp,ERROR); + return NIL; + } + /* try to rename the directory */ - if (rename (maildir_file (tmp,old),maildir_file (tmpnew,new))) { + if (rename (tmp,tmpnew)) { sprintf (tmp,"Can't rename mailbox %s to %s: %s",old,new,strerror (errno)); mm_log (tmp,ERROR); return NIL;