summaryrefslogtreecommitdiff
path: root/www/admin/user/deliver.php.in
blob: 9350d3c72cb6f86a8991760b556a8b81e56c886e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*
 *  Copyright (c) 2004 Klarälvdalens Datakonsult AB
 *
 *    Written by Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
 *
 *  This  program is free  software; you can redistribute  it and/or
 *  modify it  under the terms of the GNU  General Public License as
 *  published by the  Free Software Foundation; either version 2, or
 *  (at your option) any later version.
 *
 *  This program is  distributed in the hope that it will be useful,
 *  but WITHOUT  ANY WARRANTY; without even the  implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You can view the  GNU General Public License, online, at the GNU
 *  Project's homepage; see <http://www.gnu.org/licenses/gpl.html>.
 */

require_once '@kolab_php_module_prefix@admin/include/mysmarty.php';
require_once '@kolab_php_module_prefix@admin/include/headers.php';
require_once '@kolab_php_module_prefix@admin/include/authenticate.php';
require_once '@kolab_php_module_prefix@admin/include/sieveutils.class.php';

// Funny multiline string escaping in Sieve
function dotstuff( $str ) {
  return str_replace( "\n.", "\n..", $str );
}

function undotstuff( $str ) {
  return str_replace( "\n..", "\n.", $str );
}

$errors = array();
if( (@include_once '@kolab_php_module_prefix@admin/include/Sieve.php' ) === false ) {
  $errors[] = _('Net/Sieve.php is missing. Without that, filter settings are not available');
  $errors[] = _("Suggest your system administrator to run \"@bindir@/pear install http://pear.php.net/get/Net_Sieve\" on the server");
}

/**** Authentication etc. ***/
$sidx = 'user';

require_once('@kolab_php_module_prefix@admin/include/menu.php');

/**** Submenu for current page ***/
$menuitems[$sidx]['selected'] = 'selected';

/**** Sieve handling ***/
// this is the name KDE client stores - so we can also change the setting from KDE client
$scriptname = "kolab-deliver.siv";
if( !$errors ) {
  $obj = $ldap->read( $auth->dn() );
  $sieve =& new Net_Sieve( $auth->uid(), $auth->password(), $obj['kolabHomeServer'][0] );
  
  // Update sieve script on server in case we have submit data
  if( $_REQUEST['submit'] ) {
	$inbox  = trim($_REQUEST['inbox']);
	$active = isset($_REQUEST['active']);

	  $script = 
		"require \"fileinto\";\r\nif header :contains [\"X-Kolab-Scheduling-Message\"] [\"FALSE\"] {\r\nfileinto \"INBOX/$inbox\";\r\n}\r\n";

	  if( PEAR::isError( $res = $sieve->installScript( $scriptname, $script, $active ) ) ) {
		$errors[] = $res->getMessage();
		$errors[] = _('Script was:');
		$errors[] = '<pre>'.MySmarty::htmlentities($script).'</pre>';
	  }
	  if( !$active && $sieve->getActive() === $scriptname ) {
		$sieve->setActive( '' );
	  }

	  if( !$errors ) {
		if( $active ) $messages[] = sprintf(_("Delivery to '%s' successfully activated"), $inbox);
		else $messages[] =  sprintf(_("Delivery to '%s' successfully deactivated"), $inbox);
	  }	
  }

  $scripts = $sieve->listScripts();
  $inbox = false;
  if( in_array( $scriptname, $scripts ) ) {
	// Fetch script data from server
	$script = $sieve->getScript($scriptname);
	$inbox = SieveUtils::getDeliverFolder( $script );
  }
  if( $inbox === false ) $inbox = 'Inbox';
  $active = ( $sieve->getActive() === $scriptname );  
}

/**** Insert into template and output ***/
$smarty = new MySmarty();
$smarty->assign( 'errors', $errors );
$smarty->assign( 'messages', $messages );
$smarty->assign( 'uid', $auth->uid() );
$smarty->assign( 'group', $auth->group() );
$smarty->assign( 'page_title', $menuitems[$sidx]['title'] );
$smarty->assign( 'menuitems', $menuitems );
$smarty->assign( 'submenuitems', 
				 array_key_exists('submenu', 
								  $menuitems[$sidx])?$menuitems[$sidx]['submenu']:array() );
$smarty->assign( 'active', $active );
$smarty->assign( 'inbox', $inbox );
$smarty->assign( 'maincontent', 'deliver.tpl' );
$smarty->display('page.tpl');

/*
  Local variables:
  mode: php
  indent-tabs-mode: t
  tab-width: 4
  buffer-file-coding-system: utf-8
  End:
  vim:encoding=utf-8:
 */
?>