home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / test_sieve.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  5.8 KB  |  207 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar>       |
  17. // +----------------------------------------------------------------------+
  18.  
  19. include_once('Net/Sieve.php');
  20. error_reporting(E_ALL);
  21.  
  22.  
  23. $user='user';
  24. $pass='password';
  25. $host='localhost';
  26. $port="2000";
  27.  
  28.  
  29.  
  30. //you can create a file called passwords.php and store your $user,$pass,$host and $port values in it
  31. // or you can modify this script
  32. @include_once("./passwords.php");
  33.  
  34.  
  35.  
  36.  
  37. $sieve_script_name1='test script1';
  38. // The script
  39. $sieve_script1="require \"fileinto\";\n\rif header :contains \"From:\" \"@cnba.uba.ar\" \n\r{fileinto \"INBOX.Test1\";}\r\nelse \r\n{fileinto \"INBOX\";}";
  40.  
  41.  
  42. $sieve_script_name2='test script2';
  43. $sieve_script2="require \"fileinto\";\n\rif header :contains \"From:\" \"@cnba.uba.ar\" \n\r{fileinto \"INBOX.Test\";}\r\nelse \r\n{fileinto \"INBOX\";}";
  44.  
  45.  
  46.  
  47.  
  48. //$sieve=new Net_Sieve($user, $passwd, $host , $port , 'PLAIN');
  49. //$sieve=new Net_Sieve($user, $passwd, $host , $port, 'DIGEST-MD5' );
  50. $sieve=new Net_Sieve($user, $passwd, $host , $port);
  51.  
  52. //$sieve->setDebug(true);
  53.  
  54.  
  55. // I list the scripts that I Have installed
  56. echo "These are the scripts that I have in the server:\n";
  57. print_r($sieve->listScripts());
  58. echo "\n";
  59.  
  60. //exit();
  61.  
  62.  
  63. echo "I remove script 1 ($sieve_script_name1)......";
  64. if( !PEAR::isError($error = $sieve->removeScript($sieve_script_name1) ) ){
  65.     echo "  script '$sieve_script_name1' removed ok!\n";
  66. }else{
  67.     echo "  there was an error trying to remove the script '$sieve_script_name1'. The error is: " . $error->getMessage() ;
  68. }
  69. echo "\n";
  70.  
  71.  
  72.  
  73. // I try to delete again de same script, the method must fail
  74.  
  75. echo "I remove script 1 ($sieve_script_name1)......";
  76. if( !PEAR::isError($error = $sieve->removeScript($sieve_script_name1) ) ){
  77.     echo "  script '$sieve_script_name1' removed ok!\n";
  78. }else{
  79.     echo "  there was an error trying to remove the script '$sieve_script_name1'. The error is: " . $error->getMessage() . "\n" ;
  80. }
  81. echo "\n";
  82.  
  83.  
  84.  
  85.  
  86. /*
  87. echo "I'll check if the server has space to store '$sieve_script_name1' script .....";
  88. if(!PEAR::isError( $error = $sieve->haveSpace($sieve_script_name1, strlen($sieve_script1)))){
  89.     echo "  ok! the server has a lot of space!\n";
  90. }else{
  91.     echo "  the server can't store the script. The error is: " . $error->getMessage() . "\n" ;
  92. }
  93. echo "\n";
  94. */
  95.  
  96.  
  97.  
  98. echo "I install the script '$sieve_script_name1' and mark it active.....";
  99. if(!PEAR::isError( $error = $sieve->installScript($sieve_script_name1, $sieve_script1,true))){
  100.     echo "  script '$sieve_script_name1' installed ok!\n";
  101. }else{
  102.     echo "  there was an error trying to install the script '$sieve_script_name1'. The error is: " . $error->getMessage() . "\n" ;
  103. }
  104. echo "\n";
  105.  
  106.  
  107. echo "I install the script '$sieve_script_name2' but it is not marked as active.....";
  108. if(!PEAR::isError( $error = $sieve->installScript($sieve_script_name2, $sieve_script2))){
  109.     echo "  script '$sieve_script_name2' installed ok!\n";
  110. }else{
  111.     echo "  there was an error trying to install the script '$sieve_script_name2'. The error is: " . $error->getMessage() . "\n" ;
  112. }
  113. echo "\n";
  114.  
  115.  
  116. echo "Now set script 2 as active...";
  117. if(!PEAR::isError($error = $sieve->setActive($sieve_script_name2))){
  118.     echo "  script '$sieve_script_name2' marked as active ok!\n";
  119. }else{
  120.     echo "  there was an error trying to mark as active the script '$sieve_script_name2'. The error is: " . $error->getMessage() . "\n" ;
  121. }
  122. echo "\n";
  123.  
  124. echo "Now get the active script....";
  125. if( !PEAR::isError($error = $script= $sieve->getActive() ) ){
  126.     echo "the script marked as active is: $script\n";
  127. }else{
  128.     echo "  there was an error trying to get the activescript, the error is:" . $script->getMessage() ;
  129. }
  130. echo "\n";
  131.  
  132.  
  133. echo "The server has the following extensions:\n";
  134.  
  135. $exts=$sieve->getExtensions();
  136.  
  137. for($i=0 ; $i < count($exts) ; $i++){
  138.  
  139.         echo sprintf("    %s. %s\n", $i+1 , $exts[$i]);
  140. }
  141. echo "\n";
  142.  
  143.  
  144.  
  145.  
  146.  
  147. $ext='pichula';
  148. if($sieve->hasExtension( $ext ) ){
  149.     echo "this server supports the '$ext' extenssion\n";
  150. } else {
  151.     echo "this server does not supports the '$ext' extenssion\n";
  152. }
  153.  
  154. echo "\n";
  155.  
  156.  
  157.  
  158. $ext='fileinto';
  159. if($sieve->hasExtension( $ext ) ){
  160.     echo "this server supports the '$ext' extenssion\n";
  161. } else {
  162.     echo "this server does not supports the '$ext' extenssion\n";
  163. }
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. echo "\n\nThe server has the following Auth Methods:\n";
  171.  
  172. $meths=$sieve->getAuthMechs();
  173.  
  174. for($i=0 ; $i < count($meths) ; $i++){
  175.  
  176.         echo sprintf("    %s. %s\n", $i+1 , $meths[$i]);
  177. }
  178. echo "\n";
  179.  
  180.  
  181.  
  182.  
  183.  
  184. $meth='pichula';
  185. if($sieve->hasAuthMech( $meth ) ){
  186.     echo "this server supports the '$meth' Auth Method\n";
  187. } else {
  188.     echo "this server does not supports the '$meth' Auth Method\n";
  189. }
  190.  
  191. echo "\n";
  192.  
  193.  
  194.  
  195. $meth='cram-md5';
  196. if($sieve->hasAuthMech( $meth ) ){
  197.     echo "this server supports the '$meth' Auth Method\n";
  198. } else {
  199.     echo "this server does not supports the '$meth' Auth Method\n";
  200. }
  201.  
  202. echo "\n";
  203.  
  204.  
  205.  
  206.  
  207. ?>