#!/bin/sh

DESCRIPTION="Get top remote recipient data.  Default sort: message count."

DIR="$( cd "$( dirname "$0" )" && pwd )"
RECIPIENTS2="${DIR}/../lib/recipients2.sh"
COLUMNT=/usr/local/qmailanalog/bin/columnt
FUNCS="${DIR}/../lib/functions.sh"

sortcol=1
headers="mess sbytes dest recipient"
header_sort[1]="-rn"
header_sort[2]="-rn"
header_sort[3]=""
header_sort[4]=""

source $FUNCS

get_sort $1

( echo $headers
$RECIPIENTS2 \
   | grep ' remote ' \
   | sort ${header_sort[$sortcol]} -k$sortcol ) \
   | $COLUMNT \
   | less -F
