rugmonster.org sys admin guides, tips and one-liners

1Dec/090

Remove old messages from Plesk/Qmail Maildir mailboxes

I needed to remove messages older than a week old for a list of email accounts on a Plesk system running Qmail. I put together the following BASH script to locate the messages using find and back them up outside of the mailbox (just in case). This builds on the technique I used in my previous post, Maintain directory structure copying `find` results.

All you need to do is create a file with one address per line to be read in by the command.

cd /var/qmail/mailnames; \
IFS="@"; \ 
while read LINE ; \
do \
    ADDR=( ${LINE} ); \
    echo "${ADDR[0]}@${ADDR[1]}"; \
    find ${ADDR[1]}/${ADDR[0]}/Maildir/ \
        \( -path "*/cur/*" -o -path "*/new/*" \) \
        ! -type d -mtime +7 | \
        while read FILE; \
        do \
            DIR=$( dirname ${FILE} ); \
            mkdir -p /path/to/dst/${DIR}; \
            mv ${FILE} /path/to/dst/${DIR}; \
        done; \
done < /path/to/address_file
27Nov/090

Maintain directory structure copying `find` results

Let's say you have a directory structure consisting of files owned by various users, but you want to copy only the files of a particular user to another path, but maintain the directory structure in the destination path. If you just use something like this...

find /path/to/src/ -user foo -exec cp -a {} /path/to/dst/

...you end up with all of the files in /path/to/dst/ with the original directory structure flattened out.

I came up with the following to solve the problem:

find /path/to/src/ -user foo | while read FILE \
do \
    DIR=$( dirname ${FILE} ); \
    mkdir -p /path/to/dst/${DIR}; \
    cp -d --preserve=mode,ownership,timestamp ${FILE} /path/to/dst/${DIR}; \
done

Here's a brief explanation. Since the find command returns the relative path of the matching item in it's STDOUT, we can use the dirname command to get the original relative directory name. We then create the directory if it doesn't exist, and finally do the copy.

Filed under: Linux, One-Liners No Comments
29May/090

Squirrelmail “Invalid mailbox name” error with Plesk 9.2.1

A client today had a problem with Squirrelmail giving the following error, preventing the folder listing from coming up:

Query: CREATE "Sent"
Reason Given: Invalid mailbox name.
17May/090

Plesk and RBL checking versus SMTP Authentication

A couple of weeks ago at work, I was arguing which RBLs should be used with Plesk came up. I had always assumed that Plesk's qmail setup would allow authenticated users regardless of any RBL results. If that were the case, then using zen.spamhaus.org wouldn't pose any problem to mail users on a residential Internet service. I was wrong, but I wanted to sort out why and what options were available.

8Mar/090

Blocking spammers with Postfix alone

The battle between email admins and spammers is an ongoing arms race. The spammers are at a disadvantage because by and large, they have to rely on exploiting vulnerable systems to send their mail. With the ever growing size of botnets, they have a pretty large pool of exploited systems to send from, but Postfix can be configured to weed out most of that.

Tagged as: Continue reading