[prev in list] [next in list] [prev in thread] [next in thread]
List: courier-users
Subject: Re: [courier-users] Pythonfilter attachments.py troubles
From: Gordon Messmer <gordon.messmer () gmail ! com>
Date: 2019-12-17 4:10:52
Message-ID: 31c831ba-0291-c49e-4d86-0cabc62b9baf () gmail ! com
[Download RAW message or body]
On 12/12/19 2:22 AM, Svetozar Mihailov wrote:
> # python3.6 pythonfilter/attachments.py
> ...
> AttributeError: module 'libarchive' has no attribute 'FILTERS'
That filter was contributed, and doesn't have any tests for libarchive
currently. There are a few bits that I don't like about the archive
scanning as it was. It looks like some version of libarchive listed the
extensions that it recognized as archives, and we *could* put that back
in with an array of extensions (and probably MIME types as well), or we
could just try to open all attachments with libarchive. Although the
latter is more expensive, I tend to think it's safer.
The attached patch fixes libarchive by attempting to scan all
attachments as archives.
["pythonfilter-attachments.patch" (text/x-patch)]
diff -r 858da1231a2a filters/pythonfilter/attachments.py
--- a/filters/pythonfilter/attachments.py Fri Nov 01 16:53:27 2019 -0700
+++ b/filters/pythonfilter/attachments.py Mon Dec 16 20:05:31 2019 -0800
@@ -47,21 +47,19 @@
def check_archive(filename, part):
if not HAVE_LIBARCHIVE:
return False
- fparts = filename.split('.')
- if fparts[-1].lower() in libarchive.FILTERS:
- fparts.pop()
- if fparts[-1].lower() not in libarchive.FORMATS:
- return False
tmp_d = tempfile.mkdtemp()
- tmp_path = '%s/%s' % (tmp_d, filename.replace('/', ''))
- tmp_file = open(tmp_path, 'w')
+ tmp_path = '%s/scan-archive' % (tmp_d,)
+ tmp_file = open(tmp_path, 'wb')
tmp_file.write(part.get_payload(decode=True))
tmp_file.close()
- archive = libarchive.Archive(tmp_path)
found = False
- for entry in archive:
- if blocked_pattern.match(entry.pathname):
- found = True
+ try:
+ with libarchive.file_reader(tmp_path) as archive:
+ for entry in archive:
+ if blocked_pattern.match(entry.pathname):
+ found = True
+ except libarchive.exception.ArchiveError:
+ pass
os.unlink(tmp_path)
os.rmdir(tmp_d)
return found
_______________________________________________
courier-users mailing list
courier-users@lists.sourceforge.net
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic