Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymilter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
misc
pymilter
Commits
a94f82d8
Commit
a94f82d8
authored
20 years ago
by
Stuart Gathman
Browse files
Options
Downloads
Patches
Plain Diff
Handle zip within zip.
parent
124747c3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mime.py
+15
-5
15 additions, 5 deletions
mime.py
test/ziploop
+47
-0
47 additions, 0 deletions
test/ziploop
testmime.py
+8
-1
8 additions, 1 deletion
testmime.py
with
70 additions
and
6 deletions
mime.py
+
15
−
5
View file @
a94f82d8
# $Log$
# $Log$
# Revision 1.3 2005/06/02 15:00:17 customdesigned
# Configure banned extensions. Scan zipfile option with test case.
#
# Revision 1.2 2005/06/02 04:18:55 customdesigned
# Revision 1.2 2005/06/02 04:18:55 customdesigned
# Update copyright notices after reading article on /.
# Update copyright notices after reading article on /.
#
#
...
@@ -87,6 +90,16 @@ from email import Errors
...
@@ -87,6 +90,16 @@ from email import Errors
from
types
import
ListType
,
StringType
from
types
import
ListType
,
StringType
def
zipnames
(
txt
):
fp
=
StringIO
.
StringIO
(
txt
)
zipf
=
zipfile
.
ZipFile
(
fp
,
'
r
'
)
names
=
[]
for
nm
in
zipf
.
namelist
():
names
.
append
((
'
zipname
'
,
nm
))
if
nm
.
lower
().
endswith
(
'
.zip
'
):
names
+=
zipnames
(
zipf
.
read
(
nm
))
return
names
class
MimeGenerator
(
Generator
):
class
MimeGenerator
(
Generator
):
def
_dispatch
(
self
,
msg
):
def
_dispatch
(
self
,
msg
):
# Get the Content-Type: for the message, then try to dispatch to
# Get the Content-Type: for the message, then try to dispatch to
...
@@ -177,13 +190,10 @@ class MimeMessage(Message):
...
@@ -177,13 +190,10 @@ class MimeMessage(Message):
names
.
append
((
attr
,
val
))
names
.
append
((
attr
,
val
))
names
+=
[(
"
filename
"
,
self
.
get_filename
())]
names
+=
[(
"
filename
"
,
self
.
get_filename
())]
if
scan_zip
:
if
scan_zip
:
for
key
,
name
in
names
:
for
key
,
name
in
tuple
(
names
):
# copy by converting to tuple
if
name
and
name
.
lower
().
endswith
(
'
.zip
'
):
if
name
and
name
.
lower
().
endswith
(
'
.zip
'
):
txt
=
self
.
get_payload
(
decode
=
True
)
txt
=
self
.
get_payload
(
decode
=
True
)
fp
=
StringIO
.
StringIO
(
txt
)
names
+=
zipnames
(
txt
)
zipf
=
zipfile
.
ZipFile
(
fp
,
'
r
'
)
for
nm
in
zipf
.
namelist
():
names
.
append
((
'
zipname
'
,
nm
))
return
names
return
names
def
ismodified
(
self
):
def
ismodified
(
self
):
...
...
This diff is collapsed.
Click to expand it.
test/ziploop
0 → 100644
+
47
−
0
View file @
a94f82d8
From ttaie1@thfalcon.com Thu Jun 16 10:23:13 2005
Received: from thfalcon.com (unknown [202.90.113.150])
by thfalcon.com (Postfix) with ESMTP id 32F0DD819C
for <stuart@bmsi.com>; Thu, 16 Jun 2005 15:42:08 +0700 (ICT)
From: ttaie1@thfalcon.com
To: stuart@bmsi.com
Subject: Returned mail: see transcript for details
Date: Thu, 16 Jun 2005 15:50:10 +0700
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_000_0014_E4E04420.5619685C"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-Id: <20050616084208.32F0DD819C@thfalcon.com>
Received-SPF: pass (mail.bmsi.com: guessing: domain of thfalcon.com designates 203.147.3.44 as permitted sender) client-ip=203.147.3.44; envelope-from=ttaie1@thfalcon.com; helo=thfalcon.com;
This is a multi-part message in MIME format.
------=_NextPart_000_0014_E4E04420.5619685C
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit
Message could not be delivered
------=_NextPart_000_0014_E4E04420.5619685C
Content-Type: application/octet-stream;
name="stuart@bmsi.com.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="stuart@bmsi.com.zip"
UEsDBAoAAAAAAM6r0DL7SfbCBAEAAAQBAAAFABUAdC56aXBVVAkAA7MnskK4J7JCVXgEAIYD
ZQBQSwMECgAAAAAANVXCMtpXacQaAAAAGgAAADMAFQB6aXAuZG9jICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgIC5leGVVVAkAA6Yan0KmGp9CVXgEAIYDZQBUaGlz
IHByb2dyYW0gd2FzIGEgdmlydXMuClBLAQIXAwoAAAAAADVVwjLaV2nEGgAAABoAAAAzAA0A
AAAAAAEAAAC0gQAAAAB6aXAuZG9jICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgIC5leGVVVAUAA6Yan0JVeAAAUEsFBgAAAAABAAEAbgAAAIAAAAAAAFBLAQIXAwoA
AAAAAM6r0DL7SfbCBAEAAAQBAAAFAA0AAAAAAAAAAAC0gQAAAAB0LnppcFVUBQADsyeyQlV4
AABQSwUGAAAAAAEAAQBAAAAAPAEAAAAA
------=_NextPart_000_0014_E4E04420.5619685C--
This diff is collapsed.
Click to expand it.
testmime.py
+
8
−
1
View file @
a94f82d8
# $Log$
# $Log$
# Revision 1.2 2005/06/02 15:00:17 customdesigned
# Configure banned extensions. Scan zipfile option with test case.
#
# Revision 1.1.1.2 2005/05/31 18:23:49 customdesigned
# Revision 1.1.1.2 2005/05/31 18:23:49 customdesigned
# Development changes since 0.7.2
# Development changes since 0.7.2
#
#
...
@@ -126,10 +129,12 @@ class MimeTestCase(unittest.TestCase):
...
@@ -126,10 +129,12 @@ class MimeTestCase(unittest.TestCase):
self
.
failUnless
(
name
==
"
Jim&amp;Girlz.jpg
"
,
"
name=%s
"
%
name
)
self
.
failUnless
(
name
==
"
Jim&amp;Girlz.jpg
"
,
"
name=%s
"
%
name
)
def
testZip
(
self
,
vname
=
"
zip1
"
,
fname
=
'
zip.zip
'
):
def
testZip
(
self
,
vname
=
"
zip1
"
,
fname
=
'
zip.zip
'
):
self
.
testDefang
(
'
zip1
'
,
1
,
'
zip.zip
'
)
self
.
testDefang
(
vname
,
1
,
'
zip.zip
'
)
msg
=
mime
.
message_from_file
(
open
(
'
test/
'
+
vname
,
"
r
"
))
msg
=
mime
.
message_from_file
(
open
(
'
test/
'
+
vname
,
"
r
"
))
mime
.
defang
(
msg
,
scan_zip
=
False
)
mime
.
defang
(
msg
,
scan_zip
=
False
)
self
.
failIf
(
msg
.
ismodified
())
self
.
failIf
(
msg
.
ismodified
())
# test zip within zip
self
.
testDefang
(
'
ziploop
'
,
1
,
'
stuart@bmsi.com.zip
'
)
def
testHTML
(
self
,
fname
=
""
):
def
testHTML
(
self
,
fname
=
""
):
result
=
StringIO
.
StringIO
()
result
=
StringIO
.
StringIO
()
...
@@ -153,3 +158,5 @@ if __name__ == '__main__':
...
@@ -153,3 +158,5 @@ if __name__ == '__main__':
for
fname
in
sys
.
argv
[
1
:]:
for
fname
in
sys
.
argv
[
1
:]:
fp
=
open
(
fname
,
'
r
'
)
fp
=
open
(
fname
,
'
r
'
)
msg
=
mime
.
message_from_file
(
fp
)
msg
=
mime
.
message_from_file
(
fp
)
mime
.
defang
(
msg
,
scan_zip
=
True
)
print
msg
.
as_string
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment