Re: Add mailbox automatically

From: Scott Russell (no email)
Date: Wed Jan 01 2003 - 17:32:50 EST


On Wed, Jan 01, 2003 at 05:16:12PM -0500, Kervin L. Pierre wrote:
> Just a thought,
>
> I am working on some PHP scripts to manage mailboxes and I have to use
> passthough calls to execute cyradm to add mailboxes.
>
> I'd like to avoid opening a shell from the web for security and
> performance reasons.
>

Here's a PHP function that I use to create user mailboxes with. It
could use some clean up but it works for us. Beware line wraps.

function imap_acct_create ($mailbox, $quota="") {
    // creates user.$mailbox in cyrus 2.1.5
    global $imap_error;
    $imap = @imap_open("{localhost:143/imap/notls}", "cyrus", "passwd", OP_HALFOPEN);
    if (!$imap) {
        $imap_error = imap_last_error();
        return FALSE;
    }
    // create the new top level mailbox
    $ret = @imap_createmailbox($imap, "{localhost}user.".$mailbox);
    if (!$ret) { $imap_error = imap_last_error();
        @imap_close($imap);
        return FALSE;
    }
    // if needed, set the account quota
    if ($quota != "") {
        $ret = @imap_set_quota($imap, "user.".$mailbox, $quota);
        if (!$ret) { $imap_error = imap_last_error();
        @imap_close($imap); return FALSE; }
    }
    @imap_close($imap);
    // if we get here everything worked
    return TRUE;
}

-- 
  Scott Russell ()
  Linux Technology Center, System Admin, RHCE.
  Dial 877-735-8200 then ask for 919-543-9289 (TTY)







Hosted Email Solutions

Invaluement Anti-Spam DNSBLs



Powered By FreeBSD   Powered By FreeBSD