I'm primarily a consumer of information on the Zimbra forums, but I thought this script might be handy to those sysamins who are using/supporting Thunderbird clients.

In a nutshell, this script will update the /opt/zimbra/conf/salocal.cf file to whitelist addresses of emails that are tagged as Important in Thunderbird.

The key command to find the tagged emails is as follows... It took me awhile (and a lot of forum searches) to figure this one out.

Code:
zmmailbox -z -m $USER@$DOMAIN s -t message -v "tag:$label1"
In Thunderbird, the tag "Important" is seen by Zimbra as "$label1". You can check Thunderbird's prefs.js file to see this.


Code:
#!/bin/bash

# ==============================================================================
# Bash Script To Create Zimbra Whitelists So That Emails In The Thunderbird
# Mail Client That Are Tagged As "Important" Will Be Accepted By Zimbra's
# SpamAssassin Spam Filter.
# 
# This Script Relies On A Non-Standard Directory, /opt/zimbra/local_bin With
# Read/Write/Execute Privileges For User zimbra.  You Will Need To Make This
# Directory Prior To Running This Script.
#
# The File /opt/zimbra/local_bin/zimbra_whitelist.txt Contains A List Of
# Addresses Of All Previous Emails That Were Labeled Important In Thunderbird
# When This Script Was Executed.  Each Time This Script Is Exectuted, The List
# Will Be Grow To Include Any Newly Tagged Addresses.
#
# Run This Script Nightly In zimbra's cron To Keep The List Current.
#
# Important: Near The Bottom Of This Script, There Is A Safety Valve To Exit
# The Script Before Making Any Important Changes.  You Will Need To Comment
# The Safety Valve exit Before Putting This Script Into Production.
#
# Important: This Script Is Not Designed For Large Sites.  For Each Account,
# This Script Will Take Several Seconds.  This Means It Will Take About 1
# Hour To Process 720 Accounts At 5 Seconds Per Account.  The Reason For
# This Delay Has To Do With The Time It Takes To Initiate zmmailbox During
# The Looping Process.
# 
# Note: Change The Value Of $DOM To Your Domain Or Leave It Empty To Pick
# Up All Domains For Your Server.
#
# Note: When Viewing Mail From The Zimbra Web Interface, The Tag "$label1" Is
# The Same As The Tag "Important" When Viewing Mail In Thunderbird.  If You
# Look In The Thunderbird Config File prefs.js, You Will See That "$label1" Is
# The Same As "Important".
#
# ==============================================================================

# Uncomment For Debugging
# set -x

DOM=""

BASE=$(basename $0)
TMP=/tmp/$BASE.$$
NOW=$(date "+%Y-%m-%d_%H.%M.%S")
DIR=/opt/zimbra/local_bin
SAL=/opt/zimbra/conf/salocal.cf.in

echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Started."

if ! test -d $DIR
 then
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Missing Directory $DIR."
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Exiting With Errors."
  exit 1
fi

if ! test -s $DIR/zimbra_whitelist.txt
 then
  touch $DIR/zimbra_whitelist.txt
fi

# ==============================================================================
# Create Temporary White List From Mails That Are Tagged As Important ($label1)
# ==============================================================================

for i in $(zmprov -l gaa $DOM | egrep -v "(^ham\.|^wiki|^spam\.)")
 do
  zmmailbox -z -m $i s -t message -v "tag:\$label1" >> $TMP.tags 2>>$TMP.err
done

if ! test -s $TMP.tags
 then
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Empty Whitelist, $TMP.tags."
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Exiting With Errors."
  exit 1
fi

grep -B5 ' "type": "f"' $TMP.tags |\
 grep ' "address": ' |\
 sed -e "s/^.* \"//" -e "s/\",$//" |\
 tr "[A-Z]" "[a-z]" |\
 sort -u |\
 grep -v '*' > $TMP.1.tags

if ! test -s $TMP.1.tags
 then
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Empty Whitelist, $TMP.1.tags."
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Exiting With Errors."
  exit 1
fi

# ==============================================================================
# Add Any New Tag Emails To Permanent Tag List
# ==============================================================================

sort -u $DIR/zimbra_whitelist.txt $TMP.1.tags | sed "s/^/whitelist_from /" > $TMP.2.tags

if ! test -s $TMP.2.tags
 then
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Empty Whitelist, $TMP.2.tags."
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Exiting With Errors."
  exit 1
fi

mv $TMP.2.tags $DIR/zimbra_whitelist.txt

# ==============================================================================
# Create New salocal.cf.in In $TMP Directory
# ==============================================================================

cp -p $SAL $TMP.$NOW.sal
grep -v "^whitelist_from " $SAL > $TMP.sal
cat $DIR/zimbra_whitelist.txt >> $TMP.sal

if ! test -s $TMP.sal
 then
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Empty salocal.cf.in File, $TMP.sal"
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Exiting With Errors."
  exit 1
fi

# ==============================================================================
# Safety Valve...
# Up To This Point, No Changes Have Been Made To Zimbra.  Comment The
# Following "exit" Once You Have Verified That This Script Is Working Properly.
# ==============================================================================

exit

# ==============================================================================
# Update salocal.cf.in With New List And Restart Zimbra Processes
# ==============================================================================

cp $TMP.sal $SAL
chown zimbra:zimbra $SAL
chmod 444 $SAL

if zmmtactl restart && zmamavisdctl restart
 then
  echo "Finished $BASE At $(date "+%Y-%m-%d %H:%M:%S")"
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Finished OK."
  exit 0
 else
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Failed To Restart Zimbra Processes."
  echo "$BASE $(date "+%Y-%m-%d %H:%M:%S"): Finished With Errors."
  exit 1
fi

# ==============================================================================
# End Of Script
# ==============================================================================