From 16b4dbcd8152afabab9a16c27be816291b5390ad Mon Sep 17 00:00:00 2001 From: Jared Johnson Date: Fri, 5 Jun 2009 11:21:50 -0500 Subject: [PATCH] Add dup_body_fh to return a dup'd body FH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It wasn't suitable to dup the body FH returned by plain old body_fh(), so here's a separate function to return that. Signed-off-by: Ask Bjørn Hansen --- lib/Qpsmtpd/Transaction.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/Qpsmtpd/Transaction.pm b/lib/Qpsmtpd/Transaction.pm index 5c90bc3..545109d 100644 --- a/lib/Qpsmtpd/Transaction.pm +++ b/lib/Qpsmtpd/Transaction.pm @@ -217,6 +217,12 @@ sub body_fh { return shift->{_body_file}; } +sub dup_body_fh { + my ($self) = @_; + open(my $fh, '<&=', $self->body_fh); + return $fh; +} + sub DESTROY { my $self = shift; # would we save some disk flushing if we unlinked the file before @@ -380,6 +386,13 @@ Returns the file handle to the temporary file of the email. This will return undef if the file is not opened (yet). In I or later you can force spooling to disk by calling I<$transaction-Ebody_filename>. +=head2 dup_body_fh( ) + +Returns a dup()'d file handle to the temporary file of the email. This can be +useful if an external module may call close() on the filehandle that is passed +to it. This should only be used for reads, as writing to a dup'd filehandle +may have unintended consequences. + =head1 SEE ALSO L, L, L