[rt-users] where is my message content?

Bruce Campbell bruce_campbell at ripe.net
Mon Aug 26 16:30:53 EDT 2002


On Mon, 26 Aug 2002, timuel wrote:

> I`ve been given the task (from up above...) to write a script that regularly
> fetches tickets/emails out of a certain queue, forward them to a non-RT address,
> and mark the ticket as resolved with a note saying that it`s been forwarded
> appropriately.
>
> $ticketid = "select ID from Tickets where Queue = 'whatever' and (status = 'new'
> || status = 'open');";
> $email = "select Headers,Content from Tickets,Attachments where Tickets.Subject
> = Attachments.Subject and Tickets.Created = Attachments.Created and Tickets.id =
> '$ticketid';";

'ugh'.

Why not use the public interfaces in RT::Ticket to simply do:

	my $tickets = RT::Tickets->new( $RT::CurrentUser );
	$tickets->UnLimit;
	# Lets pretend we only want 'new' tickets.
	$tickets->LimitStatus( VALUE => 'new',
				OPERATOR => '=', );

	# In queue 'smaland'
	$tickets->LimitQueue( VALUE => 'smaland',
				OPERATOR => '=', );

	# That haven't been picked up for ages.
	my $tmpdate = RT::Date->new( $RT::CurrentUser );
	# Not sure if RT::Date will parse this.
	$tmpdate->Set( Format => 'Unknown', Value => '5 hours ago' );
	$tickets->LimitCreated( VALUE => $tmpdate->ISO,
				OPERATOR => '>=' );

	# Lets go and see what we've got.
	while( my $ticket = $tickets->Next ){
		my $headers = $ticket->Transactions->First->Message->Headers();

		# start generating message
		while( my $attachment = $ticket->Transactions->Next ){
			# attach stuff to the message
		}

		# send the message to the other address.

		# resolve the ticket.
		$ticket->Resolve();

		# remember to tell the original parent^Wrequestor that
		# their child^Wticket has been shifted elsewhere, although
		# I'd do a Scrip for this.

	}

( Note, this is untested. )

Or, you could bundle this in a thing for Escalator.

Regards,

-- 
                             Bruce Campbell                            RIPE
                   Systems/Network Engineer                             NCC
                 www.ripe.net - PGP562C8B1B             Operations/Security





More information about the rt-users mailing list