[Mimedefang] Re: Replace with URL

Yizhar Hurwitz yizhar at mail.com
Thu Oct 13 16:56:31 EDT 2005


>> 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"));      
    $Action = "replace";                                                  
    $ReplacementEntity = MIME::Entity->build(Type => "text/html",         
                                             Encoding => "-suggest",      
                Data => [ "<html><body>\n$msg\n<\/body><\/html>\n" ]);    
    $ReplacementEntity->head->mime_attr("Content-Type.name" => "comment$Warning
    $ReplacementEntity->head->mime_attr("Content-Disposition" => "inline");    
    $ReplacementEntity->head->mime_attr("Content-Disposition.filename" => "comm
    return 1;                                                                  

=== And here are the changes to the existing function replace_with_url: =============

    my($fname, $ext, $name, $url);   
    my $extension = "";              
    $msg =~ s/_URL_/$htmlurl/g;       
    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,        
        "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

More information about the MIMEDefang mailing list