Index: imce.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/filefield_sources/sources/imce.inc,v
retrieving revision 1.6
diff -u -r1.6 imce.inc
--- imce.inc	9 Aug 2010 05:24:10 -0000	1.6
+++ imce.inc	9 Aug 2010 16:43:39 -0000
@@ -175,16 +175,17 @@
   if (empty($conf['imce_custom_process'])) {
     $conf['imce_custom_process'] = array();
   }
-  $conf['imce_custom_process'] += array('filefield_source_imce_custom_process' => 1);
 
   // IMCE 6.x-2.x.
   if (module_hook('imce', 'file_references')) {
     module_load_include('inc', 'imce', 'inc/imce.page');
+    $conf['imce_custom_process'] += array('filefield_source_imce_custom_process2' => 1);
     return imce();
   }
   // IMCE 6.x-1.x.
   else {
     module_load_include('inc', 'imce', 'inc/page');
+    $conf['imce_custom_process'] += array('filefield_source_imce_custom_process1' => 1);
     return imce_page();
   }
 }
@@ -215,9 +216,9 @@
 }
 
 /**
- * Post process IMCE profile.
+ * Post process IMCE 6.x-1.x profile.
  */
-function filefield_source_imce_custom_process(&$imce) {
+function filefield_source_imce_custom_process1(&$imce) {
   // Disable file operations.
   foreach ($imce['perm'] as $name => $val) {
     if ($name != 'browse' && $name != 'subnav') {
@@ -225,3 +226,34 @@
     }
   }
 }
+
+/**
+ * Post process IMCE 6.x-2.x profile.
+ */
+function filefield_source_imce_custom_process2(&$imce) {
+  // Load field settings.
+  $field = content_fields(arg(3), arg(2));
+  $options = $field['widget'];
+
+  // Get field upload directory relative to drupal's file directory.
+  if ($options['file_path'] == '') {
+    $field_dir = '.';
+  }
+  else {
+    $path = filefield_widget_file_path($field);
+    $field_dir = substr($path, strlen(file_directory_path()) + 1);
+  }
+
+  // Apply field restrictions for field upload directory.
+  if ($field_dir == $imce['dir']) {
+    // Upload restrictions
+    if (!empty($imce['perm']['upload'])) {
+      // Allowed file extensions
+      $imce['extensions'] = $options['file_extensions'] == '' ? '*' : $options['file_extensions'];
+      // Allowed file size
+      $imce['filesize'] = parse_size($options['max_filesize_per_file']);
+    }
+    // Continue restricting....
+  }
+
+}

