[rt-users] email subject manipulation

Niels Bakker niels=rt at bakker.net
Tue Aug 10 12:14:03 EDT 2004


* dimitry.faynerman at hypermediasystems.com (Dimitry Faynerman) [Tue 10 Aug 2004, 17:58 CEST]:
>>> I need to catch an email before ticket is created, and if the email
>>> subject contains a special substring, like "[closed]", I need to remove
>>> it. So when the ticket is created and emails are sent to requestors,
>>> watchers, etc the email subject wouldn't have this substring.
[..]
> Thanks, but is it possible to do that in RT 3.0.9?
> We cannot migrate to 3.2 now

I did this myself by hacking rt-mailgate up a bit, making it read the
headers first into a Mail::Header object, doing the dirty work and only
then passing it on to LWP::UserAgent.

As a start, remove this bit of code:
---
undef $/;
---

and further on, replace this:
---
# Read the message in from STDIN
$args{'message'} = <>;
---

with something along the lines of this code:
---
my $hdr = new Mail::Header(\*STDIN, Modify => 0, MailFrom => "KEEP");

undef $/;
my $body = <>;

my $subject = $hdr->get('Subject',0);
if (defined $subject) {
	chomp $subject;

	# do your evil stuff with $subject here, such as...
	$subject =~ s/\[closed\]\s*//g;

	$hdr->replace('Subject', $subject,0);
}

# ... ready to feed it to RT
$args{'message'} = $hdr->as_string . "\n" . $body;
---

HTH,


	-- Niels.

-- 



More information about the rt-users mailing list