Source http://www.geert.triple-it.nl/rt_procmail.html

Using Procmail to deliver RT-mail to queues

By: Geert van der Ploeg
Last update: 20030710

Problem

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.

Solution

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.

Step by step

1. Create dispatcher-account
Create an account which is to gather all RT-mail.
For example:
$ useradd rt_dispatcher
2. /etc/mail/virtusertable
In /etc/mail/virtusertable, create an entry for all RT-mail.
For example:
$ cat /etc/mail/virtusertable
@rt.mydomain.com rt_dispatcher
3. Required perl snippets
Place the following perl things in the homedirectory of the dispatcher:
get_queue.pl:
#!/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";
4. Procmail config
Place the following Procmail configuration in the homedirectory of the dispatcher, in .procmailrc:

	#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
	}

You should change the parameters in the top of the configuration file to your needs.
Check the logfile (procmail.log) if things do not work as expected.

Issues

This whole setup expects that there's a generic naming-convention for you addressing. It only works if you've got your addressing like this:
queuename@rt.mydomain.com
queuename-comment@rt.mydomain.com
queue2name@rt.mydomain.com
queue2name-comment@rt.mydomain.com

Feedback

Does it work for you? Doesn't it? Is there a bug in the setup above? Please let me know!


Geert van der Ploeg
web@geert.triple-it.nl