Net_Sieve
[ class tree: Net_Sieve ] [ index: Net_Sieve ] [ all elements ]

Source for file test_sieve.php

Documentation is available at test_sieve.php

  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.  
  21.  
  22. $user='user';
  23. $pass='password';
  24. $host='localhost';
  25. $port="2000";
  26.  
  27.  
  28.  
  29. //you can create a file called passwords.php and store your $user,$pass,$host and $port values in it
  30. // or you can modify this script
  31. @include_once("./passwords.php");
  32.  
  33.  
  34.  
  35.  
  36. $sieve_script_name1='test script1';
  37. // The script
  38. $sieve_script1="require \"fileinto\";\n\rif header :contains \"From\" \"@cnba.uba.ar\" \n\r{fileinto \"INBOX.Test1\";}\r\nelse \r\n{fileinto \"INBOX\";}";
  39.  
  40.  
  41. $sieve_script_name2='test script2';
  42. $sieve_script2="require \"fileinto\";\n\rif header :contains \"From\" \"@cnba.uba.ar\" \n\r{fileinto \"INBOX.Test\";}\r\nelse \r\n{fileinto \"INBOX\";}";
  43.  
  44.  
  45. $sieve_script1="require \"vacation\";\nvacation\n:days 7\n:addresses [\"matthew@de-construct.com\"]\n:subject \"This is a test\"\n\"I'm on my holiday!\nsadfafs\";";
  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. $sieve=new Net_Sieve();
  52.  
  53. $sieve->setDebug(true);
  54.  
  55. if(PEAR::isError($error $sieve->connect($host $port) ) ){
  56.     echo "  there was an error trying to connect to the server. The error is: " $error->getMessage("\n" ;
  57.     exit();
  58. }
  59.  
  60.  
  61.  
  62. //if(PEAR::isError($error = $sieve->login($user, $passwd  , 'PLAIN' , '', false ) ) ){
  63. if(PEAR::isError($error $sieve->login($user$passwd  null ''false ) ) ){
  64.     echo "  there was an error trying to connect to the server. The error is: " $error->getMessage()  "\n";
  65.     exit();
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72. // I list the scripts that I Have installed
  73. echo "These are the scripts that I have in the server:\n";
  74. print_r($sieve->listScripts());
  75. echo "\n";
  76.  
  77.  
  78. echo "I remove script 1 ($sieve_script_name1)......\n";
  79. if!PEAR::isError($error $sieve->removeScript($sieve_script_name1) ) ){
  80.     echo "  script '$sieve_script_name1' removed ok!\n";
  81. }else{
  82.     echo "  there was an error trying to remove the script '$sieve_script_name1'. The error is: " . $error->getMessage()  "\n";
  83. }
  84. echo "\n";
  85.  
  86.  
  87.  
  88. // I try to delete again de same script, the method must fail
  89.  
  90. echo "I remove script 1 ($sieve_script_name1)......\n";
  91. if!PEAR::isError($error $sieve->removeScript($sieve_script_name1) ) ){
  92.     echo "  script '$sieve_script_name1' removed ok!\n";
  93. }else{
  94.     echo "  there was an error trying to remove the script '$sieve_script_name1'. The error is: " . $error->getMessage("\n" ;
  95. }
  96. echo "\n";
  97.  
  98.  
  99.  
  100.  
  101.  
  102. /*
  103. echo "I'll check if the server has space to store '$sieve_script_name1' script .....";
  104. if(!PEAR::isError( $error = $sieve->haveSpace($sieve_script_name1, strlen($sieve_script1)))){
  105.     echo "  ok! the server has a lot of space!\n";
  106. }else{
  107.     echo "  the server can't store the script. The error is: " . $error->getMessage() . "\n" ;
  108. }
  109. echo "\n";
  110. */
  111.  
  112.  
  113.  
  114. echo "I install the script '$sieve_script_name1' and mark it active.....\n";
  115. if(!PEAR::isError$error $sieve->installScript($sieve_script_name1$sieve_script1,true))){
  116.     echo "  script '$sieve_script_name1' installed ok!\n";
  117. }else{
  118.     echo "  there was an error trying to install the script '$sieve_script_name1'. The error is: " . $error->getMessage("\n" ;
  119. }
  120. echo "\n";
  121.  
  122.  
  123. echo "This is the script I just installed.....\n";
  124. if(!PEAR::isError$error $sieve->getScript($sieve_script_name1 ))){
  125.     echo "  script '$sieve_script_name1':\n$error\n";
  126. }else{
  127.     echo "  there was an error trying to install the script '$sieve_script_name1'. The error is: " . $error->getMessage("\n" ;
  128. }
  129.  
  130.  
  131.  
  132.  
  133. echo "I install the script '$sieve_script_name2' but it is not marked as active.....\n";
  134. if(!PEAR::isError$error $sieve->installScript($sieve_script_name2$sieve_script2))){
  135.     echo "  script '$sieve_script_name2' installed ok!\n";
  136. }else{
  137.     echo "  there was an error trying to install the script '$sieve_script_name2'. The error is: " . $error->getMessage("\n" ;
  138. }
  139. echo "\n";
  140.  
  141.  
  142. echo "Now set script 2 as active...\n";
  143. if(!PEAR::isError($error $sieve->setActive($sieve_script_name2))){
  144.     echo "  script '$sieve_script_name2' marked as active ok!\n";
  145. }else{
  146.     echo "  there was an error trying to mark as active the script '$sieve_script_name2'. The error is: " . $error->getMessage("\n" ;
  147. }
  148. echo "\n";
  149.  
  150. echo "Now get the active script....\n";
  151. if!PEAR::isError($error $script$sieve->getActive() ) ){
  152.     echo "the script marked as active is: $script\n";
  153. }else{
  154.     echo "  there was an error trying to get the activescript, the error is:" $script->getMessage(;
  155. }
  156. echo "\n";
  157.  
  158.  
  159. echo "The server has the following extensions:\n";
  160.  
  161. $exts=$sieve->getExtensions();
  162.  
  163. for($i=0 ; $i count($exts$i++){
  164.  
  165.         echo sprintf("    %s. %s\n"$i+1 $exts[$i]);
  166. }
  167. echo "\n";
  168.  
  169.  
  170.  
  171.  
  172.  
  173. $ext='pichula';
  174. if($sieve->hasExtension$ext ) ){
  175.     echo "this server supports the '$ext' extenssion\n";
  176. else {
  177.     echo "this server does not supports the '$ext' extenssion\n";
  178. }
  179.  
  180. echo "\n";
  181.  
  182.  
  183.  
  184. $ext='fileinto';
  185. if($sieve->hasExtension$ext ) ){
  186.     echo "this server supports the '$ext' extenssion\n";
  187. else {
  188.     echo "this server does not supports the '$ext' extenssion\n";
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196. echo "\n\nThe server has the following Auth Methods:\n";
  197.  
  198. $meths=$sieve->getAuthMechs();
  199.  
  200. for($i=0 ; $i count($meths$i++){
  201.  
  202.         echo sprintf("    %s. %s\n"$i+1 $meths[$i]);
  203. }
  204. echo "\n";
  205.  
  206.  
  207.  
  208.  
  209.  
  210. $meth='pichula';
  211. if($sieve->hasAuthMech$meth ) ){
  212.     echo "this server supports the '$meth' Auth Method\n";
  213. else {
  214.     echo "this server does not supports the '$meth' Auth Method\n";
  215. }
  216.  
  217. echo "\n";
  218.  
  219.  
  220.  
  221. $meth='cram-md5';
  222. if($sieve->hasAuthMech$meth ) ){
  223.     echo "this server supports the '$meth' Auth Method\n";
  224. else {
  225.     echo "this server does not supports the '$meth' Auth Method\n";
  226. }
  227.  
  228. echo "\n";
  229.  
  230.  
  231.  
  232.  
  233. ?>

Documentation generated on Mon, 11 Mar 2019 14:22:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.