MIMETools provides the ``dtml-mime`` tag for DocumentTemplate.
Project description
Products.MIMETools
Currently, the MIMETools product’s only function is to provide the <dtml-mime> DTML tag for the DocumentTemplate distribution.
The <dtml-mime> tag is used to construct MIME containers. The syntax of the <dtml-mime> tag is:
<dtml-mime type="x" disposition="y" encode="z"> Contents of first part <dtml-boundary type="x" disposition="y" encode="z"> Contents of second part <dtml-boundary type="x" disposition="y" encode="z"> Contents of nth part </dtml-mime>
The area of data between tags, called a block, is encoded into whatever is specified with the ‘encode’ tag attribute for that block. If no encoding is specified, ‘base64’ is defaulted. Valid encoding options include ‘base64’, ‘quoted-printable’ and ‘7bit’ . If the ‘encode’ attribute is set to ‘7bit’ no encoding is done on the block and the data is assumed to be in a valid MIME format.
If the ‘disposition’ attribute is not specified for a certain block, then the ‘Content-Disposition:’ MIME header is not included in that block’s MIME part.
The entire MIME container, from the opening mime tag to the closing, has it’s ‘Content-Type:’ MIME header set to ‘multipart/mixed’.
For example, the following DTML:
<dtml-mime encode="7bit" type="text/plain"> This is the first part. <dtml-boundary encode="base64" type="text/plain"> This is the second. </dtml-mime>
Is rendered to the following text:
Content-Type: multipart/mixed;
boundary="216.164.72.30.501.1550.923070182.795.22531"
--216.164.72.30.501.1550.923070182.795.22531
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
This is the first part.
--216.164.72.30.501.1550.923070182.795.22531
Content-Type: text/plain
Content-Transfer-Encoding: base64
VGhpcyBpcyB0aGUgc2Vjb25kLgo=
--216.164.72.30.501.1550.923070182.795.22531--
The dtml-mime tag is particularly handy in conjunction with the dtml-sendmail tag. This allows Zope to send attachments along with email. Here is an example.
Create a DTML method called ‘input’ with the following code:
<dtml-var standard_html_header> <form method="post" action="send" ENCTYPE="multipart/form-data"> <input type="file" name="afile"><br> Send to:<input type="textbox" name="who"/><br/> <input type="submit" value="Send"/> </form> <dtml-var standard_html_footer>
Create another DTML Method called ‘send’ with the following code:
<dtml-var standard_html_header> <dtml-sendmail smtphost="localhost"> From: michel@digicool.com To: <dtml-var who> <dtml-mime type="text/plain" encode="7bit"> Hi <dtml-var who>, someone sent you this attachment. <dtml-boundary type="application/octet-stream" disposition="attachment" encode="base64"><dtml-var "afile.read()"></dtml-mime> </dtml-sendmail> Mail with attachment was sent. <dtml-var standard_html_footer>
Notice that there is no blank line between the ‘To:’ header and the starting dtml-mime tag. If a blank line is inserted between them then the message will not be interpreted as multipart by the receiving mail reader.
Also notice that there is no newline between the dtml-boundary tag and the dtml-var tag, or the end of the dtml-var tag and the closing dtml-mime tag. This is important, if you break the tags up with newlines then they will be encoded and included in the MIME part, which is probably not what you want.
As per the MIME spec, dtml-mime tags may be nested within dtml-mime tags arbitrarily.
Changelog
5.0 (2025-11-19)
Switch to PEP 420 native namespace.
Add support for Python 3.12, 3.13 and 3.14.
Drop support for Python 3.7, 3.8 and 3.9.
4.0 (2023-02-01)
Drop support for Python 2.7, 3.5, 3.6.
3.3 (2022-12-16)
Fix insidious buildout configuration bug for tests against Zope 4.
Add support for Python 3.10 and 3.11.
3.2 (2021-03-16)
Add support for Python 3.9.
3.1 (2020-02-11)
Fix linting.
Change some imports to prevent DeprecationWarnings.
3.0 (2019-05-20)
Reimplemented using Python’s email module.
Added support for Python 3.5, 3.6, 3.7 and 3.8.
Switched documentation to standard dtml notation.
Added tox testing configuration.
Full linting.
Boosted test coverage to over 90%.
Compatible with DocumentTemplate 3.x and Zope 4.
2.13.0 (2010-07-10)
PEP8 cleanup and added basic tests.
Released as separate package.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file products_mimetools-5.0.tar.gz.
File metadata
- Download URL: products_mimetools-5.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7dae37978c321351a0ffbd49c39aff1b581a444323b24087c2ce6c845250713
|
|
| MD5 |
4521b64ce228ed725d077fe5f1ef9232
|
|
| BLAKE2b-256 |
cee0c9dfa87ed964c2a1fd1033c5a16567e85496e110b93200041e9e7bc8e209
|
File details
Details for the file products_mimetools-5.0-py3-none-any.whl.
File metadata
- Download URL: products_mimetools-5.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0dba1caec1e1a4ed3aa92bb066a43543c5ecc114697f4c9a2289f93acc10e6d
|
|
| MD5 |
be99de6f1d6bb776343f898ec0dcbfcd
|
|
| BLAKE2b-256 |
6c3f25dc716ea64b44fa4b4d0f9f27fd741273df2002977e00e28c7ac3468ab9
|