This might be a bit of a niche use case but it's useful to me so may be to others.
I run my B3 as a mail server and use Google Mail to sync my contacts between Thunderbird, iPhone, iPad and roundcube web mail on the B3.
The default spam blocking on the B3 is a little oversensitive and I found that some emails from trusted contacts were being blocked* so I've written a script that will add all the email addresses in my Google Contacts to a whitelist for Postfix. I can then run this script once a week so it picks up any new contacts I've added.
First, you need to install the package python-gdata. You will need to enable the squeeze repositories if you haven't already by adding these lines to /etc/apt/sources.list:
Code: Select all
deb http://ftp.se.debian.org/debian squeeze main
deb http://ftp.se.debian.org/debian squeeze contrib
deb http://ftp.se.debian.org/debian squeeze non-free
Code: Select all
aptitude update
aptitude install python-gdata
If you're doing this directly from your B3 then do this:
Code: Select all
cd /home/admin/downloads
wget http://googlecl.googlecode.com/files/googlecl_0.9.13-1_all.deb
Code: Select all
dpkg -i googlecl_0.9.13-1_all.deb
Enter this command:
Code: Select all
google contacts list --title=
Once you've entered your verification code your contacts should all be listed.
Run the command again and this time it should work straight away.
Assuming the above worked you now need to get the list of email addresses formatted in such as way that Postfix will accept it.
We can do this using sed to manipulate the output of the GoogleCL command.
Enter this command:
Code: Select all
google contacts list --title= --fields=email | \
grep -i @ | \
sed -e 's/;/\n/' | \
sed -e 's/;/\n/' | \
sed -e 's/home//' | \
sed -e 's/work//' | \
sed -e 's/other//' | \
sed 's/^[ \t]*//' | \
sed 's/[ \t]*$//' | \
sed 's/$/ OK/g'
Code: Select all
sed -e 's/custom//' | \
You now need to add this to a script.
In a text editor (.e.g. nano) - nano /path/to/script/googlewhitelist.sh - enter the following (remembering to include your custom lines if necessary):
Code: Select all
#!/bin/bash
google contacts list --title= --fields=email | \
grep -i @ | \
sed -e 's/;/\n/' | \
sed -e 's/;/\n/' | \
sed -e 's/home//' | \
sed -e 's/work//' | \
sed -e 's/other//' | \
sed 's/^[ \t]*//' | \
sed 's/[ \t]*$//' | \
sed 's/$/ OK/g' > /etc/postfix/sender_access
for EMAIL in `cat /home/admin/scripts/rejectedemails`
do
echo $EMAIL | sed 's/$/ REJECT/g' >> /etc/postfix/sender_access
done;
for EMAIL in `cat /home/admin/scripts/acceptedemails`
do
echo $EMAIL | sed 's/$/ OK/g' >> /etc/postfix/sender_access
done;
postmap hash:/etc/postfix/sender_access
/etc/init.d/postfix restart
You can add specific email addresses to these files or whole domains by just adding the domain part of the email address. E.g:
Code: Select all
dave@gmail.com
yahoo.com
hotmail.com
Code: Select all
check_sender_access
hash:/etc/postfix/sender_access
If you run the script you've just written (sh googlewhitelist.sh) it should run through without any hiccups.
Assuming this all works, you can add it to cron.weekly, cron.monthly or create a more specific schedule using a crontab file.
Code: Select all
chmod +x googlewhitelist.sh
ln -s /home/admin/scripts/googlewhitelist.sh /etc/cron.weekly/googleswhitelist