Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit af2a2bda977cd29b45a6703658af7aadbd0bd57e 0 parents
Dan Jacob danjac authored
25 .gitignore
@@ -0,0 +1,25 @@
+
+*.coverage
+*.egg-info
+*.log
+*.pyc
+*.db
+*.swp
+*.swo
+*.zip
+*.orig
+*.cfg
+*.tox
+
+*~
+
+fab_settings.py
+production_settings.py
+
+dist
+docs/output
+
+_uploads
+
+.hg
+.hgignore
31 LICENSE
@@ -0,0 +1,31 @@
+Copyright (c) 2010 by danjac.
+
+Some rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+* Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+* The names of the contributors may not be used to endorse or
+ promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 MANIFEST.in
@@ -0,0 +1,6 @@
+include LICENSE tests.py
+recursive-include docs *
+recursive-exclude docs *.pyc
+recursive-exclude docs *.pyo
+prune docs/_build
+prune docs/_themes/.git
7 README
@@ -0,0 +1,7 @@
+Flask-Mail is a Flask extension providing simple email sending
+capabilities.
+
+
+For full information please refer to the online docs:
+
+http://packages.python.org/Flask-Mail
89 docs/Makefile
@@ -0,0 +1,89 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
+
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+ -rm -rf $(BUILDDIR)/*
+
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/flask-mail.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/flask-mail.qhc"
+
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
+ "run these through (pdf)latex."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
BIN  docs/_static/flask-mail.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  docs/_static/flask-mail.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 docs/_themes/README
@@ -0,0 +1,31 @@
+Flask Sphinx Styles
+===================
+
+This repository contains sphinx styles for Flask and Flask related
+projects. To use this style in your Sphinx documentation, follow
+this guide:
+
+1. put this folder as _themes into your docs folder. Alternatively
+ you can also use git submodules to check out the contents there.
+2. add this to your conf.py:
+
+ sys.path.append(os.path.abspath('_themes'))
+ html_theme_path = ['_themes']
+ html_theme = 'flask'
+
+The following themes exist:
+
+- 'flask' - the standard flask documentation theme for large
+ projects
+- 'flask_small' - small one-page theme. Intended to be used by
+ very small addon libraries for flask.
+
+The following options exist for the flask_small theme:
+
+ [options]
+ index_logo = '' filename of a picture in _static
+ to be used as replacement for the
+ h1 in the index.rst file.
+ index_logo_height = 120px height of the index logo
+ github_fork = '' repository name on github for the
+ "fork me" badge
345 docs/_themes/flask/static/flasky.css_t
@@ -0,0 +1,345 @@
+/*
+ * flasky.css_t
+ * ~~~~~~~~~~~~
+ *
+ * Sphinx stylesheet -- flasky theme based on nature theme.
+ *
+ * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
+ * :license: BSD, see LICENSE for details.
+ *
+ */
+
+@import url("basic.css");
+
+/* -- page layout ----------------------------------------------------------- */
+
+body {
+ font-family: 'Georgia', serif;
+ font-size: 17px;
+ background-color: #ddd;
+ color: #000;
+ margin: 0;
+ padding: 0;
+}
+
+div.document {
+ background: #fafafa;
+}
+
+div.documentwrapper {
+ float: left;
+ width: 100%;
+}
+
+div.bodywrapper {
+ margin: 0 0 0 230px;
+}
+
+hr {
+ border: 1px solid #B1B4B6;
+}
+
+div.body {
+ background-color: #ffffff;
+ color: #3E4349;
+ padding: 0 30px 30px 30px;
+ min-height: 34em;
+}
+
+img.floatingflask {
+ padding: 0 0 10px 10px;
+ float: right;
+}
+
+div.footer {
+ position: absolute;
+ right: 0;
+ margin-top: -70px;
+ text-align: right;
+ color: #888;
+ padding: 10px;
+ font-size: 14px;
+}
+
+div.footer a {
+ color: #888;
+ text-decoration: underline;
+}
+
+div.related {
+ line-height: 32px;
+ color: #888;
+}
+
+div.related ul {
+ padding: 0 0 0 10px;
+}
+
+div.related a {
+ color: #444;
+}
+
+div.sphinxsidebar {
+ font-size: 14px;
+ line-height: 1.5;
+}
+
+div.sphinxsidebarwrapper {
+ padding: 0 20px;
+}
+
+div.sphinxsidebarwrapper p.logo {
+ padding: 20px 0 10px 0;
+ margin: 0;
+ text-align: center;
+}
+
+div.sphinxsidebar h3,
+div.sphinxsidebar h4 {
+ font-family: 'Garamond', 'Georgia', serif;
+ color: #222;
+ font-size: 24px;
+ font-weight: normal;
+ margin: 20px 0 5px 0;
+ padding: 0;
+}
+
+div.sphinxsidebar h4 {
+ font-size: 20px;
+}
+
+div.sphinxsidebar h3 a {
+ color: #444;
+}
+
+div.sphinxsidebar p {
+ color: #555;
+ margin: 10px 0;
+}
+
+div.sphinxsidebar ul {
+ margin: 10px 0;
+ padding: 0;
+ color: #000;
+}
+
+div.sphinxsidebar a {
+ color: #444;
+ text-decoration: none;
+}
+
+div.sphinxsidebar a:hover {
+ text-decoration: underline;
+}
+
+div.sphinxsidebar input {
+ border: 1px solid #ccc;
+ font-family: 'Georgia', serif;
+ font-size: 1em;
+}
+
+/* -- body styles ----------------------------------------------------------- */
+
+a {
+ color: #004B6B;
+ text-decoration: underline;
+}
+
+a:hover {
+ color: #6D4100;
+ text-decoration: underline;
+}
+
+div.body {
+ padding-bottom: 40px; /* saved for footer */
+}
+
+div.body h1,
+div.body h2,
+div.body h3,
+div.body h4,
+div.body h5,
+div.body h6 {
+ font-family: 'Garamond', 'Georgia', serif;
+ font-weight: normal;
+ margin: 30px 0px 10px 0px;
+ padding: 0;
+}
+
+div.body h1 { margin-top: 0; padding-top: 20px; font-size: 240%; }
+div.body h2 { font-size: 180%; }
+div.body h3 { font-size: 150%; }
+div.body h4 { font-size: 130%; }
+div.body h5 { font-size: 100%; }
+div.body h6 { font-size: 100%; }
+
+a.headerlink {
+ color: white;
+ padding: 0 4px;
+ text-decoration: none;
+}
+
+a.headerlink:hover {
+ color: #444;
+ background: #eaeaea;
+}
+
+div.body p, div.body dd, div.body li {
+ line-height: 1.4em;
+}
+
+div.admonition {
+ background: #fafafa;
+ margin: 20px -30px;
+ padding: 10px 30px;
+ border-top: 1px solid #ccc;
+ border-bottom: 1px solid #ccc;
+}
+
+div.admonition p.admonition-title {
+ font-family: 'Garamond', 'Georgia', serif;
+ font-weight: normal;
+ font-size: 24px;
+ margin: 0 0 10px 0;
+ padding: 0;
+ line-height: 1;
+}
+
+div.admonition p.last {
+ margin-bottom: 0;
+}
+
+div.highlight{
+ background-color: white;
+}
+
+dt:target, .highlight {
+ background: #FAF3E8;
+}
+
+div.note {
+ background-color: #eee;
+ border: 1px solid #ccc;
+}
+
+div.seealso {
+ background-color: #ffc;
+ border: 1px solid #ff6;
+}
+
+div.topic {
+ background-color: #eee;
+}
+
+div.warning {
+ background-color: #ffe4e4;
+ border: 1px solid #f66;
+}
+
+p.admonition-title {
+ display: inline;
+}
+
+p.admonition-title:after {
+ content: ":";
+}
+
+pre, tt {
+ font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;
+ font-size: 0.9em;
+}
+
+img.screenshot {
+}
+
+tt.descname, tt.descclassname {
+ font-size: 0.95em;
+}
+
+tt.descname {
+ padding-right: 0.08em;
+}
+
+img.screenshot {
+ -moz-box-shadow: 2px 2px 4px #eee;
+ -webkit-box-shadow: 2px 2px 4px #eee;
+ box-shadow: 2px 2px 4px #eee;
+}
+
+table.docutils {
+ border: 1px solid #888;
+ -moz-box-shadow: 2px 2px 4px #eee;
+ -webkit-box-shadow: 2px 2px 4px #eee;
+ box-shadow: 2px 2px 4px #eee;
+}
+
+table.docutils td, table.docutils th {
+ border: 1px solid #888;
+ padding: 0.25em 0.7em;
+}
+
+table.field-list, table.footnote {
+ border: none;
+ -moz-box-shadow: none;
+ -webkit-box-shadow: none;
+ box-shadow: none;
+}
+
+table.footnote {
+ margin: 15px 0;
+ width: 100%;
+ border: 1px solid #eee;
+}
+
+table.field-list th {
+ padding: 0 0.8em 0 0;
+}
+
+table.field-list td {
+ padding: 0;
+}
+
+table.footnote td {
+ padding: 0.5em;
+}
+
+dl {
+ margin: 0;
+ padding: 0;
+}
+
+dl dd {
+ margin-left: 30px;
+}
+
+pre {
+ background: #eee;
+ padding: 7px 30px;
+ margin: 15px -30px;
+ line-height: 1.3em;
+}
+
+dl pre {
+ margin-left: -60px;
+ padding-left: 60px;
+}
+
+dl dl pre {
+ margin-left: -90px;
+ padding-left: 90px;
+}
+
+tt {
+ background-color: #ecf0f3;
+ color: #222;
+ /* padding: 1px 2px; */
+}
+
+tt.xref, a tt {
+ background-color: #FBFBFB;
+ text-decoration: none!important;
+}
+
+a:hover tt {
+ background: #EEE;
+}
4 docs/_themes/flask/theme.conf
@@ -0,0 +1,4 @@
+[theme]
+inherit = basic
+stylesheet = flasky.css
+pygments_style = flask_theme_support.FlaskyStyle
22 docs/_themes/flask_small/layout.html
@@ -0,0 +1,22 @@
+{% extends "basic/layout.html" %}
+{% block header %}
+ {{ super() }}
+ {% if pagename == 'index' %}
+ <div class=indexwrapper>
+ {% endif %}
+{% endblock %}
+{% block footer %}
+ {% if pagename == 'index' %}
+ </div>
+ {% endif %}
+{% endblock %}
+{# do not display relbars #}
+{% block relbar1 %}{% endblock %}
+{% block relbar2 %}
+ {% if theme_github_fork %}
+ <a href="http://github.com/{{ theme_github_fork }}"><img style="position: fixed; top: 0; right: 0; border: 0;"
+ src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
+ {% endif %}
+{% endblock %}
+{% block sidebar1 %}{% endblock %}
+{% block sidebar2 %}{% endblock %}
287 docs/_themes/flask_small/static/flasky.css_t
@@ -0,0 +1,287 @@
+/*
+ * flasky.css_t
+ * ~~~~~~~~~~~~
+ *
+ * Sphinx stylesheet -- flasky theme based on nature theme.
+ *
+ * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.
+ * :license: BSD, see LICENSE for details.
+ *
+ */
+
+@import url("basic.css");
+
+/* -- page layout ----------------------------------------------------------- */
+
+body {
+ font-family: 'Georgia', serif;
+ font-size: 17px;
+ color: #000;
+ background: white;
+ margin: 0;
+ padding: 0;
+}
+
+div.documentwrapper {
+ float: left;
+ width: 100%;
+}
+
+div.bodywrapper {
+ margin: 40px auto 0 auto;
+ width: 700px;
+}
+
+hr {
+ border: 1px solid #B1B4B6;
+}
+
+div.body {
+ background-color: #ffffff;
+ color: #3E4349;
+ padding: 0 30px 30px 30px;
+}
+
+img.floatingflask {
+ padding: 0 0 10px 10px;
+ float: right;
+}
+
+div.footer {
+ text-align: right;
+ color: #888;
+ padding: 10px;
+ font-size: 14px;
+ width: 650px;
+ margin: 0 auto 40px auto;
+}
+
+div.footer a {
+ color: #888;
+ text-decoration: underline;
+}
+
+div.related {
+ line-height: 32px;
+ color: #888;
+}
+
+div.related ul {
+ padding: 0 0 0 10px;
+}
+
+div.related a {
+ color: #444;
+}
+
+/* -- body styles ----------------------------------------------------------- */
+
+a {
+ color: #004B6B;
+ text-decoration: underline;
+}
+
+a:hover {
+ color: #6D4100;
+ text-decoration: underline;
+}
+
+div.body {
+ padding-bottom: 40px; /* saved for footer */
+}
+
+div.body h1,
+div.body h2,
+div.body h3,
+div.body h4,
+div.body h5,
+div.body h6 {
+ font-family: 'Garamond', 'Georgia', serif;
+ font-weight: normal;
+ margin: 30px 0px 10px 0px;
+ padding: 0;
+}
+
+{% if theme_index_logo %}
+div.indexwrapper h1 {
+ text-indent: -999999px;
+ background: url({{ theme_index_logo }}) no-repeat center center;
+ height: {{ theme_index_logo_height }};
+}
+{% endif %}
+
+div.body h2 { font-size: 180%; }
+div.body h3 { font-size: 150%; }
+div.body h4 { font-size: 130%; }
+div.body h5 { font-size: 100%; }
+div.body h6 { font-size: 100%; }
+
+a.headerlink {
+ color: white;
+ padding: 0 4px;
+ text-decoration: none;
+}
+
+a.headerlink:hover {
+ color: #444;
+ background: #eaeaea;
+}
+
+div.body p, div.body dd, div.body li {
+ line-height: 1.4em;
+}
+
+div.admonition {
+ background: #fafafa;
+ margin: 20px -30px;
+ padding: 10px 30px;
+ border-top: 1px solid #ccc;
+ border-bottom: 1px solid #ccc;
+}
+
+div.admonition p.admonition-title {
+ font-family: 'Garamond', 'Georgia', serif;
+ font-weight: normal;
+ font-size: 24px;
+ margin: 0 0 10px 0;
+ padding: 0;
+ line-height: 1;
+}
+
+div.admonition p.last {
+ margin-bottom: 0;
+}
+
+div.highlight{
+ background-color: white;
+}
+
+dt:target, .highlight {
+ background: #FAF3E8;
+}
+
+div.note {
+ background-color: #eee;
+ border: 1px solid #ccc;
+}
+
+div.seealso {
+ background-color: #ffc;
+ border: 1px solid #ff6;
+}
+
+div.topic {
+ background-color: #eee;
+}
+
+div.warning {
+ background-color: #ffe4e4;
+ border: 1px solid #f66;
+}
+
+p.admonition-title {
+ display: inline;
+}
+
+p.admonition-title:after {
+ content: ":";
+}
+
+pre, tt {
+ font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;
+ font-size: 0.85em;
+}
+
+img.screenshot {
+}
+
+tt.descname, tt.descclassname {
+ font-size: 0.95em;
+}
+
+tt.descname {
+ padding-right: 0.08em;
+}
+
+img.screenshot {
+ -moz-box-shadow: 2px 2px 4px #eee;
+ -webkit-box-shadow: 2px 2px 4px #eee;
+ box-shadow: 2px 2px 4px #eee;
+}
+
+table.docutils {
+ border: 1px solid #888;
+ -moz-box-shadow: 2px 2px 4px #eee;
+ -webkit-box-shadow: 2px 2px 4px #eee;
+ box-shadow: 2px 2px 4px #eee;
+}
+
+table.docutils td, table.docutils th {
+ border: 1px solid #888;
+ padding: 0.25em 0.7em;
+}
+
+table.field-list, table.footnote {
+ border: none;
+ -moz-box-shadow: none;
+ -webkit-box-shadow: none;
+ box-shadow: none;
+}
+
+table.footnote {
+ margin: 15px 0;
+ width: 100%;
+ border: 1px solid #eee;
+}
+
+table.field-list th {
+ padding: 0 0.8em 0 0;
+}
+
+table.field-list td {
+ padding: 0;
+}
+
+table.footnote td {
+ padding: 0.5em;
+}
+
+dl {
+ margin: 0;
+ padding: 0;
+}
+
+dl dd {
+ margin-left: 30px;
+}
+
+pre {
+ padding: 0;
+ margin: 15px -30px;
+ padding: 8px;
+ line-height: 1.3em;
+ padding: 7px 30px;
+ background: #eee;
+ border-radius: 2px;
+ -moz-border-radius: 2px;
+ -webkit-border-radius: 2px;
+}
+
+dl pre {
+ margin-left: -60px;
+ padding-left: 60px;
+}
+
+tt {
+ background-color: #ecf0f3;
+ color: #222;
+ /* padding: 1px 2px; */
+}
+
+tt.xref, a tt {
+ background-color: #FBFBFB;
+}
+
+a:hover tt {
+ background: #EEE;
+}
10 docs/_themes/flask_small/theme.conf
@@ -0,0 +1,10 @@
+[theme]
+inherit = basic
+stylesheet = flasky.css
+nosidebar = true
+pygments_style = flask_theme_support.FlaskyStyle
+
+[options]
+index_logo = ''
+index_logo_height = 120px
+github_fork = ''
86 docs/_themes/flask_theme_support.py
@@ -0,0 +1,86 @@
+# flasky extensions. flasky pygments style based on tango style
+from pygments.style import Style
+from pygments.token import Keyword, Name, Comment, String, Error, \
+ Number, Operator, Generic, Whitespace, Punctuation, Other, Literal
+
+
+class FlaskyStyle(Style):
+ background_color = "#f8f8f8"
+ default_style = ""
+
+ styles = {
+ # No corresponding class for the following:
+ #Text: "", # class: ''
+ Whitespace: "underline #f8f8f8", # class: 'w'
+ Error: "#a40000 border:#ef2929", # class: 'err'
+ Other: "#000000", # class 'x'
+
+ Comment: "italic #8f5902", # class: 'c'
+ Comment.Preproc: "noitalic", # class: 'cp'
+
+ Keyword: "bold #004461", # class: 'k'
+ Keyword.Constant: "bold #004461", # class: 'kc'
+ Keyword.Declaration: "bold #004461", # class: 'kd'
+ Keyword.Namespace: "bold #004461", # class: 'kn'
+ Keyword.Pseudo: "bold #004461", # class: 'kp'
+ Keyword.Reserved: "bold #004461", # class: 'kr'
+ Keyword.Type: "bold #004461", # class: 'kt'
+
+ Operator: "#582800", # class: 'o'
+ Operator.Word: "bold #004461", # class: 'ow' - like keywords
+
+ Punctuation: "bold #000000", # class: 'p'
+
+ # because special names such as Name.Class, Name.Function, etc.
+ # are not recognized as such later in the parsing, we choose them
+ # to look the same as ordinary variables.
+ Name: "#000000", # class: 'n'
+ Name.Attribute: "#c4a000", # class: 'na' - to be revised
+ Name.Builtin: "#004461", # class: 'nb'
+ Name.Builtin.Pseudo: "#3465a4", # class: 'bp'
+ Name.Class: "#000000", # class: 'nc' - to be revised
+ Name.Constant: "#000000", # class: 'no' - to be revised
+ Name.Decorator: "#888", # class: 'nd' - to be revised
+ Name.Entity: "#ce5c00", # class: 'ni'
+ Name.Exception: "bold #cc0000", # class: 'ne'
+ Name.Function: "#000000", # class: 'nf'
+ Name.Property: "#000000", # class: 'py'
+ Name.Label: "#f57900", # class: 'nl'
+ Name.Namespace: "#000000", # class: 'nn' - to be revised
+ Name.Other: "#000000", # class: 'nx'
+ Name.Tag: "bold #004461", # class: 'nt' - like a keyword
+ Name.Variable: "#000000", # class: 'nv' - to be revised
+ Name.Variable.Class: "#000000", # class: 'vc' - to be revised
+ Name.Variable.Global: "#000000", # class: 'vg' - to be revised
+ Name.Variable.Instance: "#000000", # class: 'vi' - to be revised
+
+ Number: "#990000", # class: 'm'
+
+ Literal: "#000000", # class: 'l'
+ Literal.Date: "#000000", # class: 'ld'
+
+ String: "#4e9a06", # class: 's'
+ String.Backtick: "#4e9a06", # class: 'sb'
+ String.Char: "#4e9a06", # class: 'sc'
+ String.Doc: "italic #8f5902", # class: 'sd' - like a comment
+ String.Double: "#4e9a06", # class: 's2'
+ String.Escape: "#4e9a06", # class: 'se'
+ String.Heredoc: "#4e9a06", # class: 'sh'
+ String.Interpol: "#4e9a06", # class: 'si'
+ String.Other: "#4e9a06", # class: 'sx'
+ String.Regex: "#4e9a06", # class: 'sr'
+ String.Single: "#4e9a06", # class: 's1'
+ String.Symbol: "#4e9a06", # class: 'ss'
+
+ Generic: "#000000", # class: 'g'
+ Generic.Deleted: "#a40000", # class: 'gd'
+ Generic.Emph: "italic #000000", # class: 'ge'
+ Generic.Error: "#ef2929", # class: 'gr'
+ Generic.Heading: "bold #000080", # class: 'gh'
+ Generic.Inserted: "#00A000", # class: 'gi'
+ Generic.Output: "#888", # class: 'go'
+ Generic.Prompt: "#745334", # class: 'gp'
+ Generic.Strong: "bold #000000", # class: 'gs'
+ Generic.Subheading: "bold #800080", # class: 'gu'
+ Generic.Traceback: "bold #a40000", # class: 'gt'
+ }
199 docs/conf.py
@@ -0,0 +1,199 @@
+# -*- coding: utf-8 -*-
+#
+# flask-mail documentation build configuration file, created by
+# sphinx-quickstart on Fri May 28 11:39:14 2010.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+sys.path.append(os.path.abspath('_themes'))
+
+# -- General configuration -----------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'Flask-Mail'
+copyright = u'2010, Dan Jacob'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '0.5'
+# The full version, including alpha/beta/rc tags.
+release = '0.5'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of documents that shouldn't be included in the build.
+#unused_docs = []
+
+# List of directories, relative to source directory, that shouldn't be searched
+# for source files.
+exclude_trees = ['_build']
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+#pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. Major themes that come with
+# Sphinx are currently 'default' and 'sphinxdoc'.
+html_theme = 'flask_small'
+#html_theme = 'default'
+html_theme_options = {
+ 'index_logo': 'flask-mail.png',
+ 'github_fork': None
+}
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+html_theme_path = ['_themes']
+
+# The name for this set of Sphinx documents. If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar. Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_use_modindex = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it. The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = ''
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'flask-maildoc'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+# The paper size ('letter' or 'a4').
+#latex_paper_size = 'letter'
+
+# The font size ('10pt', '11pt' or '12pt').
+#latex_font_size = '10pt'
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+ ('index', 'flask-mail.tex', u'flask-mail Documentation',
+ u'Dan Jacob', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# Additional stuff for the LaTeX preamble.
+#latex_preamble = ''
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_use_modindex = True
248 docs/index.rst
@@ -0,0 +1,248 @@
+flask-mail
+======================================
+
+.. module:: flask-mail
+
+One of the most basic functions in a web application is the ability to send
+emails to your users.
+
+The **Flask-Mail** extension provides a simple interface to set up SMTP with your
+`Flask`_ application and to send messages from your views and scripts.
+
+Source code and issue tracking at `Bitbucket`_.
+
+Windows issues
+--------------
+
+**Flask-Mail** requires the use of the **Lamson** library, which unfortunately
+has dependencies that do not work on Windows.
+
+It is therefore recommended that you use the `--no-dependencies` option to first
+install Lamson, and do the same again to install **Flask-Mail**.
+
+Installing Flask-Mail
+---------------------
+
+Install with **pip** and **easy_install**::
+
+ pip install Flask-Mail
+
+or download the latest version from Bitbucket::
+
+ hg clone http://bitbucket.org/danjac/flask-mail
+
+ cd flask-mail
+
+ python setup.py install
+
+If you are using **virtualenv**, it is assumed that you are installing flask-mail
+in the same virtualenv as your Flask application(s).
+
+Configuring Flask-Mail
+----------------------
+
+**Flask-Mail** is configured through the standard Flask config API. These are the available
+options (each is explained later in the documentation):
+
+* **MAIL_SERVER** : default **'localhost'**
+
+* **MAIL_PORT** : default **25**
+
+* **MAIL_USE_TLS** : default **False**
+
+* **MAIL_USE_SSL** : default **False**
+
+* **MAIL_DEBUG** : default **app.debug**
+
+* **MAIL_USERNAME** : default **None**
+
+* **MAIL_PASSWORD** : default **None**
+
+* **DEFAULT_MAIL_SENDER** : default **None**
+
+* **DEFAULT_MAX_EMAILS** : default **None**
+
+* **MAIL_FAIL_SILENTLY** : default **True**
+
+* **MAIL_SUPPRESS_SEND** : default **False**
+
+In addition the standard Flask ``TESTING`` configuration option is used by **Flask-Mail**
+in unit tests (see below).
+
+Emails are managed through a ``Mail`` instance::
+
+ from flask import Flask
+ from flaskext.mail import Mail
+
+ app = Flask(__name__)
+ mail = Mail(app)
+
+Alternatively you can set up your ``Mail`` instance later at configuration time, using the
+**init_app** method::
+
+ mail = Mail()
+
+ app = Flask(__name__)
+ mail.init_app(app)
+
+
+Sending messages
+----------------
+
+To send a message first create a ``Message`` instance::
+
+ from flaskext.mail import Message
+
+ @app.route("/")
+ def index():
+
+ msg = Message("Hello",
+ sender="from@example.com",
+ recipients=["to@example.com"])
+
+You can set the recipient emails immediately, or individually::
+
+ msg.recipients = ["you@example.com"]
+ msg.add_recipient("somebodyelse@example.com")
+
+If you have set ``DEFAULT_MAIL_SENDER`` you don't need to set the message
+sender explicity, as it will use this configuration value by default::
+
+ msg = Message("Hello",
+ recipients=["to@example.com"])
+
+If the ``sender`` is a two-element tuple, this will be split into name
+and address::
+
+ msg = Message("Hello",
+ sender=("Me", "me@example.com"))
+
+ assert msg.sender == "Me <me@example.com>"
+
+The message can contain a body and/or HTML::
+
+ msg.body = "testing"
+ msg.html = "<b>testing</b>"
+
+Finally, to send the message, you use the ``Mail`` instance configured with your Flask application::
+
+ mail.send(msg)
+
+If the setting **MAIL_FAIL_SILENTLY** is **True**, and the connection fails (for example, the mail
+server cannot be found at that hostname) then no error will be raised, although of course no emails will
+be sent either.
+
+
+Bulk emails
+-----------
+
+Usually in a web application you will be sending one or two emails per request. In certain situations
+you might want to be able to send perhaps dozens or hundreds of emails in a single batch - probably in
+an external process such as a command-line script or cronjob.
+
+In that case you do things slightly differently::
+
+ with mail.connect() as conn:
+ for user in users:
+ message = '...'
+ subject = "hello, %s" % user.name
+ msg = Message(recipients=[user.email],
+ body=message,
+ subject=subject)
+
+ conn.send(msg)
+
+
+The connection to your email host is kept alive and closed automatically once all the messages have been sent.
+
+If you are going to run a mass email batch, be careful to pass in the ``max_emails`` parameter, which sets the maximum
+number of emails that will be sent before reconnecting. Some mail servers set a limit on the number of emails sent
+in a single connection. You can also set this globally with the **DEFAULT_MAX_EMAILS** setting.
+
+Attachments
+-----------
+
+Adding attachments is straightforward::
+
+ with app.open_resource("image.png") as fp:
+ msg.attach("image.png", "image/png", fp.read())
+
+See the `API`_ for details.
+
+Unit tests and suppressing emails
+---------------------------------
+
+When you are sending messages inside of unit tests, or in a development
+environment, it's useful to be able to suppress email sending.
+
+If the setting ``TESTING`` is set to ``True``, emails will be
+suppressed. Calling ``send()`` on your messages will not result in
+any messages being actually sent.
+
+Alternatively outside a testing environment you can set ``MAIL_SUPPRESS_SEND`` to **False**. This
+will have the same effect.
+
+However, it's still useful to keep track of emails that would have been
+sent when you are writing unit tests.
+
+In order to keep track of dispatched emails, use the ``record_messages``
+method::
+
+ with mail.record_messages() as outbox:
+
+ mail.send_message(subject='testing',
+ body='test',
+ recipients=emails)
+
+ assert len(outbox) == 1
+ assert outbox[0].subject == "testing"
+
+The **outbox** is a list of ``Message`` instances sent.
+
+The blinker package must be installed for this method to work.
+
+Note that the older way of doing things, appending the **outbox** to
+the ``g`` object, is now deprecated.
+
+
+Header injection
+----------------
+
+To prevent `header injection <http://www.nyphp.org/PHundamentals/8_Preventing-Email-Header-Injection>`_ attempts to send
+a message with newlines in the subject, sender or recipient addresses will result in a ``BadHeaderError``.
+
+Signalling support
+------------------
+
+.. versionadded:: 0.4
+
+**Flask-Mail** now provides signalling support through a ``email_dispatched`` signal. This is sent whenever an email is
+dispatched (even if the email is not actually sent, i.e. in a testing environment).
+
+A function connecting to the ``email_dispatched`` signal takes a ``Message`` instance as a first argument, and the Flask
+app instance as an optional argument::
+
+ def log_message(message, app):
+ app.logger.debug(message.subject)
+
+ email_dispatched.connect(log_message)
+
+
+API
+---
+
+.. module:: flaskext.mail
+
+.. autoclass:: Mail
+ :members: send, connect, send_message
+
+.. autoclass:: Attachment
+
+.. autoclass:: Connection
+ :members: send, send_message
+
+.. autoclass:: Message
+ :members: attach, add_recipient
+
+.. _Flask: http://flask.pocoo.org
+.. _Bitbucket: http://bitbucket.org/danjac/flask-mail
113 docs/make.bat
@@ -0,0 +1,113 @@
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+set SPHINXBUILD=sphinx-build
+set BUILDDIR=_build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
+if NOT "%PAPER%" == "" (
+ set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+ :help
+ echo.Please use `make ^<target^>` where ^<target^> is one of
+ echo. html to make standalone HTML files
+ echo. dirhtml to make HTML files named index.html in directories
+ echo. pickle to make pickle files
+ echo. json to make JSON files
+ echo. htmlhelp to make HTML files and a HTML help project
+ echo. qthelp to make HTML files and a qthelp project
+ echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+ echo. changes to make an overview over all changed/added/deprecated items
+ echo. linkcheck to check all external links for integrity
+ echo. doctest to run all doctests embedded in the documentation if enabled
+ goto end
+)
+
+if "%1" == "clean" (
+ for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+ del /q /s %BUILDDIR%\*
+ goto end
+)
+
+if "%1" == "html" (
+ %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+ goto end
+)
+
+if "%1" == "dirhtml" (
+ %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+ echo.
+ echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+ goto end
+)
+
+if "%1" == "pickle" (
+ %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+ echo.
+ echo.Build finished; now you can process the pickle files.
+ goto end
+)
+
+if "%1" == "json" (
+ %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+ echo.
+ echo.Build finished; now you can process the JSON files.
+ goto end
+)
+
+if "%1" == "htmlhelp" (
+ %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+ echo.
+ echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+ goto end
+)
+
+if "%1" == "qthelp" (
+ %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+ echo.
+ echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+ echo.^> qcollectiongenerator %BUILDDIR%\qthelp\flask-mail.qhcp
+ echo.To view the help file:
+ echo.^> assistant -collectionFile %BUILDDIR%\qthelp\flask-mail.ghc
+ goto end
+)
+
+if "%1" == "latex" (
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+ echo.
+ echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+ goto end
+)
+
+if "%1" == "changes" (
+ %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+ echo.
+ echo.The overview file is in %BUILDDIR%/changes.
+ goto end
+)
+
+if "%1" == "linkcheck" (
+ %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+ echo.
+ echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+ goto end
+)
+
+if "%1" == "doctest" (
+ %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+ echo.
+ echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+ goto end
+)
+
+:end
1  flaskext/__init__.py
@@ -0,0 +1 @@
+__import__('pkg_resources').declare_namespace(__name__)
122 flaskext/mail/__init__.py
@@ -0,0 +1,122 @@
+# -*- coding: utf-8 -*-
+"""
+ flaskext.mail
+ ~~~~~~~~~~~~~
+
+ Flask extension for sending email.
+
+ :copyright: (c) 2010 by Dan Jacob.
+ :license: BSD, see LICENSE for more details.
+"""
+from __future__ import with_statement
+
+from contextlib import contextmanager
+
+from flaskext.mail.connection import Connection
+from flaskext.mail.message import Message, Attachment, BadHeaderError
+from flaskext.mail.signals import email_dispatched
+
+
+class Mail(object):
+ """
+ Manages email messaging
+
+ :param app: Flask instance
+ """
+
+ def __init__(self, app=None):
+
+ if app is not None:
+ self.init_app(app)
+
+ def init_app(self, app):
+ """
+ Initializes your mail settings from the application
+ settings.
+
+ You can use this if you want to set up your Mail instance
+ at configuration time.
+
+ :param app: Flask application instance
+ """
+
+ self.server = app.config.get('MAIL_SERVER', '127.0.0.1')
+ self.username = app.config.get('MAIL_USERNAME')
+ self.password = app.config.get('MAIL_PASSWORD')
+ self.port = app.config.get('MAIL_PORT', 25)
+ self.use_tls = app.config.get('MAIL_USE_TLS', False)
+ self.use_ssl = app.config.get('MAIL_USE_SSL', False)
+ self.debug = int(app.config.get('MAIL_DEBUG', app.debug))
+ self.max_emails = app.config.get('DEFAULT_MAX_EMAILS')
+ self.suppress = app.config.get('MAIL_SUPPRESS_SEND', False)
+ self.fail_silently = app.config.get('MAIL_FAIL_SILENTLY', True)
+
+ self.suppress = self.suppress or app.testing
+
+ self.app = app
+
+ @contextmanager
+ def record_messages(self):
+ """
+ Records all messages. Use in unit tests for example::
+
+ with mail.record_messages() as outbox:
+ response = app.test_client.get("/email-sending-view/")
+ assert len(outbox) == 1
+ assert outbox[0].subject == "testing"
+
+ You must have blinker installed in order to use this feature.
+ :versionadded: 0.4
+ """
+
+ if not email_dispatched:
+ raise RuntimeError, "blinker must be installed"
+
+ outbox = []
+
+ def _record(message, app):
+ outbox.append(message)
+
+ email_dispatched.connect(_record)
+
+ try:
+ yield outbox
+ finally:
+ email_dispatched.disconnect(_record)
+
+ def send(self, message):
+ """
+ Sends a single message instance. If TESTING is True
+ the message will not actually be sent.
+
+ :param message: a Message instance.
+ """
+
+ with self.connect() as connection:
+ message.send(connection)
+
+ def send_message(self, *args, **kwargs):
+ """
+ Shortcut for send(msg).
+
+ Takes same arguments as Message constructor.
+
+ :versionadded: 0.3.5
+ """
+
+ self.send(Message(*args, **kwargs))
+
+ def connect(self, max_emails=None):
+ """
+ Opens a connection to the mail host.
+
+ :param max_emails: the maximum number of emails that can
+ be sent in a single connection. If this
+ number is exceeded the Connection instance
+ will reconnect to the mail server. The
+ DEFAULT_MAX_EMAILS config setting is used
+ if this is None.
+ """
+ return Connection(self, max_emails)
+
+
92 flaskext/mail/connection.py
@@ -0,0 +1,92 @@
+import smtplib
+import socket
+
+from flaskext.mail.message import Message
+from flaskext.mail.signals import email_dispatched
+
+class Connection(object):
+
+ """Handles connection to host."""
+
+ def __init__(self, mail, max_emails=None):
+
+ self.mail = mail
+ self.app = self.mail.app
+ self.suppress = self.mail.suppress
+ self.max_emails = max_emails or self.mail.max_emails or 0
+ self.fail_silently = self.mail.fail_silently
+
+ def __enter__(self):
+
+ if self.suppress:
+ self.host = None
+ else:
+ self.host = self.configure_host()
+
+ self.num_emails = 0
+
+ return self
+
+ def __exit__(self, exc_type, exc_value, tb):
+ if self.host:
+ self.host.quit()
+
+ def configure_host(self):
+
+ try:
+ if self.mail.use_ssl:
+ host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
+ else:
+ host = smtplib.SMTP(self.mail.server, self.mail.port)
+ except socket.error:
+ if self.fail_silently:
+ return
+ raise
+
+ host.set_debuglevel(int(self.app.debug))
+
+ if self.mail.use_tls:
+ host.starttls()
+ if self.mail.username and self.mail.password:
+ host.login(self.mail.username, self.mail.password)
+
+ return host
+
+ def send(self, message):
+ """
+ Sends message.
+
+ :param message: Message instance.
+ """
+
+ if self.host:
+ self.host.sendmail(message.sender,
+ message.recipients,
+ str(message.get_response()))
+
+
+ if email_dispatched:
+ email_dispatched.send(message, app=self.app)
+
+ self.num_emails += 1
+
+ if self.num_emails == self.max_emails:
+
+ self.num_emails = 0
+ if self.host:
+ self.host.quit()
+ self.host = self.configure_host()
+
+ def send_message(self, *args, **kwargs):
+ """
+ Shortcut for send(msg).
+
+ Takes same arguments as Message constructor.
+
+ :versionadded: 0.3.5
+
+ """
+
+ self.send(Message(*args, **kwargs))
+
+
147 flaskext/mail/message.py
@@ -0,0 +1,147 @@
+
+from flask import _request_ctx_stack
+
+from lamson.mail import MailResponse
+
+class BadHeaderError(Exception): pass
+
+
+class Attachment(object):
+
+ """
+ Encapsulates file attachment information.
+
+ :versionadded: 0.3.5
+
+ :param filename: filename of attachment
+ :param content_type: file mimetype
+ :param data: the raw file data
+ :param disposition: content-disposition (if any)
+
+ """
+
+ def __init__(self, filename=None, content_type=None, data=None,
+ disposition=None):
+
+ self.filename = filename
+ self.content_type = content_type
+ self.data = data
+ self.disposition = disposition or 'attachment'
+
+
+class Message(object):
+
+ """
+ Encapsulates an email message.
+
+ :param subject: email subject header
+ :param recipients: list of email addresses
+ :param body: plain text message
+ :param html: HTML message
+ :param sender: email sender address, or **DEFAULT_MAIL_SENDER** by default
+ :param attachments: list of Attachment instances
+ """
+
+ def __init__(self, subject,
+ recipients=None,
+ body=None,
+ html=None,
+ sender=None,
+ attachments=None):
+
+
+ if sender is None:
+ app = _request_ctx_stack.top.app
+ sender = app.config.get("DEFAULT_MAIL_SENDER")
+
+ if isinstance(sender, tuple):
+ # sender can be tuple of (name, address)
+ sender = "%s <%s>" % sender
+
+ self.subject = subject
+ self.sender = sender
+ self.body = body
+ self.html = html
+
+ if recipients is None:
+ recipients = []
+
+ self.recipients = list(recipients)
+
+ if attachments is None:
+ attachments = []
+
+ self.attachments = attachments
+
+ def get_response(self):
+ """
+ Creates a Lamson MailResponse instance
+ """
+
+ response = MailResponse(Subject=self.subject,
+ To=self.recipients,
+ From=self.sender,
+ Body=self.body,
+ Html=self.html)
+
+ for attachment in self.attachments:
+
+ response.attach(attachment.filename,
+ attachment.content_type,
+ attachment.data,
+ attachment.disposition)
+
+ return response
+
+ def is_bad_headers(self):
+ """
+ Checks for bad headers i.e. newlines in subject, sender or recipients.
+ """
+
+ for val in [self.subject, self.sender] + self.recipients:
+ for c in '\r\n':
+ if c in val:
+ return True
+ return False
+
+ def send(self, connection):
+ """
+ Verifies and sends the message.
+ """
+
+ assert self.recipients, "No recipients have been added"
+ assert self.body or self.html, "No body or HTML has been set"
+ assert self.sender, "No sender address has been set"
+
+ if self.is_bad_headers():
+ raise BadHeaderError
+
+ connection.send(self)
+
+ def add_recipient(self, recipient):
+ """
+ Adds another recipient to the message.
+
+ :param recipient: email address of recipient.
+ """
+
+ self.recipients.append(recipient)
+
+ def attach(self,
+ filename=None,
+ content_type=None,
+ data=None,
+ disposition=None):
+
+ """
+ Adds an attachment to the message.
+
+ :param filename: filename of attachment
+ :param content_type: file mimetype
+ :param data: the raw file data
+ :param disposition: content-disposition (if any)
+ """
+
+ self.attachments.append(
+ Attachment(filename, content_type, data, disposition))
+
14 flaskext/mail/signals.py
@@ -0,0 +1,14 @@
+
+try:
+
+ import blinker
+ signals = blinker.Namespace()
+
+ email_dispatched = signals.signal("email-dispatched", doc="""
+Signal sent when an email is dispatched. This signal will also be sent
+in testing mode, even though the email will not actually be sent.
+ """)
+
+except ImportError:
+ email_dispatched = None
+
54 setup.py
@@ -0,0 +1,54 @@
+"""
+Flask-Mail
+----------
+
+A Flask extension for sending email messages.
+
+Please refer to the online documentation for details.
+
+Links
+`````
+
+* `documentation <http://packages.python.org/Flask-Mail>`_
+* `development version
+ <http://bitbucket.org/danjac/flask-mail/get/tip.gz#egg=Flask-Mail-dev>`_
+"""
+from setuptools import setup
+
+
+setup(
+ name='Flask-Mail',
+ version='0.5.1',
+ url='http://bitbucket.org/danjac/flask-mail',
+ license='BSD',
+ author='Dan Jacob',
+ author_email='danjac354@gmail.com',
+ description='Flask extension for sending email',
+ long_description=__doc__,
+ packages=[
+ 'flaskext',
+ 'flaskext.mail',
+ ],
+ namespace_packages=['flaskext'],
+ test_suite='nose.collector',
+ zip_safe=False,
+ platforms='any',
+ install_requires=[
+ 'Flask',
+ 'Lamson',
+ ],
+ tests_require=[
+ 'nose',
+ 'blinker',
+ ],
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: BSD License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
+ 'Topic :: Software Development :: Libraries :: Python Modules'
+ ]
+)
262 tests.py
@@ -0,0 +1,262 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import with_statement
+
+import unittest
+import mailbox
+
+from email import encoders
+
+from flask import Flask, g
+from flaskext.mail import Mail, Message, BadHeaderError, Attachment
+
+from nose.tools import assert_equal
+
+class TestCase(unittest.TestCase):
+
+ TESTING = True
+ DEFAULT_MAIL_SENDER = "support@mysite.com"
+
+ def setUp(self):
+
+ self.app = Flask(__name__)
+ self.app.config.from_object(self)
+
+ assert self.app.testing
+
+ self.mail = Mail(self.app)
+
+ self.ctx = self.app.test_request_context()
+ self.ctx.push()
+
+ def tearDown(self):
+
+ self.ctx.pop()
+
+class TestMessage(TestCase):
+
+ def test_initialize(self):
+
+ msg = Message(subject="subject",
+ recipients=["to@example.com"])
+
+
+ assert msg.sender == "support@mysite.com"
+ assert msg.recipients == ["to@example.com"]
+
+ def test_recipients_properly_initialized(self):
+
+ msg = Message(subject="subject")
+
+ assert msg.recipients == []
+
+ msg2 = Message(subject="subject")
+ msg2.add_recipient("somebody@here.com")
+
+ assert len(msg.recipients) == 0
+
+ msg3 = Message(subject="subject")
+ msg3.add_recipient("somebody@here.com")
+
+ assert len(msg.recipients) == 0
+
+ def test_add_recipient(self):
+
+ msg = Message("testing")
+ msg.add_recipient("to@example.com")
+
+ assert msg.recipients == ["to@example.com"]
+
+
+ def test_sender_as_tuple(self):
+
+ msg = Message(subject="testing",
+ sender=("tester", "tester@example.com"))
+
+
+ def test_send_without_sender(self):
+
+ del self.app.config['DEFAULT_MAIL_SENDER']
+
+ msg = Message(subject="testing",
+ recipients=["to@example.com"],
+ body="testing")
+
+ self.assertRaises(AssertionError, self.mail.send, msg)
+
+ def test_send_without_recipients(self):
+
+ msg = Message(subject="testing",
+ recipients=[],
+ body="testing")
+
+ self.assertRaises(AssertionError, self.mail.send, msg)
+
+ def test_send_without_body(self):
+
+ msg = Message(subject="testing",
+ recipients=["to@example.com"])
+
+ self.assertRaises(AssertionError, self.mail.send, msg)
+
+ msg.html = "<b>test</b>"
+
+ self.mail.send(msg)
+
+ def test_normal_send(self):
+ """
+ This will not actually send a message unless the mail server
+ is set up. The error will be logged but test should still
+ pass.
+ """
+
+ self.app.config['TESTING'] = False
+ self.mail.init_app(self.app)
+
+ with self.mail.record_messages() as outbox:
+
+ msg = Message(subject="testing",
+ recipients=["to@example.com"],
+ body="testing")
+
+ self.mail.send(msg)
+
+ assert len(outbox) == 1
+
+ self.app.config['TESTING'] = True
+
+ def test_attach(self):
+
+ msg = Message(subject="testing",
+ recipients=["to@example.com"],
+ body="testing")
+
+ msg.attach(data="this is a test",
+ content_type="text/plain")
+
+
+ a = msg.attachments[0]
+
+ assert a.filename is None
+ assert a.disposition == 'attachment'
+ assert a.content_type == "text/plain"
+ assert a.data == "this is a test"
+
+
+ def test_bad_header_subject(self):
+
+ msg = Message(subject="testing\n\r",
+ sender="from@example.com",
+ body="testing",
+ recipients=["to@example.com"])
+
+ self.assertRaises(BadHeaderError, self.mail.send, msg)
+
+ def test_bad_header_sender(self):
+
+ msg = Message(subject="testing",
+ sender="from@example.com\n\r",
+ recipients=["to@example.com"],
+ body="testing")
+
+ self.assertRaises(BadHeaderError, self.mail.send, msg)
+
+ def test_bad_header_recipient(self):
+
+ msg = Message(subject="testing",
+ sender="from@example.com",
+ recipients=[
+ "to@example.com",
+ "to\r\n@example.com"],
+ body="testing")
+
+ self.assertRaises(BadHeaderError, self.mail.send, msg)
+
+
+class TestMail(TestCase):
+
+ def test_send(self):
+
+ with self.mail.record_messages() as outbox:
+ msg = Message(subject="testing",
+ recipients=["tester@example.com"],
+ body="test")
+
+ self.mail.send(msg)
+
+ assert len(outbox) == 1
+
+ def test_send_message(self):
+
+ with self.mail.record_messages() as outbox:
+ self.mail.send_message(subject="testing",
+ recipients=["tester@example.com"],
+ body="test")
+
+ assert len(outbox) == 1
+
+ msg = outbox[0]
+
+ assert msg.subject == "testing"
+ assert msg.recipients == ["tester@example.com"]
+ assert msg.body == "test"
+
+
+class TestConnection(TestCase):
+
+ def test_send_message(self):
+
+ with self.mail.record_messages() as outbox:
+ with self.mail.connect() as conn:
+ conn.send_message(subject="testing",
+ recipients=["to@example.com"],
+ body="testing")
+
+ assert len(outbox) == 1
+
+ def test_send_single(self):
+
+ with self.mail.record_messages() as outbox:
+ with self.mail.connect() as conn:
+ msg = Message(subject="testing",
+ recipients=["to@example.com"],
+ body="testing")
+
+ conn.send(msg)
+
+ assert len(outbox) == 1
+
+ def test_send_many(self):
+
+ messages = []
+
+ with self.mail.record_messages() as outbox:
+ with self.mail.connect() as conn:
+ for i in xrange(100):
+ msg = Message(subject="testing",
+ recipients=["to@example.com"],
+ body="testing")
+
+ conn.send(msg)
+
+ assert len(outbox) == 100
+
+ def test_max_emails(self):
+
+ messages = []
+
+ with self.mail.record_messages() as outbox:
+ with self.mail.connect(max_emails=10) as conn:
+ for i in xrange(100):
+ msg = Message(subject="testing",
+ recipients=["to@example.com"],
+ body="testing")
+
+ conn.send(msg)
+
+ print conn.num_emails
+ if i % 10 == 0:
+ assert conn.num_emails == 1
+
+ assert len(outbox) == 100
+
Please sign in to comment.
Something went wrong with that request. Please try again.