Source http://www.geert.triple-it.nl/rt_procmail.html
Request Tracker is capable of using e-mail to create/correspond/comment about tickets. The default way of configuring this, is to create two e-mail aliases for each queue: one for corresponding/creating, and one for commenting.
As the number of queues our company uses, continues to grow, we didn't want to create aliases manually anymore. That would leave the configuration to a single point (the web-interface) and thus simplifies the creation of queues.
In short, the solution is as follows:
All e-mail for request-tracker is gathered into one account, the 'dispatcher'.
This account determines to which queue the e-mail should be routed and whether it's a correspondence or comment.
$ useradd rt_dispatcher
$ cat /etc/mail/virtusertable
@rt.mydomain.com rt_dispatcher
#!/usr/bin/env perl
@arr = <STDIN>;
$queue = 'general';
foreach (@arr) {
if (/\s*.*<([^@]+)@.*>/g) {
$queue = $1;
} else {
if (/\s*([^@]+)@.*/g) {
$queue= $1;
}
}
}
if ($queue =~ /(.*)-comment/)
{
$queue = $1;
}
print "$queue";
get_action.pl:
#!/usr/bin/env perl
@arr = <STDIN>;
$action = "correspond";
foreach (@arr) {
if (/\s*.*<([^@]+)-comment@.*>/g) {
$action = "comment";
} else {
if (/\s*([^@]+)-comment@.*/g) {
$action = "comment";
}
}
}
print "$action";
#Preliminaries
SHELL=/bin/sh #Use the Bourne shell (check your path!)
MAILDIR=${HOME} #First check what your mail directory is!
LOGFILE=${MAILDIR}/procmail.log
LOG="--- Logging ${LOGFILE} for ${LOGNAME}, "
VERBOSE=yes
MAILDOMAIN=rt.mydomain.com
RT_MAILGATE="/usr/local/bin/rt-mailgate"
RT_URL="http://rt.mydomain.com/"
LOGABSTRACT=all
:0
{
# the following line extracts the recipient from Received-headers.
# Simply using the To: does not work, as tickets are often created
# by sending a CC/BCC to RT
TO=`formail -c -xReceived: |grep $MAILDOMAIN |sed -e 's/.*for *<*\(.*\)>* *;.*$/\1/'`
QUEUE=`echo $TO| $HOME/get_queue.pl`
ACTION=`echo $TO| $HOME/get_action.pl`
:0 h b w
|/usr/bin/perl $RT_MAILGATE --queue $QUEUE --action $ACTION --url $RT_URL
}