-sub CreateFrom822 {
- my $self = shift;
- my $content = shift;
-
-
-
- my %args = $self->_Parse822HeadersForAttributes($content);
-
- # Now we have a %args to work with.
- # Make sure we have at least the minimum set of
- # reasonable data and do our thang
- my $ticket = RT::Ticket->new($RT::SystemUser);
-
- my %ticketargs = (
- Queue => $args{'queue'},
- Subject => $args{'subject'},
- Status => $args{'status'},
- Due => $args{'due'},
- Starts => $args{'starts'},
- Started => $args{'started'},
- Resolved => $args{'resolved'},
- Owner => $args{'owner'},
- Requestor => $args{'requestor'},
- Cc => $args{'cc'},
- AdminCc => $args{'admincc'},
- TimeWorked => $args{'timeworked'},
- TimeEstimated => $args{'timeestimated'},
- TimeLeft => $args{'timeleft'},
- InitialPriority => $args{'initialpriority'},
- FinalPriority => $args{'finalpriority'},
- Type => $args{'type'},
- DependsOn => $args{'dependson'},
- DependedOnBy => $args{'dependedonby'},
- RefersTo => $args{'refersto'},
- ReferredToBy => $args{'referredtoby'},
- Members => $args{'members'},
- MemberOf => $args{'memberof'},
- MIMEObj => $args{'mimeobj'}
- );
-
- # Add custom field entries to %ticketargs.
- # TODO: allow named custom fields
- map {
- /^customfield-(\d+)$/
- && ( $ticketargs{ "CustomField-" . $1 } = $args{$_} );
- } keys(%args);
-
- my ( $id, $transid, $msg ) = $ticket->Create(%ticketargs);
- unless ($id) {
- $RT::Logger->error( "Couldn't create a related ticket for "
- . $self->TicketObj->Id . " "
- . $msg );
- }
-
- return (1);
-}
-
-# }}}
-
-# {{{ UpdateFrom822
-
-=head2 UpdateFrom822 $MESSAGE
-
-Takes an RFC822 format message as a string and uses it to make a bunch of changes to a ticket.
-Returns an um. ask me again when the code exists
-
-
-=begin testing
-
-my $simple_update = <<EOF;
-Subject: target
-AddRequestor: jesse\@example.com
-EOF
-
-my $ticket = RT::Ticket->new($RT::SystemUser);
-my ($id,$msg) =$ticket->Create(Subject => 'first', Queue => 'general');
-ok($ticket->Id, "Created the test ticket - ".$id ." - ".$msg);
-$ticket->UpdateFrom822($simple_update);
-is($ticket->Subject, 'target', "changed the subject");
-my $jesse = RT::User->new($RT::SystemUser);
-$jesse->LoadByEmail('jesse@example.com');
-ok ($jesse->Id, "There's a user for jesse");
-ok($ticket->Requestors->HasMember( $jesse->PrincipalObj), "It has the jesse principal object as a requestor ");
-
-=end testing
-
-
-=cut
-
-sub UpdateFrom822 {
- my $self = shift;
- my $content = shift;
- my %args = $self->_Parse822HeadersForAttributes($content);
-
-
- my %ticketargs = (
- Queue => $args{'queue'},
- Subject => $args{'subject'},
- Status => $args{'status'},
- Due => $args{'due'},
- Starts => $args{'starts'},
- Started => $args{'started'},
- Resolved => $args{'resolved'},
- Owner => $args{'owner'},
- Requestor => $args{'requestor'},
- Cc => $args{'cc'},
- AdminCc => $args{'admincc'},
- TimeWorked => $args{'timeworked'},
- TimeEstimated => $args{'timeestimated'},
- TimeLeft => $args{'timeleft'},
- InitialPriority => $args{'initialpriority'},
- Priority => $args{'priority'},
- FinalPriority => $args{'finalpriority'},
- Type => $args{'type'},
- DependsOn => $args{'dependson'},
- DependedOnBy => $args{'dependedonby'},
- RefersTo => $args{'refersto'},
- ReferredToBy => $args{'referredtoby'},
- Members => $args{'members'},
- MemberOf => $args{'memberof'},
- MIMEObj => $args{'mimeobj'}
- );
-
- foreach my $type qw(Requestor Cc Admincc) {
-
- foreach my $action ( 'Add', 'Del', '' ) {
-
- my $lctag = lc($action) . lc($type);
- foreach my $list ( $args{$lctag}, $args{ $lctag . 's' } ) {
-
- foreach my $entry ( ref($list) ? @{$list} : ($list) ) {
- push @{$ticketargs{ $action . $type }} , split ( /\s*,\s*/, $entry );
- }
-
- }
-
- # Todo: if we're given an explicit list, transmute it into a list of adds/deletes
-
- }
- }
-
- # Add custom field entries to %ticketargs.
- # TODO: allow named custom fields
- map {
- /^customfield-(\d+)$/
- && ( $ticketargs{ "CustomField-" . $1 } = $args{$_} );
- } keys(%args);
-
-# for each ticket we've been told to update, iterate through the set of
-# rfc822 headers and perform that update to the ticket.
-
-
- # {{{ Set basic fields
- my @attribs = qw(
- Subject
- FinalPriority
- Priority
- TimeEstimated
- TimeWorked
- TimeLeft
- Status
- Queue
- Type
- );
-
-
- # Resolve the queue from a name to a numeric id.
- if ( $ticketargs{'Queue'} and ( $ticketargs{'Queue'} !~ /^(\d+)$/ ) ) {
- my $tempqueue = RT::Queue->new($RT::SystemUser);
- $tempqueue->Load( $ticketargs{'Queue'} );
- $ticketargs{'Queue'} = $tempqueue->Id() if ( $tempqueue->id );
- }
-
- # die "updaterecordobject is a webui thingy";
- my @results;
-
- foreach my $attribute (@attribs) {
- my $value = $ticketargs{$attribute};
-
- if ( $value ne $self->$attribute() ) {
-
- my $method = "Set$attribute";
- my ( $code, $msg ) = $self->$method($value);
-
- push @results, $self->loc($attribute) . ': ' . $msg;
-
- }
- }
-
- # We special case owner changing, so we can use ForceOwnerChange
- if ( $ticketargs{'Owner'} && ( $self->Owner != $ticketargs{'Owner'} ) ) {
- my $ChownType = "Give";
- $ChownType = "Force" if ( $ticketargs{'ForceOwnerChange'} );
-
- my ( $val, $msg ) = $self->SetOwner( $ticketargs{'Owner'}, $ChownType );
- push ( @results, $msg );
- }
-
- # }}}
-# Deal with setting watchers
-
-
-# Acceptable arguments:
-# Requestor
-# Requestors
-# AddRequestor
-# AddRequestors
-# DelRequestor
-
- foreach my $type qw(Requestor Cc AdminCc) {
-
- # If we've been given a number of delresses to del, do it.
- foreach my $address (@{$ticketargs{'Del'.$type}}) {
- my ($id, $msg) = $self->DeleteWatcher( Type => $type, Email => $address);
- push (@results, $msg) ;
- }
-
- # If we've been given a number of addresses to add, do it.
- foreach my $address (@{$ticketargs{'Add'.$type}}) {
- $RT::Logger->debug("Adding $address as a $type");
- my ($id, $msg) = $self->AddWatcher( Type => $type, Email => $address);
- push (@results, $msg) ;
-
- }
-
-
-}
-
-
-}
-# }}}
-
-# {{{ _Parse822HeadersForAttributes Content
-
-=head2 _Parse822HeadersForAttributes Content
-
-Takes an RFC822 style message and parses its attributes into a hash.
-
-=cut
-
-sub _Parse822HeadersForAttributes {
- my $self = shift;
- my $content = shift;
- my %args;
-
- my @lines = ( split ( /\n/, $content ) );
- while ( defined( my $line = shift @lines ) ) {
- if ( $line =~ /^(.*?):(?:\s+(.*))?$/ ) {
- my $value = $2;
- my $tag = lc($1);
-
- $tag =~ s/-//g;
- if ( defined( $args{$tag} ) )
- { #if we're about to get a second value, make it an array
- $args{$tag} = [ $args{$tag} ];
- }
- if ( ref( $args{$tag} ) )
- { #If it's an array, we want to push the value
- push @{ $args{$tag} }, $value;
- }
- else { #if there's nothing there, just set the value
- $args{$tag} = $value;
- }
- } elsif ($line =~ /^$/) {
-
- #TODO: this won't work, since "" isn't of the form "foo:value"
-
- while ( defined( my $l = shift @lines ) ) {
- push @{ $args{'content'} }, $l;
- }
- }
-
- }
-
- foreach my $date qw(due starts started resolved) {
- my $dateobj = RT::Date->new($RT::SystemUser);
- if ( $args{$date} =~ /^\d+$/ ) {
- $dateobj->Set( Format => 'unix', Value => $args{$date} );
- }
- else {
- $dateobj->Set( Format => 'unknown', Value => $args{$date} );
- }
- $args{$date} = $dateobj->ISO;
- }
- $args{'mimeobj'} = MIME::Entity->new();
- $args{'mimeobj'}->build(
- Type => ( $args{'contenttype'} || 'text/plain' ),
- Data => ($args{'content'} || '')
- );
-
- return (%args);
-}
-
-# }}}
-
-# {{{ sub Import
-
-=head2 Import PARAMHASH
-
-Import a ticket.
-Doesn\'t create a transaction.
-Doesn\'t supply queue defaults, etc.
-
-Returns: TICKETID
-
-=cut
-
-sub Import {
- my $self = shift;
- my ( $ErrStr, $QueueObj, $Owner );