Index: lib/Vend/Dispatch.pm
===================================================================
RCS file: /var/lib/cvs/interchange/lib/Vend/Dispatch.pm,v
retrieving revision 1.111
diff -u -r1.111 Dispatch.pm
--- lib/Vend/Dispatch.pm	6 Apr 2009 12:23:22 -0000	1.111
+++ lib/Vend/Dispatch.pm	24 Apr 2009 11:05:13 -0000
@@ -370,7 +370,10 @@
 Content-Type: $CGI::values{mv_content_type}
 Content-Length: $size
 EOF
-	::response(	Vend::Util::readfile ($CGI::values{mv_data_file}) );
+	::response(
+        Vend::Util::readfile($CGI::values{mv_data_file}, undef, undef,
+							 {encoding => 'raw'}));
+
 	return 0;
 }
 
Index: lib/Vend/File.pm
===================================================================
RCS file: /var/lib/cvs/interchange/lib/Vend/File.pm,v
retrieving revision 2.30
diff -u -r2.30 File.pm
--- lib/Vend/File.pm	22 Mar 2009 19:32:31 -0000	2.30
+++ lib/Vend/File.pm	24 Apr 2009 11:05:13 -0000
@@ -65,9 +65,14 @@
 
 sub writefile {
     my($file, $data, $opt) = @_;
+	my($encoding, $fallback);
 
-	my $is_utf8;
-	$is_utf8 = is_utf8(ref $data ? $$data : $data) if $::Variable->{MV_UTF8};
+	if ($::Variable->{MV_UTF8}) {
+		$encoding = $opt->{encoding} ||= 'utf-8';
+		undef $encoding if $encoding eq 'raw';
+		$fallback = $opt->{fallback};
+		$fallback = Encode::PERLQQ unless defined $fallback;
+	}
 
 	$file = ">>$file" unless $file =~ /^[|>]/;
 	if (ref $opt and $opt->{umask}) {
@@ -91,7 +96,11 @@
 			}
 			# We have checked for beginning > or | previously
 			open(MVLOGDATA, $file) or die "open\n";
-			binmode(MVLOGDATA, ":utf8") if $is_utf8;
+            if ($encoding) {
+                local $PerlIO::encoding::fallback = $fallback;
+                binmode(MVLOGDATA, ":encoding($encoding)");
+            }
+
 			lockfile(\*MVLOGDATA, 1, 1) or die "lock\n";
 			seek(MVLOGDATA, 0, 2) or die "seek\n";
 			if(ref $data) {
@@ -105,7 +114,10 @@
 		else {
             my (@args) = grep /\S/, Text::ParseWords::shellwords($file);
 			open(MVLOGDATA, "|-") || exec @args;
-			binmode(MVLOGDATA, ":utf8") if $is_utf8;
+            if ($encoding) {
+                local $PerlIO::encoding::fallback = $fallback;
+                binmode(MVLOGDATA, ":encoding($encoding)");
+            }
 			if(ref $data) {
 				print(MVLOGDATA $$data) or die "pipe to\n";
 			}
@@ -181,10 +193,19 @@
 # the file from the database.
 
 sub readfile {
-    my($ifile, $no, $loc) = @_;
-    my($contents);
+    my($ifile, $no, $loc, $opt) = @_;
+    my($contents,$encoding,$fallback);
     local($/);
 
+	$opt ||= {};
+	
+	if ($::Variable->{MV_UTF8}) {
+		$encoding = $opt->{encoding} ||= 'utf-8';
+		$fallback = $opt->{fallback};
+		$fallback = Encode::PERLQQ unless defined $fallback;
+		undef $encoding if $encoding eq 'raw';
+	}
+	
 	unless(allowed_file($ifile)) {
 		log_file_violation($ifile);
 		return undef;
@@ -204,6 +225,7 @@
 	}
 
 	if(! $file) {
+
 		$contents = readfile_db($ifile);
 		return undef unless defined $contents;
 	}
@@ -212,7 +234,12 @@
 		$Global::Variable->{MV_FILE} = $file;
 
 		binmode(READIN) if $Global::Windows;
-		binmode(READIN, ":utf8") if $::Variable->{MV_UTF8};
+
+        if ($encoding) {
+            local $PerlIO::encoding::fallback = Encode::PERLQQ;
+            binmode(READIN, ":encoding($encoding)");
+        }
+
 		undef $/;
 		$contents = <READIN>;
 		close(READIN);

