Commit 6f910ab1 authored by Nicolas Delaby's avatar Nicolas Delaby

s/file_name/filename/

s/source_reference/filename/

Normalise API, filename will be used to store filename, in replacement of source_reference.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40967 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7d639d18
...@@ -58,7 +58,7 @@ DEFAULT_TEXT_FORMAT = 'text/html' ...@@ -58,7 +58,7 @@ DEFAULT_TEXT_FORMAT = 'text/html'
COMMASPACE = ', ' COMMASPACE = ', '
_MARKER = [] _MARKER = []
file_name_regexp = 'name="([^"]*)"' filename_regexp = 'name="([^"]*)"'
class EmailDocumentProxyMixin(DocumentProxyMixin): class EmailDocumentProxyMixin(DocumentProxyMixin):
...@@ -227,20 +227,20 @@ class EmailDocument(TextDocument): ...@@ -227,20 +227,20 @@ class EmailDocument(TextDocument):
kw = dict(part.items()) kw = dict(part.items())
kw['uid'] = 'part_%s' % i kw['uid'] = 'part_%s' % i
kw['index'] = i kw['index'] = i
file_name = part.get_filename() filename = part.get_filename()
if not file_name: if not filename:
# get_filename return name only from Content-Disposition header # get_filename return name only from Content-Disposition header
# of the message but sometimes this value is stored in # of the message but sometimes this value is stored in
# Content-Type header # Content-Type header
content_type_header = kw.get('Content-Type', content_type_header = kw.get('Content-Type',
kw.get('Content-type', '')) kw.get('Content-type', ''))
file_name_list = re.findall(file_name_regexp, filename_list = re.findall(filename_regexp,
content_type_header, content_type_header,
re.MULTILINE) re.MULTILINE)
if file_name_list: if filename_list:
file_name = file_name_list[0] filename = filename_list[0]
if file_name: if filename:
kw['file_name'] = file_name kw['filename'] = filename
else: else:
content_disposition = kw.get('Content-Disposition', content_disposition = kw.get('Content-Disposition',
kw.get('Content-disposition', None)) kw.get('Content-disposition', None))
...@@ -250,7 +250,7 @@ class EmailDocument(TextDocument): ...@@ -250,7 +250,7 @@ class EmailDocument(TextDocument):
prefix = 'attachment_' prefix = 'attachment_'
elif content_disposition.split(';')[0] == 'inline': elif content_disposition.split(';')[0] == 'inline':
prefix = 'inline_' prefix = 'inline_'
kw['file_name'] = '%s%s' % (prefix, i) kw['filename'] = '%s%s' % (prefix, i)
kw['content_type'] = part.get_content_type() kw['content_type'] = part.get_content_type()
result.append(kw) result.append(kw)
return result return result
...@@ -267,24 +267,24 @@ class EmailDocument(TextDocument): ...@@ -267,24 +267,24 @@ class EmailDocument(TextDocument):
kw = dict(part.items()) kw = dict(part.items())
content_type = part.get_content_type() content_type = part.get_content_type()
if REQUEST is not None: if REQUEST is not None:
file_name = part.get_filename() filename = part.get_filename()
if not file_name: if not filename:
# get_filename return name only from Content-Disposition header # get_filename return name only from Content-Disposition header
# of the message but sometimes this value is stored in # of the message but sometimes this value is stored in
# Content-Type header # Content-Type header
content_type_header = kw.get('Content-Type', content_type_header = kw.get('Content-Type',
kw.get('Content-type', '')) kw.get('Content-type', ''))
file_name_list = re.findall(file_name_regexp, filename_list = re.findall(filename_regexp,
content_type_header, content_type_header,
re.MULTILINE) re.MULTILINE)
if file_name_list: if filename_list:
file_name = file_name_list[0] filename = filename_list[0]
RESPONSE = REQUEST.RESPONSE RESPONSE = REQUEST.RESPONSE
RESPONSE.setHeader('Accept-Ranges', 'bytes') RESPONSE.setHeader('Accept-Ranges', 'bytes')
if content_type and file_name: if content_type and filename:
RESPONSE.setHeader('Content-Type', content_type) RESPONSE.setHeader('Content-Type', content_type)
RESPONSE.setHeader('Content-disposition', RESPONSE.setHeader('Content-disposition',
'attachment; filename="%s"' % file_name) 'attachment; filename="%s"' % filename)
if 'text/html' in content_type: if 'text/html' in content_type:
# Strip out html content in safe mode. # Strip out html content in safe mode.
mime, content = self.convert(format='html', mime, content = self.convert(format='html',
...@@ -338,18 +338,18 @@ class EmailDocument(TextDocument): ...@@ -338,18 +338,18 @@ class EmailDocument(TextDocument):
result = result[0] result = result[0]
if result: if result:
return result return result
return self.getSourceReference(*args) return self.getFilename(*args)
security.declareProtected(Permissions.AccessContentsInformation, 'getSourceReference') security.declareProtected(Permissions.AccessContentsInformation, 'getFilename')
def getSourceReference(self, *args): def getFilename(self, *args):
""" """
The Message-ID is considered here as the source reference The Message-ID is considered here as the source reference
of the message on the sender side (source) of the message on the sender side (source)
""" """
if not self.hasData(): if not self.hasData():
return self._baseGetSourceReference(*args) return self._baseGetFilename(*args)
if not len(args): if not len(args):
args = (self._baseGetSourceReference(),) args = (self._baseGetFilename(),)
content_information = self.getContentInformation() content_information = self.getContentInformation()
return content_information.get('Message-ID') or content_information.get('Message-Id', *args) return content_information.get('Message-ID') or content_information.get('Message-Id', *args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment