Skip to content

Commit

Permalink
- complete overhaul for Zope 4 and Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed May 20, 2019
1 parent 9c41ea3 commit 65df9bb
Show file tree
Hide file tree
Showing 11 changed files with 533 additions and 213 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -8,7 +8,10 @@ parts
*.pyc
*.pyo
*.so
.coverage*
.installed.cfg
default.profraw
develop-eggs/
eggs/
*.egg-info/
.tox/
18 changes: 15 additions & 3 deletions CHANGES.txt
@@ -1,13 +1,25 @@
Changelog
=========

2.14.0 (unreleased)
-------------------
3.0 (unreleased)
----------------
- 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.
102 changes: 102 additions & 0 deletions README.rst
@@ -0,0 +1,102 @@
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.
99 changes: 0 additions & 99 deletions README.txt

This file was deleted.

15 changes: 10 additions & 5 deletions buildout.cfg
@@ -1,12 +1,17 @@
[buildout]
develop = .
parts = interpreter test
parts =
test
tox

[interpreter]
recipe = zc.recipe.egg
interpreter = python
eggs = Products.MIMETools

[test]
recipe = zc.recipe.testrunner
eggs = Products.MIMETools

[tox]
recipe = zc.recipe.egg
eggs =
tox
scripts =
tox
42 changes: 42 additions & 0 deletions setup.cfg
@@ -0,0 +1,42 @@
[bdist_wheel]
universal=1

[check-manifest]
ignore =
coverage.xml
tox.ini
.travis.yml

[isort]
force_single_line = True
combine_as_imports = True
sections = FUTURE,STDLIB,THIRDPARTY,ZOPE,FIRSTPARTY,LOCALFOLDER
known_third_party = six
known_zope = DocumentTemplate
default_section = ZOPE
line_length = 79
lines_after_imports = 2
not_skip =
__init__.py

[flake8]
no-accept-encodings = True
doctests = True
exclude =
bootstrap.py
htmldir = parts/flake8

[coverage:run]
branch = True
source = src
omit =

[coverage:report]
fail_under = 85.00
ignore_errors = True
precision = 2
show_missing = False
sort = Name

[coverage:html]
directory = parts/coverage
42 changes: 34 additions & 8 deletions setup.py
Expand Up @@ -12,25 +12,51 @@
#
##############################################################################

from setuptools import setup, find_packages
from setuptools import find_packages
from setuptools import setup


setup(name='Products.MIMETools',
version = '2.14.0.dev0',
url='http://pypi.python.org/pypi/Products.MIMETools',
version='3.0.dev0',
url='https://github.com/zopefoundation/Products.MIMETools',
project_urls={
'Issue Tracker': ('https://github.com/zopefoundation'
'/Products.MIMETools/issues'),
'Sources': 'https://github.com/zopefoundation/Products.MIMETools',
},
license='ZPL 2.1',
description="MIMETools provides the &lt;!--#mime--&gt; tag for "
"DocumentTemplate.",
description='MIMETools provides the ``dtml-mime`` tag for '
'DocumentTemplate.',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
long_description=open('README.txt').read() + '\n' +
open('CHANGES.txt').read(),
long_description=(open('README.rst').read() + '\n' +
open('CHANGES.txt').read()),
packages=find_packages('src'),
namespace_packages=['Products'],
package_dir={'': 'src'},
classifiers=[
'Development Status :: 6 - Mature',
'Environment :: Web Environment',
'Framework :: Zope',
'Framework :: Zope :: 4',
'License :: OSI Approved :: Zope Public License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Communications :: Email',
],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*',
install_requires=[
'setuptools',
'six',
'ExtensionClass>=4.1a1',
'DocumentTemplate',
'DocumentTemplate>=3',
],
include_package_data=True,
zip_safe=False,
Expand Down

0 comments on commit 65df9bb

Please sign in to comment.