Difference between revisions of "AddTicketHistoryToMail"

From Request Tracker Wiki
Jump to navigation Jump to search
(Changed HTML parsing to HTML::Strip module (tested/working on 4.4.1))
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
Code cleanups: [[RuslanZakirov]]
 
Code cleanups: [[RuslanZakirov]]
  
Require: Text::Wrapper perl module
+
HTML parsing: aaverkios
  
 +
Requirements: Text::Wrapper and HTML::Strip perl modules
  
    Subject: Resolved: {$Ticket->Subject}
+
<pre style="white-space: pre;">
 +
Subject: Resolved: {$Ticket->Subject}
  
    Dear customer,
+
Dear customer,
  
    your issue regarding
+
your issue regarding
  
            "{$Ticket-&gt;Subject()}",
+
        "{$Ticket->Subject()}",
  
    has been resolved in our ticket system. See below for history of this ticket.
+
has been resolved in our ticket system. See below for history of this ticket.
  
    If you have any further questions or concerns, please reply to this
+
If you have any further questions or concerns, please reply to this
    message to reopen the ticket.
+
message to reopen the ticket.
  
    regards
+
regards
  
    {$Ticket-&gt;OwnerObj-&gt;RealName || $Ticket-&gt;OwnerObj-&gt;Name}
+
{$Ticket->OwnerObj->RealName || $Ticket->OwnerObj->Name}
    your-company-fooprint
 
  
 +
your-company-fooprint
  
    ----------------------------------------------------------------
 
      Your initial request was
 
    ----------------------------------------------------------------
 
  
    {$Ticket-&gt;Transactions-&gt;First-&gt;Content()}
+
----------------------------------------------------------------
 +
  Your initial request was
 +
----------------------------------------------------------------
  
    ----------------------------------------------------------------
