Time-worked email headers?

I’m trying to give our RT installation (3.4.2) the ability to take a
time-worked value in emailed comments and/or correspondence and use it
to update ticket time-worked values. (I’m currently taking it from the
headers, but I may switch to taking it from the body - that’s the easy
part in any case.)

I believe this would be fairly easy to do by hacking on the source, but
for the sake of smoothness of future version upgrades I’ve been trying
to do it as a scrip. But it seems to be hard to do.

My current attempt (which I know is at least somewhat defective) is to
use a scrip run “On Comment User Defined with template Blank” having
its “Custom action preparation code” reading

| my $mailbody = $self->TransactionObj->Attachments->First;
| return 1 unless ($mailbody->ContentType =~ /^text/) &&
| ($mailbody->Headers =~ /^X-RT-Magic-Headers:/iom);
| my $ticket = $self->TicketObj;
| my $content = $mailbody->Content;
| my $newcontent = undef;
| my $addcontent = sub {
| $newcontent = join “”, $newcontent, @_;
| $mailbody->__Set(
| Field => ‘Content’,
| Value => $newcontent . $content
| );
| };
| &$addcontent(ref($ticket),“\n\n”);
| if ($mailbody->Headers =~ /^X-RT-Time-Worked: (\d+)(|:(\d\d))$/om)
| { my $t = ($2 eq “”) ? $1+0 : ($1*60)+$3;
| &$addcontent(“Time from header: “.$t.”\n\n”);
| # It’s not clear how to affect the current tranaction’s TimeTaken
| # value, so instead we create a new transaction for it.
| require RT::Record;
| $ticket->_NewTransaction(
| TimeTaken => $t,
| Type => ‘Set’,
| Field => ‘TimeWorked’,
| OldValue => $ticket->__Value(‘TimeWorked’),
| NewValue => $ticket->__Value(‘TimeWorked’)+$t,
| ActivateScrips => 0
| );
| # $ticket->_UpdateTimeTaken($t);
| }
| 1;

I’d actually like to make the time appear as the time worked for the
Comment transaction (equivalent in this respect to the Worked field in
the comment-on-a-ticket Web page), and if anyone can explain how to
make that happen from a scrip, I’d be delighted.

Failing that, though, I tried to add a new transaction to record the
time, but my time-bearing transactions end up being owned by RT_System
instead of the commenting user.

Could anyone point me in the correct direction? Preferably the
direction of setting the time for the Comment transaction, but failing
that, the direction of adding a new transaction owned by the commenting

Or is there just no way to do this from a scrip, and it’s hack the
source or nothing?

On a related note, is there a proper way to replace a scrip without
having to go through the stupid Web text form? Web browser text fields
are not acceptable as text editors, especially when they’re only five
lines long. I’m currently slamming the scrip into the underlying db
with “update Scrips set CustomPrepareCode=”…" where Scrips.id=###",
but that feels rather gross, even though it seems to work fine.

/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B