Index: mailer.py =================================================================== --- mailer.py (revision 38221) +++ mailer.py (working copy) @@ -655,7 +655,7 @@ params, diffsels, diffurls, pool), other_diffs=other_diffs, ) - renderer.render(data) + renderer.render(data, cfg, group, params) def generate_list(changekind, changelist, paths, in_paths): @@ -932,7 +932,7 @@ def __init__(self, output): self.output = output - def render(self, data): + def render(self, data, cfg, group, params): "Render the commit defined by 'data'." w = self.output.write @@ -965,11 +965,11 @@ else: w('and changes in other areas\n') - self._render_diffs(data.diffs, '') + self._render_diffs(data.diffs, '', cfg, group, params) if data.other_diffs: self._render_diffs(data.other_diffs, '\nDiffs of changes in other areas also' - ' in this revision:\n') + ' in this revision:\n', cfg, group, params) def _render_list(self, header, data_list): if not data_list: @@ -1000,15 +1000,40 @@ w(' - copied%s from r%d, %s%s\n' % (text, d.base_rev, d.base_path, is_dir)) - def _render_diffs(self, diffs, section_header): + def _render_diffs(self, diffs, section_header, cfg, group, params): """Render diffs. Write the SECTION_HEADER if there are actually any diffs to render.""" if not diffs: return w = self.output.write section_header_printed = False + jdiff = cfg.get('max_diff_size', group, params) + try: + max_diff_size = int(jdiff) + diff_size = max_diff_size + except ValueError: + max_diff_size = -1 + diff_size = -1 + jmail = cfg.get('max_mail_size', group, params) + try: + max_mail_size = int(jmail) + mail_size = max_mail_size + except ValueError: + max_mail_size = -1 + mail_size = -1 + jnumber = cfg.get('max_number_of_diffs', group, params) + try: + max_number = int(jnumber) + except ValueError: + max_number = -1 + i=0 for diff in diffs: + i=i+1 + if i > max_number and -1 != max_number: + w('\n\n================ MAX NUMBER OF FILES=%s' % max_number) + w(' IS REACHED, NO MORE DIFF ================\n\n') + break if not diff.diff and not diff.diff_url: continue if not section_header_printed: @@ -1043,8 +1068,27 @@ w('Binary file (source and/or target). No diff available.\n') continue + max_diff_size = diff_size for line in diff.content: + raw_line_length = len(line.raw) + max_diff_size = max_diff_size - raw_line_length + if max_diff_size <= 0 and -1 != diff_size: + w('\n============= MAX DIFF SIZE=%s ' % diff_size) + w('IS REACHED NO MORE OF THIS DIFF INCLUDED =============\n\n') + # We ought to stop the generation of more diffs, but it + # might already be too late + break + max_mail_size = max_mail_size - raw_line_length + if max_mail_size <= 0 and -1 != mail_size: + w('\n============= MAX MAILSIZE=%s ' % mail_size) + w('IS REACHED NO MORE FILE DIFF INCLUDED =============\n\n') + # We ought to stop the generation of more diffs, but it + # might already be too late + break w(line.raw) + if max_mail_size <= 0 and -1 != mail_size: + # we dont need the rest of this email + break class Repository: Index: mailer.conf.example =================================================================== --- mailer.conf.example (revision 38221) +++ mailer.conf.example (working copy) @@ -243,6 +243,22 @@ # Set to 0 to turn off. #truncate_subject = 200 +# The maximum size in bytes that a diff can be. 0 means 0 bytes. -1 +# means no limit. If there is no such variable, the limit is -1 +# The counted bytes are ONLY the actual diffs, not which files are +# changed, modified, added, deleted, ... +# max_diff_size = 8192 + +# The maximum size in bytes that an email can be. 0 means zero +# -1 means unlimited, and if the variable is not mentioned it means -1 +# The count is ONLY the actual diffs, so there will used bytes to inform +# which files was added, changed, deleted, modified, ... +# max_mail_size = 65536 + +# Maximal number of diffed files. To prevent really big emails. +# 0 means no diffs included, below 0 means no limit +# max_number_of_diffs = 128 + # -------------------------------------------------------------------------- [maps] @@ -328,4 +344,7 @@ # # commits to personal repositories should go to that person # for_repos = /home/(?P[^/]*)/repos # to_addr = %(who)s@example.com +# max_diff_size = 16384 +# max_mail_size = 32768 +# max_number_of_diffs = 64 #