/* According to RFC2822, line lengths SHOULD be limited to 80 characters, including the CRLF, so we're limiting our header to: MAX_RFC_LINE_LENGTH - (COLON_SPACE_LEN + MAX_ASTERISKS + CRLF_LEN ) which works out to 80 - (2 + 50 + 2) = 80-54, or 26 chars for the header name Arguments: HeaderName Message data comes in on StdIn, output is on StdOut Note - although we output MAX_ASTERISKS asterisks, the mesage size is not limited. Author: Terry Carmen -- terry@cnysupport.com Released to the public domain 9/21/2007 No warranty or representations of any kind are made. If you like it or have suggestions, please drop me an email. It may operate perfectly, or break into your apartment while you're sleeping, drink all your beer and eat all your cold pizza. If it breaks, you get to keep both halves. To build, cut and paste the text between the dotted lines to the file "Makefile", then run "make" -------------------------------------------- AddMsgSizeHeader: AddMsgSizeHeader.o gcc -Wall -lm -o AddMsgSizeHeader AddMsgSizeHeader.o AddMsgSizeHeader.o: AddMsgSizeHeader.c gcc -c AddMsgSizeHeader.c -------------------------------------------- Postfix Master.cf: filter unix - n n - - pipe user=filter argv=/usr/bin/spamc -e /usr/sbin/ContentFilter -oi -f ${sender} ${recipient} -------------------------------------------- ContentFilter #!/bin/bash EX_TEMPFAIL=75 EX_UNAVAILABLE=69 /usr/sbin/AddMsgSizeHeader X-ActualMessageSize | /usr/sbin/sendmail "$@" ${sender} ${recipient} || { echo AddMsgSizeHeader failed;exit TEMPFAIL; } exit 0 -------------------------------------------- */ #include #include #include int main(int argc, char * argv[]) { const int MB_PER_ASTERISK = 1; // Scaling factor const int MAX_ASTERISKS = 50; const size_t BYTES_PER_MB = (1024 * 1024); const size_t MAX_MESSAGE_SIZE = MAX_ASTERISKS * MB_PER_ASTERISK * BYTES_PER_MB; const int COLON_SPACE_LEN = 2; const int CRLF_LEN = 2; const int MAX_RFC_LINE_LENGTH = 80; const size_t MAX_HEADER_NAME_LENGTH = MAX_RFC_LINE_LENGTH - (COLON_SPACE_LEN + MAX_ASTERISKS + CRLF_LEN ); char * cpMsg; int c; size_t i; int nRet; int nAsterisks; size_t tCurrentMsgSize; if(argc != 2) { fprintf(stderr, "Usage: | AddContentLenHeader X-MyHeaderName\nReceives input via stdin, and sends output via stdout.\n\n"); nRet=1; } else { cpMsg = (char * ) malloc(sizeof(char) * (MAX_MESSAGE_SIZE + 1)); if (cpMsg == NULL) { puts("Unable to allocate string buffer for message!"); nRet=1; } else { /* Figure out how big the message is We have a 50M fixed limit. If it's bigger than that, we max out the stars */ tCurrentMsgSize=0; while ((c = getchar()) != EOF && tCurrentMsgSize < MAX_MESSAGE_SIZE) { cpMsg[tCurrentMsgSize]=c; tCurrentMsgSize++; } if (c == EOF) cpMsg[tCurrentMsgSize]='\0'; // This might not be the end of the message fputs(argv[1], stdout); fputs(": ", stdout); nAsterisks = (int) (tCurrentMsgSize/BYTES_PER_MB); for(i=0;i