Hi,

I need help on creation imap mailbox. Im new to php. This is a code where have been created by previous programmer.

if (($USER_REG_IS_LOGIN) && ($tmp_imap_server))
   {
      if (!$user_exist) 
         {
            $form_password = $tmp_emailname . "_1234";
            $request_cmd  = "create_imap_user {$tmp_emailname}     {$tmp_imap_server} $form_password";
            $request_data = UserRegSvr::send_request($socket, $request_cmd);       
            $request_data = unserialize($request_data);                        
      if ($request_data['return_value']['value'])
         {
            $err_msg_txt .= ($err_msg_txt ? "\\n" : "") . $request_data['return_value']['msg'];
          }
          }else
            {
               $err_msg_txt .= ($err_msg_txt ? "\\n" : "") . "Unable to create mailbox. User $tmp_emailname already exist in $tmp_imap_server server";
             }
          }

But this code doesnt seems working... Can any one help me with tht? Thanks.

Thanks in advance,

By,
@--Sheru--@

How is it not working? Are you getting errors, if so what are they?

Try turning on error reporting to max, and set display errors to true.

ie:

error_reporting(E_ALL);
ini_set('display_errors', 1);

Hi... yes the codes are correct. The problem is its working well if its development site but not working for live system.

There is few other codes in source code that i found and try to change but i guess there should be some syntax error. Could anybody help me with that please.

case 'create_imap_user':

if (isset($_SESSION['action'])) { unset($_SESSION['action']); }

if (is_login ()) {
include_once (dirname(__FILE__) . "/" . "user_registration.imap.php");

list ($username, $imap_servername, $DEV, $args) = explode (' ', $args, 4);

fwrite(STDLOG, "Request to create imap mailbox for :" . $username . " in " . $imap_servername . "\n");

     $return = create_imap_user ($username, $imap_servername,
     $uname_pass);

fwrite(STDLOG, "New mailbox created for" . $username . "\n");

} else {
     $return = $not_login_errmsg;
					fwrite(STDLOG, "Cannot created\n");
           }
break;

This is codes for user_registration.imap.php that have been included in there.

function create_imap_user ($username='', $imap_servername='')
{
    $return_value = 0;
    if (!trim($username)) {
        $return_value = 70;
    }

    if (!trim($imap_servername)) {
        $return_value = 75;
    }

    if (!$return_value) {

        $descriptorspec = array(
            0 => array("pipe", "r"), 
            1 => array("pipe", "w"),  
            2 => array("pipe", "w")   
        );
		$uname_pass=$username."_1234";
		$request_cmd = "./createimapuser.php {$username} {$imap_servername} {$uname_pass}";
        $process = proc_open($request_cmd, $descriptorspec, $pipes);
		fwrite(STDLOG, "Mailbox created successfully for :" . $username . " in " . $imap_servername . "\n");
        $tmp_arr = array();

        if (is_resource($process)) {
            fclose($pipes[0]);
			
            $stdout = '';
            while (!feof($pipes[1])) {
                $stdout .= (fread($pipes[1], 1024));
            }
            fclose($pipes[1]);
			
            $stderr = '';
            while (!feof($pipes[2])) {
                $stderr .= (fread($pipes[2], 1024));
            }
            fclose($pipes[2]);
			
            if (strstr(strtoupper($stdout), 'ERROR')) {
                if (strstr($stdout, 'The mailbox already exists in the cyrus imap database')) {
                    $return_value = 76;
                } else {
                    $return_value = 69;
		}
            } else {
                $return_value = proc_close($process);
	    }
        }
    }

    $result           = array();
    $return_value_arr = array ('value'=>$return_value, 'msg'=>$GLOBALS['USER_REG_ERR_MSG'][$return_value]);
	//fwrite(STDLOG, "please wait!!!\n");
    return serialize(array('return_value'=>$return_value_arr, 'result'=>$result));
}

And this is codes for createimapuser.php

$impsvr="{".$imap_servername.":143}";
//$uname_pass=$username."_1234";
$mbox = imap_open($impsvr, "cyrus", "4u@pangkor", OP_HALFOPEN)
or die("can't connect: ". imap_last_error());

if(@imap_createmailbox($mbox, imap_utf7_encode($impsvr."user.".$username))){
	imap_createmailbox($mbox, imap_utf7_encode($impsvr."user.".$username.".Sent");
    imap_createmailbox($mbox, imap_utf7_encode($impsvr."user.".$username.".Thrash");
	imap_createmailbox($mbox, imap_utf7_encode($impsvr."user.".$username.".Drafts");
} else {
	
	$return = $not_login_errmsg;
	fwrite(STDLOG, "Cannot created".imap_last_error()."\n");
}
imap_close($mbox);

There is a err_msg page which holds all the errors messages.
When I run this code im getting:
2 => "invalid command syntax",

Could anybody point out my mistake?

Thanks in advance,

By,
@--sheru--@

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.