Skip to content

Commit

Permalink
Added charset and charset_expr attributes. The charset header is inse…
Browse files Browse the repository at this point in the history
…rted only for text/* content types and defaults to "us-ascii". The MIME spec says this header is optional, but Spam Assassin considers its absence a likely indicator of spam.
  • Loading branch information
jace committed Dec 30, 2003
1 parent af22143 commit 5671140
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions MIMETag.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__rcs_id__='$Id: MIMETag.py,v 1.11 2003/12/25 07:24:47 jace Exp $'
__version__='$Revision: 1.11 $'[11:-2]
__rcs_id__='$Id: MIMETag.py,v 1.12 2003/12/30 06:23:52 jace Exp $'
__version__='$Revision: 1.12 $'[11:-2]

from DocumentTemplate.DT_Util import *
from DocumentTemplate.DT_String import String
Expand Down Expand Up @@ -41,6 +41,7 @@ def __init__(self, blocks):
, name=None, name_expr=None
, filename=None, filename_expr=None
, cid=None, cid_expr=None
, charset=None, charset_expr=None
, skip_expr=None
, multipart=None
)
Expand All @@ -53,6 +54,7 @@ def __init__(self, blocks):
, name=None, name_expr=None
, filename=None, filename_expr=None
, cid=None, cid_expr=None
, charset=None, charset_expr=None
, skip_expr=None
)

Expand Down Expand Up @@ -105,6 +107,13 @@ def __init__(self, blocks):
elif not has_key('cid'):
args['cid']=''

if has_key('charset_expr'):
if has_key('charset'):
raise ParseError, _tm('charset and charset_expr given', 'mime')
args['charset_expr']=Eval(args['charset_expr'])
elif not has_key('charset'):
args['charset']=''

if has_key('skip_expr'):
args['skip_expr']=Eval(args['skip_expr'])

Expand Down Expand Up @@ -150,6 +159,9 @@ def render(self, md):
if has_key('cid_expr'): cid=a['cid_expr'].eval(md)
else: cid=a['cid']

if has_key('charset_expr'): charset=a['charset_expr'].eval(md)
else: charset=a['charset']

if d:
if f:
inner.addheader('Content-Disposition', '%s;\n filename="%s"' % (d, f))
Expand All @@ -166,6 +178,9 @@ def render(self, md):
else:
plist = []

if t.startswith('text/'):
plist.append(('charset', charset or 'us-ascii'))

innerfile = inner.startbody(t, plist, 1)

output = StringIO()
Expand Down

0 comments on commit 5671140

Please sign in to comment.