Hi all.

I have written a little script to export an RT search as text tickets
and file attachments, but the thing is I know ridiculously little about
handling MIME objects and even less about character encoding.

I would really appreciate it if you could give this little script a
once-over and give me any pointers you think are necessary to make it
actually worth using.

eg. I'm not handling non-utf8 at all right now, perl just spits
complaints about wide characters, and my handling of mime is limited to
"if it's plain/text or multipart/mixed then append to ticket text file,
otherwise save the content with the Filename".

All feedback is more than welcome.

Feel free to steal this script for your own use. Personally I'm using it
to archive a tiny little RT install. It's not going to be hosted any
more, but the content needs to be accessible for reference.
-- 
Kind Regards,

__________________________________________________

Mike Peachey, IT
Tel: +44 114 281 2655
Fax: +44 114 281 2951
Jennic Ltd, Furnival Street, Sheffield, S1 4QT, UK
Comp Reg No: 3191371 - Registered In England
http://www.jennic.com
__________________________________________________
#!/usr/bin/perl

use Error qw(:try);
use RT::Client::REST;

$directoryname = '/tmp/rt-export-test';
unless (-d $directoryname) {
        print "$directoryname is not a directory.\n";
        exit(1);
} 

my $rt = RT::Client::REST->new(
  server => 'http://rt',
  timeout => 30,
);
my $user = 'root';
my $pass = 'password';

try {
  $rt->login(username => $user, password => $pass);
} catch Exception::Class::Base with {
  die "problem logging in: ", shift->message;
};

# Get the tickets
my @ids = $rt->search(
  type => 'ticket',
  query => "%",
  orderby => '+id'
);

for my $id (@ids) {

  open (TIX, ">${directoryname}/${id}.txt");      
  my ($ticket) = $rt->show(type => 'ticket', id => $id);
  print TIX "Ticket: $id";
  print TIX "\nSubject: ";
  print TIX $ticket->{Subject};
  print TIX "\nContent Follows\n";
    
  my @attachments = $rt->get_attachment_ids(id => $id);
  for my $attachid (@attachments) {
    my $attachment = $rt->get_attachment(parent_id => $id, id => $attachid);
    if($attachment->{ContentType} eq "text/plain"){
      print TIX $attachment->{Content};
    } elsif ($attachment->{ContentType} eq "multipart/mixed"){
      print TIX $attachment->{Content};
    } else {
      mkdir "${directoryname}/${id}";
      open (ATTACH, ">${directoryname}/${id}/$attachment->{Filename}");
      print ATTACH $attachment->{Content};
      close (ATTACH);
    }
  } 
  close (TIX); 
}

1;
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sa...@bestpractical.com


Discover RT's hidden secrets with RT Essentials from O'Reilly Media. 
Buy a copy at http://rtbook.bestpractical.com

Reply via email to