Is there any way to have RT use some kind of "reply above this line" email delimiter?

I’m one of the RT admins at work, and the main feature I’m always asked about is the “–reply above this line” delimiter you see in most modern email-based ticket systems. I’ve done a lot of searching online, but I can’t find a way to implement this. I even looked for Linux tools that could do it–I thought I might be able to use such a tool before RT’s mail processor is called, so RT itself would only receive the email text above the delimiter. I’ve had no luck.

RT’s method of including the entire email, but automatically hiding quoted text, isn’t a great solution. The concerns I hear from users are mostly these:

  • Some mail clients mess up the quoting, especially on longer mail threads. This can lead to random bits of old messages appearing, unquoted, in newer replies.
  • Signatures aren’t quoted by most mail clients. You then get a reply, some quoted text, then the sender’s email signature. Some signatures can be long, or involve images, which makes history annoying to dig through and wastes space (on the screen and in the database).
  • The signature can appear multiple times, as it may not be quoted properly in replies. An unquoted signature could show up two, or three, or five times on a single ticket reply. This makes the previous point even worse.

A delimiter fixes all this, by only putting the text above the line into the ticket. Everyone is asking me if there’s a way to have RT do this, but I’m unable to find anything. If this is possible, how? If not, how to you deal with the problems described above? Thank you.

To clarify, the goal is to parse out content after the delimiter for incoming emails so that it never makes it in the RT transaction? I am guessing there must be a place to do this in the Email interface

Exactly. The templates would include

– Reply above this line –

at the top, after which are all the transaction details. New ticket, owner change, reply, comment, it doesn’t matter. Every template would have that line at the top. When an email came in, if that line were found in it, everything above the line would be processed by RT, while everything below it would be discarded. If the line were absent, the entire email would be processed, as that’s likely a new ticket being sent in via email.

This is similar to Jira, Zendesk, and other help systems I’ve seen. I just can’t work out how to actually make it happen. My Perl knowledge is very low, so I’m not sure how I’d modify the mailgate program. I don’t even know if that’s the place to modify. I’m fine in other languages, just not Perl.

There is the function lib::RT::Ticket::_RecordNote which could have some custom code to do this I think. Then you’d just update your outgoing email templates to contain this delimiter

Thank you, I’ll look into this and see what I can do.

Maybe something like this:

    $args{'MIMEObj'} =~ s/(- Reply above this line -).+/$1/s;

Not totally sure if something else is getting cut off there haha

MIMEObj, not Content? I figured I’d want to modify the Content argument. I may also see if I can track down where this gets called for mail-based correspondence and modify it there. This way we can have discussions about the delimiter string using the website, without those replies being filtered.

Looks like lib/RT/Interface/Email/Action/ line 146

This may work–thank you! I can just modify the message before it gets passed along. Will this work the same as HTML files, where I can create a copy in the same path under the local folder and RT will use my module instead of the one in lib? That is, rt5/local/lib/Interface/Email/Action/ will be used in place of rt5/lib/Interface/Email/Action/

Remember to tell people who do inline quoting in their reply that they’ll need to remove that line, otherwise you’ll potentially lose all/part of the reply they were sending in.

1 Like

I’ve managed to filter the incoming messages using this small python script:

#!/usr/bin/env python3

import sys
import email

SPLIT_MARKER = '## Reply above this line ##'

if __name__ == '__main__':
    message = email.message_from_file(sys.stdin)

    for part in message.walk():
        content_type = part.get_content_type()
        if content_type == 'text/plain':
            txt = part.get_payload()
            txt = txt.split(SPLIT_MARKER)[0]
        elif content_type == 'text/html':
            html = part.get_payload()
            html = html.split('<p>%s</p>' % SPLIT_MARKER)[0] + '</body>\n</html>'


Assuming this is saved to /usr/local/bin/, we only have to pipe the incoming messages through this filter in /etc/aliases, for example:

somequeue: "| /usr/local/bin/ | /usr/bin/rt-mailgate --queue 'somequeue' --action correspond --url"

The templates must include the split marker.

The approach to split the html mail part is far from perfect, but it works.

1 Like

Thank you, this script looks to do exactly what I want. Do you use it with Sendmail? I have our RT set up with Fetchmail, but I’m not at all opposed to switching if there’s no way to insert this script between Fetchmail and the RT mailgate.

I use it with postfix, but I think both sendmail and postfix /etc/aliases implementations are compatible so it should work.

I don’t know how to use this script with fetchmail.

I found a problem, if you’re replying to a message with embedded pictures, the pictures will not be removed from the message. The html split must be smarter for this to be useful.