Index: /main/trunk/greenstone2/perllib/plugins/CONTENTdmPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/CONTENTdmPlugin.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/CONTENTdmPlugin.pm	(revision 23349)
@@ -659,5 +659,7 @@
 	
 	my ($filemeta) = $file =~ /([^\\\/]+)$/;
-	$self->set_Source_metadata($doc_obj, $filemeta);
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
 	$doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
 	$doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "FileSize", (-s $filename_full_path));
Index: /main/trunk/greenstone2/perllib/plugins/ConvertBinaryFile.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ConvertBinaryFile.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/ConvertBinaryFile.pm	(revision 23349)
@@ -397,5 +397,7 @@
     $doc_obj->set_converted_filename($collect_conv_file);
 
-    $self->set_Source_metadata($doc_obj, $filename_no_path);
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+    $self->set_Source_metadata($doc_obj, $filename_no_path, $filename_encoding);
         
     $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
Index: /main/trunk/greenstone2/perllib/plugins/ConvertToRogPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ConvertToRogPlugin.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/ConvertToRogPlugin.pm	(revision 23349)
@@ -345,5 +345,7 @@
 
     my ($filemeta) = $file =~ /([^\\\/]+)$/;
-    $self->set_Source_metadata($doc_obj, $filemeta);
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+    $self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
     
     if ($self->{'cover_image'}) {
Index: /main/trunk/greenstone2/perllib/plugins/DatabasePlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/DatabasePlugin.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/DatabasePlugin.pm	(revision 23349)
@@ -270,5 +270,8 @@
 	    $doc_obj->add_utf8_metadata($cursection, "Encoding", $encoding);
 	}
-	$self->set_Source_metadata($doc_obj, $db, $encoding);
+
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+	$self->set_Source_metadata($doc_obj, $db, $filename_encoding);
 
 	if ($self->{'cover_image'}) {
Index: /main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm	(revision 23349)
@@ -316,5 +316,8 @@
 	my $collect_conv_file = &util::filename_within_collection($tidy_filename);
 	$doc_obj->set_converted_filename($collect_conv_file);
-	$self->set_Source_metadata($doc_obj, $filename_no_path);
+
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filename_no_path, $filename_encoding);
     }
 
Index: /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm	(revision 23349)
@@ -220,5 +220,5 @@
 
     $self->set_Source_metadata($doc_obj,&unicode::url_decode($filename_no_path),
-			       $filename_encoding);
+							   $filename_encoding);
 
 
Index: /main/trunk/greenstone2/perllib/plugins/MARCXMLPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/MARCXMLPlugin.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/MARCXMLPlugin.pm	(revision 23349)
@@ -212,5 +212,6 @@
 
     my $processor = $self->{'processor'};
-  
+	my $metadata  = $self->{'metadata'};
+
     ##create a new document for each record 
     if ($element eq "record") {
@@ -222,6 +223,10 @@
 	$doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Language", $language);
 	$doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Encoding", $encoding);
+
 	my ($filemeta) = $file =~ /([^\\\/]+)$/;
-	$self->set_Source_metadata($doc_obj, $filemeta, $encoding);
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
+
 	$doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "SourceSegment", "$self->{'record_count'}");
         if ($self->{'cover_image'}) {
Index: /main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm	(revision 23349)
@@ -297,5 +297,8 @@
     
     my ($filemeta) = $file =~ /([^\\\/]+)$/;
-    $self->set_Source_metadata($doc_obj, $filemeta, $encoding);
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+    $self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
+
     $doc_obj->add_utf8_metadata($top_section, "Language", $language);
     $doc_obj->add_utf8_metadata($top_section, "Encoding", $encoding);
Index: /main/trunk/greenstone2/perllib/plugins/OpenDocumentPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/OpenDocumentPlugin.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/OpenDocumentPlugin.pm	(revision 23349)
@@ -264,5 +264,9 @@
     $doc_obj->add_metadata ("", "srclink_file", $doc_obj->get_sourcefile());
     $doc_obj->add_utf8_metadata ("", "srcicon",  "<img border=\"0\" align=\"absmiddle\" src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/thumbnail.png\" alt=\"View the Open document\" title=\"View the Open document\">"); 
-    $self->set_Source_metadata($doc_obj, $file_only);
+
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file_only,$metadata,$plugin_filename_encoding);
+
+    $self->set_Source_metadata($doc_obj, $file_only, $filename_encoding);
      $doc_obj->set_utf8_metadata_element("", "FileSize", (-s $filename));
      
Index: /main/trunk/greenstone2/perllib/plugins/PagedImagePlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/PagedImagePlugin.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/PagedImagePlugin.pm	(revision 23349)
@@ -316,5 +316,5 @@
 
 	#process the .item file
