Commit 3c989a7e authored by Nicolas Delaby's avatar Nicolas Delaby

EmailDocument is a TextDocument which does not implement

IBaseConvertable.
  * replace getTextFormat by getContentType
   


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35244 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5586b333
...@@ -112,7 +112,7 @@ class ProxiedMethod(Method): ...@@ -112,7 +112,7 @@ class ProxiedMethod(Method):
return method(*args, **kw) return method(*args, **kw)
# generate all proxy method on EmailDocumentProxyMixin # generate all proxy method on EmailDocumentProxyMixin
for method_id in ('getTextFormat', for method_id in ('getContentType',
'getContentInformation', 'getAttachmentData', 'getContentInformation', 'getAttachmentData',
'getAttachmentInformationList'): 'getAttachmentInformationList'):
EmailDocumentProxyMixin.security.declareProtected( EmailDocumentProxyMixin.security.declareProtected(
...@@ -121,7 +121,7 @@ for method_id in ('getTextFormat', ...@@ -121,7 +121,7 @@ for method_id in ('getTextFormat',
setattr(EmailDocumentProxyMixin, method_id, setattr(EmailDocumentProxyMixin, method_id,
ProxiedMethod(method_id)) ProxiedMethod(method_id))
class EmailDocument(File, TextDocument): class EmailDocument(TextDocument):
""" """
EmailDocument is a File which stores its metadata in a form which EmailDocument is a File which stores its metadata in a form which
is similar to a TextDocument. is similar to a TextDocument.
...@@ -169,6 +169,18 @@ class EmailDocument(File, TextDocument): ...@@ -169,6 +169,18 @@ class EmailDocument(File, TextDocument):
self._v_message = result self._v_message = result
return result return result
def isSupportBaseDataConversion(self):
"""
"""
return False
security.declareProtected(Permissions.AccessContentsInformation, 'hasBaseData')
def hasBaseData(self):
"""
"""
return self.hasFile() or self.hasTextContent()
security.declareProtected(Permissions.AccessContentsInformation, 'getContentInformation') security.declareProtected(Permissions.AccessContentsInformation, 'getContentInformation')
def getContentInformation(self): def getContentInformation(self):
""" """
...@@ -477,8 +489,8 @@ class EmailDocument(File, TextDocument): ...@@ -477,8 +489,8 @@ class EmailDocument(File, TextDocument):
return text_result return text_result
return text_result or default return text_result or default
security.declareProtected(Permissions.AccessContentsInformation, 'getTextFormat') security.declareProtected(Permissions.AccessContentsInformation, 'getContentType')
def getTextFormat(self, default=_MARKER): def getContentType(self, default=_MARKER):
""" """
Returns the format of the email (text or html). Returns the format of the email (text or html).
...@@ -487,9 +499,9 @@ class EmailDocument(File, TextDocument): ...@@ -487,9 +499,9 @@ class EmailDocument(File, TextDocument):
if not self.hasFile(): if not self.hasFile():
# Return the standard text format if no file was provided # Return the standard text format if no file was provided
if default is _MARKER: if default is _MARKER:
return self._baseGetTextFormat() return TextDocument.getContentType(self)
else: else:
return self._baseGetTextFormat(default) return TextDocument.getContentType(self, default)
is_alternative = False is_alternative = False
for part in self._getMessage().walk(): for part in self._getMessage().walk():
if part.is_multipart(): if part.is_multipart():
...@@ -546,11 +558,11 @@ class EmailDocument(File, TextDocument): ...@@ -546,11 +558,11 @@ class EmailDocument(File, TextDocument):
This is used in order to respond to a mail, This is used in order to respond to a mail,
this put a '> ' before each line of the body this put a '> ' before each line of the body
""" """
if self.getTextFormat() == 'text/plain': if self.getContentType() == 'text/plain':
body = self.asText() body = self.asText()
if body: if body:
return '> ' + str(body).replace('\n', '\n> ') return '> ' + str(body).replace('\n', '\n> ')
elif self.getTextFormat() == 'text/html': elif self.getContentType() == 'text/html':
return '<br/><blockquote type="cite">\n%s\n</blockquote>' %\ return '<br/><blockquote type="cite">\n%s\n</blockquote>' %\
self.asStrippedHTML() self.asStrippedHTML()
return '' return ''
...@@ -690,8 +702,6 @@ class EmailDocument(File, TextDocument): ...@@ -690,8 +702,6 @@ class EmailDocument(File, TextDocument):
# is not (yet) part of Document API # is not (yet) part of Document API
if getattr(attachment, 'getContentType', None) is not None: if getattr(attachment, 'getContentType', None) is not None:
mime_type = attachment.getContentType() mime_type = attachment.getContentType()
elif getattr(attachment, 'getTextFormat', None) is not None:
mime_type = attachment.getTextFormat()
else: else:
raise ValueError, "Cannot find mimetype of the document." raise ValueError, "Cannot find mimetype of the document."
......
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