diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/config/unix/mlUnix.ml ./src/config/unix/mlUnix.ml
--- ./src/config/unix/mlUnix.ml	2005-08-07 19:39:30.000000000 +0200
+++ ./src/config/unix/mlUnix.ml	2005-11-26 16:20:36.000000000 +0100
@@ -54,14 +54,37 @@
       let sock = handler in_read out_write in
       sock, id
 
-let fork_and_exec cmd args = 
+let fork_and_exec cmd ?vars args = 
+  let env =
+    match vars with
+      | None -> None
+      | Some vars ->
+	  (* convert environment to an alist *)
+	  let env = List.map (fun kev -> 
+	    try
+	      let len = String.length kev in
+	      let equal_sign = String.index kev '=' in
+		(String.sub kev 0 equal_sign, 
+		 String.sub kev (equal_sign + 1) (len - 1 - equal_sign))
+	    with Not_found -> (* May that happen ? *)
+	      (kev, "")
+	  ) (Array.to_list (Unix.environment ())) in
+	  (* update parent's environment with vars alist *)
+	  let env = List.fold_left (fun acc ((k, v) as assoc) ->
+	    assoc :: List.remove_assoc k acc
+	  ) env vars in
+	  Some (Array.of_list (List.map (fun (k, v) -> k ^ "=" ^ v) env)) in
   match Unix.fork() with
     0 -> begin
         try
           match Unix.fork() with
             0 -> begin
                 try
-                  Unix.execv cmd args;
+		  match env with
+		    | None ->
+			Unix.execv cmd args;
+		    | Some env ->
+			Unix.execve cmd args env;
                   exit 0
                 with e -> 
                     lprintf "Exception %s while starting file_completed_cmd\n" (Printexc2.to_string e); 
diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/common/commonInteractive.ml ./src/daemon/common/commonInteractive.ml
--- ./src/daemon/common/commonInteractive.ml	2005-11-21 22:41:18.000000000 +0100
+++ ./src/daemon/common/commonInteractive.ml	2005-11-26 16:51:51.000000000 +0100
@@ -20,6 +20,7 @@
 open AnyEndian
 open LittleEndian
 open Int64ops
+open Md4
 open Misc
 open Printf2
 open CommonOptions
@@ -99,6 +100,40 @@
     else new_name in
   new_name
 
+let script_for_file file incoming new_name =
+  let info = file_info file in
+  let temp_name = file_disk_name file in
+  let file_id = Filename.basename temp_name in
+  let size = Int64.to_string (file_size file) in
+  let duration =
+    Date.time_to_string_long ((BasicSocket.last_time ()) - info.G.file_age)
+  in
+  let network = network_find_by_num info.G.file_network in
+  let filename = Filename.basename new_name in
+  let ed2k_hash =
+    if info.G.file_md4 = Md4.null then "" else
+       Printf.sprintf "ed2k://|file|%s|%s|%s|/"
+        (Url.encode filename)
+        (Int64.to_string (file_size file))
+        (Md4.to_string info.G.file_md4)
+  in
+  MlUnix.fork_and_exec !!file_completed_cmd
+      [|  (* keep those for compatibility *)
+      "";
+      file_id; (* $1 *)
+      size; (* $2 *)
+      filename (* $3 *)
+    |]
+     ~vars:[("TEMPNAME",  temp_name);
+	    ("FILEID",    file_id);
+	    ("FILESIZE",  size);
+	    ("FILENAME",  filename);
+	    ("FILEHASH",  string_of_uids info.G.file_uids);
+	    ("DURATION",  duration);
+	    ("INCOMING",  incoming);
+	    ("NETWORK",   network.network_name);
+	    ("ED2K_HASH", ed2k_hash)]
+
 (********
 These two functions 'file_commit' and 'file_cancel' should be the two only
 functions in mldonkey able to destroy a file, the first one by moving it,
@@ -127,7 +162,12 @@
         if Unix2.is_directory file_name then
           Unix2.safe_mkdir new_name;
         (try
+(*          the next line really moves the file *)
             set_file_disk_name file new_name;
+
+            if !!file_completed_cmd <> "" then
+	      script_for_file file incoming.shdir_dirname new_name;
+
             if Unix2.is_directory new_name then
               Unix2.chmod new_name (Misc.int_of_octal_string !!create_dir_mask);
             let best_name = file_best_name file in
@@ -211,17 +251,14 @@
       (let age = (BasicSocket.last_time ()) - info.G.file_age in Date.time_to_string_long age)
     in
 
-    let line3 = if (file_comment file) <> "" then
+    let line3 = if (file_comment file) = "" then "" else
         Printf.sprintf "\r\nComment: %s\r\n" (file_comment file)
-      else
-        Printf.sprintf "";
     in
 
     let subject = if !!filename_in_subject then
-        Printf.sprintf "[mldonkey] file received - %s"
-        (file_best_name file)
+        Printf.sprintf "[mldonkey] file received - %s" (file_best_name file)
       else
-        Printf.sprintf "mldonkey, file received";
+        Printf.sprintf "mldonkey, file received"
     in
 
     let incoming =
@@ -231,23 +268,25 @@
         incoming_files ()
     in
 
-    let line4 = if !!url_in_mail <> "" then
+    let line4 = if !!url_in_mail = "" then "" else
       Printf.sprintf "\r\n<%s/%s/%s>\r\n" !!url_in_mail incoming.shdir_dirname (Url.encode (file_best_name file))
-    else
-        Printf.sprintf "";
+    in
+
+    let line5 = if !!auto_commit then "" else
+        Printf.sprintf "\r\nauto_commit is disabled, file is not committed to incoming"
     in
 
     let mail = {
         M.mail_to = !!mail;
         M.mail_from = !!mail;
         M.mail_subject = subject;
-        M.mail_body = line1 ^ line2 ^ line3 ^ line4;
+        M.mail_body = line1 ^ line2 ^ line3 ^ line4 ^ line5;
       } in
     M.sendmail !!smtp_server !!smtp_port !!add_mail_brackets mail
 
 let chat_for_completed_file file =
   CommonChat.send_warning_for_downloaded_file (file_best_name file)
-
+  
 let file_completed (file : file) =
   try
     let impl = as_file_impl file in
@@ -265,15 +304,6 @@
         if !!CommonOptions.chat_warning_for_downloaded then
           chat_for_completed_file file;
 
-        if !!file_completed_cmd <> "" then begin
-            MlUnix.fork_and_exec  !!file_completed_cmd
-              [|
-              file_name;
-              file_id;
-              Int64.to_string (file_size file);
-              file_best_name file
-            |]
-          end
       end
   with e ->
       lprintf_nl "[cInt] Exception in file_completed: %s" (Printexc2.to_string e)
diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/common/commonOptions.ml ./src/daemon/common/commonOptions.ml
--- ./src/daemon/common/commonOptions.ml	2005-11-21 22:35:16.000000000 +0100
+++ ./src/daemon/common/commonOptions.ml	2005-11-26 17:09:51.000000000 +0100
@@ -950,8 +950,21 @@
     int64_option 16L
 
 let file_completed_cmd = define_option current_section
-    ["file_completed_cmd"] "A command that is called when a file is completely
-    downloaded. Arguments are: <file_name on disk> <md4> <size>"
+    ["file_completed_cmd"] "A command that is called when a file is committed, does not work on MinGW.
+    Arguments are (kept for compatability):
+      $1 - temp file name, without path
+      $2 - file size
+      $3 - filename of the committed file
+    Also these environment variables can be used (prefered way):
+      $TEMPNAME  - temp file name, including path
+      $FILEID    - same as $1
+      $FILESIZE  - same as $2
+      $FILENAME  - same as $3
+      $FILEHASH  - internal hash
+      $DURATION  - download duration
+      $INCOMING  - directory used for commit
+      $NETWORK   - network used for downloading
+      $ED2K_HASH - ed2k hash if MD4 is known"
     string_option ""
 
 let file_started_cmd = define_option current_section
diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/driver/driverMain.ml ./src/daemon/driver/driverMain.ml
--- ./src/daemon/driver/driverMain.ml	2005-11-19 18:19:45.000000000 +0100
+++ ./src/daemon/driver/driverMain.ml	2005-11-26 16:20:36.000000000 +0100
@@ -531,7 +531,7 @@
 
   if not Autoconf.windows then
     MlUnix.set_signal  Sys.sigchld
-      (Sys.Signal_handle (fun _ -> lprintf_nl "Received SIGCHLD, doing nothing"));
+      (Sys.Signal_handle (fun _ -> if !verbose then lprintf_nl "Received SIGCHLD, doing nothing"));
 
   if not Autoconf.windows then
     MlUnix.set_signal  Sys.sighup
diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/fileTP/fileTPClients.ml ./src/networks/fileTP/fileTPClients.ml
--- ./src/networks/fileTP/fileTPClients.ml	2005-10-16 22:42:54.000000000 +0200
+++ ./src/networks/fileTP/fileTPClients.ml	2005-11-26 16:20:36.000000000 +0100
@@ -207,7 +207,6 @@
                     in
                     iter ()
                   with Not_found ->
-                      lprintf "Unable to get a block !!";
                       check_finished swarmer file;
                       raise Not_found
             in
@@ -247,7 +246,6 @@
 (*      lprintf "connect_client... pending\n"; *)
       let token =
         add_pending_connection connection_manager (fun token ->
-            lprintf "Connection accepted\n";
             if List.exists (fun d ->
                   let file = d.download_file in
                   file_state file = FileDownloading
diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/fileTP/fileTPGlobals.ml ./src/networks/fileTP/fileTPGlobals.ml
--- ./src/networks/fileTP/fileTPGlobals.ml	2005-10-16 22:42:54.000000000 +0200
+++ ./src/networks/fileTP/fileTPGlobals.ml	2005-11-26 16:20:36.000000000 +0100
@@ -102,9 +102,7 @@
 let min_range_size = megabyte
 
 let set_file_size file size =
-  lprintf "set_file_size %s : %s\n" (Unix32.filename (file_fd file)) (Int64.to_string size);
   if file_size file = zero && size <> zero then begin
-      lprintf "Setting SWARMER\n";
       let file_chunk_size =
         max megabyte (
           size // (max 5L (size // (megabytes 5)))
@@ -116,7 +114,6 @@
       let swarmer = Int64Swarmer.create kernel (as_file file)
           file_chunk_size in
       file.file_swarmer <- Some swarmer;
-      lprintf "Swarmer set\n";
       Int64Swarmer.set_verified swarmer (fun _ _ ->
           file_must_update (as_file file);
       );
diff -a -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/fileTP/fileTPInteractive.ml ./src/networks/fileTP/fileTPInteractive.ml
--- ./src/networks/fileTP/fileTPInteractive.ml	2005-11-12 23:53:52.000000000 +0100
+++ ./src/networks/fileTP/fileTPInteractive.ml	2005-11-26 16:35:50.000000000 +0100
@@ -477,6 +477,7 @@
   network.op_network_share <- (fun fullname codedname size -> ());
   (* Same with Network.search and Network.forget_search... *)
   network.op_network_search <- (fun ss buf -> ());
+  file_ops.op_file_commit <- (fun file new_name -> ());
   network.op_network_forget_search <- (fun s -> ());
   (* and Network.recover_temp *)
   network.op_network_recover_temp <- (fun s -> ())
