From: Chris W. <la...@us...> - 2005-02-02 13:12:23
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24737 Modified Files: Util.pm Log Message: add digest_content() (calc MD5 digest for content vs file) and decode_base64_and_store() Index: Util.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Util.pm,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Util.pm 24 Jan 2005 17:00:43 -0000 1.17 --- Util.pm 2 Feb 2005 13:12:14 -0000 1.18 *************** *** 7,13 **** use Digest::MD5; use File::Spec::Functions qw( catdir catfile ); use Log::Log4perl qw( get_logger ); ! use Mail::Sendmail (); ! use MIME::Lite (); use OpenInteract2::Constants qw( :log ); use OpenInteract2::Context qw( CTX ); --- 7,15 ---- use Digest::MD5; use File::Spec::Functions qw( catdir catfile ); + use File::Temp qw( tempfile ); use Log::Log4perl qw( get_logger ); ! use Mail::Sendmail (); ! use MIME::Base64 qw( decode_base64 ); ! use MIME::Lite (); use OpenInteract2::Constants qw( :log ); use OpenInteract2::Context qw( CTX ); *************** *** 112,115 **** --- 114,144 ---- } + sub digest_content { + my ( $class, $content ) = @_; + my $md5 = Digest::MD5->new(); + $md5->add( $content ); + return $md5->hexdigest; + } + + + sub decode_base64_and_store { + my ( $class, $encoded_content, $output_file ) = @_; + my ( $fh ); + if ( $output_file ) { + open( $fh, '>', $output_file ) + || oi_error "Cannot write decoded base 64 content ", + "to '$output_file': $!"; + } + else { + ( $fh, $output_file ) = tempfile( 'OIPKGXXXXXX', UNLINK => 1 ); + unless ( $fh ) { + oi_error "Cannot open writeable temp file"; + } + } + print $fh decode_base64( $$encoded_content ); + close( $fh ); + return $output_file; + } + ######################################## # EMAIL ROUTINES *************** *** 254,257 **** --- 283,288 ---- my ( $class, $factory_class, @dirs ) = @_; + %FACTORY_FILES = (); + foreach my $lib_dir ( @dirs ) { next unless ( $lib_dir ); *************** *** 387,390 **** --- 418,438 ---- L<Digest::MD5> for restrictions, notably regarding unicode.) + B<digest_content( $content )> + + Returns the hex MD5 digest of C<$content>. (See L<Digest::MD5> for + restrictions, notably regarding unicode.) + + B<decode_base64_and_store( \$base64_content, [ $output_file ] )> + + Decodes C<$base64_content> (a scalar ref) and stores the decoded + content in either C<$output_file> (if specified) or in a new temp + file. Note that while the temp file is marked for deletion once the + program exits you should remove it once you're done. + + Throws exception if we cannot write to C<$output_file> or generate a + temporary file according to L<File::Temp>. + + Returns: filename with decoded content + =head1 MAIL METHODS |