[Mimedefang] Howto use mimidefang _only_ for replacing attachments with urls?

Steffen Kaiser skmimedefang at smail.inf.fh-bonn-rhein-sieg.de
Mon Apr 2 10:43:22 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 2 Apr 2007, Tony K Lindstrom wrote:

> defined, before using the code. My problem still is, that I want some
> filter code which has everything and does what I want. That is to

And this is what MIMEDefang is not, the config file of MIMEDefang is Perl 
code.
That it is strenght and weakness.

Actually, all you need is a call to action_replace_with_url() with the 
proper condition. The function is described in the man page, the condition 
is Perl code, e.g.:

                 my $size = (stat($entity->bodyhandle->path))[7];
                 if($size >= 10*1024) {          # larger than 10KB
 			return action_replace_with_url( <args> );
 		}

> replace big attachments with urls, nothing else.
>
> 	The second howto was in the wiki:
>
> 	http://www.mimedefang.org/kwiki/index.cgi?ReplaceWithURL

This page emphases on preserving the filename.

> 	but this has this skahed function which I can't find...:-(

Below the snippet is a line "My function <TT>skahead</TT> logs the message 
to syslog and, if running in verbose mode, adds a header line. These are 
my debug-in-production fallbacks."

- -> Hence, just delete these lines.

>
> 	Why does this simple task has to be so difficult. Looks like these
> howto:s are aimed for other perl-gurus and not for admins which only

these HOWTOs are aimed for people understanding perl, because perl is the 
configuration language. You need not be a guru.

> 	- what to add (and from where) to make either of those howto:s filters
> to work.

Hmm, you know bash scripts and you are interested in replacing large only, 
let's see:

The description of "if($oneRcptIsLargeList || $oneRcptIsList && 
!$isAuthed) { "
says that replacement is done only on some condition you are not 
interested in, hence, cut it.
Neither are you interested in protecting lists againsts DSNs, hence, 
remove the if() and the compound statement completely.
S/MIME is also uninteresing, cut it, too.
you're left with the block:

my $size = (stat($entity->bodyhandle->path))[7];
                 if($size >= 10*1024) {          # larger than 10KB
                         if($size > 1024) {
                                 $size = int($size / 1024);
                                 if($size > 1024) {
                                         $size = int($size / 1024);
                                         $size .= 'MB';
                                 } else {
                                         $size .= 'KB';
                                 }
                         } else {
                                 $size .= "B";
                         }
                         skahead "Replace $lcType '$friendlyName' ($size) 
with URL";
                         return action_replace_with_url($entity,
                                 "/var/spool/MIMEDefang_Captured_Files",

"http://www4.inf.fh-bonn-rhein-sieg.de/captured_mailfiles",
"Der Anhang '$friendlyName' wurde aufgrund seiner Groesse aus dieser
Nachricht entfernt, kann jedoch ueber folgende URL abgerufen werden:\n
The attachment '$friendlyName' was removed from this mail, but
may be accessed at this URL (approx. $size):\n" .
                         "\t_URL_\n"
                         , "$lcType $friendlyName\n", $skaCfg{urlsalt});
                 }

remove the skahead, as this performs only logging, as described on the 
page.
The if($size > 1024) mangles the displayed size, hence, can be removed, 
too.

Before this block, you have to polpulate the variables $lcType and 
$friendlyName, however, you could directly pass the forth argument of sub 
filter; second, I alter the filename to protect against nasty attacks, 
I've posted the function I use on the page, but you might think it not 
good. The sixth argument "$skaCfg{urlsalt}" is some constant as described 
in the man page.

So prefix this code with

my $lcType = lc(  whatever_you_called_the_forth_arg );
### The standard is $type
my $friendlyName = skaFriendlyName( whatever_you_called_the_second_arg );
### The standard is $fname

Bye,

- -- 
Steffen Kaiser
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iQEVAwUBRhEWjOgJIbZtwg6XAQIyMwf+L+B/TAgXejOixZevnKJQLJ4cQU7fqEdB
5YyZswBP3qcTj86t3m5ZQe3Ded6crtUx9SJCY/nmvvFwuMdcmzd3YLq2jZGf8Ds8
Y8N4dzbs7C5AtwQGEmAG6DzTumuUB6/h9yGOBQwQfG3jE90RL+asWLGbXPUeRn2u
+xWJJlg6714SdqD3jAHhHHlXB6sk8k5tHW22GhPLzrK5yXGrGrNtvb9M5xlELgHR
RXRqCiji2fYyN+TDn70Wx+0qaJowMy3tu54Jj9c9tDJ7TnLzG5GAkM0ekC1mnRvo
AXgNvQi1fJPrcBsZ2yUanx3xvT2tErE8nsh5iwwKPY+dHlmroSbi9g==
=JZ+h
-----END PGP SIGNATURE-----



More information about the MIMEDefang mailing list