[Mimedefang] Re: Replace with URL
Yizhar Hurwitz
yizhar at mail.com
Thu Oct 13 16:56:31 EDT 2005
HI.
>> I was thinking about a hack to the "replace_with_url" function that will add a text/html MIME part,
>> but I don't feel that I have the required skills to do that in Perl without breaking something else.
> Simply replace "text/plain" with "text/html" and then format the body
> in HTML. No perl skills required :)
OK, I have changed "mimedefang.pl" and it seems to work fine and solve the issue,
however I would like to ask you to review my code and tell me if you have any comments about it.
I did the change in a lab environment, not in production yet.
Here are the relevant changes to the file "/usr/local/bin/mimedefang.pl":
= Added a new function: ==============================================
#***********************************************************************
# %PROCEDURE: action_replace_with_comment
# %ARGUMENTS:
# msg -- message
# %RETURNS:
# Nothing
# %DESCRIPTION:
# Makes a note to drop the current part and replace it with a comment
#
# To be used in replace_with_url,
# instead of the original replace_with_warning which is plain text only.
#
# Written by Yizhar Hurwitz, http://yizhar.mvps.org
# Version 1.0 , 13-Oct-2005
#
#***********************************************************************
sub action_replace_with_comment ($) {
my($msg) = @_;
return 0 if (!in_filter_context("action_replace_with_comment"));
$Actions{'replace_with_warning'}++;
$Action = "replace";
$ReplacementEntity = MIME::Entity->build(Type => "text/html",
Encoding => "-suggest",
Data => [ "<html><body>\n$msg\n<\/body><\/html>\n" ]);
$WarningCounter++;
$ReplacementEntity->head->mime_attr("Content-Type.name" => "comment$Warning
ounter.htm");
$ReplacementEntity->head->mime_attr("Content-Disposition" => "inline");
$ReplacementEntity->head->mime_attr("Content-Disposition.filename" => "comm
nt$WarningCounter.htm");
return 1;
}
=== And here are the changes to the existing function replace_with_url: =============
my($fname, $ext, $name, $url);
my($htmlurl);
my $extension = "";
[.................]
$msg =~ s/_URL_/$htmlurl/g;
action_replace_with_comment($msg);
return 1;
==== And in "/etc/mail/mimedefang-filter" I have done the following ==============
$multimedia = '(avi|mpg|mov|pps|wmv)';
if (re_match($entity, '\.' . $multimedia)) {
return action_replace_with_url($entity,
"/var/tmp/mail_parts",
"http://10.0.0.4/mail_parts",
"multimedia file converted to URL:<p>\n_URL_\n"
);
}
==============================================
So - how does it look?
Any hidden mines or overlooked potential problems?
Thanks again.
Yizhar Hurwitz
http://yizhar.mvps.org
More information about the MIMEDefang
mailing list