+ my ( $fh, $temp_file );
+ for ( 1 .. 10 ) {
+
+ # on NFS and NTFS, it is possible that tempfile() conflicts
+ # with other processes, causing a race condition. we try to
+ # accommodate this by pausing and retrying.
+ last if ( $fh, $temp_file ) = eval { File::Temp::tempfile(undef, UNLINK => 0) };
+ sleep 1;
+ }
+ if ($fh) {
+ binmode $fh; #thank you, windows
+ $fh->autoflush(1);
+ print $fh $args{'message'};
+ close($fh);
+
+ if ( -f $temp_file ) {
+ $parser->ParseMIMEEntityFromFile($temp_file);
+ File::Temp::unlink0( $fh, $temp_file );
+ if ($parser->Entity) {
+ delete $args{'message'};
+ }
+ }
+
+ }
+
+ #If for some reason we weren't able to parse the message using a temp file
+ # try it with a scalar
+ if ($args{'message'}) {
+ $parser->ParseMIMEEntityFromScalar($args{'message'});
+
+ }
+
+ if (!$parser->Entity()) {
+ MailError(
+ To => $RT::OwnerEmail,
+ Subject => "RT Bounce: Unparseable message",
+ Explanation => "RT couldn't process the message below",
+ Attach => $args{'message'}
+ );
+
+ return(0,"Failed to parse this message. Something is likely badly wrong with the message");
+ }