diff options
| author | bwarsaw | 2002-11-22 03:59:58 +0000 |
|---|---|---|
| committer | bwarsaw | 2002-11-22 03:59:58 +0000 |
| commit | 629e8d6c8cb560b5c52d2ab353424bdf0f13cb2c (patch) | |
| tree | 1669a28df7e50b65c0fe279d2716cffcd4b03aba | |
| parent | 82524cb5a981a59781563a4fbc0b96e88a23199e (diff) | |
| download | mailman-629e8d6c8cb560b5c52d2ab353424bdf0f13cb2c.tar.gz mailman-629e8d6c8cb560b5c52d2ab353424bdf0f13cb2c.tar.zst mailman-629e8d6c8cb560b5c52d2ab353424bdf0f13cb2c.zip | |
calculate_attachments_dir(): Be defensive about bogus Date headers. ;/
| -rw-r--r-- | Mailman/Handlers/Scrubber.py | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/Mailman/Handlers/Scrubber.py b/Mailman/Handlers/Scrubber.py index 401f6db49..5b319700e 100644 --- a/Mailman/Handlers/Scrubber.py +++ b/Mailman/Handlers/Scrubber.py @@ -49,6 +49,7 @@ sre = re.compile(r'[^-\w.]') dre = re.compile(r'^\.*') BR = '<br>\n' +SPACE = ' ' @@ -70,19 +71,44 @@ class ScrubberGenerator(Generator): if not self.__skipheaders: Generator._write_headers(self, msg) - +def safe_strftime(fmt, floatsecs): + try: + return time.strftime(fmt, floatsecs) + except ValueError: + return None + + def calculate_attachments_dir(mlist, msg, msgdata): # Calculate the directory that attachments for this message will go # under. To avoid inode limitations, the scheme will be: # archives/private/<listname>/attachments/YYYYMMDD/<msgid-hash>/<files> # Start by calculating the date-based and msgid-hash components. - msgdate = msg.get('Date') - if msgdate is None: - now = time.gmtime(msgdata.get('received_time', time.time())) + fmt = '%Y%m%d' + datestr = msg.get('Date') + if datestr: + now = parsedate(datestr) else: - now = parsedate(msgdate) - datedir = time.strftime('%Y%m%d', now) + now = time.gmtime(msgdata.get('received_time', time.time())) + datedir = safe_strftime(fmt, now) + if not datedir: + datestr = msgdata.get('X-List-Received-Date') + if datestr: + datedir = safe_strftime(fmt, datestr) + if not datedir: + # What next? Unixfrom, I guess. + parts = msg.get_unixfrom().split() + try: + month = {'Jan':1, 'Feb':2, 'Mar':3, 'Apr':4, 'May':5, 'Jun':6, + 'Jul':7, 'Aug':8, 'Sep':9, 'Oct':10, 'Nov':11, 'Dec':12, + }.get(parts[3], 0) + day = int(parts[4]) + year = int(parts[6]) + except (IndexError, ValueError): + # Best we can do I think + month = day = year = 0 + datedir = '%04d%02d%02d' % (year, month, day) + assert datedir # As for the msgid hash, we'll base this part on the Message-ID: so that # all attachments for the same message end up in the same directory (we'll # uniquify the filenames in that directory as needed). We use the first 2 |
