[Rt-commit] r8628 - rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT
ruz at bestpractical.com
ruz at bestpractical.com
Sat Aug 18 01:42:41 EDT 2007
Author: ruz
Date: Sat Aug 18 01:42:40 2007
New Revision: 8628
Modified:
rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/EmailParser.pm
Log:
* add 'Exact' argument to email parser, that is equivalent of
decode_bodies(0) of MIME::Parser
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/EmailParser.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/EmailParser.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/EmailParser.pm Sat Aug 18 01:42:40 2007
@@ -89,19 +89,18 @@
}
-=head2 SmartParseMIMEEntityFromScalar { Message => SCALAR_REF, Decode => BOOL }
+=head2 SmartParseMIMEEntityFromScalar Message => SCALAR_REF [, Decode => BOOL, Exact => BOOL ] }
-Parse a message stored in a scalar from scalar_ref
+Parse a message stored in a scalar from scalar_ref.
=cut
sub SmartParseMIMEEntityFromScalar {
my $self = shift;
- my %args = ( Message => undef, Decode => 1, @_ );
+ my %args = ( Message => undef, Decode => 1, Exact => 0, @_ );
- my ( $fh, $temp_file );
eval {
-
+ my ( $fh, $temp_file );
for ( 1 .. 10 ) {
# on NFS and NTFS, it is possible that tempfile() conflicts
@@ -123,8 +122,9 @@
# We have to trust the temp file's name -- untaint it
$temp_file =~ /(.*)/;
- $self->ParseMIMEEntityFromFile( $1, $args{'Decode'} );
+ my $entity = $self->ParseMIMEEntityFromFile( $1, $args{'Decode'}, $args{'Exact'} );
unlink($1);
+ return $entity;
}
}
};
@@ -132,7 +132,7 @@
#If for some reason we weren't able to parse the message using a temp file
# try it with a scalar
if ( $@ || !$self->Entity ) {
- $self->ParseMIMEEntityFromScalar( $args{'Message'}, $args{'Decode'} );
+ return $self->ParseMIMEEntityFromScalar( $args{'Message'}, $args{'Decode'}, $args{'Exact'} );
}
}
@@ -146,12 +146,9 @@
sub ParseMIMEEntityFromSTDIN {
my $self = shift;
- my $postprocess = (@_ ? shift : 1);
- return $self->ParseMIMEEntityFromFileHandle(\*STDIN, $postprocess);
+ return $self->ParseMIMEEntityFromFileHandle(\*STDIN, @_);
}
-
-
=head2 ParseMIMEEntityFromScalar $message
Takes either a scalar or a reference to a scalar which contains a stringified MIME message.
@@ -164,12 +161,9 @@
sub ParseMIMEEntityFromScalar {
my $self = shift;
- my $message = shift;
- my $postprocess = (@_ ? shift : 1);
- $self->_ParseMIMEEntity($message,'parse_data',$postprocess);
+ return $self->_ParseMIMEEntity( shift, 'parse_data', @_ );
}
-
=head2 ParseMIMEEntityFromFilehandle *FH
Parses a mime entity from a filehandle passed in as an argument
@@ -178,13 +172,9 @@
sub ParseMIMEEntityFromFileHandle {
my $self = shift;
- my $filehandle = shift;
- my $postprocess = (@_ ? shift : 1);
- $self->_ParseMIMEEntity($filehandle,'parse', $postprocess);
+ return $self->_ParseMIMEEntity( shift, 'parse', @_ );
}
-
-
=head2 ParseMIMEEntityFromFile
Parses a mime entity from a filename passed in as an argument
@@ -193,9 +183,7 @@
sub ParseMIMEEntityFromFile {
my $self = shift;
- my $file = shift;
- my $postprocess = (@_ ? shift : 1);
- $self->_ParseMIMEEntity($file,'parse_open',$postprocess);
+ return $self->_ParseMIMEEntity( shift, 'parse_open', @_ );
}
@@ -203,12 +191,13 @@
my $self = shift;
my $message = shift;
my $method = shift;
- my $postprocess = shift;
- # Create a new parser object:
+ my $postprocess = (@_ ? shift : 1);
+ my $exact = shift;
+ # Create a new parser object:
my $parser = MIME::Parser->new();
$self->_SetupMIMEParser($parser);
-
+ $parser->decode_bodies(0) if $exact;
# TODO: XXX 3.0 we really need to wrap this in an eval { }
unless ( $self->{'entity'} = $parser->$method($message) ) {
@@ -220,10 +209,10 @@
return ( undef);
}
}
- if ($postprocess) {
- $self->_PostProcessNewEntity() ;
- }
+ $self->_PostProcessNewEntity if $postprocess;
+
+ return $self->{'entity'};
}
@@ -248,14 +237,8 @@
# try to convert text parts into utf-8 charset
RT::I18N::SetMIMEEntityToEncoding($self->{'entity'}, 'utf-8');
-
-
-
-
}
-
-
=head2 ParseCcAddressesFromHead HASHREF
Takes a hashref object containing QueueObj, Head and CurrentUser objects.
More information about the Rt-commit
mailing list