From 5e13c05f4b4a3695d6ed0a70bafd60c291c6d59d Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 23 Feb 2018 16:38:01 -0800 Subject: [PATCH] mail.sh: allow size_limit to be configured Previously mail.sh has had a hard-coded limit of 256K for each e-mail message it sends out. In the era of megapixel camera images being sent as attachments, the limit of 256K may be overly conservative. Make the limit more easily configurable with a new option in Config.pm $mailsh_sizelimit that sets the limit as the maximum size in K byte units. At the same time double the default limit from 256 K to 512 K to avoid unnecessarily constraining the output while allowing individual installations to easily customize the value. Signed-off-by: Kyle J. McKay --- Girocco/Config.pm | 7 +++++++ taskd/mail.sh | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Girocco/Config.pm b/Girocco/Config.pm index 9c8d1bf..84ac11a 100644 --- a/Girocco/Config.pm +++ b/Girocco/Config.pm @@ -281,6 +281,11 @@ our $min_dns_labels = 2; # RECOMMENDED VALUE: 1 our $xmllint_readme = 0; +# Maximum size of any single email sent by mail.sh in K (1024-byte) units +# If message is larger it will be truncated with a "...e-mail trimmed" line +# RECOMMENDED VALUE: 256 - 5120 (.25M - 5M) +our $mailsh_sizelimit = 512; + # ## ------------------- @@ -1049,6 +1054,8 @@ $fetch_stash_refs = $fetch_stash_refs ? 1 : ''; (not $mob or $mob eq 'mob') or die "Girocco::Config \$mob must be undef (or '') or 'mob'"; (not $min_key_length or $min_key_length =~ /^[1-9][0-9]*$/) or die "Girocco::Config \$min_key_length must be undef or numeric"; +(defined $mailsh_sizelimit and $mailsh_sizelimit =~ /^[1-9][0-9]*$/) + or die "Girocco::Config \$mailsh_sizelimit must be a positive number"; $admincc = $admincc ? 1 : 0; $rootcert = "$certsdir/girocco_root_crt.pem" if $httpspushurl && !$rootcert; $clientcert = "$certsdir/girocco_client_crt.pem" if $httpspushurl && !$clientcert; diff --git a/taskd/mail.sh b/taskd/mail.sh index d64070d..4ebe2a7 100755 --- a/taskd/mail.sh +++ b/taskd/mail.sh @@ -946,7 +946,7 @@ size_limit() # Include size of RFC 822 trailing CR+LF on each line size=$(($size+${#line}+2)) if [ $size -gt $1 ]; then - echol "...e-mail trimmed, has been too large." + echol "...e-mail trimmed, exceeded size limit." break fi echol "$line" @@ -1059,12 +1059,14 @@ differrtmp="$(mktemp -u "${TMPDIR:-/tmp}/difftree-$$-XXXXXX")" # if no arguments are given then run as a hook script # If --stdout is first argument send all output there instead (handled above) # Optional 4th (projectname), 5th (sender) and 6th (extra header) arguments +max_email_size="$(( ${cfg_mailsh_sizelimit:-256} * 1024 ))" +[ "${max_email_size:-0}" -ge "10240" ] || max_email_size="10240" # 10K minimum if [ -n "$1" ] && [ -n "$2" ] && [ -n "$3" ]; then # Handle a single update rather than a batch on stdin # Output will still be sent to sendmail unless --stdout is used # Same 3 args as update hook ( ) if prep_for_email $2 $3 $1; then - PAGER= generate_email | size_limit $((256*1024)) | send_mail + PAGER= generate_email | size_limit "$max_email_size" | send_mail fi else # MAIL_SH_OTHER_BRANCHES cannot possibly be valid for multiple updates @@ -1073,7 +1075,7 @@ else while read oldrev newrev refname do prep_for_email $oldrev $newrev $refname || continue - PAGER= generate_email | size_limit $((256*1024)) | send_mail + PAGER= generate_email | size_limit "$max_email_size" | send_mail done fi -- 2.11.4.GIT