#!/bin/sh
#
# Copyright (C) 2010 by Intevation GmbH
# Authors:
# Thomas Arendsen Hein <thomas@intevation.de>
#
# Output of Postfix's "mailq" in one line per mail.
# Output fields (queueid, sender and one or more recipients)
# are separated by tabs.
#
# Tries mailq of Kolab Server first, then uses "mailq" in $PATH.

MAILQ=/kolab/sbin/mailq
test -x "$MAILQ" || MAILQ="mailq"

"$MAILQ" | tail -n +2 | grep -v '^ *(' | gawk  'BEGIN { RS = "" } $1 ~ /^[A-F0-9]/ { gsub("*", "", $1); printf "%s", $1; for(i=7; i<=NF; i++) printf "\t%s", $i; print ""}'
