Index: openacs-4/packages/attachments/www/go-to-attachment.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/go-to-attachment.tcl,v
diff -u -r1.6 -r1.6.8.1
--- openacs-4/packages/attachments/www/go-to-attachment.tcl	28 Aug 2003 09:41:46 -0000	1.6
+++ openacs-4/packages/attachments/www/go-to-attachment.tcl	31 Mar 2007 07:05:32 -0000	1.6.8.1
@@ -26,7 +26,15 @@
     }
 
     file_storage_object {
-        set title [db_string select_attachment_title {}]
+        db_1row select_attachment {}
+	
+	# Test if the filename contains the extension, otherwise append it
+	# This usually happens if you just rename the title (displayed filename) but forget
+	# to append the extension to it.
+	set extension [file extension $title]
+	if {$extension ne $file_extension} {
+	    append title ".${file_extension}"
+	}
         ad_returnredirect "download/[ad_urlencode $title]?object_id=$object_id&attachment_id=$attachment_id"
         ad_script_abort
         return
Index: openacs-4/packages/attachments/www/go-to-attachment.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/go-to-attachment.xql,v
diff -u -r1.4 -r1.4.8.1
--- openacs-4/packages/attachments/www/go-to-attachment.xql	28 Aug 2003 09:41:46 -0000	1.4
+++ openacs-4/packages/attachments/www/go-to-attachment.xql	31 Mar 2007 07:05:32 -0000	1.4.8.1
@@ -10,12 +10,13 @@
 </fullquery>
 
 
-  <fullquery name="select_attachment_title">      
+  <fullquery name="select_attachment">      
     <querytext>
-      select r.title 
-      from cr_revisions r, cr_items i 
+      select r.title, m.file_extension, r.mime_type
+      from cr_revisions r, cr_items i, cr_mime_types m 
       where i.item_id = :attachment_id 
       and r.revision_id  = i.live_revision
+      and r.mime_type = m.mime_type
     </querytext>
   </fullquery>