<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://rt-wiki.bestpractical.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Crazy4chrissi</id>
	<title>Request Tracker Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://rt-wiki.bestpractical.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Crazy4chrissi"/>
	<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/wiki/Special:Contributions/Crazy4chrissi"/>
	<updated>2026-08-22T05:27:06Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://rt-wiki.bestpractical.com/index.php?title=BounceMerge&amp;diff=26436</id>
		<title>BounceMerge</title>
		<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=BounceMerge&amp;diff=26436"/>
		<updated>2016-11-17T09:02:49Z</updated>

		<summary type="html">&lt;p&gt;Crazy4chrissi: Some bug fixes / Updates. Quotemeta added (e.g. versions from Debian backports contain + characters which caused the regex to fail) and RT-Ticket header is nowadays X-RT-Ticket.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a scrip which checks if a newly generated ticket was created by a mail bounce.&lt;br /&gt;
&lt;br /&gt;
If yes, it tries to deduce the original ticket-id and merges this new ticket into the old one.&lt;br /&gt;
&lt;br /&gt;
The scrip logic is quite conservative, only if the same [[TicketID]] is found both in a quoted Message-ID and a RT-Ticket: header, then the scrip merges the tickets.&lt;br /&gt;
&lt;br /&gt;
Note that this requires an accurate Return-Path header. This should normally be added by the final MTA in the chain.&lt;br /&gt;
&lt;br /&gt;
Note also that this causes the logged creation message to be inaccurate, suggesting that the ticket being merged into has just been created.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Condition:&amp;lt;/u&amp;gt; On Create&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Action:&amp;lt;/u&amp;gt; Userdefined&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Template:&amp;lt;/u&amp;gt; Blank&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Custom Condition:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 return 1;  # n/a&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Custom Action Preparation:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 return 1;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Custom Action Cleanup Code:&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    #&lt;br /&gt;
    # Merge mail bounce into old ticket.&lt;br /&gt;
    #&lt;br /&gt;
    # Otmar Lendl &amp;amp;lt;ol@bofh.priv.at&amp;amp;gt;  2009/07/24&lt;br /&gt;
    # Minor Bugfixes/Updates by Christopher Kramer, 2016/11/17&lt;br /&gt;
    #&lt;br /&gt;
    my $ticket = $self-&amp;amp;gt;TicketObj;&lt;br /&gt;
    my $tr     = $self-&amp;amp;gt;TransactionObj;&lt;br /&gt;
    &lt;br /&gt;
    # possible sources of ticket-IDs:&lt;br /&gt;
    &lt;br /&gt;
    # Message-ID of the mail we sent:&lt;br /&gt;
    # example: Message-ID: &amp;amp;lt;rt-3.8.2-1611-1247727152-952.14150-6-0@CERT.at&amp;amp;gt;&lt;br /&gt;
    my $msgregex = &#039;&amp;amp;lt;rt-&#039;. quotemeta($RT::VERSION) .&#039;-\d+-\d+-\d+\.(\d+)-\d+-\d+@&#039;. quotemeta(RT-&amp;amp;gt;Config-&amp;amp;gt;Get(&#039;Organization&#039;)) .&#039;&amp;amp;gt;&#039;;&lt;br /&gt;
    &lt;br /&gt;
    # RT-Ticket: header:&lt;br /&gt;
    # example: RT-Ticket: CERT.at #14150&lt;br /&gt;
    my $rttregex = &#039;^X-RT-Ticket: &#039; .  quotemeta(RT-&amp;amp;gt;Config-&amp;amp;gt;Get(&#039;rtname&#039;)) .&#039; #(\d+)&#039;;&lt;br /&gt;
    &lt;br /&gt;
    my $Attachments = $tr-&amp;amp;gt;Attachments;&lt;br /&gt;
    # get first attachment&lt;br /&gt;
    my $a = $Attachments-&amp;amp;gt;Next;&lt;br /&gt;
    return(1) unless ($a);&lt;br /&gt;
    &lt;br /&gt;
    my $rp = $a-&amp;amp;gt;GetHeader(&#039;Return-Path&#039;);&lt;br /&gt;
    my $ct = $a-&amp;amp;gt;ContentType;&lt;br /&gt;
    &lt;br /&gt;
    # bounce?&lt;br /&gt;
    return(1) unless (($rp eq &#039;&amp;amp;lt;&amp;amp;gt;&#039;) or ($ct eq &#039;multipart/report&#039;));&lt;br /&gt;
    print STDERR &amp;quot;BounceMerge: Looks like a bounce ($rp/$ct). Trying to find ticket-ID.\n&amp;quot;;&lt;br /&gt;
    # .. which is potentially hidden in other attachments. Collect them all first.&lt;br /&gt;
    my $mail = &amp;quot;&amp;quot;;&lt;br /&gt;
    do {&lt;br /&gt;
     my $oh = $a-&amp;amp;gt;Headers;&lt;br /&gt;
     my $oc = $a-&amp;amp;gt;OriginalContent;&lt;br /&gt;
     $mail .= &amp;quot;\n----------------- &amp;quot; . $a-&amp;amp;gt;id . &amp;quot; ---------\n&amp;quot; . $oh if ($oh);&lt;br /&gt;
     $mail .= &amp;quot;\n----------------- &amp;quot; . $a-&amp;amp;gt;id . &amp;quot; ---------\n&amp;quot; . $oc if ($oc);&lt;br /&gt;
    } while ($a = $Attachments-&amp;amp;gt;Next);&lt;br /&gt;
    &lt;br /&gt;
    # look for a message-ID:&lt;br /&gt;
    &lt;br /&gt;
    my $id_msg = -1;&lt;br /&gt;
    my $id_hdr = -2;&lt;br /&gt;
    &lt;br /&gt;
    $id_msg = $1 if ($mail =~ /$msgregex/);&lt;br /&gt;
    $id_hdr = $1 if ($mail =~ /$rttregex/m);&lt;br /&gt;
    &lt;br /&gt;
    if (($id_hdr == $id_msg) and ($id_hdr != $ticket-&amp;amp;gt;EffectiveId) ) {&lt;br /&gt;
     print STDERR &amp;quot;BounceMerge: Removing requestors and merging into $id_msg\n&amp;quot;;&lt;br /&gt;
     my  @reqs = split(/[\s,]+/, $ticket-&amp;amp;gt;RequestorAddresses);&lt;br /&gt;
     foreach (@reqs) {&lt;br /&gt;
       $ticket-&amp;amp;gt;DeleteWatcher(&lt;br /&gt;
         Type    =&amp;amp;gt; &amp;quot;Requestor&amp;quot;,&lt;br /&gt;
         Email   =&amp;amp;gt; $_,&lt;br /&gt;
         Silent  =&amp;amp;gt; 1) ;&lt;br /&gt;
     }&lt;br /&gt;
     $ticket-&amp;amp;gt;MergeInto($id_msg);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    return(1);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It&#039;s worth bearing in mind that there are cases where the bounces may not go into the queue you intended. The branch https://github.com/jmdh/rt/tree/3.8%2Fignore_subject_ticket_for_queues may be of interest, if so.&lt;/div&gt;</summary>
		<author><name>Crazy4chrissi</name></author>
	</entry>
</feed>