diff -NuarwbB mimedefang-2.63-original/mimedefang.pl.in mimedefang-2.63/mimedefang.pl.in
--- mimedefang-2.63-original/mimedefang.pl.in	2007-08-13 15:50:18.000000000 +0200
+++ mimedefang-2.63/mimedefang.pl.in	2007-12-24 11:52:24.000000000 +0100
@@ -38,7 +38,7 @@
 	    $MessageID $Rebuild $QuarantineCount
 	    $QuarantineSubdir $QueueID $MsgID
 	    $RelayAddr $WasResent $RelayHostname
-	    $RealRelayAddr $RealRelayHostname
+	    $RealRelayAddr $RealRelayHostname @attachURLlist
 	    $ReplacementEntity $Sender $ServerMode $Subject $SubjectCount
 	    $ClamdSock $SophieSock $TrophieSock
 	    $SuspiciousCharsInHeaders
@@ -1084,23 +1084,60 @@
 # %PROCEDURE: action_replace_with_warning
 # %ARGUMENTS:
 #  msg -- warning message
+#  mtype -- mime type
+#  mext -- extension
+#  mname -- file name
 # %RETURNS:
 #  Nothing
 # %DESCRIPTION:
 #  Makes a note to drop the current part and replace it with a warning
 #***********************************************************************
-sub action_replace_with_warning ($) {
-    my($msg) = @_;
+sub action_replace_with_warning ($;$$$) {
+    my($msg, $mtype, $mext, $mname) = @_;
     return 0 if (!in_filter_context("action_replace_with_warning"));
     $Actions{'replace_with_warning'}++;
     $Action = "replace";
-    $ReplacementEntity = MIME::Entity->build(Type => "text/plain",
+    $mtype = "text/plain" unless defined($mtype);
+    $mext = "txt" unless defined($mext);
+    $mname = "warning" unless defined($mname);
+    $ReplacementEntity = MIME::Entity->build(Type => $mtype,
 					     Encoding => "-suggest",
 					     Data => [ "$msg\n" ]);
     $WarningCounter++;
-    $ReplacementEntity->head->mime_attr("Content-Type.name" => "warning$WarningCounter.txt");
+    $ReplacementEntity->head->mime_attr("Content-Type.name" => "$mname$WarningCounter.$mext");
     $ReplacementEntity->head->mime_attr("Content-Disposition" => "inline");
-    $ReplacementEntity->head->mime_attr("Content-Disposition.filename" => "warning$WarningCounter.txt");
+    $ReplacementEntity->head->mime_attr("Content-Disposition.filename" => "$mname$WarningCounter.$mext");
+    return 1;
+}
+
+#***********************************************************************
+# %PROCEDURE: action_replace_with_file
+# %ARGUMENTS:
+#  entity -- mime entity
+#  nfname -- new file path
+#  nfdesc -- description
+#  nftype -- mime type
+#  nfencode -- encoding
+# %RETURNS:
+#  Nothing
+# %DESCRIPTION:
+#  Makes a note to drop the current part and replace it with a file
+#***********************************************************************
+sub action_replace_with_file ($$;$$$$$) {
+    my($entity, $nfpath, $nfname, $nftype, $nfencode, $nfdispo) = @_;
+    return 0 if (!in_filter_context("action_replace_with_file"));
+    $Actions{'replace_with_file'}++;
+    $Action = "replace";
+    $nftype = "application/octet-stream" unless defined($nftype);
+    $nfname = "" unless defined($nfname);
+    $nfencode = "base64" unless defined($nfencode);
+    $nfdispo = "attachment" unless defined($nfdispo);
+    $ReplacementEntity = MIME::Entity->build(Type => $nftype,
+					     Encoding => $nfencode,
+					     Path => $nfpath,
+					     Filename => $nfname,
+					     Disposition => $nfdispo);
+    copy_or_link($nfpath, $entity->bodyhandle->path) or return 0;
     return 1;
 }
 
@@ -5282,6 +5319,7 @@
     undef @StatusTags;
     undef @ESMTPArgs;
     undef @SenderESMTPArgs;
+    undef @attachURLlist;
 }
 
 sub builtin_create_parser () {
@@ -6040,6 +6078,9 @@
 #  base_url -- base URL for retrieving document
 #  msg -- message to replace document with.  The string "_URL_" is
 #         replaced with the actual URL of the part.
+#  mtype -- message mime type (for the warning msg)
+#  mext -- message extension (for the warning msg)
+#  mname -- message name (for the warning msg)
 #  cd_data -- optional Content-Disposition filename data to save
 #  salt    -- optional salt to add to SHA1 hash.
 # %RETURNS:
@@ -6048,8 +6089,8 @@
 #  Places the part in doc_root/{sha1_of_part}.ext and replaces it with
 #  a text/plain part giving the URL for pickup.
 #***********************************************************************
-sub action_replace_with_url ($$$$;$$) {
-    my($entity, $doc_root, $base_url, $msg, $cd_data, $salt) = @_;
+sub action_replace_with_url ($$$$;$$$$$) {
+    my($entity, $doc_root, $base_url, $msg, $mtype, $mext, $mname, $cd_data, $salt) = @_;
     my($ctx);
     my($path);
     my($fname, $ext, $name, $url);
@@ -6099,8 +6140,16 @@
 	}
     }
 
+    push(@attachURLlist, $cd_data."\n".$url."\n");
+
     $msg =~ s/_URL_/$url/g;
+    if (defined($mtype) and ($mtype ne "") and defined($mext) and ($mext ne "") and defined($mname) and ($mname ne "")) {
+	action_replace_with_warning($msg, $mtype, $mext, $mname);
+	}
+    else {
     action_replace_with_warning($msg);
+	}
+
     return 1;
 }
 
