rpms/cyrus-imapd/devel README.autocreate-cyrus-2.2, NONE, 1.1 README.autosievefolder, NONE, 1.1 batchreconstruct, NONE, 1.1 bsd2cyrus, NONE, 1.1 cpmsg, NONE, 1.1 cyrus-deliver-wrapper.c, NONE, 1.1 cyrus-imapd-2.1.15-nobarenewlinescheck.patch, NONE, 1.1 cyrus-imapd-2.1.16-getrlimit.patch, NONE, 1.1 cyrus-imapd-2.1.3-flock.patch, NONE, 1.1 cyrus-imapd-2.1.9-fdatasync.patch, NONE, 1.1 cyrus-imapd-2.2.10-groupcache.patch, NONE, 1.1 cyrus-imapd-2.2.10-rmquota+deletemailbox-0.1.diff, NONE, 1.1 cyrus-imapd-2.2.12-autocreate-0.9.2.diff, NONE, 1.1 cyrus-imapd-2.2.12-autosievefolder-0.6.diff, NONE, 1.1 cyrus-imapd-2.2.12.tar.gz.sig, NONE, 1.1 cyrus-imapd-2.2.4-OE-seenstate.patch, NONE, 1.1 cyrus-imapd-2.2.4-munge8bit.patch, NONE, 1.1 cyrus-imapd-README.RPM, NONE, 1.1 cyrus-imapd-README.contrib, NONE, 1.1 cyrus-imapd-README.groupcache, NONE, 1.1 cyrus-imapd-acceptinvalidfrom.patch, NONE, 1.1 cyrus-imapd-db.cfg, NONE, 1.1 cyrus-imapd-gcc4.patch, NONE, 1.1 cyrus-imapd-procmail+cyrus.mc, NONE, 1.1 cyrus-imapd-sendmail-8.12.9-c! yrusv2.m4, NONE, 1.1 cyrus-imapd.cron-daily, NONE, 1.1 cyrus-imapd.cvt_cyrusdb_all, NONE, 1.1 cyrus-imapd.imap-2.2.x-conf, NONE, 1.1 cyrus-imapd.init, NONE, 1.1 cyrus-imapd.logrotate, NONE, 1.1 cyrus-imapd.magic, NONE, 1.1 cyrus-imapd.pam-config, NONE, 1.1 cyrus-imapd.rpm_set_permissions, NONE, 1.1 cyrus-imapd.spec, NONE, 1.1 cyrus-imapd.sysconfig, NONE, 1.1 cyrus-imapd.upd_groupcache, NONE, 1.1 cyrus-procmailrc, NONE, 1.1 cyrus-user-procmailrc.template, NONE, 1.1 cyrus_ldap_quota.pl, NONE, 1.1 folderxfer, NONE, 1.1 imapcreate.pl, NONE, 1.1 inboxfer, NONE, 1.1 .cvsignore, 1.1, 1.2 sources, 1.1, 1.2

John Dennis (jdennis) fedora-extras-commits at redhat.com
Fri Apr 15 20:24:17 UTC 2005


Author: jdennis

Update of /cvs/extras/rpms/cyrus-imapd/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv20272/devel

Modified Files:
	.cvsignore sources 
Added Files:
	README.autocreate-cyrus-2.2 README.autosievefolder 
	batchreconstruct bsd2cyrus cpmsg cyrus-deliver-wrapper.c 
	cyrus-imapd-2.1.15-nobarenewlinescheck.patch 
	cyrus-imapd-2.1.16-getrlimit.patch 
	cyrus-imapd-2.1.3-flock.patch 
	cyrus-imapd-2.1.9-fdatasync.patch 
	cyrus-imapd-2.2.10-groupcache.patch 
	cyrus-imapd-2.2.10-rmquota+deletemailbox-0.1.diff 
	cyrus-imapd-2.2.12-autocreate-0.9.2.diff 
	cyrus-imapd-2.2.12-autosievefolder-0.6.diff 
	cyrus-imapd-2.2.12.tar.gz.sig 
	cyrus-imapd-2.2.4-OE-seenstate.patch 
	cyrus-imapd-2.2.4-munge8bit.patch cyrus-imapd-README.RPM 
	cyrus-imapd-README.contrib cyrus-imapd-README.groupcache 
	cyrus-imapd-acceptinvalidfrom.patch cyrus-imapd-db.cfg 
	cyrus-imapd-gcc4.patch cyrus-imapd-procmail+cyrus.mc 
	cyrus-imapd-sendmail-8.12.9-cyrusv2.m4 cyrus-imapd.cron-daily 
	cyrus-imapd.cvt_cyrusdb_all cyrus-imapd.imap-2.2.x-conf 
	cyrus-imapd.init cyrus-imapd.logrotate cyrus-imapd.magic 
	cyrus-imapd.pam-config cyrus-imapd.rpm_set_permissions 
	cyrus-imapd.spec cyrus-imapd.sysconfig 
	cyrus-imapd.upd_groupcache cyrus-procmailrc 
	cyrus-user-procmailrc.template cyrus_ldap_quota.pl folderxfer 
	imapcreate.pl inboxfer 
Log Message:
auto-import cyrus-imapd-2.2.12-1.2.fc4 on branch devel from cyrus-imapd-2.2.12-1.2.fc4.src.rpm


--- NEW FILE README.autocreate-cyrus-2.2 ---
Cyrus IMAP autocreate Inbox patch
----------------------------------

NOTE : This patch has been created at the University of Athens. For more info, as well 
as more patches on Cyrus IMAPD server, please visit http://email.uoa.gr 

The design of Cyrus IMAP server does not predict the automatic creation of users'
INBOX folders. The creation of a user's INBOX is considered to be an external task,
that has to be completed as part of the user e-mail account creation procedure. 
Hence, to create a new e-mail account the site administrator has to 
a) Include the new account in the user database for the authentication procedure
   (e.g. sasldb, shadow, mysql, ldap).
b) Create the corresponding INBOX folder. 

Alternatively, the user, if succesfully authenticated, may create his own INBOX folder,
as long as the configuration of the site allows it (see "autocreatequota" in imapd.conf).
Unlike what uncareful readers may think, enabling the "autocreatequota" option, doesn't 
lead to the automatic INBOX folder creation by Cyrus IMAP server.
In fact, "autocreate" means that the IMAP clients are allowed to automatically create 
the user INBOX. 

This patch adds the functionality of automatic creation of the users' INBOX folders into
the Cyrus IMAP server. It is implemented as two features, namely the  "create on login"
and "create on post".
 


Create on login
===============
This feauture provides automatic creation of a user's INBOX folder when all of the 
following requirements are met:

i)  The user has succesfully passed the authentication procedure.

ii) The user's authorization ID (typically the same as the user's
authentication ID)  doesn't belong to the imap_admins or admins
accounts (see imapd.conf).

iii) The "autocreatequota" option in the imap configuration file 
has been set to a non zero value. 

iv) The corresponding to the user's authorizationID INBOX folder
does not exist.

The user's first login is the most typical case when all four requirements are met. 
Note that if the authenticatedID is allowed to proxy to another account for which 
all of the above requirements are met, the corresponding INBOX folder for that account 
will be created.



Create on post
==============
This feauture provides automatic creation of a user's INBOX folder when all of the 
following requirements are met. 

i) An e-mail message addressed to the user has been received.  

ii) The recipient is not any of the imap_admins or admins accounts. 
Note that passing e-mails to admins or imap_admins accounts from 
the MTA to LMTP should be avoided in any case.

iii) The recipient's INBOX does not exist.

iv) The "autocreatequota" option in the imap configuration file 
has been set to a non zero value. 

v) The "createonpost" option in the imap configuration file 
has been switched on. 


Besides the automatic creation of INBOX folder, additional functionalities are
provided:

A) Automatic creation of INBOX subfolders controlled by "autocreateinboxfolders"
configuration option. eg 

autocreateinboxfolders: sent|drafts|spam|templates

B) Automatic subscription of INBOX subfolders controlled by "autosubscribeinboxfolders"
configuration option. eg

autosubscribeinboxfolders: sent|spam

Obviously, only subscription to subfolders included in the "autocreateinboxfolder"
list is meaningfull. 

C) Automatic subscription to shared folders (bulletin boards). The user gets
automatically subscribed to the shared folders declared in the "autosubscribesharedfolders"
configuration option in imapd.conf.
eg autosubscribesharedfolders: public_folder | public_folder.subfolder

In order the above action to succeed, the shared folder has to pre-exist the INBOX creation
and the user must have the apropriate permissions in order to be able to subscribe to the
shared folder.

* A new config option has been added. 'autosubscribe_all_sharedfolders' is a yes/no
option. When set to yes, the user is automatically subscribed to all shared folders one 
has permission to subscribe to. Please, note that when this option is set to yes, then
'autosubscribesharedfolders' option is overriden.

D) Automatic creation of a predefined default sieve script.

This is very useful when a default sieve script is used for every user. Usually, a
default anti-spam script may me be written in a file and copied to each user
sieve scripts upon the INBOX creation. The imapd.conf options that have been added
are 'autocreate_sieve_script', 'autocreate_sieve_compiledscript' and 
'generate_compiled_sieve_script'. 

autocreate_sieve_script configuration option refers to the full path of the file 
that contains the sieve script. The default value is null and if no file is defined,
then no default script is created upon INBOX creation. (The feature is disabled)
eg autocreate_sieve_script: /etc/default_sieve_script

autocreate_sieve_compiledscript configuration option refers to the full path of the
file that contains the bytecode compiled sieve script. If this filename is defined
in imapd.conf and the file exists, then it is automatically copied in the user's sieve
directory. If it is not defined, then a bytecode sieve script gets on the fly compiled
by the daemon. 
eg autocreate_sieve_compiledscript: /etc/default_sieve_script.bc

generate_compiled_sieve_script is a boolean option that triggers the compilation of the 
source sieve script to bytecode sieve script. The file that the bytecode script will
be saved is pointed by autocreate_sieve_compiledscript.

Ways of compiling a sieve script : 
1. Compile a sieve script using the standard sievec utility, distributed by CMU
2. Compile a sieve script using the compile_sieve utility, released by UoA. This 
   tool is almost identical to the sievec utility, with the difference that it 
   reads the input and output file from autocreate_sieve_script and 
   autocreate_sieve_compiledscript options in imapd.conf
3. Let cyrus create a compiled sieve script using a source script. Cyrus can be
   instructed to save the compiled script any time a compiled script does not exist.

NOTES : 
1. In order this functionality to work, the following requirements must have been met:
   - 'sieveusehomedir' option must be 'no' in the configuration (default).
   - 'sievedir' option must have a valid value.
2. Currently, this patch checks the validity of the source script while generating a 
   bytecode compiled script, but not the validity of the bytecode sieve script file.
   The administrator should make sure that the provided files contain a valid sieve
   script as well as the compiled script is updated every time the source script changes.



Issues to be considered 
=======================

I) In order to use the create on post feauture one should be absolutely sure that: 
a) The MTA checks the validity of the e-mail recipient before sending the e-mail to
LMTP. This is an RFC821 requirement. This usually expands to "the mta should be 
able to use the account database as user mailbox database". 
b) Only authorized accounts/services can talk to LMTP.

II) Especially in the case of imap logins, the current patch implementation checks
for the INBOX folder existence upon login, causing an extra mailbox lookup in most 
of the cases. 
A better approach would be to chase the "IMAP_MAILBOX_NONEXISTENT" error code and
check if the error is associated with an INBOX folder. However, this would mess up
Cyrus code. The way it was implemented may not have been the most performance
optimized, but it produces a much cleaner and simple patch.



Virtual Domains Support
=======================

Virtual domains are supported by all versions of the patch for cyrus-imapd-2.2.1-BETA and 
later. However, it is not possible to declare different INBOX subfolders to be created or 
shared folders to be subscribed to for every domain.



Things to be done
=================

1. Support MURDER architecture. 


For more information and updates please visit http://email.uoa.gr/autocreate



--- NEW FILE README.autosievefolder ---
Cyrus IMAP autosievefolder patch
----------------------------------

NOTE : This patch has been created at the University of Athens. For more info, as well 
as more patches on Cyrus IMAPD server, please visit http://email.uoa.gr 


  When the lmtpd daemon receives an email message prior to delivering it to the 
INBOX folder of the user, checks if the user has specified sieve filters. If the
user has specified sieve filters the filters are evaluated. If the message matches
any of the filters the action that is specified in the filter is executed. If the action 
is FileInto it is stored in the subfolder specified in the filter. If the 
subfolder doesn't exist then the message is sent to the INBOX folder of the user.

  With this patch if the folder doesn't exist AND the name of the subfolder is 
specified in the autosievefolders option, OR the anysievefolder is set to 
yes in the cyrus-imap configuration file then the subfolder is created and the mail 
is stored there.


Check the following options of the imapd.conf file
==================================================

* anysievefolder : It must be "yes" in order to permit the autocreation of any 
INBOX subfolder requested by a sieve filter, through the "fileinto" action. (default = no)
* autosievefolders : It is a "|" separated list of subfolders of INBOX that will be 
automatically created, if requested by a sieve filter, through the "fileinto" 
action. (default = null)
	i.e. autosievefolders: Junk | Spam

WARNING: anysievefolder, takes precedence over autosievefolders . Which means that if 
anysievefolder is set to "yes", cyrus will create any INBOX subfolder requested, no-matter what the value of autosievefolders is.


Things to be done
=================

1. Support cyrus wildcards in the autosievefolders option. 


For more information and updates please visit http://email.uoa.gr/projects/cyrus/autosievefolder



--- NEW FILE batchreconstruct ---
#!/usr/bin/perl
#
# Usage:	batchreconstruct inputfile
#
# Purpose:	Runs the Cyrus reconstruct command on each newly-created 
#		Cyrus mailbox created by folderxfer
#
# Input:	List of usernames, one per line
#
#$Id: batchreconstruct,v 1.1 2004/02/04 12:59:42 karsten Exp $

#$whoami     = "/usr/ucb/whoami"; # Solaris
$whoami      = "/usr/bin/whoami";
$reconstruct = "/usr/lib/cyrus-imapd/reconstruct";
$cmd         = "$reconstruct -r";

chop ($iam = `$whoami`);
if ($iam ne "cyrus" ) { 
    die "You must be cyrus to run this script!\n"; 
}

$users   = "$ARGV[0]";
if (!$users) { die "Usage: $0 input_file\n"; }

open(MB,"$users") || die "can't open $users";

while (<MB>) {
    chop;
    system("$cmd user.$_");
}
close MB;



--- NEW FILE bsd2cyrus ---
#!/usr/bin/perl
    eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
        if $running_under_some_shell;
#
# Usage:	bsd2cyrus inputfile
#
# Purpose:	Maps a user's Berkeley-format mail folder names into the
#		Cyrus namespace
#
# Input:	List of usernames, one per line
#
# Output:	Lines of the format
#		username:Cyrus-mailbox-name:BSD-mailbox-name
#
#$Id: bsd2cyrus,v 1.1 2004/02/04 12:59:42 karsten Exp $

require "find.pl";

# User's subdirectory where personal mail folders are stored 
# (typically $HOME/mail)
$maildir = "mail";

$inputfile  = "$ARGV[0]";
if (! $inputfile) { die "Usage: $0 inputfile\n"; }

open (DATA, $inputfile) || die "can't open $inputfile";
while (<DATA>) {
    chop;
    ($user,$pw,$uid,$gid,$quota,$cmnt,$gcos,$home) = getpwnam $_;
    next if $home eq "";
    &find("$home/$maildir");
}
close DATA;

