Index: openacs-4/packages/mail-tracking/lib/messages.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/lib/messages.tcl,v
diff -u -r1.28 -r1.29
--- openacs-4/packages/mail-tracking/lib/messages.tcl	14 May 2006 16:11:19 -0000	1.28
+++ openacs-4/packages/mail-tracking/lib/messages.tcl	13 Jun 2006 06:40:49 -0000	1.29
@@ -250,25 +250,16 @@
     set files [list]
     # We get the related files for all the object_types
     set content_types [list content_revision content_item file_storage_object image]
-    foreach content_type $content_types {
-
-	foreach file [application_data_link::get_linked -from_object_id $log_id -to_object_type "$content_type"] {
-	    if { [string equal $content_type "content_revision"] } {
-		lappend files [item::get_item_from_revision $file]
-	    } else {
-		lappend files $file
-	    }
+    db_foreach files {} {
+	if { [string equal $content_type "content_revision"] } {
+	    set file [item::get_item_from_revision $file_id]
+	} else {
+	    set file $file_id
 	}
-    }
-    
-    set download_files ""
-    
-    foreach file $files {
 	set title [content::item::get_title -item_id $file]
 	if { [empty_string_p $title] } {
 	    set title [acs_object_name $file]
 	}
-	# Creating the link to dowload the files
 	append download_files "<a href=\"[export_vars -base "${tracking_url}download/$title" -url {{file_id $file}}]\">$title</a><br>"
     }
 
Index: openacs-4/packages/mail-tracking/lib/messages.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/mail-tracking/lib/messages.xql,v
diff -u -r1.9 -r1.10
--- openacs-4/packages/mail-tracking/lib/messages.xql	28 May 2006 07:17:27 -0000	1.9
+++ openacs-4/packages/mail-tracking/lib/messages.xql	13 Jun 2006 06:40:49 -0000	1.10
@@ -33,4 +33,15 @@
         </querytext>
     </fullquery>
 
+    <fullquery name="files">
+        <querytext>
+	select o.object_type as content_type, o.object_id as file_id 
+	from acs_data_links r, acs_objects o 
+	where r.object_id_one = :log_id 
+	and r.object_id_two = o.object_id 
+	and o.object_type in ([template::util::tcl_to_sql_list $content_types]) 
+	order by o.object_type, o.object_id
+        </querytext>
+    </fullquery>
+
 </queryset>