[Reportbug-commits] [SCM] Reportbug - reports bugs in the Debian distribution branch, master, updated. 4.9-184-g350057f

Sandro Tosi morph at debian.org
Tue Apr 26 07:13:34 UTC 2011


The following commit has been merged in the master branch:
commit 350057f1aef606006807a569d6356d9fb3c50ea5
Author: Sandro Tosi <morph at debian.org>
Date:   Tue Apr 26 01:15:09 2011 +0200

    added a new cli options, --max-attachment-size (also available in the config file), to limit the size of any attachment (or --body-file) to the specified value, in byte; thanks to Lionel Elie Mamane for the report and to Carl Chanet for the initial patch; Closes: #528720

diff --git a/bin/reportbug b/bin/reportbug
index b659b23..9795478 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -104,6 +104,12 @@ def stopmsg(filename):
         'submit at bugs.debian.org, editing the subject and bug text as needed '
         '(but not altering the other information).\n', filename)
 
+def check_attachment_size(attachfile, maxsize):
+    """Check if the attachment size is bigger than max allowed"""
+    statinfo = os.stat(attachfile)
+    attachsize = statinfo[6]
+    return attachsize >= maxsize
+
 def include_file_in_report(message, message_filename,
                            attachment_filenames, package_name,
                            include_filename, charset, inline=False, draftpath=None):
@@ -251,13 +257,18 @@ def handle_editing(filename, dmessage, options, sendto, attachments, package,
                     # loop over the globbed 'attachfile', you can specify wildcards now
                     for attachf in attachfglob:
                         if os.access(attachf, os.R_OK) and os.path.isfile(attachf):
-                            invalid = False
-                            inline = (x == 'i')
-                            (message, filename, attachments) = include_file_in_report(
-                                message, filename, attachments, package,
-                                attachf, charset, inline=inline, draftpath=options.draftpath)
-                            if not inline:
-                                skip_editing = True
+                            if check_attachment_size(attachf, options.max_attachment_size):
+                                ewrite('The attachment file %s size is bigger than the maximum of %d bytes: '
+                                       'reduce its size else the report cannot be sent\n' %
+                                       (attachf, options.max_attachment_size))
+                            else:
+                                invalid = False
+                                inline = (x == 'i')
+                                (message, filename, attachments) = include_file_in_report(
+                                    message, filename, attachments, package,
+                                    attachf, charset, inline=inline, draftpath=options.draftpath)
+                                if not inline:
+                                    skip_editing = True
                         else:
                             ui.display_failure("Cannot include %s!\n", attachf)
                 else:
@@ -959,12 +970,17 @@ def main():
                       help='don\'t show tags menu')
     parser.add_option('--mbox-reader-cmd', dest='mbox_reader_cmd',
                       help="Specify the program to open the reports mbox.")
+    parser.add_option('--max-attachment-size', type="int", dest='max_attachment_size', help="Specify the maximum size in byte for an attachment [default: 10485760].")
 
     (options, args) = parser.parse_args()
 
     # Load the interface, *before* the configuration step.
     sys.argv = sys.argv[:1] + list(args)
 
+    # if not set in config file or on cli, then set 10M as default
+    if not options.max_attachment_size:
+        options.max_attachment_size = 10485760
+
     # check if attachment files exist, else exiting
     # all are checked, and it doesn't exit at the first missing
 
@@ -985,8 +1001,12 @@ def main():
             if not os.path.exists(os.path.expanduser(attachment)):
                 print 'The attachment file %s does not exist.' % attachment
                 any_missing = True
+            elif check_attachment_size(attachment, options.max_attachment_size):
+                print 'The attachment file %s size is bigger than the maximum of %d bytes: reduce ' \
+                'its size else the report cannot be sent' % (attachment, options.max_attachment_size)
+                any_missing = True
         if any_missing:
-            print "The above files are missing, so can't be attached; exiting"
+            print "The above files can't be attached; exiting"
             sys.exit(1)
 
     if options.keyid and not options.sign:
