Mail Account Migration Script gives errors

Discussion in 'Tips/Tricks/Mods' started by ZeroEnna, Mar 21, 2013.

  1. ZeroEnna

    ZeroEnna Member

    Hello everyone,

    to help migrating the mail accounts from one server to another, a good friend of mine wrote a script using the Remote API.
    First of all, here's the code:

    PHP:
    <?php

    #################################
    ### (c)2013 by Marcel Beriere ###
    #################################

    function check_login($username$password) {
      
    $result false;

      
    $authOK   "235 ";
      
    $ehloEnd  "250 ";
      
    $password base64_encode($password);
      
    $username base64_encode($username);

      
    $socket fsockopen("85.214.88.184"25$errorNo$errorStr60);
      if (
    $socket) {
        
    $input fgets($socket);
        
    fwrite($socket"EHLO Kibo.FM\n");

        do {
          
    $input fgets($socket);
          
    $done  = (stripos($input$ehloEnd) !== false);
        } while (!
    $done);

        
    fwrite($socket"AUTH LOGIN\n");
        
    $input fgets($socket);
        
    fwrite($socket$username "\n");
        
    $input fgets($socket);
        
    fwrite($socket$password "\n");
        
    $input fgets($socket);

        
    $result = (stripos($input$authOK) !== false);

        
    fwrite($socket"QUIT\n");
        
    fclose($socket);
      } else {
        
    $result "Keine Verbindung zum Server";
      }
    function 
    create_mail($email$emailpass){
      
    $username 'webservices';
      
    $password 'password';
      
    $soap_location 'https://37.221.195.129:8080/remote/index.php';
      
    $soap_uri 'https://37.221.195.129:8080/remote/';

      
    $client = new SoapClient(null, array('location' => $soap_location,
                                         
    'uri'      => $soap_uri,
                                                                             
    'trace' => 1,
                                                                             
    'exceptions' => 1));


      try {
            if(
    $session_id $client->login($username,$password)) {
                    
    //echo 'Logged successfull. Session ID:'.$session_id.'<br />';
            
    }

            
    //* Set the function parameters.
            
    $client_id 1;
            
    $params = array(
                            
    'server_id' => 1,
                            
    'email' => $email,
            
    'login' => $email,
                            
    'password' => $emailpass,
                            
    'name' => $email,
                            
    'uid' => 5000,
                            
    'gid' => 5000,
                            
    'maildir' => '',
                            
    'quota' => 0,
                            
    'cc' => '',
                            
    'homedir' => '',
                            
    'autoresponder' => 'n',
                            
    'autoresponder_start_date' => '',
                            
    'autoresponder_end_date' => '',
                            
    'autoresponder_text' => 'hallo',
                            
    'move_junk' => 'n',
                            
    'custom_mailfilter' => 'spam',
                            
    'postfix' => 'y',
                            
    'access' => 'n',
                            
    'disableimap' => 'n',
                            
    'disablepop3' => 'n',
                            
    'disabledeliver' => 'n',
                            
    'disablesmtp' => 'n'
                            
    );

            
    $affected_rows $client->mail_user_add($session_id$client_id$params);

            
    //echo "New user: ".$affected_rows."<br>";

            
    if($client->logout($session_id)) {
                    
    //echo 'Logged out.<br />';
            
    }


      } catch (
    SoapFault $e) {
            
    //echo $client->__getLastResponse();
            //die('SOAP Error: '.$e->getMessage());
      
    if (isset($affected_rows)) {
        return 
    true;
      }else{
        return 
    false;
      }
    }
    $email $_POST['email'];
    if(isset(
    $_POST['email'], $_POST['passwort'])) {
      if (
    check_login($_POST['email'], $_POST['passwort']) == 1) {
        if (
    create_mail($_POST['email'], $_POST['passwort'])){
          echo 
    "Das E-Mailkonto wurde erfolgreich &uuml;bertragen";
                
    $empfaenger "[email protected]";
                
    $absendername "Mail Move Script";
                
    $absendermail "[email protected]";
                
    $betreff "Mailpostfach umgezogen";
                
    $text "Hallo Sascha,
                         Die E-Mailadresse 
    $email wurde umgezogen.";
                
    mail($empfaenger$betreff$text"From: $absendername <$absendermail>");
            echo 
    "<br>";
            echo 
    "Falls sie noch weitere Postf&auml;cher umziehen m&ouml;chten, klicken Sie bitte hier:";
            echo 
    "<br>";
            echo 
    "<a href='mail.html'>Weiteres Postfach umziehen.</a>";
        }else{
          echo 
    "Das E-Mailkonto wurde schon &uuml;bertragen";
        }
      }else{
        echo 
    "Das angegebene Konto konnte nicht gefunden werden oder die Daten sind nicht korrekt";
      }
    }
    ?>
    Now, creating mailboxes with this script gives the following errors on the target server:

    Code:
    Mar 19 18:12:01 moon dovecot: deliver([email protected]): sieve: failed to open logfile (LOGGING TO STDERR): open(/.sieve.log) failed: Permission denied (euid=5000(vmail) egid=5000(vmail))
    Mar 19 18:12:01 moon dovecot: deliver([email protected]): sieve: failed to open script /.sieve (view logfile /.sieve.log for more information)
    Mar 19 18:12:01 moon dovecot: deliver([email protected]): file dict commit: file_dotlock_open(/var/vmail/kibo.fm/wildwolf/.quotausage) failed: No such file or directory
    Mar 19 18:12:01 moon dovecot: deliver([email protected]): dict quota: Quota update failed, it's now desynced
    Mar 19 18:21:00 moon dovecot: deliver([email protected]): sieve: failed to open logfile (LOGGING TO STDERR): open(/.sieve.log) failed: Permission denied (euid=5000(vmail) egid=5000(vmail))
    Mar 19 18:21:00 moon dovecot: deliver([email protected]): sieve: failed to open script /.sieve (view logfile /.sieve.log for more information)
    Mar 19 18:21:00 moon dovecot: deliver([email protected]): file dict commit: file_dotlock_open(/var/vmail/kibo.fm/manta/.quotausage) failed: No such file or directory
    Mar 19 18:21:00 moon dovecot: deliver([email protected]): dict quota: Quota update failed, it's now desynced
    In what way do I have to alter the code? Or is there a general problem?

    Kind Regards

    ZeroEnna
     

Share This Page