"받는 사람:" 또는 "참조:" 필드에 너무 많은 항목이 포함된 메시지를 mutt로 보내지 마세요.

"받는 사람:" 또는 "참조:" 필드에 너무 많은 항목이 포함된 메시지를 mutt로 보내지 마세요.

나는 종종 mutt별칭 기능을 사용하여 더 많은 사람들에게 메시지를 보냅니다(스팸이 아니라 합법적입니다!). 일반적으로 Bcc:스팸 수집자를 제거하고 개인 정보 보호를 위해(모든 수신자가 서로 아는 것은 아님) 이 필드에 별칭을 넣습니다 .

때로는 실수로 별칭을 To:또는 Cc:필드에 입력했는데, 여기에서 확장되어 모든 수신자의 모든 주소가 표시됩니다. 한번 보내면 정보가 유출되어 되돌릴 수 없기 때문에 이는 매우 안타까운 일입니다.

  • 해당 필드에 1~5개 이상의 항목이 있는 경우 mutt메시지 전송을 거부하려면 어떻게 해야 합니까?To:Cc:

  • mutt개선 사항: 예를 들어 사용자 정의 헤더를 추가하면 어떻게 메일을 보낼 수 있나요 X-limit-cc: 50?

별도의 메일링 리스트 서비스를 설정하는 것은 제가 요구하는 것이 아니며, 오히려 문제에 대한 별도의 해결책이 될 것입니다.

답변1

AFAIK, Mutt 자체는 이러한 검사를 수행할 수 없지만 해결 방법이 있습니다! 아이디어는 $sendmail메시지를 보내기 전에 메시지를 확인하는 래퍼를 사용하도록 변수를 재정의하는 것입니다. 예를 들어 파일에서 다음과 같습니다 .muttrc.

set sendmail=$HOME/scripts/sendmail-mutt

스크립트는 오류(0이 아닌 종료 상태)로 종료되거나 아래와 같이 성공적으로 종료될 수 있습니다.

exec /usr/sbin/sendmail -oem -oi "$@"

쉘 스크립트에서 또는:

exec qw(/usr/sbin/sendmail -oem -oi), @ARGV;

펄에서.

답변2

#!/bin/bash
set -u -e -C;
shopt -s nullglob;

# This script can be used as a `sendmail` replacement in `mutt`.  It
# performs several checks on the mail before sending ist, and it's
# easy to modify these checks, or to add more.  Currently, these are:
#
#     attachment — fail on non-multipart message if text contains
#         keywords referring to an attachment (English, German).
#
#     size — refuse to send excessively large mails.
#
#     fixme — refuse to send mail containing the word `FIXME`.
#
#     longline — refuse to send mails wit long lines, unless paths
#         (URLs) containing two slashes, or quoted.
#
#     limit-to, limit-cc — limit number of recipients in the according
#         header.  Better use Bcc field.
#
# Each of the tests can be disabled by puttig its name in an
# `X-checks` header field.  E.g., `X-checks: longline limit-cc` allows
# to send mails with long lines to unlimited number of recipients in
# the Cc field.
#
# To use this script, install it where it can be found, and configure
# mutt accordingly.  I have stored this script as `~/.mutt/sendmail`,
# and my `~/.mutt/muttrc` contains the line
#
#     set sendmail = "~/.mutt/sendmail"
#
# When sending a mail, it is stored as `mutt-sendmail.*` in a
# temporary location, from where it is accessible for checks.  On
# success, the mail is sent, otherwise this script fails.  The
# temporary file is deleted.



# ---- Configuration of this script ----------------------------------

# Mail is sent using `${sendmail} "$@" <"${wholemail}"`, see last line
# of the script.

sendmail=/usr/bin/msmtp;

# You may explicitly skip some tests by putting their name in a header
# field of your mail.  On checking, these names are printed to stderr.
# The name of the header is:

myhdr='X-checks';



# ---- The script ----------------------------------------------------

# print message to stderr, maybe fail
function err { echo "$@" >&2; exit 1; }
function warn { echo "$@" >&2; }

# store the mail in a temporary file
wholemail="$(mktemp -t mutt-sendmail.XXXXXXXXXX)" &&
    trap "rm -f '${wholemail}'" EXIT &&
    cat >| "${wholemail}" ||
    err 'cannot create temporary file';

# get the header, with indented lines joined
header="$(sed -rn ':a;/^$/q;$!N;s/\n\s+/ /;ta;P;D' "${wholemail}")";

# get values of one particular header, each occurence on one line
function getHeader { sed -rn "s/^${1}:\s+//p" <<< "$header"; }

# use this function to read body of message
function getBody { sed '1,/^$/d' "${wholemail}"; }

# get list of checks to be ignored for this particular mail
checks="$(getHeader "${myhdr}")";
function requested {
    if grep -q "${1}" <<< "${checks}"; then
        warn "${myhdr}: ${1} — skipping";
        return 1;
    else
        warn "no ${myhdr}: ${1}";
        return 0;
    fi;
}


# --- do all tests here ----------------------------------------------
#
# `$wholemail` contains the file name of the whole mail, as passed to
#   sendmail.
# `getBody` writes the body of the mail to stdout.
# `getHeader foo` writes one line for each value of a `foo:` header.
# `requested bar` fails if a `$myhdr` header contains `bar`.

# make a keyword search on the whole email, if it is not multipart.
requested 'attachment' &&
getHeader "Content-Type" | grep -vq multipart &&
grep -v '^>' "$wholemail" | grep -Eni 'attach|anhang|hängt|unten' &&
err "no multipart message, but hints to attachment.";

# reject emails greater than $maxsize bytes
maxsize='32768';
requested 'size' &&
test "$(stat -c%s "${wholemail}")" -gt "${maxsize}" &&
err "bigger then ${maxsize} bytes.";

# reject emails containing FIXME
requested 'fixme' &&
getBody | grep -n FIXME &&
err "FIXME keyword found.";

# reject emails with long lines
maxline=78;
requested 'longline' &&
test "$(getBody | grep -Ev '^>|/.*/' | wc -L)" -gt "$maxline" &&
err "lines longer than $maxline chars found.";

# count number of recipients
requested 'limit-to' &&
test "$(getHeader "To" | grep -o ',' | wc -l)" -gt 2 &&
err 'Too many recipients in the To field.';

requested 'limit-cc' &&
test "$(getHeader "Cc" | grep -o ',' | wc -l)" -gt 5 &&
err 'Too many recipients in the Cc field.';


# --- now send the mail ----------------------------------------------
#err 'debugging mode: not sending';

${sendmail} "$@" <"${wholemail}";

관련 정보