| 1 | #!/bin/bash |
| 2 | # |
| 3 | # mlmmj-amime-receive |
| 4 | # |
| 5 | # Take mail from stdin, pipe it through altermime and then to mlmmj-receive |
| 6 | # needed to add footers in a MIME-aware way |
| 7 | # |
| 8 | # requires altermime, see http://www.pldaniels.com/altermime/ |
| 9 | # |
| 10 | # just replace mlmmj-receive with mlmmj-amime-receive, e.g. in /etc/aliases: |
| 11 | # myml: "|/usr/bin/mlmmj-amime-receive -L /var/spool/mlmmj/myml/" |
| 12 | # |
| 13 | # put the footer-text for the different MIME-types into |
| 14 | # control/amime-footer-text |
| 15 | # control/amime-footer-html |
| 16 | # control/amime-footer-base64 |
| 17 | # |
| 18 | # Copyright 2008 by Gerd v. Egidy, <[email protected]> |
| 19 | # |
| 20 | # Licensed under MIT License, see LICENSE file coming with mlmmj |
| 21 | # |
| 22 | |
| 23 | MLMMJRECEIVE=/usr/bin/mlmmj-receive |
| 24 | ALTERMIME=/usr/bin/altermime |
| 25 | |
| 26 | # check executables |
| 27 | if ! [ -x $MLMMJRECEIVE ]; then |
| 28 | echo "can't find $MLMMJRECEIVE executable, aborting" |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | if ! [ -x $ALTERMIME ]; then |
| 33 | echo "can't find $ALTERMIME executable, aborting" |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | # read parameters |
| 38 | I=1 |
| 39 | PARAM_L=0 |
| 40 | while [ $I -le $# ] && [ $PARAM_L == 0 ]; do |
| 41 | if [ "${!I}" == "-L" ]; then |
| 42 | PARAM_L=1 |
| 43 | fi |
| 44 | I=$[$I+1] |
| 45 | done |
| 46 | |
| 47 | if [ $PARAM_L == 1 ] && [ $I -le $# ]; then |
| 48 | MLPATH="${!I}" |
| 49 | else |
| 50 | echo "parameter -L /path/to/listdir missing, aborting" |
| 51 | exit 1 |
| 52 | fi |
| 53 | |
| 54 | if ! [ -d "${MLPATH}" ]; then |
| 55 | echo "${MLPATH} is not existing or no directory, aborting" |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | CONTROLD="${MLPATH}/control" |
| 60 | |
| 61 | if ! [ -d "${CONTROLD}" ]; then |
| 62 | echo "${CONTROLD} is not existing or no directory, aborting" |
| 63 | exit 1 |
| 64 | fi |
| 65 | |
| 66 | # look for footer-files and build parameters |
| 67 | |
| 68 | if ! [ -f "${CONTROLD}/amime-footer-text" ]; then |
| 69 | echo "${CONTROLD}/amime-footer-text is not existing or no regular file, aborting" |
| 70 | exit 1 |
| 71 | fi |
| 72 | |
| 73 | PARAM="--disclaimer=${CONTROLD}/amime-footer-text" |
| 74 | |
| 75 | if [ -f "${CONTROLD}/amime-footer-html" ]; then |
| 76 | PARAM="${PARAM} --disclaimer-html=${CONTROLD}/amime-footer-html --htmltoo --force-for-bad-html" |
| 77 | fi |
| 78 | |
| 79 | if [ -f "${CONTROLD}/amime-footer-base64" ]; then |
| 80 | PARAM="${PARAM} --disclaimer-b64=${CONTROLD}/amime-footer-base64" |
| 81 | fi |
| 82 | |
| 83 | PARAM="${PARAM} --altersigned --log-syslog" |
| 84 | |
| 85 | # go to a dir where altermime can write it's tmp-files safely |
| 86 | cd $MLPATH |
| 87 | |
| 88 | # pipe the calls |
| 89 | $ALTERMIME --input=- ${PARAM} | $MLMMJRECEIVE "$@" |