foreach (@folders) {

    ($user,$folder) = split(/:/,$_,2);
    if (! rfc822($folder) ) { next; }
    @tokens = split(/\//, $folder);
    $mailbox = $tokens[$#tokens]; 

    # Sanity checks - earlier tests should have caught these.

    next if ($mailbox =~ /\.gz$/);      # Skip gzipped files
    next if ($mailbox =~ /\.Z$/);       # Skip compressed files
    next if ($mailbox =~ /^\./);        # Skip hidden files

    # Replace "bad" characters with an underscore followed by 
    # the ASCII representation of the "bad" character.

    $mailbox = rm_badchars($mailbox);
    print "$user:user.$user.$mailbox:$folder\n";
}

sub wanted {
    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -f _;
    if ($_ ne '.') { push @folders, "$user:$dir/$_"; }
}

sub rfc822 {

    my ($file) = @_;
    my ($rc) = 1;
    if (-d $file || -z $file || -B $file || -x $file) {
        $rc = 0;
    }
    return $rc;
}

sub rm_badchars {

    my ($mailbox) = @_;
    $mailbox =~ s/ /_040/g;
    $mailbox =~ s/\!/_041/g;
    $mailbox =~ s/\"/_042/g;
    $mailbox =~ s/\#/_043/g;

    return $mailbox;
}



--- NEW FILE cpmsg ---
#!/usr/bin/perl
#
# Usage:	cat mailbox.txt | formail -s cpmsg 
#
#		where 'cpmsg' is the name of this script
#
# Purpose:	Called by formail once for each mail message in a Berkeley-
#		format mailbox
#
#$Id: cpmsg,v 1.1 2004/02/04 12:59:42 karsten Exp $

$maildir  = "$ARGV[0]";
if (!$maildir) { die "Usage: $0 $maildir"; }

# Formail increments this number for each message. The 
# leading "0"'s must be removed (e.g. 001 becomes 1)

$filenum  = ($ENV{FILENO} - 0) + 1;

open (OUTFILE,">$maildir/$filenum.");
while (<STDIN>) {
    chop;
    print OUTFILE "$_\015\012";  # Add CRLF to each line!
}
close OUTFILE;



--- NEW FILE cyrus-deliver-wrapper.c ---
/*
 * Wrapper for cyrus 'deliver' to allow anyone to run it -
 * I hope this is secure!  Should be setgid mail.
 */

#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
#include <sysexits.h>

#ifndef LIBEXECDIR
#define LIBEXECDIR "/usr/lib/cyrus-imapd"
#endif

int main(int argc, char *argv[])
{
    char *const envp[] = { NULL };
    struct passwd *ent = getpwuid(getuid());
    const char *uname = (ent && ent->pw_name && ent->pw_name[0])
                              ? ent->pw_name : "anonymous";
    
    if (argc != 2) {
        fprintf(stderr, "Usage: %s mailbox\n", argv[0]);
        return EX_USAGE; 
    }
    
    execle(LIBEXECDIR"/deliver", "deliver", "-e",
           "-a", uname, "-m", argv[1],
           NULL, envp);

    perror("exec "LIBEXECDIR"/deliver");           
    return EX_OSERR; 
}

cyrus-imapd-2.1.15-nobarenewlinescheck.patch:

--- NEW FILE cyrus-imapd-2.1.15-nobarenewlinescheck.patch ---
--- cyrus-imapd-2.1.15/imap/message.c.orig	2003-11-11 15:45:11.000000000 +0100
+++ cyrus-imapd-2.1.15/imap/message.c	2003-11-11 15:35:11.000000000 +0100
@@ -246,7 +246,8 @@
 
 	for (p = (unsigned char *)buf; *p; p++) {
 	    if (*p == '\n') {
-		if (!sawcr) r = IMAP_MESSAGE_CONTAINSNL;
+		/* Do *NOT* check for RFC compliant line breaks (bare newlines) */
+		/* if (!sawcr) r = IMAP_MESSAGE_CONTAINSNL; */
 		sawcr = 0;
 		if (blankline) {
 		    inheader = 0;

cyrus-imapd-2.1.16-getrlimit.patch:

--- NEW FILE cyrus-imapd-2.1.16-getrlimit.patch ---
--- cyrus-imapd-2.1.16/master/master.c.getrlimit	2003-12-28 17:32:46.000000000 +0100
+++ cyrus-imapd-2.1.16/master/master.c	2003-12-28 17:43:56.000000000 +0100
@@ -1208,12 +1208,10 @@
     rl.rlim_cur = x;
     rl.rlim_max = x;
     if (setrlimit(RLIMIT_NUMFDS, &rl) < 0) {
-	syslog(LOG_ERR, "setrlimit: Unable to set file descriptors limit to %ld: %m", x);
 
 #ifdef HAVE_GETRLIMIT
 
 	if (!getrlimit(RLIMIT_NUMFDS, &rl)) {
-	    syslog(LOG_ERR, "retrying with %ld (current max)", rl.rlim_max);
 	    rl.rlim_cur = rl.rlim_max;
 	    if (setrlimit(RLIMIT_NUMFDS, &rl) < 0) {
 		syslog(LOG_ERR, "setrlimit: Unable to set file descriptors limit to %ld: %m", x);
@@ -1228,6 +1226,7 @@
 	       rl.rlim_max);
     }
 #else
+	syslog(LOG_ERR, "setrlimit: Unable to set file descriptors limit to %ld: %m", x);
     }
 #endif /* HAVE_GETRLIMIT */
 }

cyrus-imapd-2.1.3-flock.patch:

--- NEW FILE cyrus-imapd-2.1.3-flock.patch ---
--- cyrus-imapd-2.1.3/lib/lock_flock.c	Tue Oct  2 16:08:13 2001
+++ cyrus-imapd-2.1.3-patched/lib/lock_flock.c	Tue Apr 16 09:44:58 2002
@@ -51,6 +51,10 @@
 #endif
 
 #include "lock.h"
+#include <syslog.h>
+
+/* Locking timeout parameter */
+#define MAXTIME 99
 
 const char *lock_method_desc = "flock";
 
@@ -69,6 +73,18 @@
  * 'failaction' is provided, it is filled in with a pointer to a fixed
  * string naming the action that failed.
  *
+ *  Modified by jwade 4/16/2002 to work around seen file locking problem
+ *  Added locking timeout parameter to allow processes that are  
+ *  waiting for a lock to eventually time out
+ *
+ *  Calls flock() in non-blocking fashion and then retries until a 
+ *  maximum delay is reached or the lock succeeds.
+ *  
+ *  As written, uses a quadratic backoff on retries with MAXTIME being
+ *  the longest interval delay.   Total delay time is the sum of the squares
+ *  of all integers whose square is less than MAXTIME.  In the case of 
+ *  MAXTIME = 99 this is 0+1+4+9+16+25+36+49+64+81= 285 Seconds   
+ *  This time is arbitrary and can be adjusted
  */
 int lock_reopen(fd, filename, sbuf, failaction)
 int fd;
@@ -79,17 +95,29 @@
     int r;
     struct stat sbuffile, sbufspare;
     int newfd;
+    int delay=0, i=0;
 
     if (!sbuf) sbuf = &sbufspare;
 
-    for (;;) {
-	r = flock(fd, LOCK_EX);
+    for(i=0,delay=0;;) {
+	r = flock(fd, LOCK_EX|LOCK_NB);
 	if (r == -1) {
-	    if (errno == EINTR) continue;
-	    if (failaction) *failaction = "locking";
+	    if (errno == EINTR) {
+                 continue;
+            }
+            else if ((errno == EWOULDBLOCK) && (delay < MAXTIME)) {
+                syslog(LOG_DEBUG, "lock: reopen-blocked sleeping for %d on interval %d (%d, %s)" , delay, i, fd, filename);
+                sleep(delay);
+                i++;
+                delay = i*i;
+                continue;
+            }
+	    if (failaction) {
+                if (delay >= MAXTIME) *failaction = "locking_timeout";
+                else *failaction = "locking";
+            }
 	    return -1;
 	}
-
 	fstat(fd, sbuf);
 	r = stat(filename, &sbuffile);
 	if (r == -1) {
@@ -97,9 +125,7 @@
 	    flock(fd, LOCK_UN);
 	    return -1;
 	}
-
 	if (sbuf->st_ino == sbuffile.st_ino) return 0;
-
 	newfd = open(filename, O_RDWR);
 	if (newfd == -1) {
 	    if (failaction) *failaction = "opening";

cyrus-imapd-2.1.9-fdatasync.patch:

--- NEW FILE cyrus-imapd-2.1.9-fdatasync.patch ---
--- lib/cyrusdb_skiplist.c.orig	Tue Apr 23 20:25:48 2002
+++ lib/cyrusdb_skiplist.c	Wed May  8 13:49:23 2002
@@ -69,6 +69,11 @@
 
 #define PROB (0.5)
 
+#ifdef __FreeBSD__
+/* #define fdatasync(fd) fsync(fd) */
+#define O_DSYNC 0
+#endif
+
 /* 
  *
  * disk format; all numbers in network byte order

cyrus-imapd-2.2.10-groupcache.patch:

--- NEW FILE cyrus-imapd-2.2.10-groupcache.patch ---
diff -Naur cyrus-imapd-2.2.10.orig/lib/auth_unix.c cyrus-imapd-2.2.10/lib/auth_unix.c
--- cyrus-imapd-2.2.10.orig/lib/auth_unix.c	Tue Sep 14 00:49:29 2004
+++ cyrus-imapd-2.2.10/lib/auth_unix.c	Thu Dec 16 08:36:32 2004
@@ -48,6 +48,7 @@
 #include <stdlib.h>
 #include <pwd.h>
 #include <grp.h>
+#include <stdio.h>
 #include <ctype.h>
 #include <string.h>
 
@@ -226,6 +227,10 @@
     struct passwd *pwd;
     struct group *grp;
     char **mem;
+    FILE *groupcache;
+    char fnamebuf[1024];
+    const char *config_dir =
+        libcyrus_config_getstring(CYRUSOPT_CONFIG_DIR);
 
     identifier = auth_canonifyid(identifier, 0);
     if (!identifier) return 0;
@@ -242,8 +247,11 @@
 
     pwd = getpwnam(identifier);
 	
+    strcpy(fnamebuf, config_dir);
+    strcat(fnamebuf, "/group.cache");
+    groupcache = fopen(fnamebuf, "r");
     setgrent();
-    while ((grp = getgrent())) {
+    while (grp = ( (groupcache) ? fgetgrent(groupcache) : getgrent() )) {
 	for (mem = grp->gr_mem; *mem; mem++) {
 	    if (!strcmp(*mem, identifier)) break;
 	}
@@ -256,6 +264,7 @@
 	}
     }
     endgrent();
+    if (groupcache) fclose(groupcache);
     return newstate;
 }
 

cyrus-imapd-2.2.10-rmquota+deletemailbox-0.1.diff:

--- NEW FILE cyrus-imapd-2.2.10-rmquota+deletemailbox-0.1.diff ---
diff -Naur cyrus-imapd-2.2.10/imap/ctl_cyrusdb.c cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/ctl_cyrusdb.c
--- cyrus-imapd-2.2.10/imap/ctl_cyrusdb.c	2004-07-13 05:34:20.000000000 +0300
+++ cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/ctl_cyrusdb.c	2004-11-24 13:30:54.000000000 +0200
@@ -136,7 +136,7 @@
     /* if it is MBTYPE_RESERVED, unset it & call mboxlist_delete */
     if(!r && (mbtype & MBTYPE_RESERVE)) {
 	if(!r) {
-	    r = mboxlist_deletemailbox(name, 1, NULL, NULL, 0, 0, 1);
+	    r = mboxlist_deletemailbox(name, 1, NULL, NULL, 0, 0, 1, 1);
 	    if(r) {
 		/* log the error */
 		syslog(LOG_ERR,
diff -Naur cyrus-imapd-2.2.10/imap/ctl_mboxlist.c cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/ctl_mboxlist.c
--- cyrus-imapd-2.2.10/imap/ctl_mboxlist.c	2004-05-22 06:45:48.000000000 +0300
+++ cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/ctl_mboxlist.c	2004-11-24 13:30:54.000000000 +0200
@@ -456,7 +456,7 @@
 	    
 	    wipe_head = wipe_head->next;
 	    
-	    ret = mboxlist_deletemailbox(me->mailbox, 1, "", NULL, 0, 1, 1);
+	    ret = mboxlist_deletemailbox(me->mailbox, 1, "", NULL, 0, 1, 1, 1);
 	    if(ret) {
 		fprintf(stderr, "couldn't delete defunct mailbox %s\n",
 			me->mailbox);
diff -Naur cyrus-imapd-2.2.10/imap/imapd.c cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/imapd.c
--- cyrus-imapd-2.2.10/imap/imapd.c	2004-11-18 00:29:03.000000000 +0200
+++ cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/imapd.c	2004-11-24 13:30:54.000000000 +0200
@@ -3725,7 +3725,7 @@
 
     r = mboxlist_deletemailbox(name, imapd_userisadmin,
 			       imapd_userid, imapd_authstate,
-			       0, 0, 0);
+			       0, 0, 0, 1);
     
     if(r) {
 	prot_printf(imapd_out, "* NO delete %s: %s\r\n",
@@ -3744,6 +3744,12 @@
     char mailboxname[MAX_MAILBOX_NAME+1];
     char *p;
     int domainlen = 0;
+    int keepQuota = 1;
+
+    if(name && *name == '+') {
+        keepQuota = 0;
+        name++;
+    }
 
     r = (*imapd_namespace.mboxname_tointernal)(&imapd_namespace, name,
 					       imapd_userid, mailboxname);
@@ -3754,7 +3760,7 @@
 
 	r = mboxlist_deletemailbox(mailboxname, imapd_userisadmin,
 				   imapd_userid, imapd_authstate, 1,
-				   localonly, 0);
+				   localonly, 0, keepQuota);
     }
 
     /* was it a top-level user mailbox? */
@@ -4715,6 +4721,7 @@
 {
     int newquota = -1;
     int badresource = 0;
+    int rmquota = 0;
     int c;
     int force = 0;
     static struct buf arg;
@@ -4729,7 +4736,8 @@
     if (c != ')' || arg.s[0] != '\0') {
 	for (;;) {
 	    if (c != ' ') goto badlist;
-	    if (strcasecmp(arg.s, "storage") != 0) badresource = 1;
+	    if (strcasecmp(arg.s, "remove") == 0) rmquota = 1;
+	    else if (strcasecmp(arg.s, "storage") != 0) badresource = 1;
 	    c = getword(imapd_in, &arg);
 	    if (c != ' ' && c != ')') goto badlist;
 	    if (arg.s[0] == '\0') goto badlist;
@@ -4766,7 +4774,10 @@
 						   imapd_userid, mailboxname);
 
 	if (!r) {
-	    r = mboxlist_setquota(mailboxname, newquota, force);
+            if(!rmquota)
+                r = mboxlist_setquota(mailboxname, newquota, force);
+            else
+                r = mboxlist_unsetquota(mailboxname);
 	}
     }
 
@@ -6413,7 +6424,7 @@
 	/* note also that we need to remember to let proxyadmins do this */
 	r = mboxlist_deletemailbox(mailboxname,
 				   imapd_userisadmin || imapd_userisproxyadmin,
-				   imapd_userid, imapd_authstate, 0, 1, 0);
+				   imapd_userid, imapd_authstate, 0, 1, 0, 1);
 	if(r) syslog(LOG_ERR,
 		     "Could not delete local mailbox during move of %s",
 		     mailboxname);
diff -Naur cyrus-imapd-2.2.10/imap/mailbox.c cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mailbox.c
--- cyrus-imapd-2.2.10/imap/mailbox.c	2004-05-22 06:45:51.000000000 +0300
+++ cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mailbox.c	2004-11-24 13:30:54.000000000 +0200
@@ -2117,27 +2117,7 @@
 
     seen_delete_mailbox(mailbox);
 
-    if (delete_quota_root && !rquota) {
-	quota_delete(&mailbox->quota, &tid);
-	free(mailbox->quota.root);
-	mailbox->quota.root = NULL;
-    } else if (!rquota) {
-	/* Free any quota being used by this mailbox */
-	if (mailbox->quota.used >= mailbox->quota_mailbox_used) {
-	    mailbox->quota.used -= mailbox->quota_mailbox_used;
-	}
-	else {
-	    mailbox->quota.used = 0;
-	}
-	r = quota_write(&mailbox->quota, &tid);
-	if (r) {
-	    syslog(LOG_ERR,
-		   "LOSTQUOTA: unable to record free of %lu bytes in quota %s",
-		   mailbox->quota_mailbox_used, mailbox->quota.root);
-	}
-	else
-	    quota_commit(&tid);
-    }
+    mailbox_updatequota(mailbox,NULL);
 
     /* remove all files in directory */
     strlcpy(buf, mailbox->path, sizeof(buf));
@@ -2751,3 +2731,49 @@
 	if (*p == '.') *p = '/';
     }
 }
+
+
+/* This function is used to update the quota. Can be used to replace
+ * identical parts of the code, and can be quite handy some times 
+ * The tid is used in order to make possible to make the quota update
+ * being a part of a bigger transaction to the quota db */
+int mailbox_updatequota(struct mailbox *mailbox, struct txn **tid)
+{
+    int r = 0, havetid = 0;
+    struct txn **ltid = NULL;
+
+    if(tid) {
+        ltid = tid;
+        havetid = 1;
+    }
+    /* Ensure that we are locked */
+    if(!mailbox->header_lock_count) return IMAP_INTERNAL;
+
+
+    if(mailbox->quota.root) {
+        r = quota_read(&mailbox->quota, ltid, 1);
+        if( r == 0 ) {
+            if (mailbox->quota.used >= mailbox->quota_mailbox_used) {
+                mailbox->quota.used -= mailbox->quota_mailbox_used;
+            }
+            else {
+                mailbox->quota.used = 0;
+            }
+            r = quota_write(&mailbox->quota, ltid);
+            if (r) {
+                syslog(LOG_ERR,
+                   "LOSTQUOTA: unable to record free of %lu bytes in quota %s",
+                   mailbox->quota_mailbox_used, mailbox->quota.root);
+            }
+            else if(!havetid)
+                quota_commit(&tid);
+        }
+        /* It is not a big mistake not to have quota .. just remove from the mailbox */
+        else if ( r == IMAP_QUOTAROOT_NONEXISTENT) {
+                free(mailbox->quota.root);
+                r = 0;
+        }
+    }
+    return r;
+}
+
diff -Naur cyrus-imapd-2.2.10/imap/mailbox.h cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mailbox.h
--- cyrus-imapd-2.2.10/imap/mailbox.h	2004-01-22 23:17:09.000000000 +0200
+++ cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mailbox.h	2004-11-24 13:30:54.000000000 +0200
@@ -305,6 +305,8 @@
 			  struct mailbox *mailboxp);
 extern int mailbox_delete(struct mailbox *mailbox, int delete_quota_root);
 
+extern int mailbox_updatequota(struct mailbox *mailbox, struct txn **tid);
+
 extern int mailbox_rename_copy(struct mailbox *oldmailbox, 
 			       const char *newname, char *newpath,
 			       bit32 *olduidvalidityp, bit32 *newuidvalidityp,
diff -Naur cyrus-imapd-2.2.10/imap/mboxlist.c cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mboxlist.c
--- cyrus-imapd-2.2.10/imap/mboxlist.c	2004-07-26 21:08:03.000000000 +0300
+++ cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mboxlist.c	2004-11-24 13:30:54.000000000 +0200
@@ -93,6 +93,11 @@
 static int mboxlist_opensubs();
 static void mboxlist_closesubs();
 
+static int child_cb(char *name,
+                    int matchlen __attribute__((unused)),
+                    int maycreate __attribute__((unused)),
+                    void *rock);
+
 static int mboxlist_rmquota(const char *name, int matchlen, int maycreate,
 			    void *rock);
 static int mboxlist_changequota(const char *name, int matchlen, int maycreate,
@@ -100,6 +105,7 @@
 
 struct change_rock {
     struct quota *quota;
+    struct quota *oldquota;
     struct txn **tid;
 };
 
@@ -893,9 +899,9 @@
  */
 int mboxlist_deletemailbox(const char *name, int isadmin, char *userid, 
 			   struct auth_state *auth_state, int checkacl,
-			   int local_only, int force)
+			   int local_only, int force, int keepQuota)
 {
-    int r;
+    int r, has_children = 0;
     char *acl;
     long access;
     struct mailbox mailbox;
@@ -907,6 +913,7 @@
     int deleteright = get_deleteright();
     const char *p;
     mupdate_handle *mupdate_h = NULL;
+    char *quotaroot = NULL;
 
     if(!isadmin && force) return IMAP_PERMISSION_DENIED;
 
@@ -1018,13 +1025,44 @@
 
     if ((r && !force) || isremote) goto done;
 
-    if (!r || force) r = mailbox_delete(&mailbox, deletequotaroot);
+    if (!r || force) {
+        /* first we have to keep the previous quota root in order to delete it */
+        if(mailbox.quota.root)
+                quotaroot = xstrdup(mailbox.quota.root);
+	r = mailbox_delete(&mailbox, deletequotaroot);
+    }
 
     /*
      * See if we have to remove mailbox's quota root
      */
-    if (!r && mailbox.quota.root != NULL) {
+    if (!r && quotaroot != NULL) {
 	/* xxx look for any other mailboxes in this quotaroot */
+        /* If we have not asked to remove the quota (default behaviour), we check 
+         * whether there are any subfolders beneeth the quota root. If there aren't
+         * any subfolders the reasonable thing is to delete the quota */
+        if(keepQuota) {
+            char pattern[MAX_MAILBOX_PATH+1];
+            strlcpy(pattern, quotaroot, sizeof(pattern));
+            if (config_virtdomains && name[strlen(name)-1] == '!') {
+                strlcat(pattern, "*", sizeof(pattern));
+            }
+            else {
+                strlcat(pattern, ".*", sizeof(pattern));
+            }
+		/* find if there are subfolders. Then we want to 
+		 * keep the existing quota */
+            mboxlist_findall(NULL, pattern, isadmin, userid,
+                    auth_state, child_cb, (void *) &has_children);
+
+	    if(!has_children)
+                if(!mboxlist_mylookup(quotaroot, NULL, NULL, NULL, NULL, NULL, 0 ))
+		    has_children = 1;
+        }
+        /* If we want to remove the quota explicitely or the quota root folder has no subfolders
+         * we execute the rmquota patch */
+        if(!keepQuota || !has_children )
+            mboxlist_unsetquota(quotaroot);
+        free(quotaroot);
     }
 
  done:
@@ -2357,6 +2395,7 @@
     if (r) return r;
 
     crock.quota = "a;
+    crock.oldquota = NULL;
     crock.tid = &tid;
     /* top level mailbox */
     if(have_mailbox)
@@ -2375,17 +2414,21 @@
  */
 int mboxlist_unsetquota(const char *root)
 {
+    char newquota[MAX_MAILBOX_PATH+1];
     char pattern[MAX_MAILBOX_PATH+1];
     struct quota quota;
-    int r=0;
+    struct change_rock crock;
+    int r=0, k=0;
 
     if (!root[0] || root[0] == '.' || strchr(root, '/')
 	|| strchr(root, '*') || strchr(root, '%') || strchr(root, '?')) {
 	return IMAP_MAILBOX_BADNAME;
     }
+	
+    crock.tid=NULL;
     
     quota.root = (char *) root;
-    r = quota_read(&quota, NULL, 0);
+    r = quota_read(&quota, crock.tid, 0);
     if (r == IMAP_QUOTAROOT_NONEXISTENT) {
 	/* already unset */
 	return 0;
@@ -2402,13 +2445,45 @@
     }
     else
 	strlcat(pattern, ".*", sizeof(pattern));
-    
-    /* top level mailbox */
-    mboxlist_rmquota(root, 0, 0, (void *)root);
-    /* submailboxes - we're using internal names here */
-    mboxlist_findall(NULL, pattern, 1, 0, 0, mboxlist_rmquota, (void *)root);
 
-    r = quota_delete(&quota, NULL);
+    r = quota_delete(&quota, crock.tid);
+
+    /* If we cannot delete the quota then abort the operation */
+    if(!r) {
+       /* quota_findroot performs several checks that we can
+        * assume that are already done, and don't have to perform
+        * them again. One of them is that it returns 1 only if
+        * quotaroot exists.
+        */
+        if(quota_findroot(newquota, sizeof(newquota), root)) {
+            struct quota rootquota;
+            rootquota.root = newquota;
+            k = quota_read(&rootquota, crock.tid, 0);
+            if (!k) {
+                crock.quota = &rootquota;
+                crock.oldquota = "a;
+                /* top level mailbox */
+                k = mboxlist_changequota(root, 0, 0, &crock);
+            }
+            /* submailboxes - we're using internal names here */
+            if (!k)
+                k = mboxlist_findall(NULL, pattern, 1, 0, 0, mboxlist_changequota, &crock);
+            if(!k)
+                k = quota_write(&rootquota, crock.tid);
+
+         }
+         else {
+           /* top level mailbox */
+           mboxlist_rmquota(root, 0, 0, (void *)root);
+           /* submailboxes - we're using internal names here */
+           mboxlist_findall(NULL, pattern, 1, 0, 0, mboxlist_rmquota, (void *)root);
+       }
+    }
+
+    if(!r && !k)
+        quota_commit(crock.tid);
+    else
+        quota_abort(crock.tid);
 
     return r;
 }
@@ -2506,6 +2581,7 @@
     struct mailbox mailbox;
     struct change_rock *crock = (struct change_rock *) rock;
     struct quota *mboxlist_newquota = crock->quota;
+    struct quota *mboxlist_oldquota = crock->oldquota;
     struct txn **tid = crock->tid;
 
     assert(rock != NULL);
@@ -2523,27 +2599,24 @@
     if (r) goto error;
 
     if (mailbox.quota.root) {
-	if (strlen(mailbox.quota.root) >= strlen(mboxlist_newquota->root)) {
-	    /* Part of a child quota root */
-	    mailbox_close(&mailbox);
-	    return 0;
-	}
-
-	r = quota_read(&mailbox.quota, tid, 1);
-	if (r) goto error;
-	if (mailbox.quota.used >= mailbox.quota_mailbox_used) {
-	    mailbox.quota.used -= mailbox.quota_mailbox_used;
-	}
-	else {
-	    mailbox.quota.used = 0;
-	}
-	r = quota_write(&mailbox.quota, tid);
-	if (r) {
-	    syslog(LOG_ERR,
-		   "LOSTQUOTA: unable to record free of %lu bytes in quota %s",
-		   mailbox.quota_mailbox_used, mailbox.quota.root);
-	}
-	free(mailbox.quota.root);
+        if(mboxlist_oldquota) {
+            if (strlen(mailbox.quota.root) > strlen(mboxlist_oldquota->root)) {
+                /* Part of a child quota root */
+                mailbox_close(&mailbox);
+                return 0;
+            }
+        }
+        else {
+            if (strlen(mailbox.quota.root) >= strlen(mboxlist_newquota->root)) {
+                /* Part of a child quota root */
+                mailbox_close(&mailbox);
+                return 0;
+            }
+        }
+
+        r = mailbox_updatequota(&mailbox,tid);
+        if (r)
+            goto error;
     }
 
     mailbox.quota.root = xstrdup(mboxlist_newquota->root);
@@ -2553,18 +2626,24 @@
     mboxlist_newquota->used += mailbox.quota_mailbox_used;
     mailbox_close(&mailbox);
     return 0;
-
+ 
  error:
     mailbox_close(&mailbox);
+    syslog(LOG_ERR, "LOSTQUOTA: unable to change quota root for %s to %s: %s. \
+                        Command aborted. Run reconstruct to make sure mailboxes \
+                         are in consistent state",
+           name, mboxlist_newquota->root, error_message(r));
+    return 1;
  error_noclose:
     syslog(LOG_ERR, "LOSTQUOTA: unable to change quota root for %s to %s: %s",
-	   name, mboxlist_newquota->root, error_message(r));
+           name, mboxlist_newquota->root, error_message(r));
 
     /* Note, we're a callback, and it's not a huge tragedy if we
      * fail, so we don't ever return a failure */
     return 0;
 }
 
+
 /* must be called after cyrus_init */
 void mboxlist_init(int myflags)
 {
diff -Naur cyrus-imapd-2.2.10/imap/mboxlist.h cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mboxlist.h
--- cyrus-imapd-2.2.10/imap/mboxlist.h	2004-03-17 20:07:49.000000000 +0200
+++ cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mboxlist.h	2004-11-24 13:30:54.000000000 +0200
@@ -122,7 +122,7 @@
  * the planet */
 int mboxlist_deletemailbox(const char *name, int isadmin, char *userid, 
 			   struct auth_state *auth_state, int checkacl,
-			   int local_only, int force);
+			   int local_only, int force, int keepQuota);
 
 /* Rename/move a mailbox (hierarchical) */
 int mboxlist_renamemailbox(char *oldname, char *newname, char *partition, 
diff -Naur cyrus-imapd-2.2.10/imap/mupdate.c cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mupdate.c
--- cyrus-imapd-2.2.10/imap/mupdate.c	2004-05-29 08:18:21.000000000 +0300
+++ cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/mupdate.c	2004-11-24 13:30:54.000000000 +0200
@@ -2191,7 +2191,7 @@
 	    remote_boxes.head = r->next;
 	} else if (ret < 0) {
 	    /* Local without corresponding remote, delete it */
-	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0);
+	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0, 1);
 	    local_boxes.head = l->next;
 	} else /* (ret > 0) */ {
 	    /* Remote without corresponding local, insert it */
@@ -2206,7 +2206,7 @@
     if(l && !r) {
 	/* we have more deletes to do */
 	while(l) {
-	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0);
+	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0, 1);
 	    local_boxes.head = l->next;
 	    l = local_boxes.head;
 	}
diff -Naur cyrus-imapd-2.2.10/imap/nntpd.c cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/nntpd.c
--- cyrus-imapd-2.2.10/imap/nntpd.c	2004-09-09 19:21:26.000000000 +0300
+++ cyrus-imapd-2.2.10.rmquota+deletemailbox.uncompiled/imap/nntpd.c	2004-11-24 13:30:54.000000000 +0200
@@ -3234,7 +3234,7 @@
     /* XXX should we delete right away, or wait until empty? */
 
     r = mboxlist_deletemailbox(mailboxname, 0,
-			       newsmaster, newsmaster_authstate, 1, 0, 0);
+			       newsmaster, newsmaster_authstate, 1, 0, 0, 1);
 
     return r;
 }

cyrus-imapd-2.2.12-autocreate-0.9.2.diff:

--- NEW FILE cyrus-imapd-2.2.12-autocreate-0.9.2.diff ---
diff -Naur cyrus-imapd-2.2.12/README.autocreate cyrus-imapd-2.2.12-autocreate.uncompiled/README.autocreate
--- cyrus-imapd-2.2.12/README.autocreate	1970-01-01 02:00:00 +0200
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/README.autocreate	2005-02-15 13:57:19 +0200
@@ -0,0 +1,181 @@
+Cyrus IMAP autocreate Inbox patch
+----------------------------------
+
+NOTE : This patch has been created at the University of Athens. For more info, as well 
+as more patches on Cyrus IMAPD server, please visit http://email.uoa.gr 
+
+The design of Cyrus IMAP server does not predict the automatic creation of users'
+INBOX folders. The creation of a user's INBOX is considered to be an external task,
+that has to be completed as part of the user e-mail account creation procedure. 
+Hence, to create a new e-mail account the site administrator has to 
+a) Include the new account in the user database for the authentication procedure
+   (e.g. sasldb, shadow, mysql, ldap).
+b) Create the corresponding INBOX folder. 
+
+Alternatively, the user, if succesfully authenticated, may create his own INBOX folder,
+as long as the configuration of the site allows it (see "autocreatequota" in imapd.conf).
+Unlike what uncareful readers may think, enabling the "autocreatequota" option, doesn't 
+lead to the automatic INBOX folder creation by Cyrus IMAP server.
+In fact, "autocreate" means that the IMAP clients are allowed to automatically create 
+the user INBOX. 
+
+This patch adds the functionality of automatic creation of the users' INBOX folders into
+the Cyrus IMAP server. It is implemented as two features, namely the  "create on login"
+and "create on post".
+ 
+
+
+Create on login
+===============
+This feauture provides automatic creation of a user's INBOX folder when all of the 
+following requirements are met:
+
+i)  The user has succesfully passed the authentication procedure.
+
+ii) The user's authorization ID (typically the same as the user's
+authentication ID)  doesn't belong to the imap_admins or admins
+accounts (see imapd.conf).
+
+iii) The "autocreatequota" option in the imap configuration file 
+has been set to a non zero value. 
+
+iv) The corresponding to the user's authorizationID INBOX folder
+does not exist.
+
+The user's first login is the most typical case when all four requirements are met. 
+Note that if the authenticatedID is allowed to proxy to another account for which 
+all of the above requirements are met, the corresponding INBOX folder for that account 
+will be created.
+
+
+
+Create on post
+==============
+This feauture provides automatic creation of a user's INBOX folder when all of the 
+following requirements are met. 
+
+i) An e-mail message addressed to the user has been received.  
+
+ii) The recipient is not any of the imap_admins or admins accounts. 
+Note that passing e-mails to admins or imap_admins accounts from 
+the MTA to LMTP should be avoided in any case.
+
+iii) The recipient's INBOX does not exist.
+
+iv) The "autocreatequota" option in the imap configuration file 
+has been set to a non zero value. 
+
+v) The "createonpost" option in the imap configuration file 
+has been switched on. 
+
+
+Besides the automatic creation of INBOX folder, additional functionalities are
+provided:
+
+A) Automatic creation of INBOX subfolders controlled by "autocreateinboxfolders"
+configuration option. eg 
+
+autocreateinboxfolders: sent|drafts|spam|templates
+
+B) Automatic subscription of INBOX subfolders controlled by "autosubscribeinboxfolders"
+configuration option. eg
+
+autosubscribeinboxfolders: sent|spam
+
+Obviously, only subscription to subfolders included in the "autocreateinboxfolder"
+list is meaningfull. 
+
+C) Automatic subscription to shared folders (bulletin boards). The user gets
+automatically subscribed to the shared folders declared in the "autosubscribesharedfolders"
+configuration option in imapd.conf.
+eg autosubscribesharedfolders: public_folder | public_folder.subfolder
+
+In order the above action to succeed, the shared folder has to pre-exist the INBOX creation
+and the user must have the apropriate permissions in order to be able to subscribe to the
+shared folder.
+
+* A new config option has been added. 'autosubscribe_all_sharedfolders' is a yes/no
+option. When set to yes, the user is automatically subscribed to all shared folders one 
+has permission to subscribe to. Please, note that when this option is set to yes, then
+'autosubscribesharedfolders' option is overriden.
+
+D) Automatic creation of a predefined default sieve script.
+
+This is very useful when a default sieve script is used for every user. Usually, a
+default anti-spam script may me be written in a file and copied to each user
+sieve scripts upon the INBOX creation. The imapd.conf options that have been added
+are 'autocreate_sieve_script', 'autocreate_sieve_compiledscript' and 
+'generate_compiled_sieve_script'. 
+
+autocreate_sieve_script configuration option refers to the full path of the file 
+that contains the sieve script. The default value is null and if no file is defined,
+then no default script is created upon INBOX creation. (The feature is disabled)
+eg autocreate_sieve_script: /etc/default_sieve_script
+
+autocreate_sieve_compiledscript configuration option refers to the full path of the
+file that contains the bytecode compiled sieve script. If this filename is defined
+in imapd.conf and the file exists, then it is automatically copied in the user's sieve
+directory. If it is not defined, then a bytecode sieve script gets on the fly compiled
+by the daemon. 
+eg autocreate_sieve_compiledscript: /etc/default_sieve_script.bc
+
+generate_compiled_sieve_script is a boolean option that triggers the compilation of the 
+source sieve script to bytecode sieve script. The file that the bytecode script will
+be saved is pointed by autocreate_sieve_compiledscript.
+
+Ways of compiling a sieve script : 
+1. Compile a sieve script using the standard sievec utility, distributed by CMU
+2. Compile a sieve script using the compile_sieve utility, released by UoA. This 
+   tool is almost identical to the sievec utility, with the difference that it 
+   reads the input and output file from autocreate_sieve_script and 
+   autocreate_sieve_compiledscript options in imapd.conf
+3. Let cyrus create a compiled sieve script using a source script. Cyrus can be
+   instructed to save the compiled script any time a compiled script does not exist.
+
+NOTES : 
+1. In order this functionality to work, the following requirements must have been met:
+   - 'sieveusehomedir' option must be 'no' in the configuration (default).
+   - 'sievedir' option must have a valid value.
+2. Currently, this patch checks the validity of the source script while generating a 
+   bytecode compiled script, but not the validity of the bytecode sieve script file.
+   The administrator should make sure that the provided files contain a valid sieve
+   script as well as the compiled script is updated every time the source script changes.
+
+
+
+Issues to be considered 
+=======================
+
+I) In order to use the create on post feauture one should be absolutely sure that: 
+a) The MTA checks the validity of the e-mail recipient before sending the e-mail to
+LMTP. This is an RFC821 requirement. This usually expands to "the mta should be 
+able to use the account database as user mailbox database". 
+b) Only authorized accounts/services can talk to LMTP.
+
+II) Especially in the case of imap logins, the current patch implementation checks
+for the INBOX folder existence upon login, causing an extra mailbox lookup in most 
+of the cases. 
+A better approach would be to chase the "IMAP_MAILBOX_NONEXISTENT" error code and
+check if the error is associated with an INBOX folder. However, this would mess up
+Cyrus code. The way it was implemented may not have been the most performance
+optimized, but it produces a much cleaner and simple patch.
+
+
+
+Virtual Domains Support
+=======================
+
+Virtual domains are supported by all versions of the patch for cyrus-imapd-2.2.1-BETA and 
+later. However, it is not possible to declare different INBOX subfolders to be created or 
+shared folders to be subscribed to for every domain.
+
+
+
+Things to be done
+=================
+
+1. Support MURDER architecture. 
+
+
+For more information and updates please visit http://email.uoa.gr/autocreate
+
diff -Naur cyrus-imapd-2.2.12/imap/Makefile.in cyrus-imapd-2.2.12-autocreate.uncompiled/imap/Makefile.in
--- cyrus-imapd-2.2.12/imap/Makefile.in	2004-05-28 21:03:02 +0300
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/imap/Makefile.in	2005-02-15 13:57:19 +0200
@@ -104,7 +104,7 @@
 	convert_code.o duplicate.o saslclient.o saslserver.o signals.o \
 	annotate.o search_engines.o squat.o squat_internal.o mbdump.o \
 	imapparse.o telemetry.o user.o notify.o protocol.o quota_db.o \