@@ -1109,6 +1129,10 @@ class UI(object):
             body = textwrap.fill(self.options.body)
         elif self.options.bodyfile:
             try:
+                if check_attachment_size(self.options.bodyfile, self.options.max_attachment_size):
+                    print 'Body file %s size bigger than the maximum of %d bytes: ' \
+                    'reduce its size else the report cannot be sent'% (self.options.bodyfile, self.options.max_attachment_size)
+                    raise Exception
                 body = open(self.options.bodyfile).read()
             except:
                 efail('Unable to read body from file %s.\n', self.options.bodyfile)
diff --git a/debian/changelog b/debian/changelog
index f3b6fd4..e853e0d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,8 +21,13 @@ reportbug (5.1) UNRELEASED; urgency=low
   * reportbug/urlutils.py
     - make the 'xdg-open' existance check be silent also when sh=dash; thanks to
       RjY for the report and patch; Closes: #616523
+  * bin/reportbug, reportbug/utils.py, man/reportbug.*
+    - added a new cli options, --max-attachment-size (also available in the
+      config file), to limit the size of any attachment (or --body-file) to the
+      specified value, in byte; thanks to Lionel Elie Mamane for the report and
+      to Carl Chanet for the initial patch; Closes: #528720
 
- -- Sandro Tosi <morph at debian.org>  Mon, 25 Apr 2011 11:25:15 +0200
+ -- Sandro Tosi <morph at debian.org>  Tue, 26 Apr 2011 01:13:24 +0200
 
 reportbug (5.0) unstable; urgency=low
 
diff --git a/man/reportbug.1 b/man/reportbug.1
index f9d4dcc..1363360 100644
--- a/man/reportbug.1
+++ b/man/reportbug.1
@@ -222,6 +222,9 @@ intended with \fBdebbugs\fP systems.
 Only send the bug to the package maintainer; the bug tracking system
 will not send a copy to the bug report distribution lists.
 .TP
+.B \-\-max-attachment-size=MAX_ATTACHMENT_SIZE
+Specity the maximum size any attachment file can have (this also include the file for \-\-body-file option). If an attachment file is too big, there could be problems in delivering the email (and also to compose it), so we set a limit to attachment size. By default this is 10 megabytes.
+.TP
 .B \-\-mirror=MIRRORS
 Add a BTS mirror.
 .TP
diff --git a/man/reportbug.conf.5 b/man/reportbug.conf.5
index 0dc7425..fd4b562 100644
--- a/man/reportbug.conf.5
+++ b/man/reportbug.conf.5
@@ -129,6 +129,12 @@ Example:
 .B maintonly
 See the \fB\-\-maintonly\fP entry in \fBreportbug(1)\fP.
 .TP
+.B max_attachment_size
+The max size any attachment can have. Example:
+
+\fBmax_attachment_size\fP \fI5000000\fP
+
+.TP
 .B mh
 Use the \fBmh\fP mailer.
 .TP
diff --git a/reportbug/utils.py b/reportbug/utils.py
index cb64de7..3a516dc 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -790,7 +790,7 @@ CONFIG_ARGS = (
     'sign', 'nocc', 'nocompress', 'dontquery', 'noconf', 'mirrors', 'keyid',
     'headers', 'interface', 'template', 'mode', 'check_available', 'query_src',
     'printonly', 'offline', 'check_uid', 'smtptls', 'smtpuser', 'smtppasswd',
-    'paranoid', 'mbox_reader_cmd')
+    'paranoid', 'mbox_reader_cmd', 'max_attachment_size')
 
 class Mua:
     command = ""
@@ -972,6 +972,9 @@ def parse_config_files():
                     args['check_uid'] = (token == 'check-uid')
                 elif token in ('paranoid', 'no-paranoid'):
                     args['paranoid'] = (token == 'paranoid')
+                elif token == 'max_attachment_size':
+                    arg = lex.get_token()
+                    args['max_attachment_size'] = int(arg)
                 else:
                     sys.stderr.write('Unrecognized token: %s\n' % token)
 

-- 
Reportbug - reports bugs in the Debian distribution



More information about the Reportbug-commits mailing list