Feature request: Checking and limiting mail size
Hej!
I implemented an mechanism for checking the size of all incoming mails. If the size exceeds a given value, the mail will discarded or rejected (depends on configuration).
The feature can be controlled in the usual way, creating files or changing the values they contain, in the listdir's control directory.
The size is set by a file called 'maxmailsize'. It contains the maximum allowed value in bytes. If it doesn't exist, no checks will be made. If the file 'nomaxmailsizedenymails' exists, no reject notification will be sent.
I appended these two "variables" to the TUNABLES and wrote a german and englich listtext.
Ciao
Chris
Only in mlmmj-1.2.11-mod/listtexts/de: maxmailsize Only in mlmmj-1.2.11-mod/listtexts: maxmailsize
src/mlmmj-process.c +71 -1
@@ -316,7 +316,9 @@int i, j, opt, noprocess =0 , moderated =0 ;int hdrfd, footfd, rawmailfd, donemailfd;int subonlypost =0 , addrtocc =1 , intocc =0 ; +int maxmailsize =0 ;int notoccdenymails =0 , noaccessdenymails =0 , nosubonlydenymails =0 ; +int nomaxmailsizedenymails =0 ;char *listdir =NULL , *mailfile =NULL , *headerfilename =NULL ;char *footerfilename =NULL , *donemailname =NULL ;char *randomstr =NULL , *mqueuename;
@@ -324,6 +326,7 @@char *bindir, *subjectprefix, *discardname, *listaddr, *listdelim;char *listfqdn, *listname, *fromaddr;char *queuefilename, *recipextra, *owner =NULL ; +char *maxmailsizestr;char *maildata[2 ] = {"posteraddr" ,NULL };struct stat st;uid_t uid;
@@ -581,6 +584,72 @@return EXIT_SUCCESS ; } +/* this declaration is needed here... */ + listaddr =getlistaddr (listdir); + alternates =ctrlvalues (listdir,"listaddress" ); + +/* checking incoming mail's size */ +/* log_error(LOG_ARGS, "%d", statctrl(listdir, "maxmailsize"));*/ + maxmailsize =statctrl (listdir,"maxmailsize" ); +if (maxmailsize) { + maxmailsizestr =ctrlvalue (listdir,"maxmailsize" ); +if (maxmailsizestr) { + maxmailsize =atol (maxmailsizestr); +myfree (maxmailsizestr); +/*log_error(LOG_ARGS, "max = %d", maxmailsize);*/ +if (stat (donemailname, &st) <0 ) { +log_error (LOG_ARGS ,"something went wrong" +" during stat(%s,..)" , donemailname); + } + nomaxmailsizedenymails =statctrl (listdir,"nomaxmailsizedenymails" ); +if ((st.st_size > maxmailsize) && nomaxmailsizedenymails) { +/*log_error(LOG_ARGS, "%d", nomaxmailsizedenymails);*/ +log_error (LOG_ARGS ,"discarding mail %s due to" +" size limit (%d bytes too big) \n" , + donemailname, (st.st_size - maxmailsize)); +/*myfree(nomaxmailsizedenymails); +myfree(maxmailsize); +myfree(st);*/ /* XXX: do we need this? */ +unlink (donemailname); +myfree (donemailname); +exit (EXIT_SUCCESS ); + } +if ((st.st_size > maxmailsize)) { +/*log_error(LOG_ARGS, "%s is %d bytes too big.\n", +donemailname, (st.st_size - maxmailsize));*/ + listdelim =getlistdelim (listdir); + listname =genlistname (listaddr); + listfqdn =genlistfqdn (listaddr); + fromaddr =concatstr (4 , listname, listdelim,"bounces-help@" , + listfqdn); + queuefilename =prepstdreply (listdir,"maxmailsize" , +"$listowner$" , fromemails.emaillist[0 ], +NULL ,0 ,NULL ); +MY_ASSERT (queuefilename) +/*myfree(nomaxmailsizedenymails); +myfree(maxmailsize); +myfree(st);*/ /* XXX: do we need this? */ +myfree (listdelim); +myfree (listname); +myfree (listfqdn); +unlink (donemailname); +myfree (donemailname); +execlp (mlmmjsend, mlmmjsend, +"-l" ,"1" , +"-L" , listdir, +"-T" , fromemails.emaillist[0 ], +"-F" , fromaddr, +"-m" , queuefilename, (char *)NULL ); + +log_error (LOG_ARGS ,"execlp() of '%s' failed" , mlmmjsend); +exit (EXIT_FAILURE ); + + } + } + } +/*myfree(maxmailsize); +myfree(nomaxmailsizedenymails);*/ /* do we need this? */ +/* discard malformed mail with invalid From: */ if (fromemails.emailcount !=1 ) {for (i =0 ; i < fromemails.emailcount; i++)
@@ -623,8 +692,9 @@unlink (mailfile); +/* maxmailsize need this earlier... listaddr = getlistaddr(listdir); - alternates =ctrlvalues (listdir,"listaddress" ); +alternates = ctrlvalues(listdir, "listaddress"); */ addrtocc = !(statctrl (listdir,"tocc" ));if (addrtocc) {
TUNABLES +9 -0
@@ -155,3 +155,12 @@ This specifies what to use as recipient delimiter for the list. Default is "+". + + � maxmailsize (normal) + + With this option the maximal allowed size of incoming mails can be specified. + + � nomaxmailsizedenymails (boolean) + + If this is set, no reject notifications caused by violation of maxmailsize + will be sent.