-	$doc_obj = $self->process_item($filename_full_path, $dir, $file, $processor);
+	$doc_obj = $self->process_item($filename_full_path, $dir, $file, $processor, $metadata);
 	
     }
@@ -513,5 +513,5 @@
     $self->{'doc_obj'} = new doc ($self->{'filename'}, "indexed_doc", $self->{'file_rename_method'});
     # TODO is file filenmae_no_path??
-    $self->set_initial_doc_fields($self->{'doc_obj'}, $self->{'file'}, $self->{'processor'});
+    $self->set_initial_doc_fields($self->{'doc_obj'}, $self->{'file'}, $self->{'processor'}, $self->{'metadata'});
 
     my ($dir, $file) = $self->{'filename'} =~ /^(.*?)([^\/\\]*)$/;
@@ -540,5 +540,5 @@
 sub set_initial_doc_fields {
     my $self = shift(@_);
-    my ($doc_obj, $filename_no_path, $processor) = @_;
+    my ($doc_obj, $filename_no_path, $processor, $metadata) = @_;
 
     my $topsection = $doc_obj->get_top_section();
@@ -552,5 +552,7 @@
     }
 
-    $self->set_Source_metadata($doc_obj, $filename_no_path);
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($filename_no_path,$metadata,$plugin_filename_encoding);
+    $self->set_Source_metadata($doc_obj, $filename_no_path, $filename_encoding);
    
     # if we want a header page, we need to add some text into the top section, otherwise this section will become invisible
@@ -615,8 +617,8 @@
 sub process_item {
     my $self = shift (@_);
-    my ($filename_full_path, $dir, $filename_no_path, $processor) = @_;
+    my ($filename_full_path, $dir, $filename_no_path, $processor, $metadata) = @_;
 
     my $doc_obj = new doc ($filename_full_path, "indexed_doc", $self->{'file_rename_method'});
-    $self->set_initial_doc_fields($doc_obj, $filename_no_path, $processor);
+    $self->set_initial_doc_fields($doc_obj, $filename_no_path, $processor, $metadata);
     my $topsection = $doc_obj->get_top_section();
     open (ITEMFILE, $filename_full_path) || die "couldn't open $filename_full_path\n";
Index: /main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm	(revision 23349)
@@ -344,5 +344,7 @@
 	$doc_obj->set_converted_filename(&util::filename_cat($dirname_within_collection, $file));
 	
-	$self->set_Source_metadata($doc_obj, $filename_no_path);
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filename_no_path,$filename_encoding);
         
 	$doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
Index: /main/trunk/greenstone2/perllib/plugins/ReadXMLFile.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ReadXMLFile.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/ReadXMLFile.pm	(revision 23349)
@@ -213,4 +213,5 @@
     $self->{'filename_no_path'} = $filename_no_path;
     $self->{'processor'} = $processor;
+
     # this contains metadata passed in from running metadata_read with other plugins (eg from MetadataXMLPlugin)
     # we are also using it to store up any metadata found during parsing the XML, so that it can be added to the doc obj.
@@ -368,10 +369,17 @@
     my $self = shift(@_);
 
+	my $metadata = $self->{'metadata'};
+
     # create a new document
-    $self->{'doc_obj'} = new doc ($self->{'filename'}, "indexed_doc", $self->{'file_rename_method'});
-    $self->{'doc_obj'}->add_utf8_metadata($self->{'doc_obj'}->get_top_section(), "Plugin", "$self->{'plugin_type'}");
-    $self->set_Source_metadata($self->{'doc_obj'}, $self->{'filename_no_path'});
-    
-
+    my $doc_obj = $self->{'doc_obj'} = new doc ($self->{'filename'}, "indexed_doc", $self->{'file_rename_method'});
+
+    $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
+
+	my $filename_no_path = $self->{'filename_no_path'};
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($filename_no_path,$metadata,$plugin_filename_encoding);
+
+    $self->set_Source_metadata($doc_obj, $filename_no_path, $filename_encoding);
+    
     # do we want other auto metadata here (see BasePlugin.read_into_doc_obj)
 }
Index: /main/trunk/greenstone2/perllib/plugins/SplitTextFile.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/SplitTextFile.pm	(revision 23348)
+++ /main/trunk/greenstone2/perllib/plugins/SplitTextFile.pm	(revision 23349)
@@ -239,6 +239,10 @@
 	$doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Language", $language);
 	$doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Encoding", $encoding);
+
 	my ($filemeta) = $file =~ /([^\\\/]+)$/;
-	$self->set_Source_metadata($doc_obj, $filemeta, $encoding);
+	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
+
 	$doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "SourceSegment", "$segment");
 	if ($self->{'cover_image'}) {
