+sub _ParseContentSimple {
+ my $self = shift;
+ my %args = (
+ Content => undef,
+ TemplateArgs => {},
+ @_,
+ );
+
+ $self->_MassageSimpleTemplateArgs(%args);
+
+ my $template = Text::Template->new(
+ TYPE => 'STRING',
+ SOURCE => $args{Content},
+ );
+ my ($ok) = $template->compile;
+ return ( undef, $self->loc('Template parsing error: [_1]', $Text::Template::ERROR) ) if !$ok;
+
+ # copied from Text::Template::fill_in and refactored to be simple variable
+ # interpolation
+ my $fi_r = '';
+ foreach my $fi_item (@{$template->{SOURCE}}) {
+ my ($fi_type, $fi_text, $fi_lineno) = @$fi_item;
+ if ($fi_type eq 'TEXT') {
+ $fi_r .= $fi_text;
+ } elsif ($fi_type eq 'PROG') {
+ my $fi_res;
+ my $original_fi_text = $fi_text;
+
+ # strip surrounding whitespace for simpler regexes
+ $fi_text =~ s/^\s+//;
+ $fi_text =~ s/\s+$//;
+
+ # if the codeblock is a simple $Variable lookup, use the value from
+ # the TemplateArgs hash...
+ if (my ($var) = $fi_text =~ /^\$(\w+)$/) {
+ if (exists $args{TemplateArgs}{$var}) {
+ $fi_res = $args{TemplateArgs}{$var};
+ }
+ }
+
+ # if there was no substitution then just reinsert the codeblock
+ if (!defined $fi_res) {
+ $fi_res = "{$original_fi_text}";
+ }
+
+ # If the value of the filled-in text really was undef,
+ # change it to an explicit empty string to avoid undefined
+ # value warnings later.
+ $fi_res = '' unless defined $fi_res;
+
+ $fi_r .= $fi_res;
+ }
+ }
+
+ return $fi_r;
+}
+
+sub _MassageSimpleTemplateArgs {
+ my $self = shift;
+ my %args = (
+ TemplateArgs => {},
+ @_,
+ );
+
+ my $template_args = $args{TemplateArgs};
+
+ if (my $ticket = $template_args->{Ticket}) {
+ for my $column (qw/Id Subject Type InitialPriority FinalPriority Priority TimeEstimated TimeWorked Status TimeLeft Told Starts Started Due Resolved RequestorAddresses AdminCcAddresses CcAddresses/) {
+ $template_args->{"Ticket".$column} = $ticket->$column;
+ }
+
+ $template_args->{"TicketQueueId"} = $ticket->Queue;
+ $template_args->{"TicketQueueName"} = $ticket->QueueObj->Name;
+
+ $template_args->{"TicketOwnerId"} = $ticket->Owner;
+ $template_args->{"TicketOwnerName"} = $ticket->OwnerObj->Name;
+ $template_args->{"TicketOwnerEmailAddress"} = $ticket->OwnerObj->EmailAddress;
+
+ my $cfs = $ticket->CustomFields;
+ while (my $cf = $cfs->Next) {
+ my $simple = $cf->Name;
+ $simple =~ s/\W//g;
+ $template_args->{"TicketCF" . $simple}
+ = $ticket->CustomFieldValuesAsString($cf->Name);
+ }
+ }
+
+ if (my $txn = $template_args->{Transaction}) {
+ for my $column (qw/Id TimeTaken Type Field OldValue NewValue Data Content Subject Description BriefDescription/) {
+ $template_args->{"Transaction".$column} = $txn->$column;
+ }
+
+ my $cfs = $txn->CustomFields;
+ while (my $cf = $cfs->Next) {
+ my $simple = $cf->Name;
+ $simple =~ s/\W//g;
+ $template_args->{"TransactionCF" . $simple}
+ = $txn->CustomFieldValuesAsString($cf->Name);
+ }
+ }
+}
+
+sub _DowngradeFromHTML {
+ my $self = shift;
+ my $orig_entity = $self->MIMEObj;
+
+ my $new_entity = $orig_entity->dup; # this will fail badly if we go away from InCore parsing
+ $new_entity->head->mime_attr( "Content-Type" => 'text/plain' );
+ $new_entity->head->mime_attr( "Content-Type.charset" => 'utf-8' );
+
+ $orig_entity->head->mime_attr( "Content-Type" => 'text/html' );
+ $orig_entity->head->mime_attr( "Content-Type.charset" => 'utf-8' );
+
+ my $body = $new_entity->bodyhandle->as_string;
+ $body = Encode::decode( "UTF-8", $body );
+ my $html = RT::Interface::Email::ConvertHTMLToText( $body );
+ $html = Encode::encode( "UTF-8", $html );
+ return unless defined $html;
+
+ $new_entity->bodyhandle(MIME::Body::InCore->new( \$html ));
+
+ $orig_entity->make_multipart('alternative', Force => 1);
+ $orig_entity->add_part($new_entity, 0); # plain comes before html
+ $self->{MIMEObj} = $orig_entity;
+
+ return;
+}
+
+=head2 CurrentUserHasQueueRight