wardmw has asked for the wisdom of the Perl Monks concerning the following question:
I am writing a Perl script to retrieve attachments from an RT instance and write them out to individual files. I did this three years ago, with a previous incarnation of the Client::RT libraries, and with assistance from your clergy got it working. I have since upgraded to a newer revision of Perl (5.16.3) and a newer version of the RT Perl libraries (0.52). I am having to rewrite this old code and have come up with a new, different problem instead.
All I want to do is take the attachments from the tickets and write them out to a file, these files need to be written in whatever format they were stored in (png, xlsx, txt, whatever). You'd think this was a simple task but I can't make it happen.
If I save a file using the RT web interface and hex dump the first few chunks it looks like this:
0000000 50 4b 03 04 14 00 09 00 08 00 67 8d 25 46 00 00 0000010 00 00 00 00 00 00 00 00 00 00 1c 00 00 00 73 63 0000020 72 65 65 6e 73 68 6f 74 2d 31 37 32 20 32 31 20 0000030 32 34 32 20 36 34 2e 7a 69 70 32 9e 8a fc b5 15
Yet if I read the attachment in to a string using the RT API and hex dump that string see:
00000000 50 4B 03 04 14 00 09 00 - 08 00 67 FFFD 25 46 00 00 PK..... +...g.%F.. 00000010 00 00 00 00 00 00 00 00 - 00 00 1C 00 00 00 73 63 ......... +.....sc 00000020 72 65 65 6E 73 68 6F 74 - 2D 31 37 32 20 32 31 20 reenshot- +172 21 00000030 32 34 32 20 36 34 2E 7A - 69 70 32 FFFD FFFD FFFD FFFD 15 2 +42 64.zip2.....
Note the four-digit hex chars on lines 1 and 4. The code I used to generate the above is as follows:
I've tried adding#!/usr/bin/env perl # # wctest.pl - A test to see where the wide characters come from. use strict; use warnings; use RT::Client::REST; use RT::Client::REST::Ticket; use Data::HexDump; my $user='user'; my $pass='pass'; my $rt = RT::Client::REST->new( server => ('https://rt.local'), basic_auth_cb => ( sub { return ($user, $pass); } ) ); $rt->login( username=> $user, password=> $pass,); my $ticket_ptr = RT::Client::REST::Ticket->new(rt => $rt); my $results = $ticket_ptr->search( limits => [ { attribute => 'id', op +erator => '=', value => '51447' }, ],); my $iterator = $results->get_iterator; my ($ticket, $attachments); while ($ticket = &$iterator) { $attachments = $ticket->attachments; # Store attachments my $atch_ater = $attachments->get_iterator; while (my $att = &$atch_ater) { next if ($att->file_name eq ''); print HexDump substr($att->content, 0, 64); } }
anduse Encode;
use utf8;
both together and alone but no difference was made, the hex dump still shows multibyte characters.
I have even tried just writing the data out to files, in case the problem was with the HexDump module, but it still failed to create the files in their native format, usually almost doubling the number of characters in the file than are in the stringed attachment.
I would appreciate any help or guidance you might be able to provide, I', banging my head against the wall here.
|\/|artin
|
|---|