Index: openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql,v
diff -u -r1.20.4.3 -r1.20.4.4
--- openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql	11 Feb 2017 17:05:49 -0000	1.20.4.3
+++ openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql	11 Feb 2017 20:23:19 -0000	1.20.4.4
@@ -331,29 +331,26 @@
     -- functions will migrate to another PL/SQL package or be replaced
     -- by direct calls to CR code in the near future.
 
-
-
--- added
 select define_function_args('acs_message__new_file','message_id,file_id;null,file_name,title;null,description;null,mime_type;text/plain,data;null,creation_date;sysdate,creation_user;null,creation_ip;null,is_live;t,storage_type;file,package_id;null');
 
 --
 -- procedure acs_message__new_file/13
 --
 CREATE OR REPLACE FUNCTION acs_message__new_file(
    p_message_id integer,
-   p_file_id integer,           -- default null
+   p_file_id integer,                         -- default null
    p_file_name varchar,
-   p_title varchar,             -- default null
-   p_description text,          -- default null
-   p_mime_type varchar,         -- default 'text/plain'
-   p_data integer,              -- default null
-   p_creation_date timestamptz, -- default sysdate
-   p_creation_user integer,     -- default null
-   p_creation_ip varchar,       -- default null
-   p_is_live boolean,           -- default 't'
-   p_storage_type varchar,      -- default 'file'
-   p_package_id integer         -- default null
-
+   p_title varchar,                           -- default null
+   p_description text,                        -- default null
+   p_mime_type varchar,                       -- default 'text/plain'
+   p_data integer,                            -- default null
+   p_creation_date timestamptz,               -- default sysdate
+   p_creation_user integer,                   -- default null
+   p_creation_ip varchar,                     -- default null
+   p_is_live boolean,                         -- default 't'
+   p_storage_type cr_items.storage_type%TYPE, -- default 'file'
+   p_package_id integer default null
+   
 ) RETURNS integer AS $$
 DECLARE
     v_file_id      cr_items.item_id%TYPE;
@@ -368,15 +365,19 @@
         p_creation_user,		   -- creation_user  
         null,				   -- context_id
         p_creation_ip,			   -- creation_ip    
-        'content_item',		   -- item_subtype
+        'content_item',		   	   -- item_subtype
         'content_revision',		   -- content_type
         null,				   -- title
         null,				   -- description
         'text/plain',			   -- mime_type
         null,				   -- nls_language
         null,				   -- text
+	null,  				   -- data
+	null,  				   -- relation_tag
+	false, 				   -- is_live
 	p_storage_type,			   -- storage_type
-        p_package_id			   -- package_id
+        p_package_id,			   -- package_id
+        true                               -- with_child_rels
     );
 
     -- create an initial revision for the new attachment
@@ -398,45 +399,6 @@
 
 
 
---
--- procedure acs_message__new_file/12
---
-CREATE OR REPLACE FUNCTION acs_message__new_file(
-   p_message_id integer,
-   p_file_id integer,           -- default null
-   p_file_name varchar,
-   p_title varchar,             -- default null
-   p_description text,          -- default null
-   p_mime_type varchar,         -- default 'text/plain'
-   p_data integer,              -- default null
-   p_creation_date timestamptz, -- default sysdate
-   p_creation_user integer,     -- default null
-   p_creation_ip varchar,       -- default null
-   p_is_live boolean,           -- default 't'
-   p_storage_type varchar       -- default 'file'
-
-) RETURNS integer AS $$
-DECLARE
-BEGIN
-    return acs_message__new_file (p_message_id,
-                                  p_file_id,
-                                  p_file_name,
-                                  p_title,
-                                  p_description,
-                                  p_mime_type,
-                                  p_data,
-                                  p_creation_date,
-                                  p_creation_user,
-                                  p_creation_ip,
-                                  p_is_live,
-                                  p_storage_type,
-                                  null
-   );
-END;
-$$ LANGUAGE plpgsql;
-
-
-
 -- added
 select define_function_args('acs_message__edit_file','file_id,title;null,description;null,mime_type;text/plain,data;null,creation_date;sysdate,creation_user;null,creation_ip;null,is_live;t');
 
Index: openacs-4/packages/acs-messaging/sql/postgresql/upgrade/upgrade-5.9.1d2-5.9.1d3.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-messaging/sql/postgresql/upgrade/upgrade-5.9.1d2-5.9.1d3.sql,v
diff -u -r1.1.2.1 -r1.1.2.2
--- openacs-4/packages/acs-messaging/sql/postgresql/upgrade/upgrade-5.9.1d2-5.9.1d3.sql	11 Feb 2017 17:05:49 -0000	1.1.2.1
+++ openacs-4/packages/acs-messaging/sql/postgresql/upgrade/upgrade-5.9.1d2-5.9.1d3.sql	11 Feb 2017 20:23:19 -0000	1.1.2.2
@@ -59,3 +59,66 @@
 END;
 $$ LANGUAGE plpgsql;
 
+DROP FUNCTION IF EXISTS acs_message__new_file(integer,integer,character varying,character varying,text,character varying,integer,timestamp with time zone,integer,character varying,boolean,character varying,integer);
+DROP FUNCTION IF EXISTS acs_message__new_file(integer,integer,character varying,character varying,text,character varying,integer,timestamp with time zone,integer,character varying,boolean,character varying);
+
+CREATE OR REPLACE FUNCTION acs_message__new_file(
+   p_message_id integer,
+   p_file_id integer,                         -- default null
+   p_file_name varchar,
+   p_title varchar,                           -- default null
+   p_description text,                        -- default null
+   p_mime_type varchar,                       -- default 'text/plain'
+   p_data integer,                            -- default null
+   p_creation_date timestamptz,               -- default sysdate
+   p_creation_user integer,                   -- default null
+   p_creation_ip varchar,                     -- default null
+   p_is_live boolean,                         -- default 't'
+   p_storage_type cr_items.storage_type%TYPE, -- default 'file'
+   p_package_id integer default null
+   
+) RETURNS integer AS $$
+DECLARE
+    v_file_id      cr_items.item_id%TYPE;
+    v_revision_id  cr_revisions.revision_id%TYPE;
+BEGIN
+    v_file_id := content_item__new (
+        p_file_name,			   -- name           
+        p_message_id,			   -- parent_id      
+        p_file_id,			   -- item_id        
+        null,				   -- locale
+        p_creation_date,		   -- creation_date  
+        p_creation_user,		   -- creation_user  
+        null,				   -- context_id
+        p_creation_ip,			   -- creation_ip    
+        'content_item',		   	   -- item_subtype
+        'content_revision',		   -- content_type
+        null,				   -- title
+        null,				   -- description
+        'text/plain',			   -- mime_type
+        null,				   -- nls_language
+        null,				   -- text
+	null,  				   -- data
+	null,  				   -- relation_tag
+	false, 				   -- is_live
+	p_storage_type,			   -- storage_type
+        p_package_id,			   -- package_id
+        true                               -- with_child_rels
+    );
+
+    -- create an initial revision for the new attachment
+    v_revision_id := acs_message__edit_file (
+         v_file_id,			-- file_id        
+         p_title,			-- title          
+         p_description,			-- description    
+         p_mime_type,			-- mime_type      
+         p_data,			-- data        
+         p_creation_date,		-- creation_date  
+         p_creation_user,		-- creation_user  
+         p_creation_ip,			-- creation_ip    
+         p_is_live			-- is_live        
+    );
+
+    return v_file_id;
+END;
+$$ LANGUAGE plpgsql;