Sieve forwarding not working

I can’t get sieve filters to “send a copy” to another email address.

This is a brand new installation of HestiaCP and I added sieve to the installation script.

I restored several users from my VestaCP server and noticed that managesieve rules were not in the same place so I manually moved and changed permissions and created sym links. Once I had the rules showing up in roundcube and I sent a test email that was properly put into a sub folder based on one of the rules, I THOUGHT it was working perfectly, but now I realize that the “Send a copy” rules where it should forward to a different email address are not working.

I’ve been reading all the forum messages for the past several hours but I can’t get it working.

What is wrong? I definitely might have not set a permission to a specific folder properly but I can’t figure out where.

Thanks!

Also, note that I am seeing these errors in the file:

/home/testingfilters/mail/domainname.com/testing/dovecot.sieve.log

redirect action: failed to check for duplicate forward: internal error occurred: refer to server log for more information.

Try this workaround (replace user by your actual user):

touch /home/user/.dovecot.lda-dupes
mkdir /home/user/.dovecot.lda-dupes.locks
chown user:user /home/user/.dovecot.lda-dupes*

If you want to know the reason for this, check this post:

2 Likes

Thanks for the FAST reply!

Unfortunately, that didn’t make it work. I had already found your post and tried this, but just to be safe I tried it again, I ran this:

touch /home/testingfilters/.dovecot.lda-dupes
mkdir /home/testingfilters/.dovecot.lda-dupes.locks
chown testingfilters:testingfilters /home/testingfilters/.dovecot.lda-dupes*

Then I resent a test email, the only difference is that nothing shows up in:

/home/testingfilters/mail/domainname.com/testing/dovecot.sieve.log

But, it doesn’t forward still.

Any other log files I can look at?

You know what, I found these messages in the “/var/log/dovecot.log” file, but I can’t understand them

Jan 06 02:12:35 lda([email protected])<656906><//c/HXMLmWUKBgoAE4T90w>: Error: duplicate db: transaction: file_dotlock_open(/home/testingfilters/.dovecot.lda-dupes) failed: Permission denied
Jan 06 02:12:35 lda([email protected])<656906><//c/HXMLmWUKBgoAE4T90w>: Error: unlink(/home/testingfilters/.dovecot.lda-dupes) failed: Permission denied (in mail-duplicate.c:365)
Jan 06 02:12:35 lda([email protected])<656906><//c/HXMLmWUKBgoAE4T90w>: Info: sieve: msgid=[email protected]: redirect action: forwarded to [email protected]
Jan 06 02:12:35 lda([email protected])<656906><//c/HXMLmWUKBgoAE4T90w>: Info: sieve: msgid=[email protected]: stored mail into mailbox ‘INBOX’
Jan 06 02:12:35 lda([email protected])<656906><//c/HXMLmWUKBgoAE4T90w>: Error: duplicate db: transaction: file_dotlock_open(/home/testingfilters/.dovecot.lda-dupes) failed: Permission denied

OK, another update,

I changed the forwarding email address to a different [email protected] and it worked!

So, I think that workaround DID make it kinda work. Although the original forward to email address DID work with a sieve filter on vesta, so I don’t know why it doesn’t work now?

so, do I need to run the 3 commands:

touch /home/user/.dovecot.lda-dupes
mkdir /home/user/.dovecot.lda-dupes.locks
chown user:user /home/user/.dovecot.lda-dupes*

for every user I currently have? and then every user that I add in the future?

I’m probably way off in terms of the logs you sent, but you could try running /usr/local/hestia/install/upgrade/manual/install_sieve.sh to first uninstall and then reinstall Sieve

You can see what it does here: hestiacp/install/upgrade/manual/install_sieve.sh at main · hestiacp/hestiacp · GitHub

Just wanted to throw it in there :innocent:

Thanks CStangerup ! you aren’t way off. I had tried that command, I had found it in another conversation. It just shows:

transport = dovecot_virtual_delivery
dovecot_virtual_delivery:
Plugin allready enabled

So I think it is just solving a previous issue, which is fine, but didn’t help me. I think the 3 commands:

touch /home/user/.dovecot.lda-dupes
mkdir /home/user/.dovecot.lda-dupes.locks
chown user:user /home/user/.dovecot.lda-dupes*

Does solve the issue. I just hope this is made part of the hestiaCP updates because I won’t remember this in the future when I add new users.

1 Like

Hello, my friend.

To avoid having to remember this every time and to ensure that the process is carried out for all users, I created a script and set it to run via cron every day.

It will create the structure only for those who don’t have it.

I placed this file in:

/code/sieve.sh

#!/bin/bash

# Path to the home directory
home_dir="/home"

# List of users to be ignored
ignore_users=("backup" "admin")

# Function to check if a user should be ignored
should_ignore() {
    local user="$1"
    for ignore in "${ignore_users[@]}"; do
        if [ "$user" == "$ignore" ]; then
            return 0
        fi
    done
    return 1
}

# Loop through each directory in /home
for user_dir in "$home_dir"/*; do
    if [ -d "$user_dir" ]; then
        user=$(basename "$user_dir")
        
        # Check if the user should be ignored
        if should_ignore "$user"; then
            echo "Ignoring user: $user"
            continue
        fi
        
        # Check and create if it doesn't exist
        if [ ! -f "$user_dir/.dovecot.lda-dupes" ]; then
            touch "$user_dir/.dovecot.lda-dupes"
        else
            echo "File already exists: $user_dir/.dovecot.lda-dupes"
        fi
        
        # Check and create if it doesn't exist
        if [ ! -d "$user_dir/.dovecot.lda-dupes.locks" ]; then
            mkdir "$user_dir/.dovecot.lda-dupes.locks"
        else
            echo "Directory already exists: $user_dir/.dovecot.lda-dupes.locks"
        fi
        
        # Change ownership of the file and directory
        chown "$user:$user" "$user_dir/.dovecot.lda-dupes" "$user_dir/.dovecot.lda-dupes.locks"

        echo "Configuration completed for user: $user"
    fi
done

Once it’s done, just include it in our Cron.

30 12 * * * root /bin/bash /code/sieve.sh >> /var/log/sieve.log 2>&1

1 Like

Thanks @molero.renan !!! this code is perfect. I added it and ran it and it fixed up about 6 new users that I’d completely forgotten about in the last 5 months so thank you very much for the code and for reminding me about this little problem!

If I was more confident, I would add that command to the end of the file that hestiacp runs when creating new users, that way it would run right after a user was added. But I don’t want to break something, so I just set the cronjob to run every 15 mins.

Show :slight_smile: