<?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=Cure</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=Cure"/>
	<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/wiki/Special:Contributions/Cure"/>
	<updated>2026-08-22T20:02:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://rt-wiki.bestpractical.com/index.php?title=AddWatchersOnCorrespond&amp;diff=26424</id>
		<title>AddWatchersOnCorrespond</title>
		<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=AddWatchersOnCorrespond&amp;diff=26424"/>
		<updated>2016-11-04T14:13:09Z</updated>

		<summary type="html">&lt;p&gt;Cure: Fix truncated line in scrip&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= AddWatchersOnCorrespond =&lt;br /&gt;
&lt;br /&gt;
This RT [[Scrip]] will add the person making the correspondence as a [[Watcher]] to the ticket if they are not already a [[Watcher]], also, if the transaction originated from an email message, the script will scan the email headers and add all other recipients to the ticket as [[Watcher]]s (if they are not yet [[Watcher]]s). This can be used to complement the [[ParseNewMessageForTicketCcs]] [[SiteConfig]] option, which is part of the [[EmailInterface]] and does the same thing when tickets are created.&lt;br /&gt;
&lt;br /&gt;
In our RT setup, we have a group named &#039;&#039;&#039;general&#039;&#039;&#039; which contains all admins for our site. If the user this [[Scrip]] is going to add as a [[Watcher]] to the ticket is also a member of the &#039;&#039;&#039;general&#039;&#039;&#039; group, then the Scrip will add them as an [[AdminCC]] [[Watcher]] instead of a [[CC]] [[Watcher]]. It should be fairly easy for others who do not need this feature to remove or modify this [[Scrip]] accordingly.&lt;br /&gt;
&lt;br /&gt;
I wrote this [[Scrip]] to replace the patch we used to make to the RT Email Interface code, called [[ParseFollowupMessageForTicketCcs]]. Accordingly, it carries the same security warning about allowing basically &#039;&#039;&#039;anyone&#039;&#039;&#039; to add themselves to &#039;&#039;&#039;any&#039;&#039;&#039; ticket, simply by sending an appropriately formatted email. Some RT sites might not want this behavior, but it is necessary for us.&lt;br /&gt;
&lt;br /&gt;
Changelog&lt;br /&gt;
&lt;br /&gt;
2012-01-01: Fixed a bug in which the owner of the ticket would have been added as a Cc: for every reply he made. (HaimDimer)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Description:&#039;&#039;&#039; [[AddWatchersOnCorrespond]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Condition:&#039;&#039;&#039; On Correspond&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Action:&#039;&#039;&#039; User Defined&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Template:&#039;&#039;&#039; Global template: Blank&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Stage:&#039;&#039;&#039; [[TransactionBatch]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Custom condition:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Custom action preparation code:&#039;&#039;&#039; &amp;lt;code&amp;gt;return 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Custom action cleanup code:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Get some info:&lt;br /&gt;
my $scrip = &#039;Scrip:AddWatchersOnCorrespond&#039;;&lt;br /&gt;
my $Transaction = $self-&amp;gt;TransactionObj;&lt;br /&gt;
my $EmailAddr = $self-&amp;gt;TransactionObj-&amp;gt;CreatorObj-&amp;gt;EmailAddress;&lt;br /&gt;
my $Queue = $self-&amp;gt;TicketObj-&amp;gt;QueueObj;&lt;br /&gt;
my $Ticket = $self-&amp;gt;TicketObj;&lt;br /&gt;
my $Id = $self-&amp;gt;TicketObj-&amp;gt;id;&lt;br /&gt;
&lt;br /&gt;
# Extract a list of people associated with this transaction:&lt;br /&gt;
#  - including the transaction creator, and if it is an email, the sender and recipients of that email&lt;br /&gt;
my @People = ($EmailAddr);&lt;br /&gt;
foreach my $h (qw(From To Cc)) {&lt;br /&gt;
    my $header = $Transaction-&amp;gt;Attachments-&amp;gt;First-&amp;gt;GetHeader($h);&lt;br /&gt;
    my @addr = Mail::Address-&amp;gt;parse($header);&lt;br /&gt;
    foreach my $addrobj (@addr) {&lt;br /&gt;
        my $addr = lc $RT::Nobody-&amp;gt;UserObj-&amp;gt;CanonicalizeEmailAddress($addrobj-&amp;gt;address);&lt;br /&gt;
        # Ignore the specific addresses for this queue:&lt;br /&gt;
        next if lc $Queue-&amp;gt;CorrespondAddress eq $addr;&lt;br /&gt;
        next if lc $Queue-&amp;gt;CommentAddress eq $addr;&lt;br /&gt;
        # Ignore any email address that looks like one for ANY of our queues:&lt;br /&gt;
        next if RT::EmailParser-&amp;gt;IsRTAddress($addr);&lt;br /&gt;
        $RT::Logger-&amp;gt;debug(&amp;quot;$scrip: Ticket #$Id correspondence contains header - $h: $addr&amp;quot;);&lt;br /&gt;
        push @People, $addr;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Lookup the &#039;experts&#039; (general) group to use below:&lt;br /&gt;
my $Experts = RT::Group-&amp;gt;new($self-&amp;gt;CurrentUser);&lt;br /&gt;
$Experts-&amp;gt;LoadUserDefinedGroup(&#039;general&#039;);&lt;br /&gt;
&lt;br /&gt;
# Now check if each user is already watching the ticket or queue:&lt;br /&gt;
foreach my $addr (@People) {&lt;br /&gt;
    my $User = RT::User-&amp;gt;new($RT::SystemUser);&lt;br /&gt;
    $User-&amp;gt;LoadOrCreateByEmail($addr);&lt;br /&gt;
    my $Name = $User-&amp;gt;Name;&lt;br /&gt;
    my $Principal = $User-&amp;gt;PrincipalId;&lt;br /&gt;
    if ( not ($Queue-&amp;gt;IsWatcher(Type =&amp;gt; &#039;Cc&#039;, PrincipalId =&amp;gt; $Principal) or&lt;br /&gt;
            $Queue-&amp;gt;IsWatcher(Type =&amp;gt; &#039;AdminCc&#039;, PrincipalId =&amp;gt; $Principal) or&lt;br /&gt;
            $Ticket-&amp;gt;IsWatcher(Type =&amp;gt; &#039;Cc&#039;, PrincipalId =&amp;gt; $Principal) or&lt;br /&gt;
            $Ticket-&amp;gt;IsWatcher(Type =&amp;gt; &#039;AdminCc&#039;, PrincipalId =&amp;gt; $Principal) or&lt;br /&gt;
            $Ticket-&amp;gt;IsWatcher(Type =&amp;gt; &#039;Requestor&#039;, PrincipalId =&amp;gt; $Principal) or&lt;br /&gt;
            $Ticket-&amp;gt;IsOwner($User) )) {&lt;br /&gt;
        # If the user is a member of the experts group, then add them as an AdminCc, otherwise as a nor&lt;br /&gt;
        my $type = &#039;Cc&#039;;&lt;br /&gt;
        $type = &#039;AdminCc&#039; if $Experts-&amp;gt;HasMember($User-&amp;gt;PrincipalObj);&lt;br /&gt;
        # Add the new watcher now and check for errors:&lt;br /&gt;
        my ($ret, $msg) = $Ticket-&amp;gt;AddWatcher(Type  =&amp;gt; $type, PrincipalId =&amp;gt; $Principal);&lt;br /&gt;
        if ($ret) {&lt;br /&gt;
            $RT::Logger-&amp;gt;info(&amp;quot;$scrip: New $type watcher added to ticket #$Id: $addr (#$Principal)&amp;quot;);&lt;br /&gt;
        } else {&lt;br /&gt;
            $RT::Logger-&amp;gt;error(&amp;quot;$scrip: Failed to add new $type watcher to ticket #$Id: $addr (#$Principal) - $msg&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&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;
 # vim:ft=perl:&lt;br /&gt;
&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>Cure</name></author>
	</entry>
</feed>