[rt-users] Headers from a transaction

Bruce Campbell bruce_campbell at ripe.net
Fri Jul 19 13:49:46 EDT 2002


On Fri, 19 Jul 2002, Damian Gerow wrote:

> Right now, our template is $Transaction->Content(), but that gives us the
> body. Is there any way to pull the headers from a transaction object?

Well, you could use $Transaction->Message->First->Headers() , but thats a
bit of a mouthful, and doesn't give you other nice options.

The following can be added to lib/RT/Transaction.pm, and will let you
sauce your Templates to your preferred taste with $Transaction->Headers(),
$Transaction->Headers( Prefix => '> ' ), or $Transaction->Headers( Quote
=> '1', Wrap => '76', Prefix => ': ' ).

( Note, this code is a 5 minute hack, and may require slight adjustment
  for use )

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

# To be added to Transaction.pm
# Mostly same usage as RT::Transaction->Content()
# Takes a paramhash.  If the $args{'Quote'} parameter is set, wraps this
# message at $args{'Wrap'}.  $args{'Wrap'} defaults to 70.
# If $args{'Prefix'} is set, prefixes each line with this sequence (ie, use
# '> ' if thats what you want).

sub Headers () {
	my $self = shift;
	my %args = (	Quote => 0,
			Wrap => 70,
			Prefix => undef,
			@_ );

	my $headers = undef;

	# The headers of the messages are in the first attachment.
	if( defined( $self->Message->First ) ){

		# Assign it.
		$headers = $self->Message->First->Headers;

	}

	# If we have to do anything.
	if( $args{"Quote"} ne "0" && defined( $headers ) && defined( $args{"Wrap"} ) ){
		# Run it through Text::Wrapper
		require Text::Wrapper;
		my $columns = $args{"Wrap"};

		# Adjust for the prefix.
		if( defined( $args{"Prefix"} ) ){
			$columns = $columns - length( $args{"Prefix"} );
		}

		# Wrap it.
		my $wrapper = new Text::Wrapper(
				columns => $args{"Wrap"},
				body_start => "    ",
				);
		$headers = $wrapper->wrap( $headers );
	}

	# If we have to prefix stuff.
	if( defined( $args{"Prefix"} ) && defined( $headers ) ){

		my @tsplit = split( /\n/, $headers );
		$headers = undef;

		# Reassemble it with the Prefix.
		foreach my $poppy( @tsplit ){

			$headers .= $args{"Prefix"} . $poppy . "\n";
		}
	}

	# return whatever we found.
	return( $headers );
}






More information about the rt-users mailing list