You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

managesieve.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. # Use the interface
  3. require 'sieve_transfer.php';
  4. class ManagesieveTransfer extends SieveTransfer
  5. {
  6. private $app = null;
  7. private $managesieve = null;
  8. private function GetManagesieve()
  9. {
  10. $this->app = rcmail::get_instance();
  11. // Add include path for internal classes
  12. $include_path = $this->app->plugins->dir . 'managesieve/lib' . PATH_SEPARATOR;
  13. $include_path .= ini_get('include_path');
  14. set_include_path($include_path);
  15. if (empty($this->params['port'])) {
  16. $this->params['port'] = getservbyname('sieve', 'tcp');
  17. if (empty($this->params['port'])) {
  18. $this->params['port'] = "4190";
  19. }
  20. }
  21. // try to connect to managesieve server
  22. $this->managesieve = new rcube_sieve(
  23. method_exists($this->app, get_user_name) ? $this->app->get_user_name() : $_SESSION['username'],
  24. method_exists($this->app, get_user_password) ? $this->app->get_user_password() : $this->app->decrypt($_SESSION['password']),
  25. $this->params['host'],
  26. $this->params['port'],
  27. null,
  28. $this->params['usetls']
  29. );
  30. if ($error = $this->managesieve->error()) {
  31. $this->ShowError($error, "GetManageSieve");
  32. }
  33. return $error;
  34. }
  35. private function ShowError($error, $method)
  36. {
  37. if ($error) {
  38. switch ($error) {
  39. case SIEVE_ERROR_CONNECTION:
  40. case SIEVE_ERROR_LOGIN:
  41. $this->app->output->show_message('Managesieve: Connection error', 'error');
  42. break;
  43. case SIEVE_ERROR_NOT_EXISTS:
  44. $this->app->output->show_message('Managesieve: Script does not exist', 'error');
  45. break;
  46. case SIEVE_ERROR_INSTALL:
  47. $this->app->output->show_message('Managesieve: Script failed to install', 'error');
  48. break;
  49. case SIEVE_ERROR_ACTIVATE:
  50. case SIEVE_ERROR_DEACTIVATE:
  51. $this->app->output->show_message('Managesieve: Activation change failed', 'error');
  52. break;
  53. case 255:
  54. $this->app->output->show_message('Managesieve: No sieve scripts found (This can be ignored on first run)', 'info');
  55. break;
  56. default:
  57. $this->app->output->show_message('Managesieve: Unknown error: ' . $error . ' (' . $method . ')', 'error');
  58. break;
  59. }
  60. }
  61. }
  62. public function LoadScript($script_name)
  63. {
  64. $script = '';
  65. if (!$this->managesieve) {
  66. if($this->GetManagesieve()) { return 0; }
  67. }
  68. if ($script_name) {
  69. $script = $this->managesieve->get_script($script_name);
  70. if($error = $this->managesieve->error()) {
  71. $this->ShowError($error, "LoadScript");
  72. return 0;
  73. }
  74. }
  75. return $script;
  76. }
  77. public function SaveScript($script_name,$script)
  78. {
  79. $success = false;
  80. $success_save = false;
  81. $success_activate = false;
  82. if (!$this->managesieve) {
  83. if($this->GetManagesieve()) { return 0; }
  84. }
  85. if ($script_name) {
  86. $success_save = $this->managesieve->save_script($script_name,$script);
  87. if($error = $this->managesieve->error()) {
  88. $this->ShowError($error, "SaveScript");
  89. return 0;
  90. }
  91. if($this->params['enable'] && $this->params['ms_activate_script'])
  92. {
  93. $success_activate = $this->managesieve->activate($script_name);
  94. if($success_save && $success_activate){ $success = true; }
  95. }
  96. else
  97. {
  98. if($success_save){ $success = true; }
  99. }
  100. }
  101. return $success;
  102. }
  103. }