+
{$Ticket->Transactions->First->Content()}
      Complete Ticket History
 
    ----------------------------------------------------------------
 
  
    {
+
----------------------------------------------------------------
      my $resolved_message = '';
+
  Complete Ticket History
      my $last_content = '';
+
----------------------------------------------------------------
  
      my $transactions = $Ticket-&gt;Transactions;
+
{
 +
  my $resolved_message = '';
 +
  my $last_content = '';
  
 +
  my $transactions = $Ticket->Transactions;
  
      $transactions-&gt;Limit( FIELD =&gt; 'Type', VALUE =&gt; 'Correspond' );
 
      #If for some reason you want to expose internal comments to end users,
 
      #probably a bad idea, comment out the previous line &amp; uncomment these:
 
      #$transactions-&gt;Limit( FIELD =&gt; 'Type', VALUE =&gt; 'Correspond', ENTRYAGGREGATOR =&gt; 'OR', OPERATOR =&gt; '=' );
 
      #$transactions-&gt;Limit( FIELD =&gt; 'Type', VALUE =&gt; 'Comment', ENTRYAGGREGATOR =&gt; 'OR', OPERATOR =&gt; '=' );
 
  
 +
  $transactions->Limit( FIELD => 'Type', VALUE => 'Correspond' );
 +
  # If for some reason you want to expose internal comments to end users,
 +
  # probably a bad idea, comment out the previous line and uncomment these:
 +
  # $transactions->Limit( FIELD => 'Type', VALUE => 'Correspond', ENTRYAGGREGATOR => 'OR', OPERATOR => '=' );
 +
  # $transactions->Limit( FIELD => 'Type', VALUE => 'Comment', ENTRYAGGREGATOR => 'OR', OPERATOR => '=' );
  
      while (my $transaction = $transactions-&gt;Next) {
 
        my $attachments = $transaction-&gt;Attachments;
 
  
        while (my $message = $attachments-&gt;Next) {
+
  while (my $transaction = $transactions->Next) {
          next unless $message-&gt;ContentType =~
+
    my $attachments = $transaction->Attachments;
                  m!^(text/html|text/plain|message|text$)!i;
 
  
          my $content = $message-&gt;Content;
+
    while (my $message = $attachments->Next) {
          $content =~ s/&lt;(([^ &gt;]|\n)*)&gt;//g;  # strip HTML tags from text/html
+
      next unless $message->ContentType =~
          next unless $content;
+
              m!^(text/html|text/plain|message|text$)!i;
  
          next if $last_content eq $content;
+
      my $content = $message->Content;
          $last_content = $content;
 
  
          my $subject = ($message-&gt;Subject || $Ticket-&gt;Subject);
+
      #HTML parsing start
 +
      #Initialize the installed module
 +
      use base "HTML::Strip";
 +
      #Create the strip object with the default constructor
 +
      my $p = HTML::Strip->new();
 +
      # strip the content of HTML
 +
      $content = $p->parse($content);
 +
      #HTML parsing end
  
          my $wrapper = Text::Wrapper-&gt;new(columns=&gt;70);
+
      next unless $content;
          $content = $wrapper-&gt;wrap($content);
 
  
          $resolved_message .= "Subject: ";
+
      next if $last_content eq $content;
          $resolved_message .= $subject;
+
      $last_content = $content;
          $resolved_message .= "\n";
 
          $resolved_message .= "From: ";
 
          $resolved_message .= $message-&gt;CreatorObj-&gt;RealName || $message-&gt;CreatorObj-&gt;EmailAddress;
 
          $resolved_message .= "\n";
 
          $resolved_message .= "Time: ";
 
          $resolved_message .= $message-&gt;CreatedObj-&gt;AsString;
 
          $resolved_message .= "\n";
 
          $resolved_message .= "\n";
 
          $resolved_message .= "$content\n";
 
          $resolved_message .= "------------------------------------------------\n";
 
        }
 
      }
 
      $resolved_message;
 
    }
 
  
    -------------------------------------------------------------------------
+
      my $subject = ($message->Subject || $Ticket->Subject);
        Common Information
 
    -------------------------------------------------------------------------
 
  
    There is no need to reply to this message unless you want to RE-OPEN your
+
      my $wrapper = Text::Wrapper->new(columns=>70);
    ticket with ID [{$rtname} #{$Ticket-&gt;id}].
+
      $content = $wrapper->wrap($content);
  
    If you want to simply add a COMMENT to this ticket without re-opening the ticket, click below:
+
      $resolved_message .= "Subject: ";
    mailto:rt-comment@yourdomain.com?subject=[{$rtname}%20#{$Ticket-&gt;id()}]&amp;body=%20
+
      $resolved_message .= $subject;
 +
      $resolved_message .= "\n";
 +
      $resolved_message .= "From: ";
 +
      $resolved_message .= $message->CreatorObj->RealName || $message->CreatorObj->EmailAddress;
 +
      $resolved_message .= "\n";
 +
      $resolved_message .= "Time: ";
 +
      $resolved_message .= $message->CreatedObj->AsString;
 +
      $resolved_message .= "\n";
 +
      $resolved_message .= "\n";
 +
      $resolved_message .= "$content\n";
 +
      $resolved_message .= "------------------------------------------------\n";
 +
    }
 +
  }
 +
  $resolved_message;
 +
}
  
 +
-------------------------------------------------------------------------
 +
    Common Information
 +
-------------------------------------------------------------------------
  
    Please note:
+
There is no need to reply to this message unless you want to RE-OPEN your
    - ALWAYS include the string [{$rtname} #{$Ticket-&gt;id}] in the subject line of all future correspondence about this issue.
+
ticket with ID [{$rtname} #{$Ticket->id}].
    - Do NOT attach or include the content of previous emails already sent to you by rt.
+
 
 +
If you want to simply add a COMMENT to this ticket without re-opening the ticket, click below:
 +
mailto:rt-comment@yourdomain.com?subject=[{$rtname}%20#{$Ticket->id()}]&body=%20
 +
 
 +
Please note:
 +
- ALWAYS include the string [{$rtname} #{$Ticket->id}] in the subject line of all future correspondence about this issue.
 +
- Do NOT attach or include the content of previous emails already sent to you by rt.
 +
</pre>

Latest revision as of 19:31, 27 April 2017

Original author: Michael Markstaller - IFCO

Code cleanups: RuslanZakirov

HTML parsing: aaverkios

Requirements: Text::Wrapper and HTML::Strip perl modules

 Subject: Resolved: {$Ticket->Subject}

 Dear customer,

 your issue regarding

        "{$Ticket->Subject()}",

 has been resolved in our ticket system. See below for history of this ticket.

 If you have any further questions or concerns, please reply to this
 message to reopen the ticket.

 regards

 {$Ticket->OwnerObj->RealName || $Ticket->OwnerObj->Name}

 your-company-fooprint


 ----------------------------------------------------------------
   Your initial request was
 ----------------------------------------------------------------

 {$Ticket->Transactions->First->Content()}

 ----------------------------------------------------------------
   Complete Ticket History
 ----------------------------------------------------------------

 {
  my $resolved_message = '';
  my $last_content = '';

  my $transactions = $Ticket->Transactions;


  $transactions->Limit( FIELD => 'Type', VALUE => 'Correspond' );
  # If for some reason you want to expose internal comments to end users,
  # probably a bad idea, comment out the previous line and uncomment these:
  # $transactions->Limit( FIELD => 'Type', VALUE => 'Correspond', ENTRYAGGREGATOR => 'OR', OPERATOR => '=' );
  # $transactions->Limit( FIELD => 'Type', VALUE => 'Comment', ENTRYAGGREGATOR => 'OR', OPERATOR => '=' );


  while (my $transaction = $transactions->Next) {
    my $attachments = $transaction->Attachments;

    while (my $message = $attachments->Next) {
      next unless $message->ContentType =~
               m!^(text/html|text/plain|message|text$)!i;

      my $content = $message->Content;

      #HTML parsing start
      #Initialize the installed module
      use base "HTML::Strip";
      #Create the strip object with the default constructor
      my $p = HTML::Strip->new();
      # strip the content of HTML
      $content = $p->parse($content);
      #HTML parsing end

      next unless $content;

      next if $last_content eq $content;
      $last_content = $content;

      my $subject = ($message->Subject || $Ticket->Subject);

      my $wrapper = Text::Wrapper->new(columns=>70);
      $content = $wrapper->wrap($content);

      $resolved_message .= "Subject: ";
      $resolved_message .= $subject;
      $resolved_message .= "\n";
      $resolved_message .= "From: ";
      $resolved_message .= $message->CreatorObj->RealName || $message->CreatorObj->EmailAddress;
      $resolved_message .= "\n";
      $resolved_message .= "Time: ";
      $resolved_message .= $message->CreatedObj->AsString;
      $resolved_message .= "\n";
      $resolved_message .= "\n";
      $resolved_message .= "$content\n";
      $resolved_message .= "------------------------------------------------\n";
    }
  }
  $resolved_message;
 }

 -------------------------------------------------------------------------
    Common Information
 -------------------------------------------------------------------------

 There is no need to reply to this message unless you want to RE-OPEN your
 ticket with ID [{$rtname} #{$Ticket->id}].

 If you want to simply add a COMMENT to this ticket without re-opening the ticket, click below:
 mailto:rt-comment@yourdomain.com?subject=[{$rtname}%20#{$Ticket->id()}]&body=%20

 Please note:
 - ALWAYS include the string [{$rtname} #{$Ticket->id}] in the subject line of all future correspondence about this issue.
 - Do NOT attach or include the content of previous emails already sent to you by rt.