-	$(SEEN) $(IDLE)
+	autosieve.o $(SEEN) $(IDLE)
 
 IMAPDOBJS=pushstats.o backend.o imapd.o index.o tls.o version.o
 
@@ -122,7 +122,7 @@
 	fud smmapd reconstruct quota mbpath ipurge \
[...1760 lines suppressed...]
+
+    /*
+     * Exclude admin's accounts
+     */
+
+     authstate = auth_newstate(popd_userid);
+     userisadmin = global_authisa(authstate, IMAPOPT_ADMINS);
+     if (userisadmin)
+          return IMAP_MAILBOX_NONEXISTENT;
+
+     r = mboxlist_autocreateinbox(&popd_namespace, auth_userid,
+                         authstate, inboxname, autocreatequota);
+     return r;
+}
+
+
+/*
  * Complete the login process by opening and locking the user's inbox
  */
 int openinbox(void)
@@ -1349,6 +1392,10 @@
 					      userid, inboxname);
 
     if (!r) r = mboxlist_detail(inboxname, &type, NULL, &server, &acl, NULL);
+    /* Try once again after autocreate_inbox */
+    if (r == IMAP_MAILBOX_NONEXISTENT && !(r = autocreate_inbox(inboxname, userid)))
+        r = mboxlist_detail(inboxname, &type, NULL, &server, &acl, NULL);
+
     if (!r && (config_popuseacl = config_getswitch(IMAPOPT_POPUSEACL)) &&
 	(!acl ||
 	 !((myrights = cyrus_acl_myrights(popd_authstate, acl)) & ACL_READ))) {
diff -Naur cyrus-imapd-2.2.12/lib/auth.h cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth.h
--- cyrus-imapd-2.2.12/lib/auth.h	2003-10-22 21:50:12 +0300
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth.h	2005-02-15 13:57:19 +0200
@@ -60,4 +60,6 @@
 extern struct auth_state *auth_newstate(const char *identifier);
 extern void auth_freestate(struct auth_state *auth_state);
 
+extern char *auth_canonuser(struct auth_state *auth_state);
+
 #endif /* INCLUDED_AUTH_H */
diff -Naur cyrus-imapd-2.2.12/lib/auth_krb.c cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth_krb.c
--- cyrus-imapd-2.2.12/lib/auth_krb.c	2003-11-11 05:26:00 +0200
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth_krb.c	2005-02-15 13:57:19 +0200
@@ -338,3 +338,11 @@
     free((char *)auth_state);
 }
 
+char *
+auth_canonuser(struct auth_state *auth_state)
+{
+    if (auth_state)
+       return auth_state->userid;
+    return NULL;
+}
+
diff -Naur cyrus-imapd-2.2.12/lib/auth_krb5.c cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth_krb5.c
--- cyrus-imapd-2.2.12/lib/auth_krb5.c	2004-01-16 17:28:58 +0200
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth_krb5.c	2005-02-15 13:57:19 +0200
@@ -193,4 +193,11 @@
     free(auth_state);
 }
 
+char *
+auth_canonuser(struct auth_state *auth_state)
+{
+    if (auth_state)
+       return auth_state->userid;
+    return NULL;
+}
 
diff -Naur cyrus-imapd-2.2.12/lib/auth_pts.c cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth_pts.c
--- cyrus-imapd-2.2.12/lib/auth_pts.c	2004-02-25 01:11:37 +0200
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth_pts.c	2005-02-15 13:57:19 +0200
@@ -349,3 +349,11 @@
 {
     free(auth_state);
 }
+
+char *auth_canonuser(struct auth_state *auth_state)
+{
+    if (auth_state)
+       return auth_state->userid.id;
+    return NULL;
+}
+
diff -Naur cyrus-imapd-2.2.12/lib/auth_unix.c cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth_unix.c
--- cyrus-imapd-2.2.12/lib/auth_unix.c	2004-09-14 01:49:29 +0300
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/lib/auth_unix.c	2005-02-15 13:57:19 +0200
@@ -267,4 +267,11 @@
     free((char *)auth_state);
 }
 
+char *auth_canonuser(struct auth_state *auth_state)
+{
+    if (auth_state)
+         return auth_state->userid;
+    
+    return NULL;
+}
 
diff -Naur cyrus-imapd-2.2.12/lib/imapoptions cyrus-imapd-2.2.12-autocreate.uncompiled/lib/imapoptions
--- cyrus-imapd-2.2.12/lib/imapoptions	2004-07-21 22:07:45 +0300
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/lib/imapoptions	2005-02-15 13:57:19 +0200
@@ -169,6 +169,51 @@
 /* Number of seconds to wait before returning a timeout failure when
    performing a client connection (e.g. in a murder enviornment) */
 
+{ "createonpost", 0, SWITCH }
+/* If yes, when lmtpd receives an incoming mail for an INBOX that does not exist,
+   then the INBOX is automatically created by lmtpd. */
+
+{ "autocreateinboxfolders", NULL, STRING }
+/* If a user does not have an INBOX created then the INBOX as well as some INBOX subfolders are
+   created under two conditions.
+     1. The user logins via the IMAP or the POP3 protocol. (autocreatequota option must have a nonzero value)
+     2. A message arrives for the user through the LMTPD protocol.(createonpost option must yes)
+   autocreateinboxfolders is a list of INBOX's subfolders separated by a "|", that are automatically created by the server
+   under the previous two situations. */
+
+{ "autosubscribeinboxfolders", NULL, STRING }
+/* A list of folder names, separated by "|" that the users get automatically subscribed to, when their INBOX
+  is created.
+  These folder names must have been included in the autocreateinboxfolders option of the imapd.conf. */
+
+{ "autosubscribesharedfolders", NULL, STRING }
+/* A list of shared folders (bulletin boards), separated by "|" that the users get
+   automatically subscribed to, after their INBOX
+   is created. The shared folder must have been created and the user must have the
+   required permissions to get subscribed to the it. Otherwise the subscription fails. */
+
+{ "autosubscribe_all_sharedfolders", 0, SWITCH }
+/* If set to yes then the user is automatically subscribed to all shared folders, one has permission
+   to subscribe to. */
+
+{ "autocreate_sieve_script", NULL, STRING }
+/* The full path of a file that contains a sieve script. This script automatically becomes a
+   user's initial default sieve filter script. When this option is not defined, no default 
+   sieve filter is created. The file must be readable by the cyrus daemon. */
+
+{ "autocreate_sieve_compiledscript", NULL, STRING }
+/* The full path of a file that contains a compiled in bytecode sieve script. This script 
+   automatically becomes a user's initial default sieve filter script. 
+   If this option is not specified, or the filename doesn't exist then the script defined 
+   by autocreate_sieve_script is compiled on the fly and installed as the user's default
+   sieve script */
+
+{ "generate_compiled_sieve_script", 0, SWITCH }
+/* If set to yes and no compiled sieve script file exists then the sieve script that is 
+   compiled on the fly will be saved in the file name that autocreate_sieve_compiledscript 
+   option points. In order a compiled script to be generated, autocreate_sieve_script and 
+   autocreate_sieve_compiledscript must have valid values */
+
 { "configdirectory", NULL, STRING }
 /* The pathname of the IMAP configuration directory.  This field is
    required. */
diff -Naur cyrus-imapd-2.2.12/notifyd/Makefile.in cyrus-imapd-2.2.12-autocreate.uncompiled/notifyd/Makefile.in
--- cyrus-imapd-2.2.12/notifyd/Makefile.in	2004-05-28 21:03:06 +0300
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/notifyd/Makefile.in	2005-02-15 13:57:19 +0200
@@ -69,10 +69,11 @@
 SERVICE=../master/service.o
 
 IMAP_LIBS = @IMAP_LIBS@ @LIB_RT@
+SIEVE_LIBS = @SIEVE_LIBS@
 IMAP_COM_ERR_LIBS = @IMAP_COM_ERR_LIBS@
 LIB_WRAP = @LIB_WRAP@
 LIBS = @ZEPHYR_LIBS@ @LIBS@ $(IMAP_COM_ERR_LIBS)
-DEPLIBS=../imap/mutex_fake.o ../imap/libimap.a ../lib/libcyrus.a ../lib/libcyrus_min.a @DEPLIBS@
+DEPLIBS=../imap/mutex_fake.o ../imap/libimap.a $(SIEVE_LIBS) ../lib/libcyrus.a ../lib/libcyrus_min.a @DEPLIBS@
 
 PURIFY=/usr/local/bin/purify
 PUREOPT=-best-effort
diff -Naur cyrus-imapd-2.2.12/notifyd/notifyd.c cyrus-imapd-2.2.12-autocreate.uncompiled/notifyd/notifyd.c
--- cyrus-imapd-2.2.12/notifyd/notifyd.c	2004-12-17 18:32:25 +0200
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/notifyd/notifyd.c	2005-02-15 13:57:19 +0200
@@ -97,7 +97,7 @@
 
 #define NOTIFY_MAXSIZE 8192
 
-int do_notify()
+static int do_notify()
 {
     struct sockaddr_un sun_data;
     socklen_t sunlen = sizeof(sun_data);
diff -Naur cyrus-imapd-2.2.12/ptclient/Makefile.in cyrus-imapd-2.2.12-autocreate.uncompiled/ptclient/Makefile.in
--- cyrus-imapd-2.2.12/ptclient/Makefile.in	2004-05-28 21:03:08 +0300
+++ cyrus-imapd-2.2.12-autocreate.uncompiled/ptclient/Makefile.in	2005-02-15 13:57:19 +0200
@@ -57,10 +57,11 @@
 AFS_LDFLAGS = @AFS_LDFLAGS@ @COM_ERR_LDFLAGS@
 AFS_LIBS = @AFS_LIBS@
 IMAP_LIBS = @IMAP_LIBS@ @LIB_RT@
+SIEVE_LIBS = @SIEVE_LIBS@
 LIBS = $(IMAP_LIBS) @COM_ERR_LIBS@
 LIB_SASL = @LIB_SASL@
 LIB_WRAP = @LIB_WRAP@
-DEPLIBS = ../imap/libimap.a ../lib/libcyrus.a ../lib/libcyrus_min.a @DEPLIBS@
+DEPLIBS = ../imap/libimap.a $(SIEVE_LIBS) ../lib/libcyrus.a ../lib/libcyrus_min.a @DEPLIBS@ 
 UTIL_LIBS = ../imap/mutex_fake.o ../imap/cli_fatal.o
 
 LDAP_LIBS=@LDAP_LIBS@

cyrus-imapd-2.2.12-autosievefolder-0.6.diff:

--- NEW FILE cyrus-imapd-2.2.12-autosievefolder-0.6.diff ---
diff -Naur cyrus-imapd-2.2.12/README.autosievefolder cyrus-imapd-2.2.12-autosieve.uncompiled/README.autosievefolder
--- cyrus-imapd-2.2.12/README.autosievefolder	1970-01-01 02:00:00 +0200
+++ cyrus-imapd-2.2.12-autosieve.uncompiled/README.autosievefolder	2005-02-15 13:59:51 +0200
@@ -0,0 +1,42 @@
+Cyrus IMAP autosievefolder patch
+----------------------------------
+
+NOTE : This patch has been created at the University of Athens. For more info, as well 
+as more patches on Cyrus IMAPD server, please visit http://email.uoa.gr 
+
+
+  When the lmtpd daemon receives an email message prior to delivering it to the 
+INBOX folder of the user, checks if the user has specified sieve filters. If the
+user has specified sieve filters the filters are evaluated. If the message matches
+any of the filters the action that is specified in the filter is executed. If the action 
+is FileInto it is stored in the subfolder specified in the filter. If the 
+subfolder doesn't exist then the message is sent to the INBOX folder of the user.
+
+  With this patch if the folder doesn't exist AND the name of the subfolder is 
+specified in the autosievefolders option, OR the anysievefolder is set to 
+yes in the cyrus-imap configuration file then the subfolder is created and the mail 
+is stored there.
+
+
+Check the following options of the imapd.conf file
+==================================================
+
+* anysievefolder : It must be "yes" in order to permit the autocreation of any 
+INBOX subfolder requested by a sieve filter, through the "fileinto" action. (default = no)
+* autosievefolders : It is a "|" separated list of subfolders of INBOX that will be 
+automatically created, if requested by a sieve filter, through the "fileinto" 
+action. (default = null)
+	i.e. autosievefolders: Junk | Spam
+
+WARNING: anysievefolder, takes precedence over autosievefolders . Which means that if 
+anysievefolder is set to "yes", cyrus will create any INBOX subfolder requested, no-matter what the value of autosievefolders is.
+
+
+Things to be done
+=================
+
+1. Support cyrus wildcards in the autosievefolders option. 
+
+
+For more information and updates please visit http://email.uoa.gr/projects/cyrus/autosievefolder
+
diff -Naur cyrus-imapd-2.2.12/imap/lmtp_sieve.c cyrus-imapd-2.2.12-autosieve.uncompiled/imap/lmtp_sieve.c
--- cyrus-imapd-2.2.12/imap/lmtp_sieve.c	2004-06-01 16:47:16 +0300
+++ cyrus-imapd-2.2.12-autosieve.uncompiled/imap/lmtp_sieve.c	2005-02-15 13:59:51 +0200
@@ -72,6 +72,8 @@
 #include "util.h"
 #include "version.h"
 #include "xmalloc.h"
+#include "imap_err.h"
+
 
 static int sieve_usehomedir = 0;
 static const char *sieve_dir = NULL;
@@ -98,6 +100,9 @@
 			   int quotaoverride,
 			   int acloverride);
 
+static int autosieve_subfolder(char *userid, struct auth_state *auth_state,
+                               char *subfolder, struct namespace *namespace);
+
 static char *make_sieve_db(const char *user)
 {
     static char buf[MAX_MAILBOX_PATH+1];
@@ -312,6 +317,7 @@
 }
 
 
+
 static int sieve_redirect(void *ac, 
 			  void *ic __attribute__((unused)), 
 			  void *sc, void *mc, const char **errmsg)
@@ -444,7 +450,18 @@
 			      sd->username, mdata->notifyheader,
 			      namebuf, quotaoverride, 0);
     }
-
+    if (ret == IMAP_MAILBOX_NONEXISTENT) {
+        /* if "plus" folder under INBOX, then try to create it */
+        syslog(LOG_DEBUG, "calling autosieve folder for : %s", namebuf);
+        ret = autosieve_subfolder((char *) sd->username, sd->authstate, namebuf, mdata->namespace);
+
+        if (!ret)
+            ret = deliver_mailbox(md->data, mdata->stage, md->size,
+                                  fc->imapflags->flag, fc->imapflags->nflags,
+                                  (char *) sd->username, sd->authstate, md->id,
+                                  sd->username, mdata->notifyheader,
+                                  namebuf, quotaoverride, 0);
+    }
     if (!ret) {
 	snmp_increment(SIEVE_FILEINTO, 1);
 	return SIEVE_OK;
@@ -882,3 +899,77 @@
 
     return r;
 }
