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.1 -r1.20.4.2
--- openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql	17 Aug 2016 08:32:11 -0000	1.20.4.1
+++ openacs-4/packages/acs-messaging/sql/postgresql/acs-messaging-packages.sql	20 Sep 2016 15:35:54 -0000	1.20.4.2
@@ -114,38 +114,45 @@
 DECLARE
         p_creation_date timestamptz := current_timestamp;  -- alias for $13 --default sysdate,
         v_message_id   acs_messages.message_id%TYPE;
-        v_rfc822_id    acs_messages.rfc822_id%TYPE;
         v_revision_id  cr_revisions.revision_id%TYPE;
-		v_system_url   varchar;
-		v_domain_name  varchar;
-		v_idx		   integer;
     BEGIN
-        -- generate a message id now so we can get an rfc822 message-id
-        if p_message_id is null then
-            select nextval('t_acs_object_id_seq') into v_message_id;
-        else
-            v_message_id := p_message_id;
-        end if;
+        -- -- generate a message id now so we can get an rfc822 message-id
+        -- if p_message_id is null then
+        --     select nextval('t_acs_object_id_seq') into v_message_id;
+        -- else
+        --     v_message_id := p_message_id;
+        -- end if;
 
-        -- need to make this mandatory also - jg
-        -- this needs to be fixed up, but Oracle doesn't give us a way
-        -- to get the FQDN
+        -- -- need to make this mandatory also - jg
+        -- -- this needs to be fixed up, but Oracle doesn't give us a way
+        -- -- to get the FQDN
 
-	-- vk: get SystemURL parameter and use it to extract domain name
-         select apm__get_value(package_id, 'SystemURL') into v_system_url
-          from apm_packages where package_key='acs-kernel';
-		v_idx := position('http://' in v_system_url);
-		v_domain_name := trim (substr(v_system_url, v_idx + 7));
+	-- -- vk: get SystemURL parameter and use it to extract domain name
+        --  select apm__get_value(package_id, 'SystemURL') into v_system_url
+        --   from apm_packages where package_key='acs-kernel';
+	-- 	v_idx := position('http://' in v_system_url);
+	-- 	v_domain_name := trim (substr(v_system_url, v_idx + 7));
 
-        if p_rfc822_id is null then
-           v_rfc822_id := current_date || '.' || v_message_id || '@' ||
-               v_domain_name || '.hate';
-        else
-            v_rfc822_id := p_rfc822_id;
+        -- if p_rfc822_id is null then
+        --    v_rfc822_id := current_date || '.' || v_message_id || '@' ||
+        --        v_domain_name || '.hate';
+        -- else
+        --     v_rfc822_id := p_rfc822_id;
+        -- end if;
+    
+	-- Antonio Pisano 2016-09-20
+	-- rfc822_id MUST come from the tcl, no more
+	-- sql tricks to retrieve one if missing.
+	-- Motivations:
+	-- 1) duplication. We have same logics in acs_mail_lite::generate_message_id
+	-- 2) what if SystemURL is https?
+	-- 3) empty SystemURL would break General Comments
+	if p_rfc822_id is null then
+	   RAISE null_value_not_allowed;
         end if;
 
         v_message_id := content_item__new (
-            v_rfc822_id,			  -- 1   name           
+            p_rfc822_id,			  -- 1   name           
             p_parent_id,			  -- 2   parent_id      
             p_message_id,			  -- 3   item_id        
             null,				  -- 4   locale
@@ -167,7 +174,7 @@
         insert into acs_messages 
             (message_id, reply_to, sent_date, sender, rfc822_id)
         values 
-            (v_message_id, p_reply_to, p_sent_date, p_sender, v_rfc822_id);
+            (v_message_id, p_reply_to, p_sent_date, p_sender, p_rfc822_id);
 
         -- create an initial revision for the new message
         v_revision_id := acs_message__edit (
