Subject: pkg/19128: a fix to make mail/cyrus-imapd21's autocreatequota do what it says for new users too
To: None <gnats-bugs@gnats.netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
Date: 11/21/2002 16:49:33
>Number:         19128
>Category:       pkg
>Synopsis:       a fix to make mail/cyrus-imapd21's autocreatequota do what it says for new users too
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 21 13:50:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Greg A. Woods
>Release:        pkgsrc-current 2002/11/20
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Environment:
System: NetBSD 1.5W
>Description:

	In NetBSD the mailer is usually authoritative as to which
	mailboxes are valid and should exist, and which do not.  For
	example with the default "mail.local" a spool file is
	automatically created if it did not exist prior to the first
	message being delivered to it.  Further both SMTP mailers
	delivered by default on NetBSD, as well as most of the ones that
	can be added in place of those two, can be configured to reject
	invalid mailboxes during the initial SMTP transaction thus
	implying that they are authoritative for any mailboxes they
	don't reject.

	So it seems the Cyrus mail store, at least when installed on
	NetBSD, should simply create INBOXes for users whenever they are
	first delivered to, just like "mail.local" does.

	The attached patch provides this capability in a user
	configurable manner.  If the "autocreatequota" parameter is
	given a non-zero value then mailboxes (the user's INBOX) will
	automatically be created with the specified quota when the first
	message arrives for that mailbox.  Without this fix the
	autocreatequota feature only allows users to create their own
	INBOX through an IMAP transaction, but IIRC it won't work for
	POP-only users, nor will it prevent loss of e-mail should the
	user fail to create their INBOX prior to someone sending them
	their first e-mail(s).

	Note this patch has been sent a couple of times to the Cyrus
	authors ever since 1.5.16 or so, but they don't seem to think
	it's important enough to include in their base distribution.  In
	the mean while I've been using previous incarnations of it
	successfully with Postfix and Smail in a number of installations
	over the years since first creating the first version of it.

>How-To-Repeat:

>Fix:

	add this patch to the collection in mail/cyrus-imapd21/patches:

	note the required error handling fixes too

	also note a new syslog() call in the last hunk which will help
	an administrator identify properly problems in a broken
	/etc/imapd.conf

Index: imap/lmtpd.c
===================================================================
RCS file: /cvs/src/cyrus/imap/lmtpd.c,v
retrieving revision 1.102
diff -c -r1.102 lmtpd.c
*** lmtpd.c	2002/11/06 20:43:22	1.102
--- lmtpd.c	2002/11/10 18:57:48
***************
*** 1127,1132 ****
--- 1127,1133 ----
      struct appendstate as;
      char namebuf[MAX_MAILBOX_PATH];
      time_t now = time(NULL);
+     int autocreatequota = config_getint("autocreatequota", 0);
  
      /* Translate any separators in user */
      if (user) mboxname_hiersep_tointernal(&lmtpd_namespace, user);
***************
*** 1145,1150 ****
--- 1146,1163 ----
  	r = append_setup(&as, namebuf, MAILBOX_FORMAT_NORMAL,
  			 authuser, authstate, acloverride ? 0 : ACL_POST, 
  			 quotaoverride ? -1 : 0);
+     }
+     if (r == IMAP_MAILBOX_NONEXISTENT && autocreatequota > 0) {
+ 	r = mboxlist_createmailbox(namebuf, 0, (char *) NULL, 1,
+ 				   user, authstate, (char *) NULL, 0);
+ 	if (!r && autocreatequota > 0) {
+ 	    (void) mboxlist_setquota(namebuf, autocreatequota, 0);
+ 	}
+ 	if (!r) {
+ 	    r = append_setup(&as, namebuf, MAILBOX_FORMAT_NORMAL,
+ 			     authuser, authstate, acloverride ? 0 : ACL_POST, 
+ 			     quotaoverride ? -1 : 0);
+ 	}
      }
  
      if (!r) {
Index: imap/lmtpengine.c
===================================================================
RCS file: /cvs/src/cyrus/imap/lmtpengine.c,v
retrieving revision 1.84
diff -c -r1.84 lmtpengine.c
*** lmtpengine.c	2002/11/03 14:20:10	1.84
--- lmtpengine.c	2002/11/10 18:57:49
***************
*** 239,244 ****
--- 239,249 ----
  		    "554 5.6.0 Message has no header/body separator\r\n");
  	break;
  
+     case IMAP_MAILBOX_BADNAME:
+ 	prot_printf(pout, 
+ 		    "550 5.1.1 Bad mail box name\r\n");
+ 	break;
+ 
      case IMAP_MAILBOX_NONEXISTENT:
  	/* XXX Might have been moved to other server */
  	if (LMTP_LONG_ERROR_MSGS) {
***************
*** 249,254 ****
--- 254,265 ----
  	} else {
  	    prot_printf(pout, "550 5.1.1 User unknown\r\n");
  	}
+ 	break;
+ 
+     case IMAP_PARTITION_UNKNOWN:
+ 	prot_printf(pout, 
+ 		    "550 5.1.1 Internal configuration error: partition unknown, please inform %s\r\n",
+ 		    POSTMASTER);
  	break;
  
      case IMAP_PROTOCOL_BAD_PARAMETERS:
Index: imap/mboxlist.c
===================================================================
RCS file: /cvs/src/cyrus/imap/mboxlist.c,v
retrieving revision 1.205
diff -c -r1.205 mboxlist.c
*** mboxlist.c	2002/11/06 20:43:22	1.205
--- mboxlist.c	2002/11/10 18:57:50
***************
*** 586,591 ****
--- 586,592 ----
  	root = config_getstring(buf, (char *)0);
  	if (!root) {
  	    r = IMAP_PARTITION_UNKNOWN;
+ 	    syslog(LOG_ERR, "Could not find partition-%s during create", newpartition);
  	    goto done;
  	}
  	if (strlen(root)+strlen(name)+20 > MAX_MAILBOX_PATH) {
>Release-Note:
>Audit-Trail:
>Unformatted: