Subject: [patch] hashed spool directories

From: Matt Selsky <[email-masked]>
Date: Tue, 6 Jan 2004 00:33:00 -0500

I noticed that some people have asked about hashed spool directories in 
the past.  This means the spool is /var/mail/s/e/selsky instead of 
/var/mail/selsky

The attached patch against imap-2002e implements hashed spool
directories (which are disabled by default).  If there are any changes 
which would help this get accepted into the main distribution, please 
let me know.

Cheers.
--- src/osdep/unix/env_unix.c	2003/10/04 03:51:51	1.2
+++ src/osdep/unix/env_unix.c	2004/01/06 05:25:52
@@ -92,6 +92,8 @@
 				/* block notification */
 static blocknotify_t mailblocknotify = mm_blocknotify;
 
+static short spool_hash_depth = 0; /* 2 means spool is /var/mail/f/o/foo */
+
 /* Note: setting disableLockWarning means that you assert that the
  * so-modified copy of this software will NEVER be used:
  *  1) in conjunction with any software which expects .lock files
@@ -820,7 +822,23 @@
 {
   char tmp[MAILTMPLEN];
   if (!sysInbox) {		/* initialize if first time */
-    sprintf (tmp,"%s/%s",MAILSPOOL,myusername ());
+    int i;
+    char c;
+
+    sprintf (tmp,"%s/",MAILSPOOL);
+
+    for (i = 0; i < spool_hash_depth; i++)
+    {
+      /* deal with usernames shorter than hash depth */
+      if (strlen (myusername ()) > i)
+      {
+        c = myusername ()[i];
+      }
+      sprintf (tmp+strlen (tmp),"%c/", c);
+    }
+
+    strcat (tmp,myusername ());
+
     sysInbox = cpystr (tmp);	/* system inbox is from mail spool */
   }
   return sysInbox;

---

From: Mark Crispin <[email-masked]>
Date: Mon, 5 Jan 2004 22:29:10 -0800 (PST)

On Tue, 6 Jan 2004, Matt Selsky wrote:
> If there are any changes

My feeling about hashed spool directories is that this functionality is
site-specific, with no obvious single definition of how it is to be
implemented that applies in all instances.  Consequently, I consider it to
be something that should always be of the form of a third-party patch
rather than an official part of c-client.  I do encourage you to continue
distributing this patch since it's likely to be useful for some people

For what it's worth, I suggest the following alternative implementation of
your patch, which avoids needless rescans of the string:

   int i;
   char *u,*s;
   strcpy (tmp,MAILSPOOL);
   for (i = 0, u = myusername (), s = tmp + strlen (tmp);
        (*s++ = '/') && (i < spool_hash_depth) && u[i];
        *s++ = u[i++]);
   strcpy (s,u);

-- Mark --

http://staff.washington.edu/mrc
Science does not emerge from voting, party politics, or public debate.
Si vis pacem, para bellum.

---

From: Matt Selsky <[email-masked]>
Date: Sun, 1 Feb 2004 17:59:13 -0500

> distributing this patch since it's likely to be useful for some people

Thank you for your feedback.

Procmail has included support for hashed spool directories since 3.13,
so I don't think the feature is that site specific. (see
procmail/src/authenticate.c "#define MAILSPOOLHASH 0")

>         (*s++ = '/') && (i < spool_hash_depth) && u[i];

See my new patch against imap-2004rc6.  Further comments are welcome.

Cheers.

---

From: Matt Selsky <[email-masked]>
Date: Sun, 1 Feb 2004 18:01:00 -0500

Sorry, I forgot to include the attachment.

Cheers.

> See my new patch against imap-2004rc6.  Further comments are welcome.
--- imap-2004.RC6/src/osdep/unix/env_unix.c	2004/02/01 21:30:40	1.2
+++ imap-2004.RC6/src/osdep/unix/env_unix.c	2004/02/01 22:55:31
@@ -92,6 +92,8 @@
 				/* block notification */
 static blocknotify_t mailblocknotify = mm_blocknotify;
 
+static short spool_hash_depth = 0; /* 2 means spool is /var/mail/f/o/foo */
+
 /* Note: setting disableLockWarning means that you assert that the
  * so-modified copy of this software will NEVER be used:
  *  1) in conjunction with any software which expects .lock files
@@ -818,7 +820,23 @@
 {
   char tmp[MAILTMPLEN];
   if (!sysInbox) {		/* initialize if first time */
-    sprintf (tmp,"%s/%s",MAILSPOOL,myusername ());
+    int i;
+    char *u,*s, c;
+    static short endofstring = NIL;
+
+    strcpy (tmp,MAILSPOOL);
+    for (i = 0, u = myusername (), s = tmp + strlen (tmp);
+	 (*s++ = '/') && (i < spool_hash_depth);
+	 i++) {
+      /* deal with usernames shorter than hash depth */
+      if (u[i] && !endofstring)
+	c = u[i];
+      else
+	endofstring = T;
+      *s++ = c;
+    }
+    strcpy (s,u);
+
     sysInbox = cpystr (tmp);	/* system inbox is from mail spool */
   }
   return sysInbox;