Skip to content

Commit

Permalink
Fixed: Create default sieve script (filters), even if sieve is not av…
Browse files Browse the repository at this point in the history
…ailable (Dovecot IMAP/POP server implementation)
  • Loading branch information
nuxwin committed May 21, 2019
1 parent 0f30af9 commit a6f3975
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -9,6 +9,7 @@ BACKEND
Added: Array::Utils library (PerlVendor)
Enhancement: Make it possible to override any default DNS resource record (Bind9 server implementation)
Fixed: Can't locate object method "remove" via package "iMSCP::File" (iMSCP::Service)
Fixed: Create default sieve script (filters), even if sieve is not available (Dovecot IMAP/POP server implementation)
Fixed: Create symlink for sieve filters on email account creation/update, even when those are not available (Dovecot IMAP/POP server implementation)
Fixed: Error output is badly captured, leading to 'Unknown error' (named-compilezone / Bind9 server implementation)
Fixed: Missing check for SSL private key and SSL certificate matching (iMSCP::OpenSSL)
Expand Down
55 changes: 46 additions & 9 deletions engine/PerlLib/Servers/po/dovecot.pm
Expand Up @@ -213,17 +213,21 @@ sub addMail

# Mailboxes

# Note: We also create the sieve directory, even if sieve isn't
# available. See the comments about sieve below for further explanation.
local $@;
eval {
for my $mailbox ( qw/ .Drafts .Junk .Sent .Trash / ) {
for my $mailbox ( qw/ .Drafts .Junk .Sent .Trash sieve / ) {
iMSCP::Dir->new( dirname => "$mailDir/$mailbox" )->make( {
user => $mailUidName,
group => $mailGidName,
mode => 0750,
fixpermissions => iMSCP::Getopt->fixPermissions
} );

for my $dir( qw/ cur new tmp /) {
next if $mailbox eq 'sieve';

for my $dir ( qw/ cur new tmp / ) {
iMSCP::Dir->new( dirname => "$mailDir/$mailbox/$dir" )->make( {
user => $mailUidName,
group => $mailGidName,
Expand All @@ -233,13 +237,13 @@ sub addMail
}
}
};
if( $@ ) {
if ( $@ ) {
error( $@ );
return 1;
}

# Subscriptions

my @subscribedFolders = qw/ Drafts Junk Sent Trash /;
my $subscriptionsFile = iMSCP::File->new(
filename => "$mailDir/subscriptions"
Expand All @@ -264,12 +268,45 @@ sub addMail
return $rs if $rs;

# Sieve filters
# Create symlink for sieve filters, even if those are not installed.
# If we don't do that, sieve filters will not be enabled by default, even
# when installed. Users will have to enable them through the Roundcube
# managesieve plugin and that's not acceptable for beginners...

# Note: the 'dovecot.sieve' symlink was the one created by the old
# Unless a sieve script (filters) is already present, we provide a default
# one that define two rules: one for moving SPAM to Junk folder, and another
# one for vacation. However, by default, only the 'spam' rule need to be
# enabled because this doesn't make sense to enable vacation for new email
# accounts.
#
# If we don't do that, users will have to enable sieve through the Roundcube
# managesieve plugin and that's not acceptable for beginners, mostly for SPAM
# filtering...
unless ( -f "$mailDir/sieve/managesieve.sieve" ) {
my $file = iMSCP::File->new( filename => "$mailDir/sieve/managesieve.sieve" );
$file->set( <<'EOF' );
require ["fileinto","vacation"];
# rule:[spam]
if header :contains "x-spam-flag" "YES"
{
fileinto "INBOX.Junk";
stop;
}
# rule:[vacation]
if false
{
vacation :subject "Out of office" text:
Hello,
Thank you for your message. I'm out of office, with no email access.
.
;
}
EOF
$rs = $file->save();
$rs ||= $file->owner( $mailUidName, $mailGidName );
$rs ||= $file->mode( 0600 );
return $rs if $rs;
}

# We need also create the symlink to the sieve filters script
# Note: The 'dovecot.sieve' symlink was the one created by the old
# RoundcubePlugins plugin (managesieve plugin configuration). It is now
# '.dovecot.sieve'. We need remove it if present...
for my $lnk ( qw/ .dovecot.sieve dovecot.sieve / ) {
Expand Down

0 comments on commit a6f3975

Please sign in to comment.