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

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