Skip to content

Commit 3ce7425

Browse files
author
Till Brehm
committed
Merge branch 'stable-3.1' into 'stable-3.1'
dovecot lmtp, quota-status and managesieve See merge request ispconfig/ispconfig3!932
2 parents 7cb0905 + 64a58f2 commit 3ce7425

25 files changed

+404
-68
lines changed

install/dist/lib/debian60.lib.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ class installer extends installer_base {
3333
public function configure_dovecot()
3434
{
3535
global $conf;
36-
36+
3737
$virtual_transport = 'dovecot';
3838

3939
$configure_lmtp = false;
40-
40+
41+
// use lmtp if installed
42+
if($configure_lmtp = is_file('/usr/lib/dovecot/lmtp')) {
43+
$virtual_transport = 'lmtp:unix:private/dovecot-lmtp';
44+
}
45+
4146
// check if virtual_transport must be changed
4247
if ($this->is_update) {
4348
$tmp = $this->db->queryOneRecord("SELECT * FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $conf['server_id']);
@@ -138,7 +143,7 @@ public function configure_dovecot()
138143
}
139144
//remove #2.3+ comment
140145
$content = file_get_contents($config_dir.'/'.$configfile);
141-
$content = str_replace('#2.3+','',$content);
146+
$content = str_replace('#2.3+ ','',$content);
142147
file_put_contents($config_dir.'/'.$configfile,$content);
143148
unset($content);
144149

@@ -155,11 +160,20 @@ public function configure_dovecot()
155160
}
156161
}
157162

163+
$dovecot_protocols = 'imap pop3';
164+
158165
//* dovecot-lmtpd
159166
if($configure_lmtp) {
160-
replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', 'protocols = imap pop3 lmtp', 1, 0);
167+
$dovecot_protocols .= ' lmtp';
168+
}
169+
170+
//* dovecot-managesieved
171+
if(is_file('/usr/lib/dovecot/managesieve')) {
172+
$dovecot_protocols .= ' sieve';
161173
}
162174

175+
replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', "protocols = $dovecot_protocols", 1, 0);
176+
163177
//* dovecot-sql.conf
164178
$configfile = 'dovecot-sql.conf';
165179
if(is_file($config_dir.'/'.$configfile)){

install/lib/install.lib.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,29 +471,38 @@ function rf($file){
471471
}
472472

473473
function wf($file, $content){
474-
mkdirs(dirname($file));
474+
if(!$ret_val = mkdirs(dirname($file))) return false;
475475
if(!$fp = fopen($file, 'wb')){
476476
ilog('WARNING: could not open file '.$file);
477+
// implicitly returned false because the following fwrite and fclose both fail,
478+
// but to be explicit:
479+
$ret_val = false;
477480
}
478-
fwrite($fp, $content);
479-
fclose($fp);
481+
fwrite($fp, $content) or $ret_val = false;
482+
fclose($fp) or $ret_val = false;
483+
return $ret_val;
480484
}
481485

482486
function af($file, $content){
483-
mkdirs(dirname($file));
487+
if(!$ret_val = mkdirs(dirname($file))) return false;
484488
if(!$fp = fopen($file, 'ab')){
485489
ilog('WARNING: could not open file '.$file);
490+
$ret_val = false;
486491
}
487-
fwrite($fp, $content);
488-
fclose($fp);
492+
fwrite($fp, $content) or $ret_val = false;
493+
fclose($fp) or $ret_val = false;
494+
return $ret_val;
489495
}
490496

491497
function aftsl($file, $content){
498+
$ret_val = true;
492499
if(!$fp = fopen($file, 'ab')){
493500
ilog('WARNING: could not open file '.$file);
501+
$ret_val = false;
494502
}
495-
fwrite($fp, $content);
496-
fclose($fp);
503+
fwrite($fp, $content) or $ret_val = false;
504+
fclose($fp) or $ret_val = false;
505+
return $ret_val;
497506
}
498507

499508
function unix_nl($input){

install/lib/installer_base.lib.php

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ public function get_postfix_service($service, $type) {
864864
exec ("postconf -M $service.$type 2> /dev/null", $out, $ret);
865865
}
866866
$postfix_service = @($out[0]=='')?false:true;
867-
} else { //* fallback - Postfix < 2.9
867+
} else { //* fallback - Postfix < 2.9
868868
$content = rf($conf['postfix']['config_dir'].'/master.cf');
869869
$regex = "/^((?!#)".$service.".*".$type.".*)$/m";
870870
$postfix_service = @(preg_match($regex, $content))?true:false;
@@ -873,6 +873,68 @@ public function get_postfix_service($service, $type) {
873873
return $postfix_service;
874874
}
875875

876+
public function remove_postfix_service( $service, $type ) {
877+
global $conf;
878+
879+
// nothing to do if the service isn't even defined.
880+
if (! $this->get_postfix_service( $service, $type ) ) {
881+
return true;
882+
}
883+
884+
$postfix_version = `postconf -d mail_version 2>/dev/null`;
885+
$postfix_version = preg_replace( '/mail_version\s*=\s*(.*)\s*/', '$1', $postfix_version );
886+
887+
if ( version_compare( $postfix_version, '2.11', '>=' ) ) {
888+
889+
exec("postconf -X -M $service/$type 2> /dev/null", $out, $ret);
890+
891+
# reduce 3 or more newlines to 2
892+
$content = rf($conf['postfix']['config_dir'].'/master.cf');
893+
$content = preg_replace( '/(\r?\n){3,}/', '$1$1', $content );
894+
wf( $conf['postfix']['config_dir'].'/master.cf', $content );
895+
896+
} else { //* fallback - Postfix < 2.11
897+
898+
if ( ! $cf = fopen( $conf['postfix']['config_dir'].'/master.cf', 'r' ) ) {
899+
return false;
900+
}
901+
902+
$out = "";
903+
$reading_service = false;
904+
905+
while ( !feof( $cf ) ) {
906+
$line = fgets( $cf );
907+
908+
if ( $reading_service ) {
909+
# regex matches a new service or "empty" (whitespace) line
910+
if ( preg_match( '/^([^\s#]+.*|\s*)$/', $line ) &&
911+
! preg_match( '/^'.$service.'\s+'.$type.'/', $line ) ) {
912+
$out .= $line;
913+
$reading_service = false;
914+
}
915+
916+
# $skipped_lines .= $line;
917+
918+
# regex matches definition matching service to be removed
919+
} else if ( preg_match( '/^'.$service.'\s+'.$type.'/', $line ) ) {
920+
921+
$reading_service = true;
922+
# $skipped_lines .= $line;
923+
924+
} else {
925+
$out .= $line;
926+
}
927+
}
928+
fclose( $cf );
929+
930+
$out = preg_replace( '/(\r?\n){3,}/', '$1$1', $out ); # reduce 3 or more newlines to 2
931+
932+
return wf( $conf['postfix']['config_dir'].'/master.cf', $out );
933+
}
934+
935+
return true;
936+
}
937+
876938
public function configure_postfix($options = '') {
877939
global $conf,$autoinstall;
878940
$cf = $conf['postfix'];
@@ -927,17 +989,26 @@ public function configure_postfix($options = '') {
927989
//* mysql-virtual_uids.cf
928990
$this->process_postfix_config('mysql-virtual_uids.cf');
929991

992+
// test if lmtp if available
993+
$configure_lmtp = $this->get_postfix_service('lmtp','unix');
994+
930995
//* postfix-dkim
931996
$filename='tag_as_originating.re';
932997
$full_file_name=$config_dir.'/'.$filename;
933998
if(is_file($full_file_name)) copy($full_file_name, $full_file_name.'~');
934999
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/postfix-'.$filename.'.master', 'tpl/postfix-'.$filename.'.master');
1000+
if($configure_lmtp) {
1001+
$content = preg_replace('/amavis:/', 'lmtp:', $content);
1002+
}
9351003
wf($full_file_name, $content);
9361004

9371005
$filename='tag_as_foreign.re';
9381006
$full_file_name=$config_dir.'/'.$filename;
9391007
if(is_file($full_file_name)) copy($full_file_name, $full_file_name.'~');
9401008
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/postfix-'.$filename.'.master', 'tpl/postfix-'.$filename.'.master');
1009+
if($configure_lmtp) {
1010+
$content = preg_replace('/amavis:/', 'lmtp:', $content);
1011+
}
9411012
wf($full_file_name, $content);
9421013

9431014
//* Changing mode and group of the new created config files.
@@ -1233,11 +1304,16 @@ public function configure_courier() {
12331304

12341305
public function configure_dovecot() {
12351306
global $conf;
1236-
1307+
12371308
$virtual_transport = 'dovecot';
12381309

12391310
$configure_lmtp = false;
1240-
1311+
1312+
// use lmtp if installed
1313+
if($configure_lmtp = is_file('/usr/lib/dovecot/lmtp')) {
1314+
$virtual_transport = 'lmtp:unix:private/dovecot-lmtp';
1315+
}
1316+
12411317
// check if virtual_transport must be changed
12421318
if ($this->is_update) {
12431319
$tmp = $this->db->queryOneRecord("SELECT * FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $conf['server_id']);
@@ -1347,7 +1423,7 @@ public function configure_dovecot() {
13471423
}
13481424
//remove #2.3+ comment
13491425
$content = file_get_contents($config_dir.'/'.$configfile);
1350-
$content = str_replace('#2.3+','',$content);
1426+
$content = str_replace('#2.3+ ','',$content);
13511427
file_put_contents($config_dir.'/'.$configfile,$content);
13521428
unset($content);
13531429

@@ -1358,11 +1434,20 @@ public function configure_dovecot() {
13581434
}
13591435
}
13601436

1437+
$dovecot_protocols = 'imap pop3';
1438+
13611439
//* dovecot-lmtpd
13621440
if($configure_lmtp) {
1363-
replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', 'protocols = imap pop3 lmtp', 1, 0);
1441+
$dovecot_protocols .= ' lmtp';
1442+
}
1443+
1444+
//* dovecot-managesieved
1445+
if(is_file('/usr/lib/dovecot/managesieve')) {
1446+
$dovecot_protocols .= ' sieve';
13641447
}
13651448

1449+
replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', "protocols = $dovecot_protocols", 1, 0);
1450+
13661451
//* dovecot-sql.conf
13671452
$configfile = 'dovecot-sql.conf';
13681453
if(is_file($config_dir.'/'.$configfile)) {
@@ -1409,14 +1494,17 @@ public function configure_amavis() {
14091494

14101495
// TODO: chmod and chown on the config file
14111496

1497+
// test if lmtp if available
1498+
$configure_lmtp = $this->get_postfix_service('lmtp','unix');
14121499

14131500
// Adding the amavisd commands to the postfix configuration
14141501
// Add array for no error in foreach and maybe future options
14151502
$postconf_commands = array ();
14161503

14171504
// Check for amavisd -> pure webserver with postfix for mailing without antispam
14181505
if ($conf['amavis']['installed']) {
1419-
$postconf_commands[] = 'content_filter = amavis:[127.0.0.1]:10024';
1506+
$content_filter_service = ($configure_lmtp) ? 'lmtp' : 'amavis';
1507+
$postconf_commands[] = "content_filter = ${content_filter_service}:[127.0.0.1]:10024";
14201508
$postconf_commands[] = 'receive_override_options = no_address_mappings';
14211509
}
14221510

@@ -1432,11 +1520,16 @@ public function configure_amavis() {
14321520
$config_dir = $conf['postfix']['config_dir'];
14331521

14341522
// Adding amavis-services to the master.cf file if the service does not already exists
1435-
$add_amavis = !$this->get_postfix_service('amavis','unix');
1436-
$add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
1437-
$add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
1523+
// $add_amavis = !$this->get_postfix_service('amavis','unix');
1524+
// $add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
1525+
// $add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
14381526
//*TODO: check templates against existing postfix-services to make sure we use the template
14391527

1528+
// Or just remove the old service definitions and add them again?
1529+
$add_amavis = $this->remove_postfix_service('amavis','unix');
1530+
$add_amavis_10025 = $this->remove_postfix_service('127.0.0.1:10025','inet');
1531+
$add_amavis_10027 = $this->remove_postfix_service('127.0.0.1:10027','inet');
1532+
14401533
if ($add_amavis || $add_amavis_10025 || $add_amavis_10027) {
14411534
//* backup master.cf
14421535
if(is_file($config_dir.'/master.cf')) copy($config_dir.'/master.cf', $config_dir.'/master.cf~');

install/sql/incremental/upd_dev_collection.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ ALTER TABLE `mail_user`
2626

2727
-- doveadm should be enabled for all mailboxes
2828
UPDATE `mail_user` set `disabledoveadm` = 'n';
29+
30+
-- add disablequota-status for quota-status policy daemon
31+
ALTER TABLE `mail_user` ADD `disablequota-status` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'n' AFTER `disabledoveadm`;
32+
33+
-- add disableindexer-worker for solr search
34+
ALTER TABLE `mail_user` ADD `disableindexer-worker` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'n' AFTER `disablequota-status`;

install/sql/ispconfig3.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,8 @@ CREATE TABLE `mail_user` (
10621062
`disablelda` enum('n','y') NOT NULL default 'n',
10631063
`disablelmtp` enum('n','y') NOT NULL default 'n',
10641064
`disabledoveadm` enum('n','y') NOT NULL default 'n',
1065+
`disablequota-status` enum('n','y') NOT NULL default 'n',
1066+
`disableindexer-worker` enum('n','y') NOT NULL default 'n',
10651067
`last_quota_notification` date NULL default NULL,
10661068
`backup_interval` VARCHAR( 255 ) NOT NULL default 'none',
10671069
`backup_copies` INT NOT NULL DEFAULT '1',

install/tpl/debian6_dovecot.conf.master

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ plugin {
5757
# the maildir quota does not need to be set.
5858
# You do not need: quota = maildir
5959

60+
# no longer needed, as 'sieve' is in userdb extra fields:
6061
sieve=/var/vmail/%d/%n/.sieve
62+
63+
sieve_after=/var/vmail/%d/%n/.ispconfig.sieve
64+
sieve_max_script_size = 2M
65+
sieve_max_actions = 100
66+
sieve_max_redirects = 25
6167
}
6268

6369

install/tpl/debian6_dovecot2.conf.master

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ssl_dh = </etc/dovecot/dh.pem
1010
ssl_protocols = !SSLv2 !SSLv3
1111
ssl_min_protocol = TLSv1
1212
mail_max_userip_connections = 100
13+
mail_plugins = quota
1314
passdb {
1415
args = /etc/dovecot/dovecot-sql.conf
1516
driver = sql
@@ -23,7 +24,13 @@ userdb {
2324
}
2425
plugin {
2526
quota = dict:user::file:/var/vmail/%d/%n/.quotausage
27+
28+
# no longer needed, as 'sieve' is in userdb extra fields:
2629
sieve=/var/vmail/%d/%n/.sieve
30+
31+
sieve_after=/var/vmail/%d/%n/.ispconfig.sieve
32+
sieve_max_script_size = 2M
33+
sieve_max_actions = 100
2734
sieve_max_redirects = 25
2835
}
2936
service auth {
@@ -49,6 +56,7 @@ service lmtp {
4956
# process_min_avail = 5
5057
}
5158
}
59+
lmtp_rcpt_check_quota = yes
5260
service imap-login {
5361
client_limit = 1000
5462
process_limit = 512
@@ -83,3 +91,39 @@ protocol lmtp {
8391
#2.3+ }
8492
#2.3+ }
8593

94+
service quota-status {
95+
executable = quota-status -p postfix
96+
unix_listener /var/spool/postfix/private/quota-status {
97+
group = postfix
98+
mode = 0660
99+
user = postfix
100+
}
101+
client_limit = 1
102+
}
103+
plugin {
104+
quota_status_success = DUNNO
105+
quota_status_nouser = DUNNO
106+
quota_status_overquota = "552 5.2.2 Mailbox is full"
107+
}
108+
109+
imap_capability=+SEPCIAL-USE XLIST
110+
namespace inbox {
111+
inbox = yes
112+
separator = .
113+
mailbox Drafts {
114+
special_use = \Drafts
115+
}
116+
mailbox Junk {
117+
special_use = \Junk
118+
}
119+
mailbox Sent {
120+
special_use = \Sent
121+
}
122+
mailbox "Sent Messages" {
123+
special_use = \Sent
124+
}
125+
mailbox Trash {
126+
special_use = \Trash
127+
}
128+
}
129+

0 commit comments

Comments
 (0)