mimestrip / mimereject
PATCH 1/1 mimestrip / mimereject
Hi,
this is a first attempt to implement stripping and rejecting of multipart/mime messages for mlmmj.
There are 2 patches. mlmmj-1.2.13-split_do_all_the_vodoo_here.patch
splits do_all_the_vodoo_here()
so that the header reading can be found in an extra function. This function can then later be reused to read the mime headers.
mlmmj-1.2.13-mimestrip-mimereject.patch
makes it possible to add the files
mimereject and mimeremove to the control/ directory.
Each of them can contain a list with different mime types like "application/octet-stream" or "text/html"
Messages that contain parts with one of these mime types then either get rejected or the unwanted part gets removed.
It also parses "multipart/alternative" parts that contain multiple parts themselves.
I'm not sure if the parser should always be enabled, though.
Please review.
Thanks.
Sascha
include/do_all_the_voodo_here.h +1 -1
@@ -30,6 +30,6 @@void getinfo (const char *line,struct mailhdr *readhdrs);int do_all_the_voodo_here (int infd,int outfd,int hdrfd,int footfd,const char **delhdrs,struct mailhdr *readhdrs, -struct strlist *allhdrs,const char *subjectprefix); +struct strlist *allhdrs,const char *subjectprefix,const char ** delmime,struct strlist *allmime);#endif /* DO_ALL_THE_VOODO_HERE_H */
README +7 -0
@@ -126,6 +126,13 @@ 10) Have a look at the file TUNABLES for runtime configurable things. +11) If you want to strip parts with certain mimetypes from multipart/mime messages + add a file called 'mimestrip' containing these mimetypes to the control/ directory. + +12) If you want to deny multipart/mime messages with certain mimetypes add a file + called 'mimedeny' continaing these mimetypes to the control/directory + + Tunables in include/mlmmj.h: · There's some time intervals for how mlmmj-maintd operates. I've choosen non-strict defaults, so depending on your BOFH rate you might want to tweak.
src/do_all_the_voodo_here.c +172 -1
195 lines not on this page · raw message
src/mlmmj-process.c +62 -6
112 lines not on this page · raw message
src/do_all_the_voodo_here.c +70 -38
155 lines not on this page · raw message
Hi,
Quoted 2 lines
this is a first attempt to implement stripping and rejecting of multipart/mime messages for mlmmj.
Oh. Last time I made a patch that improved the MIME handling (for list footers in that case), I was told this stuff does not belong into the list software.
Hi Sascha,
Welcome to this project!
Quoted 2 lines · Sascha Sommer
this is a first attempt to implement stripping and rejecting of multipart/mime messages for mlmmj.
As Jakob Hirsch replied, I'm not very fond of adding mime handling in mlmmj itself.
I believe a better way of doing this would be for a seperate program to strip unwanted mime parts and/or add a header like X-ThisMailContainsEvilMimeParts (and later check for it in the mlmmj access rules) before handing the mail to mlmmj.
If you move this code into a seperate program, I will be happy to include it in the contrib/ directory of the mlmmj tarballs.
Morten
Signature · 2 lines
Morten K. Poulsen <[email protected]> http://www.afdelingp.dk/
Hi,
Thanks for your feedback.
Quoted 11 lines · Morten K.Poulsen
Hi Sascha,
Welcome to this project!
Quoted 2 lines · Sascha Sommer
this is a first attempt to implement stripping and rejecting of multipart/mime messages for mlmmj.
As Jakob Hirsch replied, I'm not very fond of adding mime handling in mlmmj itself.
Ok.
Quoted 8 lines
I believe a better way of doing this would be for a seperate program to strip unwanted mime parts and/or add a header like X-ThisMailContainsEvilMimeParts (and later check for it in the mlmmj access rules) before handing the mail to mlmmj.
If you move this code into a seperate program, I will be happy to include it in the contrib/ directory of the mlmmj tarballs.
So the seperate program should then more or less replace mlmmj-receive? Or should the preprocess program be called from within mlmmj?
Regards
Sascha
Hi,
Quoted 8 lines
I believe a better way of doing this would be for a seperate program to strip unwanted mime parts and/or add a header like X-ThisMailContainsEvilMimeParts (and later check for it in the mlmmj access rules) before handing the mail to mlmmj.
If you move this code into a seperate program, I will be happy to include it in the contrib/ directory of the mlmmj tarballs.
Some more thoughts about this:
When this mime stripping and analysis should be done in a seperate program that then calls either mlmmj-process or mlmmj-receive.
Could we have a commandline parameter for these mlmmj tools to reject mails?
Adding a header is not optimal because it would require to either keep the parsed mail in memory or to parse it again in order to add the header. It would also require to do 2 configuration changes to activate mime stripping:
- activating the mime parser + its rules
- setting the X-ThisMailContainsEvilMimeParts deny rules in the lists rules files
The last step could be avoided if mlmmj had a commandline parameter to reject mails.
What do you think?
Regards
Sascha
Hi Sascha,
Quoted 7 lines · Sascha Sommer
Quoted 2 lines
If you move this code into a seperate program, I will be happy to include it in the contrib/ directory of the mlmmj tarballs.
Some more thoughts about this:
When this mime stripping and analysis should be done in a seperate program that then calls either mlmmj-process or mlmmj-receive.
Call mlmmj-process if you are already running "in the background." Mail servers (may) kill sub-processes, if they are running for too long. Or call mlmmj-recieve [sic] to background the process.
Quoted 2 lines
Could we have a commandline parameter for these mlmmj tools to reject mails?
If you have not backgrounded your process, you can do this by exit()ing with something other than EXIT_SUCCESS. Just write your error message to stdout (or stderr) and e.g. exit(EX_UNAVAILABLE) - then your MTA will deliver the error message.
Quoted 3 lines
Adding a header is not optimal because it would require to either keep the parsed mail in memory or to parse it again in order to add the header.
A bit ugly, but you could also
(echo 'X-NewHeader: blah'; cat $mailfile) |mlmmj-recieve
Quoted 7 lines
It would also require to do 2 configuration changes to activate mime stripping:
- activating the mime parser + its rules
- setting the X-ThisMailContainsEvilMimeParts deny rules in the lists rules files
The last step could be avoided if mlmmj had a commandline parameter to reject mails.
True, but you should be able to use the exit code trick, if it is only a question about denying every mail with "bad" mime parts.
Adding a header and using the access control have the advantage that you can mix it with other rules:
allow ^Subject: something
deny ^X-ThisMailContainsEvilMimeParts: yes
allow
Quoted 1 line
What do you think?
I am lazy and conservative :-)
I don't think we need to change anything in mlmmj to allow this to work, but I may be wrong.
Happy hacking,
Morten
Signature · 2 lines
Morten K. Poulsen <[email protected]> http://www.afdelingp.dk/
Hi,
Quoted 42 lines · Morten K.Poulsen
Hi Sascha,
Quoted 7 lines · Sascha Sommer
Quoted 2 lines
If you move this code into a seperate program, I will be happy to include it in the contrib/ directory of the mlmmj tarballs.
Some more thoughts about this:
When this mime stripping and analysis should be done in a seperate program that then calls either mlmmj-process or mlmmj-receive.
Call mlmmj-process if you are already running "in the background." Mail servers (may) kill sub-processes, if they are running for too long. Or call mlmmj-recieve [sic] to background the process.
Quoted 2 lines
Could we have a commandline parameter for these mlmmj tools to reject mails?
If you have not backgrounded your process, you can do this by exit()ing with something other than
EXIT_SUCCESS. Just write your error message to stdout (or stderr) and e.g.exit(EX_UNAVAILABLE)- then your MTA will deliver the error message.Quoted 3 lines
Adding a header is not optimal because it would require to either keep the parsed mail in memory or to parse it again in order to add the header.
A bit ugly, but you could also
(echo 'X-NewHeader: blah'; cat $mailfile) |mlmmj-recieve
Quoted 7 lines
It would also require to do 2 configuration changes to activate mime stripping:
- activating the mime parser + its rules
- setting the X-ThisMailContainsEvilMimeParts deny rules in the lists rules files
The last step could be avoided if mlmmj had a commandline parameter to reject mails.True, but you should be able to use the exit code trick, if it is only a question about denying every mail with "bad" mime parts.
Quoted 7 lines
Adding a header and using the access control have the advantage that you can mix it with other rules:
allow ^Subject: something
deny ^X-ThisMailContainsEvilMimeParts: yes
allow
Here is a patch that adds a tool called mlmmj-recievestrip to the contrib directory. It does the stripping directly when the mail is received and adds an extra header X-ThisMailContainsUnwantedMimeParts. It can be used as direct replacement for mlmmj-recieve.
Regards
Sascha
configure.ac +1 -0
@@ -42,4 +42,5 @@ AC_CONFIG_FILES([src/Makefile]) AC_CONFIG_FILES([src/mlmmj-make-ml.sh]) AC_CONFIG_FILES([listtexts/Makefile]) +AC_CONFIG_FILES([contrib/recievestrip/Makefile]) AC_OUTPUT
contrib/recievestrip/Makefile.am +12 -0
@@ -0,0 +1,12 @@ +# + +AUTOMAKE_OPTIONS = foreign + +AM_CFLAGS = -g -Wall -pedantic -Wsign-compare -DDEFAULTTEXTDIR='"@textlibdir@"' +INCLUDES = -I$(srcdir)/../../include + +bin_PROGRAMS = mlmmj-recieve-strip + +mlmmj_recieve_strip_SOURCES = mlmmj-recieve-strip.c ../../src/mygetline.c ../../src/memory.c ../../src/readn.c \ + ../../src/strgen.c ../../src/random-int.c ../../src/log_error.c ../../src/print-version.c \ + ../../src/writen.c ../../src/dumpfd2fd.c ../../src/ctrlvalues.c ../../src/chomp.c
contrib/recievestrip/mlmmj-recieve-strip.c +520 -0
520 lines not on this page · raw message
contrib/recievestrip/README +33 -0
@@ -0,0 +1,33 @@ +mlmmj-recieve-strip is a replacement for mlmmj-recieve + +It opens the files control/mimedeny and control/mimestrip to get a list of mimetypes +for parts of multipart/mime messages that should be denied or stripped + +The parts then get stripped directly when the mail is recieved. + +mlmmj-recieve-strip also appends an extra header + +X-ThisMailContainsUnwantedMimeParts: Y when the mail contains unwanted mime parts + + +Usage: +Compile the program in this directory with make and use "make install" to install it. +Afterwards replace mlmmj-receive with mlmmj-receive-strip in /etc/aliases for the mailinglist +you want to enable stripping and run newaliases + + +Then create the files mimedeny mimestrip in the control directory of your mailinglist. + +If control/mimestrip for example contains: + +text/html +application/octet-stream + +html texts and binarys will be stripped from the mail. + +When you also want to deny mails with certain mimeparts add the mimetypes to the mimedeny file +and add the following lines to the access file in the control dir: + +deny ^X-ThisMailContainsUnwantedMimeParts: Y +allow +
Hi Sascha,
Quoted 4 lines · Sascha Sommer
Here is a patch that adds a tool called mlmmj-recievestrip to the contrib directory. It does the stripping directly when the mail is received and adds an extra header X-ThisMailContainsUnwantedMimeParts. It can be used as direct replacement for mlmmj-recieve.
Very nice, thanks a lot.
I have committed it now. It will be part of the next release.
Morten
Signature · 2 lines
Morten K. Poulsen <[email protected]> http://www.afdelingp.dk/