Mercurial > p > roundup > code
comparison roundup/roundupdb.py @ 3882:46ef2a6fd79d
config option to limit nosy attachments based on size
reworking of patch [SF#772323] from Philipp Gortan
It tries to avoid reading the file contents just to
get the file size but that was too hard for metakit backends.
They don't inherit from blobfiles.FileStorage which makes
it more challenging. Really that backend should be reworked
to inherit from FileStorage.
I'm not sure I like the default being sys.maxint. Maybe have
0 == unlimited? But what if someone really wanted to set it to
0 to mean "don't attach anything"?
| author | Justus Pendleton <jpend@users.sourceforge.net> |
|---|---|
| date | Mon, 03 Sep 2007 17:14:09 +0000 |
| parents | 83748b2de465 |
| children | 5c4a039aa465 |
comparison
equal
deleted
inserted
replaced
| 3881:e7050411a774 | 3882:46ef2a6fd79d |
|---|---|
| 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 18 # | 18 # |
| 19 # $Id: roundupdb.py,v 1.129 2007-09-01 16:30:11 forsberg Exp $ | 19 # $Id: roundupdb.py,v 1.130 2007-09-03 17:14:08 jpend Exp $ |
| 20 | 20 |
| 21 """Extending hyperdb with types specific to issue-tracking. | 21 """Extending hyperdb with types specific to issue-tracking. |
| 22 """ | 22 """ |
| 23 __docformat__ = 'restructuredtext' | 23 __docformat__ = 'restructuredtext' |
| 24 | 24 |
| 25 import re, os, smtplib, socket, time, random | 25 import re, os, smtplib, socket, time, random |
| 26 import cStringIO, base64, quopri, mimetypes | 26 import cStringIO, base64, quopri, mimetypes |
| 27 import os.path | |
| 27 | 28 |
| 28 from rfc2822 import encode_header | 29 from rfc2822 import encode_header |
| 29 | 30 |
| 30 from roundup import password, date, hyperdb | 31 from roundup import password, date, hyperdb |
| 31 from roundup.i18n import _ | 32 from roundup.i18n import _ |
| 320 | 321 |
| 321 # add the content | 322 # add the content |
| 322 if msgid is not None: | 323 if msgid is not None: |
| 323 m.append(messages.get(msgid, 'content', '')) | 324 m.append(messages.get(msgid, 'content', '')) |
| 324 | 325 |
| 326 # get the files for this message | |
| 327 message_files = [] | |
| 328 if msgid : | |
| 329 for fileid in messages.get(msgid, 'files') : | |
| 330 # try to avoid reading in the file contents just to check the size | |
| 331 # backends that inherit from blobfiles.FileStorage have a filename class | |
| 332 if hasattr(self.db, 'filename'): | |
| 333 filename = self.db.filename('file', fileid, None) | |
| 334 filesize = os.path.getsize(filename) | |
| 335 else: | |
| 336 # metakit doesn't inherit from FileStorage so we read the | |
| 337 # full file contents to get the size :-/ | |
| 338 filesize = len(self.db.file.get(fileid, 'content')) | |
| 339 | |
| 340 if filesize <= self.db.config.NOSY_MAX_ATTACHMENT_SIZE: | |
| 341 message_files.append(fileid) | |
| 342 else: | |
| 343 base = self.db.config.TRACKER_WEB | |
| 344 link = "".join((base, files.classname, fileid)) | |
| 345 filename = files.get(fileid, 'name') | |
| 346 m.append(_("File '%(filename)s' not attached - you can " | |
| 347 "download it from %(link)s." % locals())) | |
| 348 | |
| 325 # add the change note | 349 # add the change note |
| 326 if note: | 350 if note: |
| 327 m.append(note) | 351 m.append(note) |
| 328 | 352 |
| 329 # put in roundup's signature | 353 # put in roundup's signature |
| 337 m = unicode(m, 'utf-8').encode(charset) | 361 m = unicode(m, 'utf-8').encode(charset) |
| 338 content = cStringIO.StringIO(m) | 362 content = cStringIO.StringIO(m) |
| 339 content_encoded = cStringIO.StringIO() | 363 content_encoded = cStringIO.StringIO() |
| 340 quopri.encode(content, content_encoded, 0) | 364 quopri.encode(content, content_encoded, 0) |
| 341 content_encoded = content_encoded.getvalue() | 365 content_encoded = content_encoded.getvalue() |
| 342 | |
| 343 # get the files for this message | |
| 344 if msgid is None: | |
| 345 message_files = None | |
| 346 else: | |
| 347 message_files = messages.get(msgid, 'files') | |
| 348 | 366 |
| 349 # make sure the To line is always the same (for testing mostly) | 367 # make sure the To line is always the same (for testing mostly) |
| 350 sendto.sort() | 368 sendto.sort() |
| 351 | 369 |
| 352 # make sure we have a from address | 370 # make sure we have a from address |
