I'm using Web-Cyradm to maintain the mail server of our small company
(about 25 users). Thanks for the great tool!
I set up amavis to sort junk mail into different mailboxes via
plus-addressing. So I had to create some standard folders for each new
user, and I had to set the ACL 'p' to the user anyone.
So I extended the functionality of the "Standard Folders":
You can define multiple mailboxes and ACLs which shall be set in the
following format:
"<MailboxName> [(UserId UserRights [, UserId UserRights] [...]] [, ...]"
For example the sting
"Junk, Junk/Virus (anyone p), Junk/BadHeader (anyone p, everyone rl),
Junk/Spam, Junk/Banned"
will create the mailbox Junk, the mailbox Junk/Virus with additional ACL
p for user anyone, and so on.
I've tested this with cyrus imapd 2.2.13 (openSUSE 10.2), configured with
unixhierarchysep: yes, altnamespace: yes
I attached the patch.
By the way: the Standard Folders creation does not work if the username
contains upper-case letters (e.g. TestUser1). Must be an authentication
problem, the imap_login as the new created user fails. Usernames in
lowercase (testuser1) work fine. But not a problem for me, may be I'll
have some time to look closer to this later.
Greetings,
Andreas
Index: newaccount.php
===================================================================
--- newaccount.php (revision 838)
+++ newaccount.php (working copy)
@@ -311,24 +311,59 @@
}
$result = $cyr_conn->setacl("user" . $separator .
$username, $CYRUS['ADMIN'], $cyr_conn->allacl);
$result = $cyr_conn->setmbquota("user" . $separator .
$username, $_POST['quota']);
- $AUTOCREATE_MAILBOXES = array();
- if (!empty($folders)) $AUTOCREATE_MAILBOXES =
explode(',',$folders);
- if(sizeof($AUTOCREATE_MAILBOXES) > 0) {
+
+ /*** Auto-Create mailboxes and set ACLs
***********************************************
+ * Format of the folders mailbox creation string:
+ * "<MailboxName> [(UserId UserRights [, UserId
UserRights] [...]] [, ...]"
+ * Example:
+ * "Junk, Junk/Virus (anyone p), Junk/BadHeader (anyone
p, everyone rl), Junk/Spam, Junk/Banned"
+ *
+ */
+ if (!empty($folders)) {
+
+ // split the folder creation string in
different strings for each folder to be created
+ $AUTOCREATE_MAILBOXES = array();
+ $regexp = '#\w[^,\(]+(\()?(?(1)[^\)]+\))#';
+ $numberOfFolders = preg_match_all($regexp, $folders,
$AUTOCREATE_MAILBOXES);
+
//log out of admin, log in as user
$cyr_conn->imap_logout();
- $cyr_conn->imap_login($username,
$_POST['password']);
+ $error = $cyr_conn->imap_login($username,
$_POST['password']);
+ if ($error != 0) {
+ die ("IMAP Error:
".$cyr_conn->geterror());
+ }
+
+ // create each mailbox
+ foreach($AUTOCREATE_MAILBOXES[0] as
$createMailboxCommand) {
+ syslog(LOG_DEBUG, "Create Folder Command
\"$createMailboxCommand\"");
- //create and subscribe to each mailbox listed
in AUTOCREATE_MAILBOXES
- for($i=0; $i < sizeof($AUTOCREATE_MAILBOXES);
$i++) {
- $new_folder =
trim($AUTOCREATE_MAILBOXES[$i]);
+ $numberOfStrings = preg_match_all('#[\w/]+#',
$createMailboxCommand, $strings);
+ if(($numberOfStrings%2) != 1) {
+ echo "Illegal syntax";
+ continue;
+ }
+ $new_folder = trim($strings[0][0]);
//if
(function_exists('mb_convert_encoding')) {
$new_folder =
mb_convert_encoding($new_folder,"UTF7-IMAP",$charset);
//}
-
$cyr_conn->createmb("INBOX".$separator.$new_folder);
- $cyr_conn->command('. subscribe
"INBOX'.$separator.$new_folder.'"');
- }
+
$cyr_conn->createmb(/*"INBOX".$separator.*/$new_folder);
+
+ //$cyr_conn->command('. subscribe
"INBOX'.$separator.$new_folder.'"');
+ $cyr_conn->command('. subscribe
"'.$new_folder.'"');
+
+ syslog(LOG_INFO, "Creating mailbox
\"$new_folder\"");
+
+ for($i = 1; isset($strings[0][$i]) AND
isset($strings[0][$i+1]);) {
+ $userId = $strings[0][$i++];
+ $userRights = $strings[0][$i++];
+
+ $cyr_conn->command('. setacl
"'.$new_folder.'" '.$userId.' '.$userRights);
+ syslog(LOG_INFO, " ACL for user
\"$userId\": set \"$userRights\"");
+ }
+ } // foreach($AUTOCREATE_MAILBOXES[0])
$cyr_conn->imap_logout();
- }
+ } // endif(!empty(...)
+
$_GET['domain'] = $_POST['domain'];
include WC_BASE . "/browseaccounts.php";
} // End of if (empty($_POST['confirmed']))
_______________________________________________
This mailing list is hosted and supported
by bit-heads GmbH | http://www.bit-heads.ch
_______________________________________________
Web-cyradm mailing list
[email protected]
http://www.web-cyradm.org/mailman/listinfo/web-cyradm