--- /dev/null
+#!/bin/bash
+
+set -e
+set -u
+
+LDAP_SERVER='ldap://ldap.pixelpark.com'
+LDAP_BIND_DN='cn=admin'
+LDAP_BIND_PW='3o.o0dlt'
+LDAP_BASE_DN='o=isp'
+
+USER="${1:-frank.brehm}"
+
+echo "Suche DN für User '${USER}' ..." >&2
+
+USER_DN=$( ldapsearch -LLL \
+ -H "${LDAP_SERVER}" \
+ -b "${LDAP_BASE_DN}" \
+ -x -D "${LDAP_BIND_DN}" -w "${LDAP_BIND_PW}" \
+ "uid=${USER}" \
+ dn | sed -e 's/^dn:[ ][ ]*//i' )
+echo "Fand DN '${USER_DN}'." >&2
+echo >&2
+
+SIEVE64=$( ldapsearch -LLL \
+ -H "${LDAP_SERVER}" \
+ -b "${USER_DN}" \
+ -x -D "${LDAP_BIND_DN}" -w "${LDAP_BIND_PW}" \
+ "objectclass=*" mailSieveRuleSource | \
+ grep -v '^dn:' | \
+ sed -e 's/^mailSieveRuleSource::*[ ]*//i' \
+ -e 's/[ ]//g' \
+ -e 's/=//g' )
+
+echo "${SIEVE64}" | base64 -d
+
+
+# vim: ts=4 list
--- /dev/null
+#!/bin/bash
+
+set -e
+set -u
+
+LDAP_SERVER='ldap://ldap.pixelpark.com'
+LDAP_BIND_DN='cn=admin'
+LDAP_BIND_PW='3o.o0dlt'
+LDAP_BASE_DN='o=isp'
+
+
+usage() {
+ cat <<-EOF
+ Usage: USER_NAME SIEVE_FILE
+
+ EOF
+}
+
+if [[ "$#" -ne 2 ]] ; then
+ usage >&2
+ exit 1
+fi
+
+USER="${1}"
+SIEVE_FILE="${2}"
+
+if [[ ! -f "${SIEVE_FILE}" ]] ; then
+ echo "Sieve file '${SIEVE_FILE}' existiert nicht." >&2
+ echo >&2
+ usage >&2
+ exit 1
+fi
+SIEVE_FILE=$( readlink -f "${SIEVE_FILE}" )
+
+echo "Suche DN für User '${USER}' ..."
+
+USER_DN=$( ldapsearch -LLL \
+ -H "${LDAP_SERVER}" \
+ -b "${LDAP_BASE_DN}" \
+ -x -D "${LDAP_BIND_DN}" -w "${LDAP_BIND_PW}" \
+ "uid=${USER}" \
+ dn | sed -e 's/^dn:[ ][ ]*//i' )
+
+if [[ -z "${USER_DN}" ]] ; then
+ echo "User '${USER}' nicht im LDAP gefunden." >&2
+ echo >&2
+ exit 1
+fi
+
+LDIF_FILE=$( mktemp modify-sieve-XXXXXXXX.ldif )
+
+#------------------------------------------------------------------------------
+cleanup_tmp_script() {
+
+ if [[ -n "${LDIF_FILE}" ]] ; then
+ if [[ -f "${LDIF_FILE}" ]] ; then
+ rm -fv "${LDIF_FILE}"
+ fi
+ fi
+
+}
+
+trap cleanup_tmp_script INT TERM EXIT
+
+cat > "${LDIF_FILE}" <<-EOF
+ dn: ${USER_DN}
+ changetype: modify
+ EOF
+
+echo
+echo "Fand DN '${USER_DN}'."
+echo
+echo "Suche existierenden Sieve Eintrag ..."
+echo
+
+CUR_SIEVE64=$( ldapsearch -LLL \
+ -H "${LDAP_SERVER}" \
+ -b "${USER_DN}" \
+ -x -D "${LDAP_BIND_DN}" -w "${LDAP_BIND_PW}" \
+ "objectclass=*" mailSieveRuleSource | \
+ grep -i '^mailSieveRuleSource:' || true )
+
+if [[ -z "${CUR_SIEVE64}" ]] ; then
+ echo "Füge Attribut mailSieveRuleSource hinzu ..."
+ cat >> "${LDIF_FILE}" <<-EOF
+ add: mailSieveRuleSource
+ EOF
+else
+ echo "Ändere Attribut mailSieveRuleSource ..."
+ cat >> "${LDIF_FILE}" <<-EOF
+ replace: mailSieveRuleSource
+ EOF
+fi
+
+echo "mailSieveRuleSource:< file://${SIEVE_FILE}" >> "${LDIF_FILE}"
+echo "-" >> "${LDIF_FILE}"
+echo '' >> "${LDIF_FILE}"
+
+echo
+echo "Resultierendes LDIF:"
+echo "--------------------"
+echo
+cat "${LDIF_FILE}"
+
+CMD="ldapmodify -H \"${LDAP_SERVER}\""
+CMD+=" -x -D \"${LDAP_BIND_DN}\" -w \"${LDAP_BIND_PW}\""
+CMD+=" -f \"$( readlink -f "${LDIF_FILE}" )\""
+
+echo
+echo "Ausführen:"
+echo "${CMD}"
+echo
+
+eval ${CMD}
+
+echo
+
+# vim: ts=4 list