+
+
+#define SEP '|'
+
+static int autosieve_subfolder(char *userid, struct auth_state *auth_state,
+                               char *subfolder, struct namespace *namespace)
+{
+     char option_name_external[MAX_MAILBOX_NAME + 1];
+     char option_name_internal[MAX_MAILBOX_NAME + 1];
+     const char *subf ;
+     char *p, *q, *next_subf;
+     int len, r = 0;
+     int createsievefolder = 0;
+
+    /* Check if subfolder or userid are NULL */
+    if(subfolder == NULL || userid == NULL)
+         return IMAP_MAILBOX_NONEXISTENT;
+
+    if (config_getswitch(IMAPOPT_ANYSIEVEFOLDER))
+         createsievefolder = 1;
+    else if ((subf = config_getstring(IMAPOPT_AUTOSIEVEFOLDERS)) != NULL) {
+         /* Roll through subf */
+         next_subf = (char *) subf;
+         while (*next_subf) {
+              for (p = next_subf ; isspace((int) *p) || *p == SEP ; p++);
+              for (next_subf = p ; *next_subf && *next_subf != SEP ; next_subf++);
+              for (q = next_subf ; q > p && (isspace((int) *q) || *q == SEP || !*q); q--);
+
+              if (!*p) continue;
+                    
+              len = q - p + 1;
+             /*
+              * This is a preliminary length check based on the assumption
+              * that the *final* internal format will be something
+              * like user.userid.subfolder(s).
+              */
+              if (len > sizeof(option_name_external) - strlen(userid) - 5)
+                   return IMAP_MAILBOX_BADNAME;
+
+              strlcpy(option_name_external, namespace->prefix[NAMESPACE_INBOX], sizeof(option_name_external));
+	      strncat(option_name_external, p, len);
+                    
+              /* 
+               * Transform the option folder name to internal namespace and compare it
+	       * with what must be created.
+               */
+              r = namespace->mboxname_tointernal(namespace, option_name_external, userid, option_name_internal);
+              if (r) continue;
+
+              if (!strcmp(option_name_internal, subfolder)) {
+                  createsievefolder = 1;
+                  break;
+              }
+         }
+    }
+
+    if (createsievefolder) {
+        /* Folder is already in internal namespace format */
+        r = mboxlist_createmailbox(subfolder, MAILBOX_FORMAT_NORMAL, NULL,
+                                           1, userid, auth_state, 0, 0, 0);
+        if (!r) {
+            mboxlist_changesub(subfolder, userid, auth_state, 1, 1);
+            syslog(LOG_DEBUG, "autosievefolder: User %s, folder %s creation succeeded.",
+                                                   userid, subfolder);
+            return 0;
+        } else {
+            syslog(LOG_ERR, "autosievefolder: User %s, folder %s creation failed. %s",
+                                                  userid, subfolder,error_message(r));
+            return r;
+        }
+    } else
+        return IMAP_MAILBOX_NONEXISTENT;
+}
+
diff -Naur cyrus-imapd-2.2.12/lib/imapoptions cyrus-imapd-2.2.12-autosieve.uncompiled/lib/imapoptions
--- cyrus-imapd-2.2.12/lib/imapoptions	2004-07-21 22:07:45 +0300
+++ cyrus-imapd-2.2.12-autosieve.uncompiled/lib/imapoptions	2005-02-15 13:59:51 +0200
@@ -752,6 +752,15 @@
 /* If enabled, lmtpd will look for Sieve scripts in user's home
    directories: ~user/.sieve. */
 
+{ "anysievefolder", 0, SWITCH }
+/* It must be "yes" in order to permit the autocreation of any INBOX subfolder 
+   requested by a sieve filter, through the "fileinto" action. (default = no) */
+
+{ "autosievefolders", NULL, STRING }
+/* It is a "|" separated list of subfolders of INBOX that will be automatically created, 
+   if requested by a sieve filter, through the "fileinto" action. (default = null)
+   i.e. autosievefolders: Junk | Spam */
+
 { "singleinstancestore", 1, SWITCH }
 /* If enabled, lmtpd and nntpd attempt to only write one copy of a message per
    partition and create hard links, resulting in a potentially large


--- NEW FILE cyrus-imapd-2.2.12.tar.gz.sig ---
‰
cyrus-imapd-2.2.4-OE-seenstate.patch:

--- NEW FILE cyrus-imapd-2.2.4-OE-seenstate.patch ---
# Small patch to Cyrus IMAP 2.2.4 which modifies \Seen state handling to
# make it compatible with Outlook Express. OE makes two connections to a
# given mailfolder: one generates indexes while the other fetches messages.
# Unfortunately it gets confused if \Seen updates caused by the message
# stream aren't immediately flushed and picked up by the index stream.
#
# This patch is a 2.2.4 port from the patch found here:
# http://www-uxsup.csx.cam.ac.uk/~dpc22/cyrus/patches/2.1.16/OutLookExpress-seenstate.patch
#
diff -Naur cyrus-imapd-2.2.4.orig/imap/imapd.c cyrus-imapd-2.2.4/imap/imapd.c
--- cyrus-imapd-2.2.4.orig/imap/imapd.c	Thu May  6 20:46:21 2004
+++ cyrus-imapd-2.2.4/imap/imapd.c	Fri May 21 02:10:25 2004
@@ -3063,6 +3063,10 @@
     snprintf(mytime, sizeof(mytime), "%2.3f", 
 	     (clock() - start) / (double) CLOCKS_PER_SEC);
 
+    /* Checkpoint \Seen immediately after each FETCH completes. Checks for
+     * changes from other processes at the same time */
+    index_check_existing(imapd_mailbox, usinguid, 1);
+
     if (r) {
 	prot_printf(imapd_out, "%s NO %s (%s sec)\r\n", tag,
 		    error_message(r), mytime);
@@ -3184,7 +3188,7 @@
 
     index_fetch(imapd_mailbox, msgno, 0, &fetchargs, &fetchedsomething);
 
-    index_check(imapd_mailbox, 0, 0);
+    index_check_existing(imapd_mailbox, 0, 1);
 
     if (fetchedsomething) {
 	prot_printf(imapd_out, "%s OK %s\r\n", tag,
@@ -3321,7 +3325,9 @@
 		    flag, nflags);
 
     if (usinguid) {
-	index_check(imapd_mailbox, 1, 0);
+	index_check(imapd_mailbox, 1, 1);   /* Check \Seen too */
+    } else {
+        index_check_existing(imapd_mailbox, 0, 1);
     }
 
     if (r) {
diff -Naur cyrus-imapd-2.2.4.orig/imap/imapd.h cyrus-imapd-2.2.4/imap/imapd.h
--- cyrus-imapd-2.2.4.orig/imap/imapd.h	Wed Oct 22 20:50:07 2003
+++ cyrus-imapd-2.2.4/imap/imapd.h	Fri May 21 02:06:02 2004
@@ -233,6 +233,8 @@
 extern void index_operatemailbox(struct mailbox *mailbox);
 extern void index_check(struct mailbox *mailbox, int usinguid,
 			   int checkseen);
+extern void
+index_check_existing(struct mailbox *mailbox, int usinguid, int checkseen);
 extern void index_checkseen(struct mailbox *mailbox, int quiet,
 			       int usinguid, int oldexists);
 
diff -Naur cyrus-imapd-2.2.4.orig/imap/index.c cyrus-imapd-2.2.4/imap/index.c
--- cyrus-imapd-2.2.4.orig/imap/index.c	Wed Apr 21 19:40:48 2004
+++ cyrus-imapd-2.2.4/imap/index.c	Fri May 21 02:06:02 2004
@@ -425,6 +425,45 @@
     }
 }
 
+/* Nasty hack to report system + user flags updates without checking for
+ * new mail or expunge (relies on index atomic rewrite+rename for expunge).
+ *
+ * Needed to keep Outlook Express happy without breaking IMAP concurrent
+ * access regime which (quite correctly) prohibits unsolicited EXPUNGE and
+ * EXIST responses for non-UID versions of FETCH and STORE. Otherwise you
+ * can end up with hilarous situations such as:
+ *
+ *   . FETCH 2 fast
+ *   * EXPUNGE 1          <-- from concurrent session.
+ *   . FETCH (data relating to previous message _3_, if it exists)
+ *
+ */
+
+void
+index_check_existing(struct mailbox *mailbox, int usinguid, int checkseen)
+{
+    int msgno, i;
+    bit32 user_flags[MAX_USER_FLAGS/32];
+
+    if (imapd_exists == -1)
+        return;
+
+    if (checkseen)
+        index_checkseen(mailbox, 0, usinguid, imapd_exists);
+
+    for (msgno = 1; msgno <= imapd_exists; msgno++) {
+	if (flagreport[msgno] < LAST_UPDATED(msgno)) {
+	    for (i = 0; i < VECTOR_SIZE(user_flags); i++) {
+		user_flags[i] = USER_FLAGS(msgno, i);
+	    }
+	    index_fetchflags(mailbox, msgno, SYSTEM_FLAGS(msgno), user_flags,
+			     LAST_UPDATED(msgno));
+	    if (usinguid) prot_printf(imapd_out, " UID %u", UID(msgno));
+	    prot_printf(imapd_out, ")\r\n");
+	}
+    }
+}
+
 /*
  * Checkpoint the user's \Seen state
  *

cyrus-imapd-2.2.4-munge8bit.patch:

--- NEW FILE cyrus-imapd-2.2.4-munge8bit.patch ---
diff -Naur cyrus-imapd-2.2.4.orig/doc/man/deliver.8.html cyrus-imapd-2.2.4/doc/man/deliver.8.html
--- cyrus-imapd-2.2.4.orig/doc/man/deliver.8.html	Sun May 16 23:05:05 2004
+++ cyrus-imapd-2.2.4/doc/man/deliver.8.html	Thu May 20 19:21:15 2004
@@ -221,13 +221,15 @@
 <td width="10%"></td>
 <td width="89%">
 <p>Depending on the setting of <b>reject8bit</b> in
-<b>imapd.conf(5)</b>, deliver either rejects messages with
-8-bit-set characters in the headers or changes these
-characters to ‘X’. This is because such
-characters can’t be interpreted since the character
-set is not known, although some communities not well-served
-by US-ASCII assume that those characters can be used to
-represent characters not present in US-ASCII.</p>
+<b>imapd.conf(5)</b>, deliver either rejects/accepts
+messages with 8-bit-set characters in the headers. If we
+accept messages with 8-bit-set characters in the headers,
+then depending on the setting of <b>munge8bit</b>, these
+characters are either left un-touched or changed to . This
+is because such characters can’t be interpreted since
+the character set is not known, although some communities
+not well-served by US-ASCII assume that those characters can
+be used to represent characters not present in US-ASCII.</p>
 <!-- INDENTATION -->
 <p>A method for encoding 8-bit-set characters is provided by
 RFC 2047.</p>
diff -Naur cyrus-imapd-2.2.4.orig/imap/message.c cyrus-imapd-2.2.4/imap/message.c
--- cyrus-imapd-2.2.4.orig/imap/message.c	Fri Feb 27 18:44:55 2004
+++ cyrus-imapd-2.2.4/imap/message.c	Thu May 20 19:15:23 2004
@@ -227,6 +227,7 @@
     int n;
     int sawcr = 0, sawnl;
     int reject8bit = config_getswitch(IMAPOPT_REJECT8BIT);
+    int munge8bit = config_getswitch(IMAPOPT_MUNGE8BIT);
     int inheader = 1, blankline = 1;
 
     while (size) {
@@ -262,7 +263,7 @@
 			/* We have been configured to reject all mail of this
 			   form. */
 			if (!r) r = IMAP_MESSAGE_CONTAINS8BIT;
-		    } else {
+		    } else if (munge8bit) {
 			/* We have been configured to munge all mail of this
 			   form. */
 			*p = 'X';
diff -Naur cyrus-imapd-2.2.4.orig/imap/spool.c cyrus-imapd-2.2.4/imap/spool.c
--- cyrus-imapd-2.2.4.orig/imap/spool.c	Thu Mar  4 17:09:34 2004
+++ cyrus-imapd-2.2.4/imap/spool.c	Thu May 20 19:16:52 2004
@@ -140,6 +140,7 @@
     state s = NAME_START;
     int r = 0;
     int reject8bit = config_getswitch(IMAPOPT_REJECT8BIT);
+    int munge8bit = config_getswitch(IMAPOPT_MUNGE8BIT);
     const char **skip = NULL;
 
     if (namelen == 0) {
@@ -266,7 +267,7 @@
 			   form. */
 			r = IMAP_MESSAGE_CONTAINS8BIT;
 			goto ph_error;
-		    } else {
+		    } else if (munge8bit) {
 			/* We have been configured to munge all mail of this
 			   form. */
 			c = 'X';
diff -Naur cyrus-imapd-2.2.4.orig/lib/imapoptions cyrus-imapd-2.2.4/lib/imapoptions
--- cyrus-imapd-2.2.4.orig/lib/imapoptions	Wed May  5 20:53:09 2004
+++ cyrus-imapd-2.2.4/lib/imapoptions	Thu May 20 19:15:23 2004
@@ -454,6 +454,12 @@
 { "mboxlist_db", "skiplist", STRINGLIST("flat", "berkeley", "skiplist")}
 /* The cyrusdb backend to use for the mailbox list. */
 
+{ "munge8bit", 1, SWITCH }
+/* If enabled, lmtpd munges messages with 8-bit characters.  These characters
+   are changed to .  If \fBreject8bit\fR is enabled, setting \fBmunge8bit\fR
+   has no effect.  (A proper soultion to non-ASCII characters in headers is
+   offered by RFC 2047 and its predecessors.) */
+
 # xxx badly worded
 { "mupdate_connections_max", 128, INT }
 /* The max number of connections that a mupdate process will allow, this
@@ -654,9 +660,7 @@
 
 { "reject8bit", 0, SWITCH }
 /* If enabled, lmtpd rejects messages with 8-bit characters in the
-   headers.  Otherwise, 8-bit characters are changed to `X'.  (A
-   proper soultion to non-ASCII characters in headers is offered by  
-   RFC 2047 and its predecessors.) */
+   headers. */
 
 { "rfc2046_strict", 0, SWITCH }
 /* If enabled, imapd will be strict (per RFC 2046) when matching MIME
diff -Naur cyrus-imapd-2.2.4.orig/man/deliver.8 cyrus-imapd-2.2.4/man/deliver.8
--- cyrus-imapd-2.2.4.orig/man/deliver.8	Sat May 25 21:57:47 2002
+++ cyrus-imapd-2.2.4/man/deliver.8	Thu May 20 19:15:23 2004
@@ -147,8 +147,10 @@
 Accept messages using the LMTP protocol.
 .SH NOTES
 Depending on the setting of \fBreject8bit\fR in \fBimapd.conf(5)\fR, deliver
-either rejects messages with 8-bit-set characters in the headers or 
-changes these characters to `X'.
+either rejects/accepts messages with 8-bit-set characters in the headers.
+If we accept messages with 8-bit-set characters in the headers, then depending
+on the setting of \fBmunge8bit\fR, these characters are either left un-touched
+or changed to .
 This is because such characters can't be interpreted since the
 character set is not known, although some communities not well-served by
 US-ASCII assume that those characters can be used to represent characters not


--- NEW FILE cyrus-imapd-README.RPM ---
---------------
Cyrus IMAPd RPM
---------------

This is a _very_ 'quick and dirty' install howto.

The following steps should lead you to a running Cyrus IMAP server:

1)  Install on a distribution which is supported by this RPM. Don't install
    on a dirty system, where you have previously tried to install from source.
2)  Don't install if you have a previous Cyrus IMAPd installation <=2.1.x on
    your box. Upgrading any Invoca rpm based installation should be fine.
3)  Make sure you understand that this RPM installs in FHS compliant
    directories, like /var/lib/imap and /var/spool/imap
4)  Make sure cyrus-sasl 2.x is installed.
5)  Make sure saslauthd is running. If not, edit /etc/sysconfig/saslauthd as
    needed and do 'chkconfig saslauthd on ; service saslauthd start'
6)  Install the cyrus-imapd RPMs.
7)  If it's your first install of Cyrus IMAPd, then set a password for the
    cyrus user in whatever database you are using to authenticate.
8)  Make sure your MTA delivers to Cyrus IMAPd, I recommend LMTP for this.
9)  Start Cyrus IMAPd with 'service cyrus-imapd start'
10) Run cyradm and create a user. Usually it's something like this:
    'cyradm --user=cyrus --auth=login localhost'
11) If you're using sendmail, be aware that cyrusv2.m4 included in standard
    sendmail distribution uses socket /var/imap/socket/lmtp while this rpm
    uses /var/lib/imap/socket/lmtp.
12) Check your syslog configuration. This RPM uses the mail facility to log
    messages. On busy sites you may want to limit the mail facility to the
    info priority with something like 'mail.info    /var/log/maillog' in
    /etc/syslog.conf.

Enjoy!


--- NEW FILE cyrus-imapd-README.contrib ---
The programs provided here in the contrib directory are taken from
various places on the net. Sometimes I even don't know where I found
them and the license may also be unclear. If the creator of one of the
scripts doesn't like to see it included in this contrib section, let
me know and I'll remove it from the package.

I have never used any of the scripts here so I really don't know how
they work or whether there are better ways to complete a task. I've
been told that there are better tools to migrate from UW-IMAP. So be
warned, use at your own risk.


--- NEW FILE cyrus-imapd-README.groupcache ---
If you have a lot of groups or very large groups, cyrus-imapd login can become
quite slow due to the way cyrus-imapd handles groups. This may become worse
when using nss_ldap or other slow nss backends to resolve groups.
Caching using nscd can increase speed dramatically but unfortunately not for
all functions cyrus-imapd uses. nscd helps speeding up getgrnam() calls but not
getgrent() calls, which are used by cyrus-imapd to get a complete list of all
groups available.
The groupfile patch implements a quick fix to the problem by using a separate
group.cache file to speed up those operations using getgrent() calls.
Calls to getgrnam() are not touched which means that the group.cache
file must be kept in sync with the group source you are using with nss
configured in /etc/nsswitch.conf. If group.cache doesn't exist,
the patch has no effect and cyrus-imapd handles groups through getgrent().

Quick HOWTO:
- configure group lookup in /etc/nsswitch.conf if not already done
- configure name service cache in /etc/nscd.conf               (not mandatory)
- start nscd with "service nscd start"                         (not mandatory)
- configure a service which periodically updates the group.cache file using the
  upd_groupcache script. Either set up a cronjob or use a event in the cyrus
  configuration.

Sample /etc/cyrus.conf event to update the group cache every 10 minutes:
EVENTS {
  # some events removed here ***
  ...........................***

  # this is only necessary if using group cache feature
  groupcache    cmd="upd_groupcache" period=10
}

cyrus-imapd-acceptinvalidfrom.patch:

--- NEW FILE cyrus-imapd-acceptinvalidfrom.patch ---
--- cyrus-imapd-2.2.6/imap/message.c.acceptinvalidfrom	2004-10-30 15:03:02.220642392 -0700
+++ cyrus-imapd-2.2.6/imap/message.c	2004-10-30 15:06:01.838336352 -0700
@@ -229,6 +229,8 @@
     int reject8bit = config_getswitch(IMAPOPT_REJECT8BIT);
     int munge8bit = config_getswitch(IMAPOPT_MUNGE8BIT);
     int inheader = 1, blankline = 1;
+    char is_from;
+    static const char * from_header = "From ";
 
     while (size) {
 	n = prot_read(from, buf, size > 4096 ? 4096 : size);
@@ -294,8 +296,20 @@
 	/* Check for valid header name */
 	if (sawnl && buf[0] != ' ' && buf[0] != '\t') {
 	    if (buf[0] == ':') return IMAP_MESSAGE_BADHEADER;
-	    for (p = (unsigned char *)buf; *p != ':'; p++) {
-		if (*p <= ' ') return IMAP_MESSAGE_BADHEADER;
+            p = (unsigned char *) buf;
+            if (*p == '>')
+                p++;
+            if (*p == from_header[0])
+                is_from = 0;
+            else
+                is_from = -1;
+            for (; *p != ':' && is_from < 5; p++) {
+                if (is_from > 0 && *p != from_header[is_from])
+                    is_from = -1;
+                if (is_from >= 0)
+                    is_from++;
+                else
+                    if (*p <= ' ') return IMAP_MESSAGE_BADHEADER;
 	    }
 	}
 


--- NEW FILE cyrus-imapd-db.cfg ---
CONFIG_DB_DUPLICATE=berkeley
CONFIG_DB_MBOX=skiplist
CONFIG_DB_SEEN=skiplist
CONFIG_DB_SUBS=flat
CONFIG_DB_TLS=berkeley
CONFIG_DB_ANNOTATION=skiplist
CONFIG_DB_SIEVE=2.2.3

cyrus-imapd-gcc4.patch:

--- NEW FILE cyrus-imapd-gcc4.patch ---
--- cyrus-imapd-2.2.10/tools/config2header.orig	2005-03-04 17:18:04.519026273 -0500
+++ cyrus-imapd-2.2.10/tools/config2header	2005-03-04 17:19:45.234962450 -0500
@@ -214,7 +214,6 @@
 print HFILE <<EOF
   IMAPOPT_LAST
 };
-extern struct imapopt_s imapopts[];
 
 enum enum_value {
   IMAP_ENUM_ZERO = 0,
@@ -260,6 +259,7 @@
 
 print HFILE <<EOF
 };
+extern struct imapopt_s imapopts[];
 #endif /* INCLUDED_IMAPOPTIONS_H */
 EOF
     ;


--- NEW FILE cyrus-imapd-procmail+cyrus.mc ---
divert(-1)
include(`../m4/cf.m4')
define(`confDEF_USER_ID',``8:12'')
OSTYPE(`linux')
undefine(`UUCP_RELAY')
undefine(`BITNET_RELAY')
FEATURE(redirect)
FEATURE(always_add_domain)
FEATURE(use_cw_file)
FEATURE(local_procmail)
define(`CYRUS_MAILER_FLAGS',`Aw5:/|@o')
define(`confLOCAL_MAILER',`cyrus')
dnl # Note: CYUSER isn't needed, but must put $u in mailer args otherwise
dnl # it uses SMTP for delivery!
define(`CYRUS_MAILER_ARGS', `procmail -p /etc/procmailrc.cyrus CYUSER=$u')
define(`CYRUS_MAILER_PATH', `/usr/bin/procmail')
MAILER(cyrus)
MAILER(procmail)
MAILER(smtp)
HACK(check_mail3,`hash -a at JUNK /etc/mail/deny')
HACK(use_ip,`/etc/mail/ip_allow')
HACK(use_names,`/etc/mail/name_allow')
HACK(use_relayto,`/etc/mail/relay_allow')
HACK(check_rcpt4)
HACK(check_relay3)
dnl Not yet tested...
dnl LOCAL_RULE_0
dnl Rbb + $+ < @ $=w . >	$#cyrusbb $: $1


--- NEW FILE cyrus-imapd-sendmail-8.12.9-cyrusv2.m4 ---
PUSHDIVERT(-1)
#
# Copyright (c) 2002 Sendmail, Inc. and its suppliers.
#	All rights reserved.
#
# By using this file, you agree to the terms and conditions set
# forth in the LICENSE file which can be found at the top level of
# the sendmail distribution.
#
#	Contributed by Kenneth Murchison.
#

_DEFIFNOT(`_DEF_CYRUSV2_MAILER_FLAGS', `lsDFMnqXz')
_DEFIFNOT(`CYRUSV2_MAILER_FLAGS', `A@/:|m')
ifdef(`CYRUSV2_MAILER_ARGS',, `define(`CYRUSV2_MAILER_ARGS', `FILE /var/imap/socket/lmtp')')
define(`_CYRUSV2_QGRP', `ifelse(defn(`CYRUSV2_MAILER_QGRP'),`',`', ` Q=CYRUSV2_MAILER_QGRP,')')dnl

POPDIVERT

#########################################
###   Cyrus V2 Mailer specification   ###
#########################################

VERSIONID(`$Id: cyrus-imapd-sendmail-8.12.9-cyrusv2.m4,v 1.1 2004/02/04 12:59:42 karsten Exp $')

Mcyrusv2,	P=[IPC], F=_MODMF_(CONCAT(_DEF_CYRUSV2_MAILER_FLAGS, CYRUSV2_MAILER_FLAGS), `CYRUSV2'),
		S=EnvFromSMTP/HdrFromL, R=EnvToL/HdrToL, E=\r\n,
		_OPTINS(`CYRUSV2_MAILER_MAXMSGS', `m=', `, ')_OPTINS(`CYRUSV2_MAILER_MAXRCPTS', `r=', `, ')_OPTINS(`CYRUSV2_MAILER_CHARSET', `C=', `, ')T=DNS/RFC822/SMTP,_CYRUSV2_QGRP
		A=CYRUSV2_MAILER_ARGS


--- NEW FILE cyrus-imapd.cron-daily ---
#!/bin/sh
#
# This file is run on a daily basis to perform a backup of your
# mailbox list which can be used to recreate mailboxes.db from backup.
# Restore is done using ctl_mboxlist after uncompressing the file.

BACKDIR="/var/lib/imap/backup"
MBOXLIST="${BACKDIR}/mboxlist"
ROTATE=6

# fallback to su if runuser not available
if [ -x /sbin/runuser ]; then
  RUNUSER=runuser
else
  RUNUSER=su
fi

# source custom configuration
if [ -f /etc/sysconfig/cyrus-imapd ]; then
  . /etc/sysconfig/cyrus-imapd
fi

[ -x /usr/lib/cyrus-imapd/ctl_mboxlist ] || exit 0

# rotate mailbox lists
seq $[ $ROTATE - 1 ] 1 | while read i; do
  [ -f ${MBOXLIST}.${i}.gz ] && mv -f ${MBOXLIST}.${i}.gz ${MBOXLIST}.$[ $i + 1 ].gz
done
[ -f ${MBOXLIST}.gz ] && mv -f ${MBOXLIST}.gz ${MBOXLIST}.1.gz

# export mailboxes.db
$RUNUSER - cyrus -c "umask 077 < /dev/null ; /usr/lib/cyrus-imapd/ctl_mboxlist -d | gzip > ${MBOXLIST}.gz"

exit 0
# EOF


--- NEW FILE cyrus-imapd.cvt_cyrusdb_all ---
#!/bin/sh

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# This script converts all db files of a cyrus installation from their
# existing format to the format required by the current installation.
# The format of current db files is determined using the 'file' command
# with a magic file added for skiplist db, the new format is read from
# a config file usually in /usr/share/cyrus-imapd/rpm/db.cfg, which is
# created while compiling. After converting, the db.cfg file is
# copied to a cache file usually at /var/lib/imap/rpm/db.cfg.cache to
# allow bypassing this converting script if both files are identical.
# While this is a bit less secure, it may be useful on big server where
# db converting is done automatically.
#
# This script can safely be run as root, it will reexec itself as user
# cyrus if needed.
#
# author: Simon Matter, Invoca Systems <simon.matter at invoca.ch>

# changelog
# v1.0.1, Oct 22 2002 Simon Matter <simon.matter at invoca.ch>
# - added two-step conversion method
#
# v1.0.2, Jan 10 2003 Simon Matter <simon.matter at invoca.ch>
# - fixed a bug where cvt_cyrusdb was called to convert empty or
#   nonexistent files
#
# v1.0.3, Mar 14 2003 Simon Matter <simon.matter at invoca.ch>
# - fixed a problem with new versions of the file command
#
# v1.0.4
# - added GPL license
#
# v1.0.5, May 02 2003 Simon Matter <simon.matter at invoca.ch>
# - modified exec path
#
# v1.0.6, Jul 18 2003 Simon Matter <simon.matter at invoca.ch>
# - changed db3 to berkeley
# - added new db backends for 2.2
#
# v1.0.7, Jan 23 2004 Simon Matter <simon.matter at invoca.ch>
# - included some modifications from Luca Olivetti <luca at olivetti.cjb.net>
# - added masssievec functionality
#
# v1.0.8, Jan 28 2004 Simon Matter <simon.matter at invoca.ch>
# - convert sieve scripts to UTF-8 before calling masssievec
#
# v1.0.9, Jan 29 2004 Simon Matter <simon.matter at invoca.ch>
# - convert sieve scripts to UTF-8 only if sievec failed before
#
# v1.0.10, Feb 24 2004 Simon Matter <simon.matter at invoca.ch>
# - change su within init script to get input from
#   /dev/null, this prevents hang when running in SELinux
#
# v1.0.11, Mar 02 2004 Simon Matter <simon.matter at invoca.ch>
# - fixed SELinux fix
#
# v1.0.12, Dec 16 2004 Simon Matter <simon.matter at invoca.ch>
# - use runuser instead of su if available

if [ -n "$(/sbin/pidof cyrus-master)" ]; then
  echo "ERROR: cyrus-master is running, unable to convert mailboxes!"
  exit 1
fi

if [ ! -f /etc/imapd.conf ]; then
  echo "ERROR: configuration file not found."
  exit 1
fi

# fallback to su if runuser not available
if [ -x /sbin/runuser ]; then
  RUNUSER=runuser
else
  RUNUSER=su
fi

# force cyrus user for security reasons
if [ ! $(whoami) = "cyrus" ]; then
  exec $RUNUSER - cyrus -c "cd $PWD < /dev/null ; $0"
fi

# files get mode 0600
umask 166

# get_config [config default]
# extracts config option from config file
get_config() {
  if config=$(grep "^$1" /etc/imapd.conf); then
    echo $config | cut -d: -f2 | sed -e 's/^ *//' -e 's/-nosync//' -e 's/ *$//'
  else
    echo $2
  fi
}

# where to find files and directories
system_magic=$(file --version | awk '/magic file/ {print $4}')
cyrus_magic=/usr/share/cyrus-imapd/rpm/magic
cvt_cyrusdb=/usr/lib/cyrus-imapd/cvt_cyrusdb
sievec=/usr/lib/cyrus-imapd/sievec
imap_prefix=$(get_config configdirectory /var/lib/imap)
sieve_dir=$(get_config sievedir /var/lib/imap/sieve)
db_cfg=/usr/share/cyrus-imapd/rpm/db.cfg
db_current=${imap_prefix}/rpm/db.cfg.current
db_cache=${imap_prefix}/rpm/db.cfg.cache

# source default db backend config
. $db_cfg

# get configured db backend config
CONFIG_DB_DUPLICATE=$(get_config duplicate_db $CONFIG_DB_DUPLICATE)
CONFIG_DB_MBOX=$(get_config mboxlist_db $CONFIG_DB_MBOX)
CONFIG_DB_SEEN=$(get_config seenstate_db $CONFIG_DB_SEEN)
CONFIG_DB_SUBS=$(get_config subscription_db $CONFIG_DB_SUBS)
CONFIG_DB_TLS=$(get_config tlscache_db $CONFIG_DB_TLS)
CONFIG_DB_ANNOTATION=$(get_config annotation_db $CONFIG_DB_ANNOTATION)

# remember current db backend config
{
echo "CONFIG_DB_DUPLICATE=$CONFIG_DB_DUPLICATE"
echo "CONFIG_DB_MBOX=$CONFIG_DB_MBOX"
echo "CONFIG_DB_SEEN=$CONFIG_DB_SEEN"
echo "CONFIG_DB_SUBS=$CONFIG_DB_SUBS"
echo "CONFIG_DB_TLS=$CONFIG_DB_TLS"
echo "CONFIG_DB_ANNOTATION=$CONFIG_DB_ANNOTATION"
echo "CONFIG_DB_SIEVE=$CONFIG_DB_SIEVE"
} > $db_current

# file_type [file]
file_type() {
  this_type=$(file -b -m "$system_magic:$cyrus_magic" "$1" 2> /dev/null)
  if echo "$this_type" | grep -qi skip > /dev/null 2>&1; then
    echo skiplist
  elif echo "$this_type" | grep -qi text > /dev/null 2>&1; then
    echo flat
  else
    echo berkeley
  fi
}

# cvt_file [file] [db]
cvt_file() {
  target="$1"
  new_db="$2"
  if [ -s "$target" ]; then
    old_db=$(file_type "$target")
    if [ ! "$old_db" = "$new_db" ]; then
      # The two-step conversion is paranoia against the filenames being encoded
      # inside the database or logfiles (berkeley does this, for example).
      rm -f "${target}.flat"
      if [ "$old_db" = "flat" ]; then
        cp -a "$target" "${target}.flat"
      else
        $cvt_cyrusdb "$target" "$old_db" "${target}.flat" flat
      fi
      RETVAL=$?
      ERRVAL=$[ $ERRVAL + $RETVAL ]
      if [ $RETVAL -eq 0 ]; then
        rm -f "$target"
        if [ -s "${target}.flat" ]; then
          if [ "$new_db" = "flat" ]; then
            cp -a "${target}.flat" "$target"
          else
            $cvt_cyrusdb "${target}.flat" flat "$target" "$new_db"
          fi
        fi
        RETVAL=$?
        ERRVAL=$[ $ERRVAL + $RETVAL ]
        if [ $RETVAL -eq 0 ]; then
          rm -f "${target}.flat"
        else
          echo "ERROR: unable to convert ${target}.flat from flat to $new_db"
        fi
      else
        echo "ERROR: unable to convert $target from $old_db to flat"
      fi
    fi
  fi
}

# cvt_to_utf8 [file]
cvt_to_utf8() {
  target="$1"
  if [ -s "$target" ]; then
    if ! $sievec "$target" "${target}.sievec"; then
      iconv --from-code=ISO-8859-1 --to-code=UTF-8 --output="${target}.UTF-8" "$target"
      if [ -s "${target}.UTF-8" ]; then
        # preserve timestamp
        touch --reference="$target" "${target}.UTF-8"
        mv -f "${target}.UTF-8" "$target"
      else
        ERRVAL=$[ $ERRVAL + 1 ]
      fi
    fi
    rm -f "${target}.sievec"
  fi
}

ERRVAL=0

# do we need to convert databases ?
if ! cmp -s $db_current $db_cache; then
  # we treat sieve scripts the same way like db files
  find ${sieve_dir}/ -name "*.script" -type f | while read db_file trash; do
    cvt_to_utf8 "$db_file"
  done
  /usr/lib/cyrus-imapd/masssievec /usr/lib/cyrus-imapd/sievec
  # convert all db files
  cvt_file $imap_prefix/deliver.db           "$CONFIG_DB_DUPLICATE"
  cvt_file $imap_prefix/mailboxes.db         "$CONFIG_DB_MBOX"
  cvt_file $imap_prefix/tls_sessions.db      "$CONFIG_DB_TLS"
  cvt_file $imap_prefix/annotations.db       "$CONFIG_DB_ANNOTATION"
  find ${imap_prefix}/user/ -name "*.seen" -type f | while read db_file trash; do
    cvt_file "$db_file" "$CONFIG_DB_SEEN"
  done
  find ${imap_prefix}/user/ -name "*.sub" -type f | while read db_file trash; do
    cvt_file "$db_file" "$CONFIG_DB_SUBS"
  done
fi

# copy the current config file so we can check whether something has changed
if [ $ERRVAL -eq 0 ]; then
  mv -f $db_current $db_cache
else
  rm -f $db_cache
  rm -f $db_current
fi

exit $ERRVAL


--- NEW FILE cyrus-imapd.imap-2.2.x-conf ---
configdirectory: /var/lib/imap
partition-default: /var/spool/imap
admins: cyrus
sievedir: /var/lib/imap/sieve
sendmail: /usr/sbin/sendmail
hashimapspool: true
sasl_pwcheck_method: saslauthd
sasl_mech_list: PLAIN
tls_cert_file: /usr/share/ssl/certs/cyrus-imapd.pem
tls_key_file: /usr/share/ssl/certs/cyrus-imapd.pem
tls_ca_file: /usr/share/ssl/certs/ca-bundle.crt


--- NEW FILE cyrus-imapd.init ---
#!/bin/sh
#
# chkconfig: - 65 35
# description: The Cyrus IMAPD master serves as a master process for the Cyrus \
#              IMAP and POP servers.
# config: /etc/cyrus.conf
# config: /etc/imapd.conf
# pidfile: /var/run/cyrus-master.pid

# author:       Simon Matter, Invoca Systems <simon.matter at invoca.ch>
# version:	2005010600
# changed:	2002020200 chkconfig modified
#               2002042500 rewrote start function
#               2002091800 added auto db converting functionality
#		2003020400 modified to use builtin daemon mode
#		2003050200 modified exec path
#		2003050900 return RETVAL from rhstatus(), did some cleanup
#		2003060700 added umask for cvt_cyrusdb_all log
#		2004012300 modified auto db converting functionality for 2.2
#		2004012700 fixed startup procedure
#		2004022400 change su within init script to get input from
#			   /dev/null, this prevents hang when running in SELinux
#		2004052000 don't enable cyrus-imapd per default
#		2004111900 use runuser instead of su if available
#		2005010600 removed LIB placeholder

# Source function library
if [ -f /etc/init.d/functions ]; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# check if the config files are present
[ -f /etc/cyrus.conf ] || exit 0
[ -f /etc/imapd.conf ] || exit 0
 
# This is our service name
BASENAME=$(basename $0)
if [ -L $0 ]; then
  BASENAME=$(find $0 -name $BASENAME -printf %l)
  BASENAME=$(basename $BASENAME)
fi

# fallback to su if runuser not available
if [ -x /sbin/runuser ]; then
  RUNUSER=runuser
else
  RUNUSER=su
fi

CYRUSMASTER=/usr/lib/cyrus-imapd/cyrus-master
CYRUS_PROC_NAME=$(basename $CYRUSMASTER)
ALWAYS_CONVERT=1

# Source service configuration.
if [ -f /etc/sysconfig/$BASENAME ]; then
  . /etc/sysconfig/$BASENAME
else
  echo "$BASENAME: configfile /etc/sysconfig/$BASENAME does NOT exist !"
  exit 1
fi

RETVAL=0

start() {
  echo -n $"Starting $BASENAME: "
  if [ $(/sbin/pidof -s $CYRUSMASTER) ]; then
    echo -n $"$BASENAME already running."
    false
  else
    echo -n $"preparing databases... "
    $RUNUSER - cyrus -c "umask 166 ; /usr/lib/cyrus-imapd/cvt_cyrusdb_all > /var/lib/imap/rpm/cvt_cyrusdb_all.log 2>&1" < /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
      echo -n $"done. "
      daemon $CYRUSMASTER -d $CYRUSOPTIONS
    else
      echo -n $"error! "
      initlog -n $BASENAME -s "error converting databases, check /var/lib/imap/rpm/cvt_cyrusdb_all.log"
      failure $"$BASENAME startup"
    fi
  fi
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASENAME
  return $RETVAL
}

stop() {
  echo -n $"Shutting down $BASENAME: "
  killproc $CYRUSMASTER
  RETVAL=$?
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASENAME
  echo
  return $RETVAL
}

restart() {
  stop
  start
}

reload() {
  echo -n $"Reloading cyrus.conf file: "
  killproc $CYRUSMASTER -HUP
  RETVAL=$?
  echo
  return $RETVAL
}
 
condrestart() {
  [ -e /var/lock/subsys/$BASENAME ] && restart || :
}

rhstatus() {
  status $CYRUSMASTER
  RETVAL=$?
  return $RETVAL
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  reload)
    reload
    ;;
  condrestart)
    condrestart
    ;;
  status)
    rhstatus
    ;;
  *)
    echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status}"
    RETVAL=1
esac

exit $RETVAL


--- NEW FILE cyrus-imapd.logrotate ---
/var/log/imapd.log /var/log/auth.log {
    missingok
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}


--- NEW FILE cyrus-imapd.magic ---
# Magic
# Magic data for file(1) command.
# Format is described in magic(files), where:
# files is 5 on V7 and BSD, 4 on SV, and ?? in the SVID.

#------------------------------------------------------------------------------
# skiplist:  file(1) magic Cyrus skiplist DB
#
0	string		\241\002\213\015skiplist\ file\0\0\0	Cyrus skiplist DB


--- NEW FILE cyrus-imapd.pam-config ---
#%PAM-1.0
auth       required	pam_stack.so service=system-auth
account    required	pam_stack.so service=system-auth


--- NEW FILE cyrus-imapd.rpm_set_permissions ---
#!/bin/sh
IMAPCONF=/etc/imapd.conf

CONFDIR=$(grep -se "^configdirectory:" $IMAPCONF | cut -d":" -f2)
if [ "x$CONFDIR" = "x" ]; then
  echo "$0 error: configdirectory not found in /etc/imapd.conf, exiting!"
  exit 1
fi

find $CONFDIR -type d ! -name "lost+found" -exec chmod 700 {} \; -exec chown cyrus:mail {} \;
grep -se "^partition-.*:" $IMAPCONF | cut -d":" -f2 | while read SPOOLDIR; do
  if [ "x$SPOOLDIR" = "x" ]; then
    echo "$0 warning: invalid partition configuration in /etc/imapd.conf found!"
  else
    find $SPOOLDIR -type d ! -name "lost+found" -exec chmod 700 {} \; -exec chown cyrus:mail {} \;
  fi
done

find $CONFDIR -type f ! -name "lost+found" -exec chmod 600 {} \; -exec chown cyrus:mail {} \;
grep -se "^partition-.*:" $IMAPCONF | cut -d":" -f2 | while read SPOOLDIR; do
  if [ "x$SPOOLDIR" = "x" ]; then
    echo "$0 warning: invalid partition configuration in /etc/imapd.conf found!"
  else
    find $SPOOLDIR -type f ! -name "lost+found" -exec chmod 600 {} \; -exec chown cyrus:mail {} \;
  fi
done

# lmtp socket must be accessible by group mail
chmod 750 $CONFDIR
chmod 750 ${CONFDIR}/socket


--- NEW FILE cyrus-imapd.spec ---
Name:			cyrus-imapd
Version:		2.2.12
Release:		1.2.fc4

# ********************** BUILD TIME OPTIONS START **********************

# To modify parameters, edit the .spec file or build like this:
# rpm --rebuild --define='SEEN_DB skiplist' cyrus-imapd-2.x.x-x.src.rpm

# use saslauth group
%{!?SASLGROUP:		%define		SASLGROUP 0}

# include deliver-wrapper
%{!?DEL_WRAP:		%define		DEL_WRAP 0}

# use preforking cyrus.conf
%{!?PREFORK:		%define		PREFORK 1}

# enable Netscape hack (recommended)
%{!?NETSCAPEHACK:	%define		NETSCAPEHACK 1}

# enable IMAP4 LIST extensions
%{!?LISTEXT:		%define		LISTEXT 1}

# enable IDLED support
%{!?IDLED:		%define		IDLED 1}

# force syncronous updates on ext3
%{!?FORCESYNCEXT3:	%define		FORCESYNCEXT3 0}

# include autocreate feature
%{!?AUTOCREATE:		%define		AUTOCREATE 1}

# include groupcache feature
%{!?GROUPCACHE:		%define		GROUPCACHE 1}

# don't check for RFC compliant line termination (bare newlines)
%{!?NO_BARE_NL:		%define		NO_BARE_NL 0}

# used syslog facility for logging
%{!?SYSLOGFACILITY:	%define		SYSLOGFACILITY MAIL}

# use -fpie for linking
%{!?USEPIE:		%define		USEPIE 0}

# OutlookExpress seenstate patch
%{!?OE_SEEN_ST:		%define		OE_SEEN_ST 1}

# use authorization module METHOD [unix|krb5]
%{!?AUTH_METHOD:	%define		AUTH_METHOD unix}

# ********************** BUILD TIME OPTIONS END ************************

%define			_use_internal_dependency_generator 0
%define			_rhver %(eval rpm -q --queryformat '%{VERSION}' $(rpm -qf /etc/redhat-release))
%define			_rhrelease %(eval %{__cat} /etc/redhat-release)
%define			_dbver db4
%define			_dbrpmver %(eval "rpm -q %{_dbver}")
# Do we need the perl install hack for RedHat > 7.3 ?
%define			_perlhack %(eval [ %{_rhver} = "6.2" -o %{_rhver} = "7.0" -o %{_rhver} = "7.1" -o %{_rhver} = "7.2" -o %{_rhver} = "7.3" -o %{_rhver} = "2.1AS" -o %{_rhver} = "2.1ES" ] && echo 0 || echo 1)
%define			_perl_man3dir %(eval "$(perl -V:man3dir)"; echo $man3dir)
# Disable -debuginfo package generation
#define debug_package	%{nil}

Summary:		A high-performance mail server with IMAP, POP3, NNTP and SIEVE support.
License:		OSI Approved
Group:			System Environment/Daemons
URL:			http://asg.web.cmu.edu/cyrus/imapd/
#Packager:		Simon Matter <simon.matter at invoca.ch>
#Vendor:		Invoca Systems
#Distribution:		Invoca Linux Server
Source0:		ftp://ftp.andrew.cmu.edu/pub/cyrus/%{name}-%{version}.tar.gz
Source1:		ftp://ftp.andrew.cmu.edu/pub/cyrus/%{name}-%{version}.tar.gz.sig
Source2:		cyrus-procmailrc
Source3:		cyrus-deliver-wrapper.c
Source4:		cyrus-user-procmailrc.template
Source5:		cyrus-imapd.logrotate
Source6:		cyrus-imapd.imap-2.2.x-conf
Source7:		cyrus-imapd.pam-config
Source8:		http://email.uoa.gr/projects/cyrus/autocreate/README.autocreate-cyrus-2.2
Source9:		http://email.uoa.gr/projects/cyrus/autosievefolder/README.autosievefolder
Source10:		cyrus-imapd-db.cfg
Source11:		cyrus-imapd.init
Source12:		cyrus-imapd.sysconfig
Source13:		cyrus-imapd.cvt_cyrusdb_all
Source14:		cyrus-imapd.magic
Source15:      		http://clement.hermann.free.fr/scripts/Cyrus/imapcreate.pl
Source16:		http://eu.dl.sourceforge.net/cyrus-utils/cyrus_ldap_quota.pl
Source17:		ftp://kalamazoolinux.org/pub/projects/awilliam/cyrus/batchreconstruct
Source18:		ftp://kalamazoolinux.org/pub/projects/awilliam/cyrus/bsd2cyrus
Source19:		ftp://kalamazoolinux.org/pub/projects/awilliam/cyrus/cpmsg
Source20:		ftp://kalamazoolinux.org/pub/projects/awilliam/cyrus/folderxfer
Source21:		ftp://kalamazoolinux.org/pub/projects/awilliam/cyrus/inboxfer
Source22:		http://email.uoa.gr/download/cyrus/cyrus_sharedbackup/cyrus_sharedbackup-0.1.tar.gz
Source23:		cyrus-imapd-README.RPM
Source24:		cyrus-imapd-README.HOWTO-recover-mailboxes.db
Source25:		cyrus-imapd.cron-daily
Source27:		cyrus-imapd-procmail+cyrus.mc
Source28:		cyrus-imapd.rpm_set_permissions
Source29:		cyrus-imapd-sendmail-8.12.9-cyrusv2.m4
Source30:		cyrus-imapd-README.contrib
Source31:		cyrus-imapd-README.groupcache
Source32:		cyrus-imapd.upd_groupcache
Patch0:			cyrus-imapd-2.1.9-fdatasync.patch
Patch1:			http://email.uoa.gr/download/cyrus/cyrus-imapd-2.2.12/cyrus-imapd-2.2.12-autocreate-0.9.2.diff
Patch2:			http://email.uoa.gr/download/cyrus/cyrus-imapd-2.2.12/cyrus-imapd-2.2.12-autosievefolder-0.6.diff
Patch3:			http://email.uoa.gr/download/cyrus/cyrus-imapd-2.2.10/cyrus-imapd-2.2.10-rmquota+deletemailbox-0.1.diff
Patch4:			http://servercc.oakton.edu/~jwade/cyrus/cyrus-imapd-2.1.3/cyrus-imapd-2.1.3-flock.patch
Patch5:			cyrus-imapd-2.2.4-munge8bit.patch
Patch6:			cyrus-imapd-2.1.16-getrlimit.patch
Patch7:			cyrus-imapd-2.1.15-nobarenewlinescheck.patch
Patch8:			cyrus-imapd-2.2.10-groupcache.patch
Patch9:			cyrus-imapd-2.2.4-OE-seenstate.patch
Patch10:		cyrus-imapd-acceptinvalidfrom.patch
Patch50:		cyrus-imapd-gcc4.patch
# Patches >= 100 are fixed in CVS
BuildRoot:		%{_tmppath}/%{name}-%{version}-root
Prereq:			e2fsprogs, diffutils, /sbin/chkconfig, /sbin/service
Requires:		cyrus-sasl >= 2.1.15, file >= 3.35-1
BuildPrereq:		cyrus-sasl-devel >= 2.1.15-1, perl, tcp_wrappers, %{_dbver}-devel, openssl-devel
BuildPrereq:		flex, bison, groff >= 1.15-8, autoconf

%define			uid 76
%if %{SASLGROUP}
%define			gid 76
%define			_saslgroup saslauth
%endif
%define			_cyrususer cyrus
%define			_cyrusgroup mail
%define			_vardata %{_var}/lib/imap
%define			_spooldata %{_var}/spool/imap
%define			_cyrexecdir %{_exec_prefix}/lib/%{name}
%define			_confdir master/conf
%define			_contribdir doc/contrib
%if %{PREFORK}
%define			_cyrusconf %{_confdir}/prefork.conf
%else
%define			_cyrusconf %{_confdir}/normal.conf
%endif

%description
The %{name} package contains the core of the Cyrus IMAP server.
It is a scaleable enterprise mail system designed for use from
small to large enterprise environments using standards-based
internet mail technologies.

A full Cyrus IMAP implementation allows a seamless mail and bulletin
board environment to be set up across multiple servers. It differs from
other IMAP server implementations in that it is run on "sealed"
servers, where users are not normally permitted to log in. The mailbox
database is stored in parts of the filesystem that are private to the
Cyrus IMAP server. All user access to mail is through software using
the IMAP, POP3, or KPOP protocols. TLSv1 and SSL are supported for
security.

%package murder
Group: System Environment/Daemons
Summary: Cyrus IMAP server murder aggregator system files.
Requires: %{name} = %{version}-%{release}

%description murder
The %{name}-murder package contains the Cyrus murder aggregator system,
i.e. IMAP, POP3 and LMTP proxies, and the mupdate mailbox master daemon.
It allows for cluster setups where there are many backend Cyrus spools
and frontend proxy servers.

%package nntp
Group: System Environment/Daemons
Summary: Cyrus IMAP server NNTP system files.
Requires: %{name} = %{version}-%{release}
 
%description nntp
The %{name}-nntp package contains the Cyrus NNTP server component.
Cyrus has the ability to export Usenet via IMAP and/or export shared IMAP
mailboxes via NNTP. This is made possible by a new NNTP daemon which is
included with Cyrus.

%package devel
Group: Development/Libraries
Summary: Cyrus IMAP server development files.
Requires: %{name} = %{version}-%{release}

%description devel
The %{name}-devel package contains header files and libraries
necessary for developing applications which use the imclient library.

%package -n perl-Cyrus
Group: System Environment/Libraries
Summary: Cyrus IMAP server utility Perl modules.

%description -n perl-Cyrus
The perl-Cyrus package contains Perl modules necessary to use the
Cyrus IMAP server administration utilities.

%package utils
Group: Applications/System
Summary: Cyrus IMAP server administration utilities.
Requires: perl-Cyrus = %{version}-%{release}

%description utils
The %{name}-utils package contains administrative tools for the
Cyrus IMAP server. It can be installed on systems other than the
one running the server.

%prep
%setup -q
%patch0 -p0 -b .fdatasync
%if %{AUTOCREATE}
%patch1 -p1 -b .autocreate
%patch2 -p1 -b .autosievefolder
%patch3 -p1 -b .rmquota
%endif
%patch4 -p1 -b .flock
%patch5 -p1 -b .munge8bit
%patch6 -p1 -b .getrlimit
%if %{NO_BARE_NL}
%patch7 -p1 -b .nobarenewlinescheck
%endif
%if %{GROUPCACHE}
%patch8 -p1 -b .groupcache
%endif
%if %{OE_SEEN_ST}
%patch9 -p1 -b .oeseenstate
%endif
%patch10 -p1 -b .acceptinvalidfrom
%patch50 -p1

%build
# kerberos include is needed (because of openssl-0.9.7 ?)
CPPFLAGS="-I%{_includedir}/et -I%{_prefix}/kerberos/include"; export CPPFLAGS
CFLAGS="$RPM_OPT_FLAGS -fPIC"; export CFLAGS
CCDLFLAGS="-rdynamic"; export CCDLFLAGS
LDFLAGS="-L%{_prefix}/kerberos/%{_lib}"; export LDFLAGS
%if %{USEPIE}
%ifnarch ppc ppc64
LDFLAGS="$LDFLAGS -pie"; export LDFLAGS
%endif
%endif

%{configure} \
%if %{NETSCAPEHACK}
  --enable-netscapehack \
%endif
%if %{LISTEXT}
  --enable-listext \
%endif
%if %{IDLED}
  --with-idle=idled \
%endif
  --enable-murder \
  --enable-nntp \
  --without-snmp \
  --with-perl=%{__perl} \
  --with-cyrus-prefix=%{_cyrexecdir} \
  --with-service-path=%{_cyrexecdir} \
  --with-auth=%{AUTH_METHOD} \
  --with-bdb-incdir=%{_includedir}/%{_dbver} \
  --with-extraident="Invoca-RPM-%{version}-%{release}" \
  --with-syslogfacility=%{SYSLOGFACILITY}

%{__make}
%if %{DEL_WRAP}
%{__cc} $CFLAGS -DLIBEXECDIR=\"%{_cyrexecdir}\" -Wall -o deliver-wrapper %{SOURCE3}
%endif

# Modify docs master --> cyrus-master
pushd man
  %{__perl} -pi -e "s at master\(8\)@cyrus-master(8)@" $(ls *5 *8)
popd
pushd doc
  %{__perl} -pi -e "s at master@cyrus-master at g;" man.html
popd
pushd doc/man
  %{__perl} -pi -e "s at master\(8\)@cyrus-master(8)@;" $(ls *html)
popd

# Modify path in perl scripts
%{__perl} -pi -e "s@/usr/local/bin/perl@%{__perl}@" $(find . -type f -name "*.pl")

# Fix permissions on perl programs
find . -type f -name "*.pl" -exec %{__chmod} 755 {} \;

# Cleanup of doc dir
find doc perl -name CVS -type d | xargs -r %{__rm} -fr
find doc -name "*~" -type f | xargs -r %{__rm} -f
%{__rm} -f doc/Makefile.dist
%{__rm} -f doc/text/htmlstrip.c

# Create README.buildoptions
%{__cat} << EOF >> doc/README.buildoptions
This RPM has been compiled on %{_rhrelease} using
Berkeley DB version %{_dbrpmver} with the following source
RPM build options:

use saslauth group
SASLGROUP       : %{SASLGROUP}

include deliver-wrapper
DEL_WRAP        : %{DEL_WRAP}

use preforking cyrus.conf
PREFORK         : %{PREFORK}

enable Netscape hack (recommended)
NETSCAPEHACK    : %{NETSCAPEHACK}

enable IMAP4 LIST extensions
LISTEXT         : %{LISTEXT}

enable IDLED support
IDLED           : %{IDLED}

force syncronous updates on ext3
FORCESYNCEXT3   : %{FORCESYNCEXT3}

include autocreate feature
AUTOCREATE      : %{AUTOCREATE}

include groupcache feature
GROUPCACHE      : %{GROUPCACHE}

include nobarenewlinescheck patch
NO_BARE_NL      : %{NO_BARE_NL}

used syslog facility for logging
SYSLOGFACILITY  : %{SYSLOGFACILITY}

used -fpie for linking
USEPIE          : %{USEPIE}

include OutlookExpress seenstate patch
OE_SEEN_ST      : %{OE_SEEN_ST}

use authorization module METHOD [unix|krb5]
AUTH_METHOD     : %{AUTH_METHOD}


To modify parameters, edit the .spec file or build like this:
rpm --rebuild --define='FULLDIRHASH 1' %{name}-%{version}-%{release}.src.rpm
EOF

%{__install} -m 644 %{SOURCE23}	doc/README.RPM
%{__install} -m 644 %{SOURCE24}	doc/README.HOWTO-recover-mailboxes.db
%if %{GROUPCACHE}
%{__install} -m 644 %{SOURCE31}	doc/README.groupcache
%endif
%if %{AUTOCREATE}
%{__install} -m 644 %{SOURCE8}  doc/README.autocreate
%{__install} -m 644 %{SOURCE9}  doc/README.autosievefolder
%endif
%{__install} -d doc/m4
%{__install} -m 644 %{SOURCE2}	doc/m4/cyrus-procmailrc
%{__install} -m 644 %{SOURCE4}	doc/m4/cyrus-user-procmailrc.template
%{__install} -m 644 %{SOURCE27}	doc/m4/%{name}-procmail+cyrus.mc
%{__install} -m 644 %{SOURCE29}	doc/m4/%{name}-sendmail-8.12.9-cyrusv2.m4

# modify lmtp socket path in .conf files
%{__perl} -pi -e "s@/var/imap/@%{_vardata}/@" %{_confdir}/*.conf doc/cyrusv2.mc doc/m4/%{name}-sendmail-8.12.9-cyrusv2.m4

# enable/disable idled in .conf files to prevent error messages
%if %{IDLED}
  %{__perl} -pi -e "s/#  idled/  idled/" %{_confdir}/*.conf
%else
  %{__perl} -pi -e "s/  idled/#  idled/" %{_confdir}/*.conf
%endif

%install
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

# This hack is needed on RedHat > 7.3 to install the perl files correctly
%if %{_perlhack}
pushd perl/imap
  %{__perl} Makefile.PL PREFIX=%{buildroot}%{_prefix}
popd
pushd perl/sieve/managesieve
  %{__perl} Makefile.PL PREFIX=%{buildroot}%{_prefix}
popd

# Do what the regular make install does
  %{__make} install DESTDIR=%{buildroot} PREFIX=%{_prefix} mandir=%{_mandir}
  %{__make} -C man install DESTDIR=%{buildroot} PREFIX=%{_prefix} mandir=%{_mandir}
%else
  %{__make} install DESTDIR=%{buildroot} PREFIX=%{buildroot}%{_prefix} mandir=%{_mandir}
  %{__make} -C man install DESTDIR=%{buildroot} PREFIX=%{buildroot}%{_prefix} mandir=%{_mandir}
%endif

%if %{DEL_WRAP}
%{__install} -m 2755 deliver-wrapper	%{buildroot}%{_cyrexecdir}/
%endif
%{__install} -m 755 imtest/imtest	%{buildroot}%{_cyrexecdir}/
%{__install} -m 755 perl/imap/cyradm	%{buildroot}%{_cyrexecdir}/

# Install tools
for tool in tools/* ; do
  test -f ${tool} && %{__install} -m 755 ${tool} %{buildroot}%{_cyrexecdir}/
done

# Create directories
%{__install} -d \
  %{buildroot}%{_sysconfdir}/{rc.d/init.d,logrotate.d,pam.d,sysconfig,cron.daily} \
  %{buildroot}%{_libdir}/sasl \
  %{buildroot}%{_bindir} \
  %{buildroot}%{_spooldata} \
  %{buildroot}%{_vardata}/{user,quota,proc,log,msg,socket,db,sieve,rpm,backup} \
  %{buildroot}%{_datadir}/%{name}/rpm \
  %{_contribdir}

# Install additional files
%{__install} -m 755 %{SOURCE13}   %{buildroot}%{_cyrexecdir}/cvt_cyrusdb_all
%if %{GROUPCACHE}
%{__install} -m 755 %{SOURCE32}   %{buildroot}%{_cyrexecdir}/upd_groupcache
%endif
%{__install} -m 755 %{SOURCE28}   %{buildroot}%{_cyrexecdir}/rpm_set_permissions
%{__install} -m 644 %{SOURCE14}   %{buildroot}%{_datadir}/%{name}/rpm/magic
%{__install} -m 644 %{SOURCE10}   %{buildroot}%{_datadir}/%{name}/rpm/db.cfg
%{__install} -m 644 %{SOURCE15}   %{_contribdir}/imapcreate
%{__install} -m 644 %{SOURCE16}   %{_contribdir}/cyrus_ldap_quota
%{__install} -m 644 %{SOURCE17}   %{_contribdir}/batchreconstruct
%{__install} -m 644 %{SOURCE18}   %{_contribdir}/bsd2cyrus
%{__install} -m 644 %{SOURCE19}   %{_contribdir}/cpmsg
%{__install} -m 644 %{SOURCE20}   %{_contribdir}/folderxfer
%{__install} -m 644 %{SOURCE21}   %{_contribdir}/inboxfer
%{__install} -m 644 %{SOURCE22}   %{_contribdir}/
%{__install} -m 644 %{SOURCE30}   %{_contribdir}/README

# Install config files
%{__install} -m 644 %{_cyrusconf} %{buildroot}%{_sysconfdir}/cyrus.conf
%{__install} -m 644 %{SOURCE6}    %{buildroot}%{_sysconfdir}/imapd.conf
%{__install} -m 644 %{SOURCE7}    %{buildroot}%{_sysconfdir}/pam.d/pop
%{__install} -m 644 %{SOURCE7}    %{buildroot}%{_sysconfdir}/pam.d/imap
%{__install} -m 644 %{SOURCE7}    %{buildroot}%{_sysconfdir}/pam.d/sieve
%{__install} -m 644 %{SOURCE7}    %{buildroot}%{_sysconfdir}/pam.d/mupdate
%{__install} -m 644 %{SOURCE7}    %{buildroot}%{_sysconfdir}/pam.d/lmtp
%{__install} -m 644 %{SOURCE7}    %{buildroot}%{_sysconfdir}/pam.d/nntp
%{__install} -m 644 %{SOURCE12}   %{buildroot}%{_sysconfdir}/sysconfig/%{name}
%{__install} -m 644 %{SOURCE5}    %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
%{__install} -m 755 %{SOURCE25}   %{buildroot}%{_sysconfdir}/cron.daily/%{name}
%{__install} -m 755 %{SOURCE11}   %{buildroot}%{_sysconfdir}/rc.d/init.d/%{name}

# Install templates
%{__install} -m 755 -d doc/conf
%{__install} -m 644 %{_confdir}/*.conf doc/conf/

# Rename 'master' binary and manpage to avoid crash with postfix
%{__mv} -f %{buildroot}%{_cyrexecdir}/master         %{buildroot}%{_cyrexecdir}/cyrus-master
%{__mv} -f %{buildroot}%{_mandir}/man8/master.8      %{buildroot}%{_mandir}/man8/cyrus-master.8
%{__mv} -f doc/man/master.8.html                     doc/man/cyrus-master.8.html
%{__perl} -pi -e 's/master/cyrus-master/g'           %{buildroot}%{_mandir}/man8/cyrus-master.8
%{__perl} -pi -e 's/Master/Cyrus-master/g'           %{buildroot}%{_mandir}/man8/cyrus-master.8
%{__perl} -pi -e 's/MASTER/CYRUS-MASTER/g'           %{buildroot}%{_mandir}/man8/cyrus-master.8
%{__perl} -pi -e 's/master/cyrus-master/g'           doc/man/cyrus-master.8.html
%{__perl} -pi -e 's/Master/Cyrus-master/g'           doc/man/cyrus-master.8.html
%{__perl} -pi -e 's/MASTER/CYRUS-MASTER/g'           doc/man/cyrus-master.8.html

# Rename 'fetchnews' binary and manpage to avoid crash with leafnode
%{__mv} -f %{buildroot}%{_cyrexecdir}/fetchnews      %{buildroot}%{_cyrexecdir}/cyrfetchnews
%{__mv} -f %{buildroot}%{_mandir}/man8/fetchnews.8   %{buildroot}%{_mandir}/man8/cyrfetchnews.8
%{__mv} -f doc/man/fetchnews.8.html                  doc/man/cyrfetchnews.8.html
%{__perl} -pi -e 's/fetchnews/cyrfetchnews/g'        %{buildroot}%{_mandir}/man8/cyrfetchnews.8
%{__perl} -pi -e 's/Fetchnews/Cyrfetchnews/g'        %{buildroot}%{_mandir}/man8/cyrfetchnews.8
%{__perl} -pi -e 's/FETCHNEWS/CYRFETCHNEWS/g'        %{buildroot}%{_mandir}/man8/cyrfetchnews.8
%{__perl} -pi -e 's/fetchnews/cyrfetchnews/g'        doc/man/cyrfetchnews.8.html
%{__perl} -pi -e 's/Fetchnews/Cyrfetchnews/g'        doc/man/cyrfetchnews.8.html
%{__perl} -pi -e 's/FETCHNEWS/CYRFETCHNEWS/g'        doc/man/cyrfetchnews.8.html

# Create symlinks
%{__ln_s} -f %{_exec_prefix}/lib/%{name}/cyradm %{buildroot}%{_bindir}/
%{__ln_s} -f %{_exec_prefix}/lib/%{name}/imtest %{buildroot}%{_bindir}/

# Create filelist for perl package, compress manpages before
[ -x /usr/lib/rpm/brp-compress ] && /usr/lib/rpm/brp-compress
find %{buildroot}%{perl_sitearch}/Cyrus %{buildroot}%{perl_sitearch}/auto/Cyrus -type f -print |
  %{__sed} "s@^%{buildroot}@@g" |
  %{__grep} -v perllocal.pod |
  %{__grep} -v "\.packlist" > perl-Cyrus-%{version}-filelist
find %{buildroot}%{_perl_man3dir} -type f -name "Cyrus*" -print |
  %{__sed} "s@^%{buildroot}@@g" >> perl-Cyrus-%{version}-filelist
if [ "$(%{__cat} perl-Cyrus-%{version}-filelist)X" = "X" ] ; then
  echo "ERROR: EMPTY FILE LIST"
  exit -1
fi

# Strip binaries
%{__strip} --strip-unneeded %{buildroot}%{_cyrexecdir}/* ||:

# Remove installed but not packaged files
%{__rm} -f %{buildroot}%{_cyrexecdir}/not-mkdep
%{__rm} -f %{buildroot}%{_cyrexecdir}/config2header
%{__rm} -f %{buildroot}%{_cyrexecdir}/config2man
%{__rm} -f %{buildroot}%{_cyrexecdir}/pop3proxyd
find %{buildroot} -name "perllocal.pod" -exec %{__rm} -f {} \;
find %{buildroot} -name ".packlist" -exec %{__rm} -f {} \;
%if !%{IDLED}
%{__rm} -f %{buildroot}%{_mandir}/man8/idled.8*
%{__rm} -f doc/man/idled.8.html
%endif

# On RedHat 7.3, this file is created here
%{__rm} -f /perllocal.pod

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%pre
# Create 'cyrus' user on target host
%if %{SASLGROUP}
/usr/sbin/groupadd -g %{gid} -r %{_saslgroup} 2> /dev/null || :
/usr/sbin/useradd -c "Cyrus IMAP Server" -d %{_vardata} -g %{_cyrusgroup} \
  -G %{_saslgroup} -s /bin/bash -u %{uid} -r %{_cyrususer} 2> /dev/null || :
%else
/usr/sbin/useradd -c "Cyrus IMAP Server" -d %{_vardata} -g %{_cyrusgroup} \
  -s /bin/bash -u %{uid} -r %{_cyrususer} 2> /dev/null || :
%endif
# Let postun know whether cyrus-imapd was running
if [ -e /var/lock/subsys/cyrus-imapd ]; then
  /sbin/service %{name} stop >/dev/null 2>&1 || :
  touch /var/lock/subsys/cyrus-imapd
fi

%post
/sbin/chkconfig --add %{name}

# Create SSL certificates
exec > /dev/null 2> /dev/null
if [ ! -f %{_datadir}/ssl/certs/%{name}.pem ]; then
pushd %{_datadir}/ssl/certs
umask 077
%{__cat} << EOF | make %{name}.pem
--
SomeState
SomeCity
SomeOrganization
SomeOrganizationalUnit
localhost.localdomain
root at localhost.localdomain
EOF
%{__chown} root.%{_cyrusgroup} %{name}.pem
%{__chmod} 640 %{name}.pem
popd
fi

# Force synchronous updates, usually only on ext2 filesystems
for i in %{_vardata}/{user,quota} %{_spooldata}
do
%if %{FORCESYNCEXT3}
  if [ $(find $i -maxdepth 0 -printf %%F) = "ext2" -o $(find $i -maxdepth 0 -printf %%F) = "ext3" ]; then
%else
  if [ $(find $i -maxdepth 0 -printf %%F) = "ext2" ]; then
%endif
    chattr -R +S $i 2>/dev/null
  fi
done

# "ctl_deliver -E" is deprecated, now is "cyr_expire -E"
if grep -q "ctl_deliver *-E" %{_sysconfdir}/cyrus.conf ; then
  %{__perl} -pi -e "s/ctl_deliver *-E/cyr_expire -E/" %{_sysconfdir}/cyrus.conf
fi

# prevent idled related errors to show up
%if %{IDLED}
  if grep -q "^#  idled" %{_sysconfdir}/cyrus.conf ; then
    %{__perl} -pi -e "s/^#  idled/  idled/" %{_sysconfdir}/cyrus.conf
  fi
%else
  if grep -q "^  idled" %{_sysconfdir}/cyrus.conf ; then
    %{__perl} -pi -e "s/^  idled/#  idled/" %{_sysconfdir}/cyrus.conf
  fi
%endif

%preun
if [ $1 = 0 ]; then
  /sbin/service %{name} stop >/dev/null 2>&1 || :
  /sbin/chkconfig --del %{name}
  %{__rm} -f %{_vardata}/socket/lmtp 2> /dev/null
fi

%postun
if [ $1 = 0 ]; then
  /usr/sbin/userdel %{_cyrususer} 2> /dev/null || :
%if %{SASLGROUP}
  if [ "$(%{__grep} ^%{_saslgroup}: %{_sysconfdir}/group | cut -d: -f4-)" = "" ]; then
    /usr/sbin/groupdel %{_saslgroup} 2> /dev/null || :
  fi
%endif
else
  /sbin/service %{name} condrestart >/dev/null 2>&1 || :
fi

%files
%defattr(0644,root,root,0755)
%config(noreplace) %{_sysconfdir}/cyrus.conf
%config(noreplace) %{_sysconfdir}/imapd.conf
%attr(0755,root,root) %config %{_sysconfdir}/rc.d/init.d/%{name}
%config %{_sysconfdir}/logrotate.d/%{name}
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%config(noreplace) %{_sysconfdir}/pam.d/pop
%config(noreplace) %{_sysconfdir}/pam.d/imap
%config(noreplace) %{_sysconfdir}/pam.d/sieve
%config(noreplace) %{_sysconfdir}/pam.d/lmtp
%attr(0755,root,root) %config %{_sysconfdir}/cron.daily/%{name}
%dir %{_cyrexecdir}
%attr(0755,root,root) %{_cyrexecdir}/arbitron
%attr(0755,root,root) %{_cyrexecdir}/arbitronsort.pl
%attr(0755,root,root) %{_cyrexecdir}/chk_cyrus
%attr(0755,root,root) %{_cyrexecdir}/convert-sieve.pl
%attr(0755,root,root) %{_cyrexecdir}/ctl_cyrusdb
%attr(0755,root,root) %{_cyrexecdir}/ctl_deliver
%attr(0755,root,root) %{_cyrexecdir}/ctl_mboxlist
%attr(0755,root,root) %{_cyrexecdir}/cvt_cyrusdb
%attr(0755,root,root) %{_cyrexecdir}/cyr_expire
%attr(0755,root,root) %{_cyrexecdir}/cyrdump
%attr(0755,root,root) %{_cyrexecdir}/cyrus-master
%attr(0755,root,root) %{_cyrexecdir}/deliver
%attr(0755,root,root) %{_cyrexecdir}/dohash
%attr(0755,root,root) %{_cyrexecdir}/fud
%attr(0755,root,root) %{_cyrexecdir}/imapd
%attr(0755,root,root) %{_cyrexecdir}/ipurge
%attr(0755,root,root) %{_cyrexecdir}/lmtpd
%attr(0755,root,root) %{_cyrexecdir}/masssievec
%attr(0755,root,root) %{_cyrexecdir}/mbexamine
%attr(0755,root,root) %{_cyrexecdir}/mbpath
%attr(0755,root,root) %{_cyrexecdir}/mkimap
%attr(0755,root,root) %{_cyrexecdir}/mknewsgroups
%attr(0755,root,root) %{_cyrexecdir}/notifyd
%attr(0755,root,root) %{_cyrexecdir}/pop3d
%attr(0755,root,root) %{_cyrexecdir}/quota
%attr(0755,root,root) %{_cyrexecdir}/reconstruct
%attr(0755,root,root) %{_cyrexecdir}/rehash
%attr(0755,root,root) %{_cyrexecdir}/sievec
%attr(0755,root,root) %{_cyrexecdir}/smmapd
%attr(0755,root,root) %{_cyrexecdir}/squatter
%attr(0755,root,root) %{_cyrexecdir}/timsieved
%attr(0755,root,root) %{_cyrexecdir}/tls_prune
%attr(0755,root,root) %{_cyrexecdir}/translatesieve
%attr(0755,root,root) %{_cyrexecdir}/undohash
%attr(0755,root,root) %{_cyrexecdir}/upgradesieve
%attr(0755,root,root) %{_cyrexecdir}/cvt_cyrusdb_all
%if %{GROUPCACHE}
%attr(0755,root,root) %{_cyrexecdir}/upd_groupcache
%endif
%attr(0755,root,root) %{_cyrexecdir}/rpm_set_permissions
%if %{IDLED}
%attr(0755,root,root) %{_cyrexecdir}/idled
%endif
%if %{AUTOCREATE}
%attr(0755,root,root) %{_cyrexecdir}/compile_sieve
%endif
%if %{DEL_WRAP}
%attr(2755,%{_cyrususer},%{_cyrusgroup}) %{_cyrexecdir}/deliver-wrapper
%endif
%attr(0750,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}
%attr(0750,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/socket
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/user
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/quota
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/proc
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/log
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/msg
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/db
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/sieve
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/rpm
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_vardata}/backup
%attr(0700,%{_cyrususer},%{_cyrusgroup}) %dir %{_spooldata}
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/rpm
%{_datadir}/%{name}/rpm/*
%{_mandir}/man5/*
%{_mandir}/man8/*
%doc COPYRIGHT README
%doc doc/*

%files murder
%defattr(0644,root,root,0755)
%config(noreplace) %{_sysconfdir}/pam.d/mupdate
%attr(0755,root,root) %{_cyrexecdir}/lmtpproxyd
%attr(0755,root,root) %{_cyrexecdir}/mupdate
%attr(0755,root,root) %{_cyrexecdir}/proxyd

%files nntp
%defattr(0644,root,root,0755)
%config(noreplace) %{_sysconfdir}/pam.d/nntp
%attr(0755,root,root) %{_cyrexecdir}/cyrfetchnews
%attr(0755,root,root) %{_cyrexecdir}/nntpd

%files devel
%defattr(0644,root,root,0755)
%{_includedir}/cyrus
%{_libdir}/lib*.a
%{_mandir}/man3/imclient.3*

%files -n perl-Cyrus -f perl-Cyrus-%{version}-filelist
%defattr(-,root,root)
%doc perl/imap/README
%doc perl/imap/Changes
%doc perl/imap/examples

%files utils
%defattr(0644,root,root,0755)
%attr(0755,root,root) %{_cyrexecdir}/cyradm
%attr(0755,root,root) %{_cyrexecdir}/imtest
%attr(0755,root,root) %{_cyrexecdir}/mupdate-loadgen.pl
%attr(0755,root,root) %{_bindir}/*
%{_mandir}/man1/*

%changelog
* Fri Apr 15 2005 John Dennis <jdennis at redhat.com> - 2.2.12-1.2.fc4
- fix debug_package macro, it was still being expanded,
  comments don't hide macro expansion
- fix changelog chronological order
- fix bug 118832, cyrus-imapd is modifying /etc/services

* Mon Apr  4 2005 John Dennis <jdennis at redhat.com> - 2.2.12-1.1.fc4
- bring up to 2.2.12, includes security fix for CAN-2005-0546

* Fri Mar  4 2005 John Dennis <jdennis at redhat.com> - 2.2.10-11.4.fc4
- fix gcc4 build problems

* Thu Mar  3 2005 John Dennis <jdennis at redhat.com> 2.2.10-11.3.fc4
- bump rev for build

* Mon Feb 14 2005 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.12
- updated autocreate and autosievefolder patches

* Fri Feb 11 2005 John Dennis <jdennis at redhat.com> - 2.2.10-11.2.fc4
- make _contribdir identical to Simon's,
  I had been getting burned by rpm's bizarre handling of macros in comments

* Thu Feb 10 2005 John Dennis <jdennis at redhat.com> - 2.2.10-11.1.fc4
- bring up to date with Simon Matter's 2.2.10-11 rpm

* Sat Feb 05 2005 Simon Matter <simon.matter at invoca.ch>
- updated autosievefolder patch

* Tue Feb 01 2005 Simon Matter <simon.matter at invoca.ch>
- remove special ownership and permissions from deliver
- enable deliver-wrapper per default
- enable OutlookExpress seenstate patch per default

* Wed Jan 19 2005 Simon Matter <simon.matter at invoca.ch>
- updated autocreate patch

* Fri Jan 14 2005 Simon Matter <simon.matter at invoca.ch>
- spec file cleanup

* Tue Jan 11 2005 Simon Matter <simon.matter at invoca.ch>
- updated autocreate patch

* Fri Jan 07 2005 Simon Matter <simon.matter at invoca.ch>
- moved contrib dir into doc, made scripts not executable

* Thu Jan 06 2005 Simon Matter <simon.matter at invoca.ch>
- added more fixes to the autocreate patch
- don't use %_libdir for %_cyrexecdir, it's a mess on x86_64
- don't use %_libdir for symlinks
- remove %_libdir pachtes
- change pam configs to work on x86_64
- changed default build option for IDLED to on
- changed rpm_set_permissions to honor partitions in /etc/imapd.conf

* Tue Jan 04 2005 Simon Matter <simon.matter at invoca.ch>
- updated autocreate patch

* Mon Dec 20 2004 Simon Matter <simon.matter at invoca.ch>
- remove idled docs when disabled, fixes RedHat's bug #142345

* Fri Dec 17 2004 Simon Matter <simon.matter at invoca.ch>
- removed allnumeric patch, not needed anymore
- made groupcache a compile time option
- rename nntp's pam service, fixes RedHat's bug #142672

* Thu Dec 16 2004 Simon Matter <simon.matter at invoca.ch>
- updated groupcache patch
- updated cvt_cyrusdb_all to use runuser instead of su if available
- added upd_groupcache tool

* Wed Dec 15 2004 Simon Matter <simon.matter at invoca.ch>
- added groupfile patch to help those using nss_ldap

* Thu Dec 02 2004 Simon Matter <simon.matter at invoca.ch>
- modified config directives and removed verify options

* Thu Dec  2 2004 John Dennis <jdennis at redhat.com> 2.2.10-3.devel
- fix bug #141673, dup of bug #141470
  Also make cyrus.conf noreplace in addition to imapd.conf
  Remove the verify overrides on the noreplace config files,
  we do want config file changes visible when verifying

* Wed Dec  1 2004 John Dennis <jdennis at redhat.com> 2.2.10-2.devel
- fix bug #141470, make imapd.conf a noreplace config file

* Wed Dec  1 2004 John Dennis <jdennis at redhat.com> 2.2.10-1.devel
- update to Simon Matter's 2.2.10 RPM,
  fixes bug #139382, 
  security advisories: CAN-2004-1011 CAN-2004-1012 CAN-2004-1013 CAN-2004-1015

* Tue Nov 24 2004 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.10

* Tue Nov 23 2004 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.9

* Fri Nov 19 2004 Simon Matter <simon.matter at invoca.ch>
- changed scripts to use runuser instead of su if available

* Thu Nov 18 2004 Simon Matter <simon.matter at invoca.ch>
- changed requirement for file >= 3.35-1 from BuildPrereq to
  Requires, fixes RedHat's bug #124991
- added acceptinvalidfrom patch to fix RedHat's bug #137705

* Mon Oct 4 2004 Dan Walsh <dwalsh at redhat.com> 2.2.6-2.FC3.6
- Change cyrus init scripts and cron job to use runuser instead of su

* Fri Aug  6 2004 John Dennis <jdennis at redhat.com> 2.2.6-2.FC3.5
- remove obsoletes tag, fixes bugs #127448, #129274

* Wed Aug  4 2004 John Dennis <jdennis at redhat.com>
- replace commas in release field with dots, bump build number

* Tue Aug 03 2004 Simon Matter <simon.matter at invoca.ch>
- fixed symlinks for x86_64, now uses the _libdir macro
  reported by John Dennis, fixes RedHat's bug #128964
- removed obsoletes tag, fixes RedHat's bugs #127448, #129274

* Mon Aug  2 2004 John Dennis <jdennis at redhat.com> 2.2.6-2,FC3,3
- fix bug #128964, lib symlinks wrong on x86_64

* Thu Jul 29 2004 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.8

* Thu Jul 29 2004 Simon Matter <simon.matter at invoca.ch>
- updated autocreate and autosieve patches
- made authorization a compile time option
- added sieve-bc_eval patch

* Tue Jul 27 2004 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.7
- modified autocreate patch or 2.2.7
- removed snmpargs patch which was needed for RedHat 6.2

* Tue Jul 13 2004 Simon Matter <simon.matter at invoca.ch>
- added mboxlist / mboxname patches from CVS

* Tue Jul 06 2004 Simon Matter <simon.matter at invoca.ch>
- updated rmquota+deletemailbox patch

* Sat Jul  3 2004 John Dennis <jdennis at redhat.com> - 2.2.6-2,FC3,1
- bring up to date with Simon Matter's latest upstream rpm 2.2.6-2
- comment out illegal tags Packager, Vendor, Distribution
  build for FC3

* Wed Jun 30 2004 Simon Matter <simon.matter at invoca.ch>
- added quota patches from CVS

* Fri Jun 25 2004 Simon Matter <simon.matter at invoca.ch>
- updated autocreate patch

* Fri Jun 18 2004 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.6

* Fri Jun 11 2004 Simon Matter <simon.matter at invoca.ch>
- updated autocreate and autosieve patches

* Tue Jun 01 2004 Simon Matter <simon.matter at invoca.ch>
- updated autocreate, autosieve and rmquota patches
- fixed rmquota patch to build on gcc v3.3.x
- added lmtp_sieve patch

* Sat May 29 2004 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.5

* Fri May 28 2004 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.5 pre-release

* Mon May 24 2004 Simon Matter <simon.matter at invoca.ch>
- added hash patch to fix a sig11 problem
- added noncritical typo patch

* Fri May 21 2004 Simon Matter <simon.matter at invoca.ch>
- include OutlookExpress seenstate patch
- fixed allnumeric patch

* Thu May 20 2004 Simon Matter <simon.matter at invoca.ch>
- don't enable cyrus-imapd per default
- rename fetchnews to cyrfetchnews to avoid namespace conflicts with leafnode
- replace fetchnews with cyrfetchnews in man pages
- replace master with cyrus-master in man pages

* Tue May 18 2004 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.4

* Fri Apr 30 2004 Simon Matter <simon.matter at invoca.ch>
- Don't provides: imap

* Wed Mar 17 2004 Simon Matter <simon.matter at invoca.ch>
- fix init script

* Thu Mar 04 2004 Simon Matter <simon.matter at invoca.ch>
- strip binaries

* Tue Mar 02 2004 Simon Matter <simon.matter at invoca.ch>
- add more SELinux fixes

* Wed Feb 25 2004 Simon Matter <simon.matter at invoca.ch>
- add makedepend to path, thank you Andreas Piesk for reporting it

* Mon Feb 23 2004 Dan Walsh <dwalsh at redhat.com>
- change su within init script to get input from /dev/null
  this prevents hang when running in SELinux
- don't use -fpie as default, it breaks different distributions

* Thu Feb 19 2004 Simon Matter <simon.matter at invoca.ch>
- merged in most changes from Karsten Hopp's RedHat package
- fixed permissions of files in contrib, thank you
  Edward Rudd for reporting it.
- modified snmp patch to make it build on RedHat 6.2 again

* Tue Feb 03 2004 Karsten Hopp <karsten at redhat.de>
- switch to Simon Matter's cyrus-imapd package, which has
  some major improvements over the old Red Hat package.
  - configdirectory moved from /var/imap to /var/lib/imap
  - sasl_pwcheck_method changed to saslauthd
- needed to delete package/vendor tags for buildsystem.
- added USEPIE variable for linking with -fpie flag
- removed rpath from linker arguments
- removed email header from README.HOWTO-recover-mailboxes
- added lib64 patch
- use CFLAGS from specfile in imtest subdir
- disable -pie on ppc for now

* Tue Feb 03 2004 Simon Matter <simon.matter at invoca.ch>
- added tls_ca_file: to imapd.conf
- updated autocreate patch which fixes a small sig11 problem

* Thu Jan 29 2004 Simon Matter <simon.matter at invoca.ch>
- convert sieve scripts to UTF-8 only if sievec failed before
- add note to the readme about limiting loggin on busy servers
- added build time option to chose the syslog facility

* Wed Jan 28 2004 Simon Matter <simon.matter at invoca.ch>
- sieve scripts are now converted to UTF-8 with cvt_cyrusdb_all

* Tue Jan 27 2004 Simon Matter <simon.matter at invoca.ch>
- fixed problems with masssievec
- lots of small fixes in the init scripts

* Fri Jan 23 2004 Simon Matter <simon.matter at invoca.ch>
- updated auto db converting functionality
- added auto masssievec functionality

* Thu Jan 22 2004 Simon Matter <simon.matter at invoca.ch>
- updated autocreate/autosievefolder patches

* Fri Jan 16 2004 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.3

* Wed Jan 14 2004 Simon Matter <simon.matter at invoca.ch>
- number of mailbox list dumps can now be configured

* Fri Jan 01 2004 Simon Matter <simon.matter at invoca.ch>
- updated autosievefolder patch

* Thu Dec 18 2003 Simon Matter <simon.matter at invoca.ch>
- updated autocreate/autosievefolder/rmquota patches

* Tue Oct 28 2003 Simon Matter <simon.matter at invoca.ch>
- updated to 2.2.2-BETA

* Tue Aug 05 2003 Simon Matter <simon.matter at invoca.ch>
- add sendmail m4 macro, some people were looking for it
- just one source for pam default configuration (they were all the same)
- added /etc/pam.d/lmtp
- added build support for RedHat Beta severn

* Wed Jul 30 2003 Simon Matter <simon.matter at invoca.ch>
- updated autocreate patch to 0.8.1
- removed creation of spool/config dirs, not needed anymore
- added cyrus_sharedbackup to contrib

* Fri Jul 18 2003 Simon Matter <simon.matter at invoca.ch>
- modified for 2.2.1-BETA

* Wed Jul 09 2003 Simon Matter <simon.matter at invoca.ch>
- modified rpm_set_permissions script

* Mon Jul 07 2003 Simon Matter <simon.matter at invoca.ch>
- changed permissions on config and spool dirs
- modified init script

* Thu Jul 03 2003 Simon Matter <simon.matter at invoca.ch>
- upgraded to 2.1.14
- removed now obsolete forcedowncase patch
- use --with-extraident to add extra version information
- updated munge8bit patch

* Wed Jun 04 2003 Simon Matter <simon.matter at invoca.ch>
- added RedHat 2.1ES support to the perlhack detection

* Tue May 20 2003 Simon Matter <simon.matter at invoca.ch>
- upgraded autocreate patch

* Fri May 09 2003 Simon Matter <simon.matter at invoca.ch>
- upgraded autocreate patch
- modified init script

* Mon May 05 2003 Simon Matter <simon.matter at invoca.ch>
- upgraded to 2.1.13
- replaced commands with macros, cleaned up spec file

* Fri May 02 2003 Simon Matter <simon.matter at invoca.ch>
- added murder subpackage
- changed exec path to /usr/lib/cyrus-imapd

* Thu May 01 2003 Simon Matter <simon.matter at invoca.ch>
- included modified munge8bit patch again

* Tue Apr 29 2003 Simon Matter <simon.matter at invoca.ch>
- added new 8bit header patch
- upgraded IPv6 patch
- upgraded autocreate patch to 0.7

* Mon Apr 28 2003 Simon Matter <simon.matter at invoca.ch>
- added new autocreate patch

* Mon Mar 31 2003 H-E Sandstrom <hes at mailcore.net>
- added munge8bit patch

* Mon Mar 24 2003 Simon Matter <simon.matter at invoca.ch>
- added createonpost fix patch

* Thu Mar 20 2003 Simon Matter <simon.matter at invoca.ch>
- added functionality to patch the IPv6 patch on the fly if
  autoconf > 2.13, we can now use newer autoconf again.

* Tue Mar 18 2003 Paul Bender <pbender at qualcomm.com>
- fixed spec file so that autoconf 2.13 will always be used,
  since the IPv6 patch requires autoconf <= 2.13

* Fri Mar 14 2003 Simon Matter <simon.matter at invoca.ch>
- fixed problems with new file package

* Thu Mar 13 2003 Simon Matter <simon.matter at invoca.ch>
- added kerberos include for RedHat Beta phoebe 2
- added Henrique's forcedowncase patch

* Mon Mar 03 2003 Simon Matter <simon.matter at invoca.ch>
- corrected imapd.conf

* Sat Mar 01 2003 Simon Matter <simon.matter at invoca.ch>
- added note about lmtp socket in sendmail
- added flock patches

* Fri Feb 07 2003 Simon Matter <simon.matter at invoca.ch>
- added build time option for fulldirhash

* Wed Feb 05 2003 Simon Matter <simon.matter at invoca.ch>
- added IPV6 patch to source rpm
- fixed build on RedHat 6.2

* Tue Feb 04 2003 Simon Matter <simon.matter at invoca.ch>
- update to 2.1.12
- added logrotate entry for /var/log/auth.log
- modified init script to use builtin daemon mode

* Fri Jan 10 2003 Simon Matter <simon.matter at invoca.ch>
- small change in mboxlist backup script

* Fri Jan 10 2003 Simon Matter <simon.matter at invoca.ch>
- fixed a cosmetic bug in cvt_cyrusdb_all
- added cron.daily job to backup mailboxes.db

* Mon Jan 06 2003 Simon Matter <simon.matter at invoca.ch>
- add more entries to /etc/services

* Wed Jan 01 2003 Simon Matter <simon.matter at invoca.ch>
- include snmpargs patch for build on RedHat 6.2
- added build support for RedHat 6.2

* Mon Dec 30 2002 Simon Matter <simon.matter at invoca.ch>
- removed autoconf hack, not needed anymore
- enabled build on RedHat Beta Phoebe
- added services entry for lmtp
- cleanup spec file

* Thu Dec 26 2002 Simon Matter <simon.matter at invoca.ch>
- removed BuildPrereq for e2fsprogs-devel

* Thu Dec 12 2002 Simon Matter <simon.matter at invoca.ch>
- modified RedHat release detection
- added BuildPrereq for file

* Thu Dec 05 2002 Simon Matter <simon.matter at invoca.ch>
- upgraded to cyrus-imapd 2.1.11
- upgrade IPV6 patch to 20021205

* Thu Nov 28 2002 Simon Matter <simon.matter at invoca.ch>
- Fixed some default attributes

* Thu Nov 28 2002 Troels Arvin <troels at arvin.dk>
- Explicitly changed files-section to
   - use defattr for simple (root-owned 0644) files
   - explictly set root as user/group owner where
     the user/group ownership was previously indicated
     as "-"; this allows building valid packages without
     having to being root when building

* Mon Nov 25 2002 Simon Matter <simon.matter at invoca.ch>
- changed default build option for IDLED to off
- included some useful info in README.*

* Thu Nov 21 2002 Simon Matter <simon.matter at invoca.ch>
- added build time option for IDLED, thank you Roland Pope

* Tue Nov 19 2002 Simon Matter <simon.matter at invoca.ch>
- fixed spec to really use fdatasync patch
- added createonpost patch

* Thu Nov 14 2002 Simon Matter <simon.matter at invoca.ch>
- upgraded to cyrus-imapd 2.1.10
- build without IPv6 support by default

* Tue Nov 12 2002 Simon Matter <simon.matter at invoca.ch>
- fixed db detection in .spec

* Mon Oct 21 2002 Simon Matter <simon.matter at invoca.ch>
- updated cvt_cyrusdb_all script

* Fri Oct 18 2002 Simon Matter <simon.matter at invoca.ch>
- added fdatasync patch

* Thu Oct 03 2002 Simon Matter <simon.matter at invoca.ch>
- add RPM version 4.1 compatibility, which means remove installed
  but not packaged files

* Wed Sep 18 2002 Simon Matter <simix at datacomm.ch>
- added auto db converting functionality
- changed default for MBOXLIST_DB and SEEN_DB to skiplist

* Mon Sep 16 2002 Simon Matter <simix at datacomm.ch>
- remove creation of cyrus user at build time
- added scripts from ftp://kalamazoolinux.org/pub/projects/awilliam/cyrus/

* Mon Sep 02 2002 Simon Matter <simix at datacomm.ch>
- upgraded to cyrus-imapd 2.1.9

* Fri Aug 30 2002 Simon Matter <simix at datacomm.ch>
- included extra ident string

* Thu Aug 29 2002 Simon Matter <simix at datacomm.ch>
- modified path in deliver-wrapper, thank you Richard L. Phipps
- added RedHat 2.1AS support to the perlhack detection
- added build time option to force syncronous updates on ext3

* Wed Aug 28 2002 Simon Matter <simix at datacomm.ch>
- added updated IPv6 patch from Hajimu UMEMOTO

* Wed Aug 28 2002 Simon Matter <simix at datacomm.ch>
- upgraded to cyrus-imapd 2.1.8

* Thu Aug 22 2002 Simon Matter <simix at datacomm.ch>
- included IPv6 patch from Hajimu UMEMOTO

* Wed Aug 21 2002 Simon Matter <simix at datacomm.ch>
- upgraded to cyrus-imapd 2.1.7 because of wrong version info

* Wed Aug 21 2002 Simon Matter <simix at datacomm.ch>
- upgraded to cyrus-imapd 2.1.6

* Mon Aug 19 2002 Simon Matter <simix at datacomm.ch>
- change db version detection, thank you Chris for reporting

* Tue Aug 13 2002 Simon Matter <simix at datacomm.ch>
- fixed autoconf detection

* Mon Aug 12 2002 Simon Matter <simix at datacomm.ch>
- included support for different autoconf versions
- modified the perl build and install process
- made some .spec changes to build on RedHat 7.x and limbo

* Fri Aug 09 2002 Simon Matter <simix at datacomm.ch>
- included sieve matching patch

* Thu Jun 27 2002 Simon Matter <simix at datacomm.ch>
- fixed %post script where %F was expanded to file.file

* Wed Jun 26 2002 Simon Matter <simix at datacomm.ch>
- fixed missing man page

* Tue Jun 25 2002 Simon Matter <simix at datacomm.ch>
- upgraded to cyrus-imapd 2.1.5

* Mon Jun 24 2002 Simon Matter <simix at datacomm.ch>
- added compile time parameters to configure the package based on
  the idea from Luca Olivetti <luca at olivetti.cjb.net>
- make deliver-wrapper a compile time option

* Fri May 02 2002 Simon Matter <simix at datacomm.ch>
- upgraded to cyrus-imapd 2.1.4

* Mon Apr 22 2002 Simon Matter <simix at datacomm.ch>
- small initscript fix

* Fri Mar 08 2002 Simon Matter <simix at datacomm.ch>
- upgraded to cyrus-imapd 2.1.3
- removed some stuff that was cleaned up in the sources
- added compile time options for db backends

* Wed Mar 06 2002 Simon Matter <simix at datacomm.ch>
- removed requires perl-File-Temp for utils package, it's in the RedHat
  perl RPM now

* Fri Feb 22 2002 Simon Matter <simix at datacomm.ch>
- removed deliverdb/db

* Wed Feb 20 2002 Simon Matter <simix at datacomm.ch>
- upgraded to cyrus-imapd 2.1.2

* Mon Feb 11 2002 Simon Matter <simix at datacomm.ch>
- changed sasl_mech_list: PLAIN in /etc/imapd.conf
- added sieve to /etc/pam.d

* Fri Feb 08 2002 Simon Matter <simix at datacomm.ch>
- added requires perl-File-Temp for utils package

* Wed Feb 06 2002 Simon Matter <simix at datacomm.ch>
- added some %dir flags
- removed /usr/lib/sasl/Cyrus.conf
- added conf templates
- build time option for usage of saslauth group

* Tue Feb 05 2002 Simon Matter <simix at datacomm.ch>
- upgraded to cyrus-imapd 2.1.1
- dependency of cyrus-sasl >= 2.1.0-1

* Sun Feb 03 2002 Simon Matter <simix at datacomm.ch>
- saslauth group is only deleted on uninstall if there is no other
  member in this group

* Sat Feb 02 2002 Simon Matter <simix at datacomm.ch>
- changed start/stop level in init file

* Tue Jan 29 2002 Simon Matter <simix at datacomm.ch>
- dependency of cyrus-sasl >= 1.5.24-22
- dotstuffing patch for sendmail calls made by sieve for outgoing
  mails
- patch for ability to force ipurge to traverse personal folders

* Mon Jan 28 2002 Simon Matter <simix at datacomm.ch>
- minor spec file changes

* Sat Jan 19 2002 Simon Matter <simix at datacomm.ch>
- changed default auth to pam
- remove several %dir from %files sections
- change from /usr/lib/cyrus -> /usr/libexec/cyrus
- rename source files to something like cyrus...
- added rehash tool
- changed to hashed spool

* Fri Jan 18 2002 Simon Matter <simix at datacomm.ch>
- fixed init script
- fixed %post section in spec

* Thu Jan 17 2002 Simon Matter <simix at datacomm.ch>
- ready for first build

* Wed Jan 09 2002 Simon Matter <simix at datacomm.ch>
- initial package, with help from other packages out there


--- NEW FILE cyrus-imapd.sysconfig ---
# Options to cyrus-master
CYRUSOPTIONS=""

# Mailbox list dumps are rotated n times via cron.daily
#ROTATE=6


--- NEW FILE cyrus-imapd.upd_groupcache ---
#!/bin/sh

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# This script updates a cache of the unix group database. It's purpose is to
# speedup group authorization when using large groups with slow nss backends.
# For more info consult the README.groupcache file.
#
# This script can safely be run as root, it will reexec itself as user
# cyrus if needed.
#
# author: Simon Matter, Invoca Systems <simon.matter at invoca.ch>

# changelog
# v1.0.0, Dec 15 2004 Simon Matter <simon.matter at invoca.ch>
# - initial release

if [ ! -f /etc/imapd.conf ]; then
  echo "ERROR: configuration file not found."
  exit 1
fi

# fallback to su if runuser not available
if [ -x /sbin/runuser ]; then
  RUNUSER=runuser
else
  RUNUSER=su
fi

# force cyrus user for security reasons
if [ ! $(whoami) = "cyrus" ]; then
  exec $RUNUSER - cyrus -c "cd $PWD < /dev/null ; $0"
fi

# files get mode 0600
umask 166

# get_config [config default]
# extracts config option from config file
get_config() {
  if config=$(grep "^$1" /etc/imapd.conf); then
    echo $config | cut -d: -f2
  else
    echo $2
  fi
}

# where to find files and directories
imap_prefix=$(get_config configdirectory /var/lib/imap)
group_cache=${imap_prefix}/group.cache

TMPCACHE=$(mktemp ${group_cache}.XXXXXX) || exit 1
getent group >> $TMPCACHE
mv -f $TMPCACHE $group_cache


--- NEW FILE cyrus-procmailrc ---
#################################################
# procmailrc
# This is the main procmail file with common SPAM recipes
# Based on the article at
# http://www.ncworldmag.com/ncw-05-1998/ncw-05-imap.html
# 
#
# First we define some basics

PATH=/usr/bin:/bin
SHELL=/bin/sh

# We define DELIVERTO just to prevent a lot of extra
# typing later on.  We define SPAMIT to prevent even more
# repetitive typing, as it's the same action for every user.
# This assumes we set up a SPAM folder right off the INBOX
# for every user on the system.  If we neglect to do that, we'll
# get in a bit of trouble.

DELIVERTO=/usr/cyrus/bin/deliver-wrapper
SPAMIT="$DELIVERTO user.$LOGNAME.SPAM"

# This file includes the appropriate procmail.$LOGNAME
# file so that each user has his or her own recipe techniques
# for subscribed lists, e-mail alerts, etc.

# Before we begin any recipes, let's make a backup
# copy of any incoming mail.
#
# Remember to comment out the next recipe once
# you know everything is working fine, otherwise
# you'll fill up the backup directory very quickly.
# Some procmail tutorials demonstrate how you can
# set a quota on the backup directory so that you can
# leave it in force at all times.

:0 ic
| $DELIVERTO user.$LOGNAME.Backup

###############################
# If there used to be an existing system-wide procmailrc, you can
# include it here
#INCLUDERC=/etc/procmailrc

# We shouldn't be running as a privileged user, but just in case,
# make sure we drop any privileges we have
DROPPRIVS=1

###############################
# If users want to be able to define their own private recipes
# and put them in their home .procmailrc files, comment out
# the next definition.
#
# These recipes will be processed BEFORE the user-specific
# recipes that are kept in the /home/cyrus directory
#
# setup some variables, before we start
ALERTSBOX=user.$LOGNAME.Folders.Alerts
LISTSBOX=user.$LOGNAME.Folders.Lists
#
INCLUDERC=$HOME/.procmailrc

# If you want to define user-specific recipes that
# you manage centrally (perhaps because you don't want
# to allow your users to "roll their own," then
# uncomment the following line.  In this case, you have
# to create a file for each user in the form:
# procmail.username -- for example, procmail.Joe
#
# INCLUDERC=/usr/cyrus/etc/procmail.$LOGNAME

#############################
# Now we begin our recipes

#############################
# Email-specific SPAM recipes
# Here's one example

#### NOTE: surely cyrus 'deliver' does its own locking? There should
#### thus be no need for :0:$LOGNAME.lock

:0
* ^To:.*anyplace at juno.com
| $SPAMIT

#############################
# General SPAM Recipes
# Here are a few examples
#
# The "To:" line doesn't exist

#:0
#* !^To:
#| $SPAMIT

# The "To:" line is empty

#:0
#* ^To: $
#| $SPAMIT

# The "From:" line is empty

#:0
#* ^From: $
#| $SPAMIT

#############################
# All the mail that falls
# through the above recipes
# will be put into the user's
# inbox.  This is always the LAST
# recipe to appear in the file.

:0W
| $DELIVERTO user.$LOGNAME

# If that fails - maybe because the user is out of quota, or the mailbox
# hasn't been created - then force a bounce (otherwise the message would
# get silently appended to /var/spool/mail/$LOGNAME).

# This is EX_CANTCREAT (Can't create output)
EXITCODE=73
:0
/dev/null

#
# End of procmailrc file
##############################


--- NEW FILE cyrus-user-procmailrc.template ---
##############################
# Begin procmailrc.joe file
#
# This is Joe's specific set of procmail
# recipes.  It assumes that Joe has a
# number of specific folders created
# to which these recipes refer.  Otherwise
# the mail cannot be sorted properly.
#
# First, let's define some high-level
# folder macros to save typing later on.
# The ALERTSBOX points to the
# folder where we'll sort out various
# incoming news alerts.
# The LISTSBOX will point to a
# folder where we'll sort out various
# list services to which we're subscribed.
#
# Both ALERTSBOX and LISTSBOX
# are subfolders of a generic folder called,
# duh, Folders, which is right off the
# user's INBOX.
#
# So if a Linux-kernel message comes in
# it gets deposited in the folder
# Folders/Lists/Linux_Kernel which is
# represented in Cyrus IMAP terms as
# user.Joe.Folders.Lists.Linux_kernel
#

############################
# Put anchordesk alerts in news alerts folder

:0:$LOGNAME.lock
* ^From:.*anchordesk
| $DELIVERTO $ALERTSBOX.News-Alerts

# Put NC World alerts in their own folder

:0:$LOGNAME.lock
* ^From:.*NCWorld at FDDS.com
| $DELIVERTO $ALERTSBOX.NCWorld-Alerts

#############################
# List processing & Misc Alerts

:0:$LOGNAME.lock
* (^Cc:|^CC:|^To:|^Sender:).*linux-kernel at vger.rutgers.edu
| $DELIVERTO $LISTSBOX.Linux_Kernel

:0:$LOGNAME.lock
* (^Cc:|^CC:|^To:|^Sender:).*linux-net at vger.rutgers.edu
| $DELIVERTO $LISTSBOX.Linux_Net

#
# End of procmailrc.joe file
##############################



--- NEW FILE cyrus_ldap_quota.pl ---
#!/usr/bin/perl
use Cyrus::IMAP::Admin;

# This script was created by Kevin J. Menard, Jr. <kmenard at wpi.edu>.
# It requires root privileges to write to a file in /etc.  Best use is
# to set this up as cron job.  Works for me.  Hope it does for you.  
# Any questions/complaints/praise/whatever, send 'em to the address
# above.   -- 08/16/2001


# These are the variables you might want to tweak.
my $quota_attr = "mailQuota";
my $mail_attr = "mailRoutingAddress";
my $user = "cyrus";
my $passwd = "blah";

# These are the ones that you shouldn't have to.
my @entries = ();
my $index = 0;
my $counter = 0;
my $old_timestamp = 0;
my $timestamp = "199412161032Z";

# Open the /etc/cyrus_ldap_quota_time file; it's a long name, but
# shouldn't interfere with existing files :)  This file contains 1 line,
# the generalized time format of the last time the script ran.  This is
# used for the search, so we only update quotas that have been modified
# since then.

{
    if (-e "/etc/cyrus_ldap_quota_time")
    {
         open(TIME_FILE, "/etc/cyrus_ldap_quota_time") or die "could not
                              open the time file: $!\n";
     
         while(<TIME_FILE>) { $old_timestamp = $_; }

         close(TIME_FILE);
    }  

    # Now we deal with the case where the file doesn't exist, that is to
    # say the first time the script was run.

    unless ($old_timestamp == 0) { $timestamp = $old_timestamp; }


    # Now that we have that information, we can overwrite the file with
    # the new timestamp.  Maybe this overkill, but this is only a
    # temporary solution anyway.

    open(TIME_FILE, ">/etc/cyrus_ldap_quota_time") or die "could not
                              create file: $!\n";

    my @time = (localtime)[0..5];

    printf TIME_FILE $time[5] + 1900;
    printf TIME_FILE "%02d", $time[4] + 1;
    for (my $i = 3; $i >= 0; $i--) { printf TIME_FILE "%02d", $time[$i];}
    print TIME_FILE 'Z';

    close(TIME_FILE);
}


# This is where we do the search and then parse the results into a
# useable form.  In this case, an arry of hash entries.
{
    # Okay, this very ugly line sets up the LDAP search, and the strips
    # away the meaningless stuff.  This could be prettier, but I didn't 
    # want to add a dependency for an LDAP module, and everyone should
    # have LDAP search.  The greps are just to make things simpler.

    (my $query = "ldapsearch -x '(&(modifyTimestamp>=$timestamp)($quota_attr=*))' $quota_attr $mail_attr 
    | grep -v ^# | grep -v ^dn | grep -v ^version | grep -v ^search | grep -v ^result | grep -v ^\$") =~ s!\n!!;

    # Now actually do the commands in the above line.
    my $result = `$query`;


    # Split the output into an array, one entry per line.
    my @output = split(/\n/, $result);

    # Now go through each line . . .
    foreach (@output)
    {
         # Split on the attribute:value boundary.
         (my $key, my $value) = split(/: /);

         # Handle mailRoutingAddress; strip away everything after '@'.
         if ($value =~ m!@!)
         {
	     ($value, undef) = split (/@/, $value);
         }

         # Add each doctored up attribute:value pair to the entries array.
         $entries[$index]{$key} = $value;

         # A crude hack to make sure each of the two attributes makes it
         # into one of the entries array element.
         if ($counter % 2)
         {
  	     $index++;
         }

         $counter++;
    }
}

# Now here's the actual interaction with Cyrus IMAPd.  It's all pretty
# self-explanatory.
{
     my $imap = Cyrus::IMAP::Admin->new('localhost') or die "imap:
                         cannot connect to server: $!\n";

     $imap->send(undef, undef, "LOGIN %s %s", $user, $passwd) or die
                 "could not send user:pass to the server: $!\n";

     for (my $i = 0; $i <= $#entries; $i++)
     {
          $imap->setquota("user." . $entries[$i]{$mail_attr}, "STORAGE",
                          $entries[$i]{$quota_attr}) 
               or die "imap: could not set quota for
                            user.$entries[$i]{$mail_attr}: $!\n";
     }

     $imap=undef;
}


--- NEW FILE folderxfer ---
#!/usr/bin/perl
#
# Usage:	folderxfer inputfile
#
# Purpose:	Converts contents of Berkeley-format mail folders
#		to Cyrus mailboxes
#
# Input:	Output of 'bsd2cyrus' 
#		(username:Cyrus-folder-name:Berkeley-folder-path)
#
# Warnings:	The root mailbox and empty Cyrus folder must 
#		exist before conversion takes place, and source folders 
#		should be checked for RFC 822 content before being processed
#
#$Id: folderxfer,v 1.1 2004/02/04 12:59:42 karsten Exp $

$pwd       = "/usr/lib/cyrus-imapd";      
$mailstore = "/var/spool/imap";        # Cyrus mailstore
$cat       = "/bin/cat";
$cmd       = "/usr/bin/formail -n 20 -s $pwd/cpmsg";

$folders = "$ARGV[0]";
if (!$folders) { die "Usage: $0 filename"; }

open (MB,"$folders") || die "can't open $folders";

while (<MB>) {

    chop;

    # Be careful with this split - the last token might have
    # whitespace we want to preserve

    ($user,$cyrusfolder,$folder) = split(/:/,$_,3);
    @fields = split(/\./,$cyrusfolder);
    $cyrfol = $fields[$#fields];

    $fcat = "$cat \"$folder\"";
    print $fcat;
    $prefix = substr($user,0,1);
    system ("$fcat | $cmd '$mailstore/$prefix/user/$user/$cyrfol'");
    #print "'$mailstore/$prefix/user/$user/$cyrfol";
}
close MB;




--- NEW FILE imapcreate.pl ---
#!/usr/bin/perl -w
# 
# imapcreate: create IMAP mailboxes with quotas
#			 Reads user names from standard input.
# launch without argument for a short help.
#
# originally found on http://cyrus-utils.sourceforge.net
# (could not find any copyright info, thought)
# 
# enhanced by Clément "nodens" Hermann <clement.hermann at free.fr>
#
# I'd like to consider this as GPL'd (cf www.gnu.org), but won't add any copyright without the original author's consent.
# 

use Getopt::Long;
use Cyrus::IMAP::Admin;
use strict;


my $debug;
my $user;
my $pass;
my $quota;
my @part;
my $useunixhierarchy;
my @mailboxes;
my $delete;
my $cyrus;

sub usage {
  print <<EOU;
imapcreate - create IMAP mailboxes with quotas
  usage:
	imapcreate [-d] [-u user] [-p pass] [-m mailbox1[,mailbox2][,mailbox<n>]] 
	[-q quota] [-t partition:list] [-s] [-v] <server>

Options:
   -t : the partition to use. Default to the \"default\" partition
   -q ; the quota, if a quota is needed. It is normally in KiloBytes, but you can use m,M,g or G suffix to use MB or GB instead, e.g 10k, 2048M or 100g
   -m : a comma-separated mailbox list
   -u : your cyrus admin user (usually cyrus or cyradm)
   -p : your cyrus admin password (if not provided, it will be asked for)
   -s : use the unix hierarchy separator (see imapd.conf(1))
   -d : delete mailboxes instead of creating them
   -v : run in debug mode, and print information on stdout

If no password is submitted with -p, we'll prompt for one.
if no mailbox name is specified with -m, read user names from standard input

  examples: 
	imapcreate -u cyradm -m foo,bar,joe -q 50000 -t p1:p2 mail.testing.umanitoba.ca
	cat list.txt | imapcreate -u cyradm -p 'cyruspass' -q 50M mail.testing.umanitoba.ca
EOU
  exit 1;
}

# Create a mailbox... usage : &CreateMailBox(user,partition[,quota]).
# You have to be authentified already. We use "$cyrus" as the connection name.
# partition can be 'default'
sub CreateMailBox {
	my $mbuser = $_[0];
	my $mbpart = $_[1];
	my $mbquota = $_[2];
	
	print "Creating $mbuser on $mbpart\n" if $debug;
	if ($mbpart eq 'default') {
	$cyrus->createmailbox($mbuser);
	}
	else {
	$cyrus->createmailbox($mbuser, $mbpart);
	}
	warn $cyrus->error if $cyrus->error;
	
	# Set the quota
	if ($mbquota) {
	print "Setting quota for $mbuser to $mbquota\n" if $debug;
	$cyrus->setquota($mbuser, 'STORAGE', $mbquota);
	warn $cyrus->error if $cyrus->error;
	}
}

# Delete a mailbox. Usage: $DeleteMailBox($user)
# Assuming we use $user as the admin.
sub DeleteMailBox {
	my $mbuser = $_[0];
	my $delacl = "c";
	
	print "Deleting $mbuser\n" if $debug;
	$cyrus->setaclmailbox($mbuser, $user, $delacl);
	$cyrus->deletemailbox($mbuser);
	warn $cyrus->error if $cyrus->error;
}

GetOptions("d|delete" => \$delete, "u|user=s" => \$user, "p|pass=s" => \$pass, "m|mailboxes=s" => \@mailboxes, "q|quota=s" => \$quota,
   "t|part=s" => \@part, "s|UnixHierarchy" => \$useunixhierarchy, "v|verbose" => \$debug );
@part = split(/:/, join(':', @part));
push @part, 'default' unless @part;
my $pn = 0;
@mailboxes = split(/,/, join(',', @mailboxes));

my $server = shift(@ARGV) if (@ARGV);
usage unless $server;

# quotas formatting:
if ($quota) {
	if ($quota =~ /^(\d+)([mk]?)$/i) {
		my $numb = $1;
		my $letter = $2;
		if ($letter =~ /^m$/i) {
			$quota = $numb * 1024;
			print "debug: quota=$quota\n" if $debug;
		} elsif ($letter =~ /^k$/i) {
			$quota = $numb;
			print "debug: quota=$quota\n" if $debug;
		} else {
			die "malformed quota: $quota (must be at least one digit eventually followed by m, M, k or K\n";
#			$quota = $numb;
#			print "debug: quota=$quota\n" if $debug;
		}
	} else {
		die "malformed quota: $quota (must be at least one digit eventually followed by m, M, k or K\n";
	}
}

# Authenticate
$cyrus = Cyrus::IMAP::Admin->new($server);
$cyrus->authenticate(-mechanism => 'login', -user => $user,
	 -password => $pass);
die $cyrus->error if $cyrus->error;

# if there isn't any mailbox defined yet, get them from standard input
if (! (defined $mailboxes[0])) { 
	# For all users
	while (<>) {
		chomp;
		my $mbox = $_;
		push @mailboxes, $mbox;
	}
}

# create/delete mailboxes for each user
foreach my $mailbox (@mailboxes) {
	if ($useunixhierarchy) {
	$mailbox = 'user/' . $mailbox;
	} else {
	$mailbox = 'user.' . $mailbox;
	}

	if ($delete) {
		&DeleteMailBox($mailbox)
	} else {
		# Select the partition
		my $pt = $part[$pn];
		$pn += 1;
		$pn = 0 unless $pn < @part;
		&CreateMailBox($mailbox,$pt,$quota)
	}
}



--- NEW FILE inboxfer ---
#!/usr/bin/perl
#
# Usage:	inboxfer inputfile
#
# Purpose:	Transfer messages from Berkeley-format inbox to Cyrus inbox
#
# Input:	Text file containing one username per line
#
# Warning:	Do not use this script to transfer messages into a Cyrus 
#		mailbox that already contain messages. Existing messages 
#		will be overwritten.
#
#$Id: inboxfer,v 1.1 2004/02/04 12:59:42 karsten Exp $

$mailstore = "/var/spool/imap";  # Cyrus mailstore
$oldspool  = "/var/spool/mail";       # Old mail spool
$cat       = "/bin/cat";              # /usr/bin/cat on Solaris
$formail   = "/usr/bin/formail";
$pwd       = "/usr/lib/cyrus-imapd";
$cpmsg     = "cpmsg";               

$cmd       = "$formail -n 20 -s $pwd/$cpmsg";

$users = "$ARGV[0]";
if (!$users) { die "Usage: $0 $users\n"; }

open(USERS,"$users") || die "can't open $users";

while (<USERS>) {
    chop;
    $inbox = "$oldspool/$_";
    $prefix = substr($_,0,1);
    system("$cat $inbox | $cmd $mailstore/$prefix/user/$_");
}




Index: .cvsignore
===================================================================
RCS file: /cvs/extras/rpms/cyrus-imapd/devel/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- .cvsignore	15 Apr 2005 20:21:04 -0000	1.1
+++ .cvsignore	15 Apr 2005 20:24:15 -0000	1.2
@@ -0,0 +1,3 @@
+cyrus-imapd-2.2.12.tar.gz
+cyrus-imapd-README.HOWTO-recover-mailboxes.db
+cyrus_sharedbackup-0.1.tar.gz


Index: sources
===================================================================
RCS file: /cvs/extras/rpms/cyrus-imapd/devel/sources,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- sources	15 Apr 2005 20:21:04 -0000	1.1
+++ sources	15 Apr 2005 20:24:15 -0000	1.2
@@ -0,0 +1,3 @@
+70b3bba526a8d36d3bb23a87d37e9188  cyrus-imapd-2.2.12.tar.gz
+f3d52a0eb84ec6c8a127cd4c1bc6af7b  cyrus-imapd-README.HOWTO-recover-mailboxes.db
+8f7a26b0556369827bb5c8084a3e3ea1  cyrus_sharedbackup-0.1.tar.gz




More information about the fedora-extras-commits mailing list