module render.email_message_renderer

Inheritance diagram of pymmails.render.email_message_renderer

Short summary

module pymmails.render.email_message_renderer

Functions to dump emails

source on GitHub

Classes

class

truncated documentation

EmailMessageRenderer

defines way to render an email

Properties

property

truncated documentation

BufferWrite

returns self._buffer_write

Methods

method

truncated documentation

__init__

Defines a template based on Jinja2.

process_body_html

replaces link to images included in the mail body

produce_table_html

produces a table with the values of some fields of the message

render

Renders a mail.

write

Writes a mail, the function assumes the attachments were already dumped.

Documentation

@file @brief Functions to dump emails

class pymmails.render.email_message_renderer.EmailMessageRenderer(tmpl=None, css=None, style_table='dataframe100l', style_highlight='dataframe100l_hl', buffer_write=None, fLOG=<function noLOG>)[source]

Bases: pymmails.render.renderer.Renderer

defines way to render an email

Defines a template based on Jinja2.

@param tmpl template (string or file) @param css style @param style_table style for the table @param style_highlight style for highlighted cells @param buffer_write instance of class @see cl BufferFilesWriting @param fLOG logging function

@example(Template to render an email)

See file email_message_style

HTML template:

<?xml version="1.0" encoding="utf-8"?>
<body>
<html>
<head>
<title>{{ message.get_field("subject") }}</title>
<link rel="stylesheet" type="text/css" href="{{ css }}">
</head>
<body>
{{ '<a href="{0}">&lt;--</a>'.format(prev_mail) if prev_mail else '' }}
{{ '<a href="{0}">--&gt;</a>'.format(next_mail) if next_mail else '' }}
<h1>{{ message.get_date().strftime('%Y/%m/%d') }} - {{ message.get_field("subject") }}</h1>
<h2>attributes</h2>
{{ render.produce_table_html(message, toshow=EmailMessage.subset, location=location, avoid=EmailMessage.avoid) }}
<h2>message</h2>
{{ render.process_body_html(location, message.body_html, attachments) }}
<h2>full list of attributes</h2>
{{ render.produce_table_html(message, toshow=message.Fields, location=location, tohighlight=EmailMessage.subset) }}
</body>
</html>

CSS style:

.dataframe100l {
    padding: 0;
    width=75%
    font-family: Calibri;
    font-size: 100%;
    cursor: pointer;
}

.dataframe100l table {
    border-collapse: collapse;
    text-align: left;
    font-size: 11px;
}

.dataframe100l table td, .dataframe100l table th {
    padding: 3px 6px;
}

.dataframe100l table thead th {
    background-color:#AAAAAA;
    color:#ffffff;
    font-size: 11px;
    font-weight: bold;
    border-left: 1px solid #0070A8;
}

.dataframe100l table tbody td {
    color: #00496B;
    border-left: 1px solid #E1EEF4;
    font-size: 11px;
    font-weight: normal;
}

.dataframe100l table tbody .alt td {
    background: #E1EEF4;
    color: #00496B;
    }

.dataframe100l_hl td {
    background: #FFFF00;
    }

.dataframe100l_hl th {
    background: #FFFF00;
    }

.dataframe100l_hl tr {
    background: #FFFF00;
    }

.dataframe100l table tbody td:first-child {
    border-left: none;
}

.dataframe100l table tbody tr:last-child td {
    border-bottom: none;
}

.dataframe100l table tfoot td div {
    border-top: 1px solid #006699;
    background: #E1EEF4;
}

.dataframe100l table tfoot td {
    padding: 0;
    font-size: 11px
}

.dataframe100l table tfoot td div{ padding: 2px; }
.dataframe100l table tfoot td ul {
    margin: 0;
    padding:0;
    list-style: none;
    text-align: right;
}

.dataframe100l table tfoot  li { display: inline; }
.dataframe100l table tfoot li a {
    text-decoration: none;
    display: inline-block;
    padding: 2px 8px;
    margin: 1px;
    color: #FFFFFF;
    border: 1px solid #006699;
    border-radius: 3px;
    background-color:#006699;
}

.dataframe100l table tfoot ul.active, .dataframe100l table tfoot ul a:hover {
    text-decoration: none;
    border-color: #006699;
    color: #FFFFFF;
    background: none;
    background-color:#00557F;
}

@endexample

__init__(tmpl=None, css=None, style_table='dataframe100l', style_highlight='dataframe100l_hl', buffer_write=None, fLOG=<function noLOG>)[source]

Defines a template based on Jinja2.

@param tmpl template (string or file) @param css style @param style_table style for the table @param style_highlight style for highlighted cells @param buffer_write instance of class @see cl BufferFilesWriting @param fLOG logging function

@example(Template to render an email)

See file email_message_style

HTML template:

<?xml version="1.0" encoding="utf-8"?>
<body>
<html>
<head>
<title>{{ message.get_field("subject") }}</title>
<link rel="stylesheet" type="text/css" href="{{ css }}">
</head>
<body>
{{ '<a href="{0}">&lt;--</a>'.format(prev_mail) if prev_mail else '' }}
{{ '<a href="{0}">--&gt;</a>'.format(next_mail) if next_mail else '' }}
<h1>{{ message.get_date().strftime('%Y/%m/%d') }} - {{ message.get_field("subject") }}</h1>
<h2>attributes</h2>
{{ render.produce_table_html(message, toshow=EmailMessage.subset, location=location, avoid=EmailMessage.avoid) }}
<h2>message</h2>
{{ render.process_body_html(location, message.body_html, attachments) }}
<h2>full list of attributes</h2>
{{ render.produce_table_html(message, toshow=message.Fields, location=location, tohighlight=EmailMessage.subset) }}
</body>
</html>

CSS style:

.dataframe100l {
    padding: 0;
    width=75%
    font-family: Calibri;
    font-size: 100%;
    cursor: pointer;
}

.dataframe100l table {
    border-collapse: collapse;
    text-align: left;
    font-size: 11px;
}

.dataframe100l table td, .dataframe100l table th {
    padding: 3px 6px;
}

.dataframe100l table thead th {
    background-color:#AAAAAA;
    color:#ffffff;
    font-size: 11px;
    font-weight: bold;
    border-left: 1px solid #0070A8;
}

.dataframe100l table tbody td {
    color: #00496B;
    border-left: 1px solid #E1EEF4;
    font-size: 11px;
    font-weight: normal;
}

.dataframe100l table tbody .alt td {
    background: #E1EEF4;
    color: #00496B;
    }

.dataframe100l_hl td {
    background: #FFFF00;
    }

.dataframe100l_hl th {
    background: #FFFF00;
    }

.dataframe100l_hl tr {
    background: #FFFF00;
    }

.dataframe100l table tbody td:first-child {
    border-left: none;
}

.dataframe100l table tbody tr:last-child td {
    border-bottom: none;
}

.dataframe100l table tfoot td div {
    border-top: 1px solid #006699;
    background: #E1EEF4;
}

.dataframe100l table tfoot td {
    padding: 0;
    font-size: 11px
}

.dataframe100l table tfoot td div{ padding: 2px; }
.dataframe100l table tfoot td ul {
    margin: 0;
    padding:0;
    list-style: none;
    text-align: right;
}

.dataframe100l table tfoot  li { display: inline; }
.dataframe100l table tfoot li a {
    text-decoration: none;
    display: inline-block;
    padding: 2px 8px;
    margin: 1px;
    color: #FFFFFF;
    border: 1px solid #006699;
    border-radius: 3px;
    background-color:#006699;
}

.dataframe100l table tfoot ul.active, .dataframe100l table tfoot ul a:hover {
    text-decoration: none;
    border-color: #006699;
    color: #FFFFFF;
    background: none;
    background-color:#00557F;
}

@endexample

process_body_html(location, body, atts)[source]

replaces link to images included in the mail body:

<img name="14a318e16161c62a_14a31789f7a34aae_null"
     title="pastedImage.png"
     src="cid:1146aa0a-244a-440e-8ea5-7b272c94f89a"
     height="153.02644466209597"
     width="560">

@param location location where the HTML body will be saved @param body html body @param atts attachements (filename, message id, content id) @return modified body html

produce_table_html(email, location, toshow, tohighlight=None, atts=None, avoid=None)[source]

produces a table with the values of some fields of the message

@param toshow list of fields to show, if None, it considers all fields @param tohighlight list of fields to highlights @param atts list of files to append at the end of the table,

list of tuple ((filename,message_id,content_id))

@param location folder where this page will be saved (for attachment) @param avoid fields to avoid @return html string

render(location, mail, attachments, file_css='mail_style.css', prev_mail=None, next_mail=None, **addition)[source]

Renders a mail.

@paramp location location where this mail should be saved @param mail instance of @see cl EmailMessage @param file_css css file (where it is supposed to be stored) @param attachments attachments @param prev_mail previous mail (or None if there is none) @param next_mail next mail (or None if there is none) @param addition sent to Jinja @return html, css (content), attachments

The mail is stored in object message, css means the style sheet, render means this object, location means location, EmailMessage is the class EmailMessage, attachments is attachments:

{{ message.get_subject() }}

The value stored in file_css will be relative to location.

write(location, mail, filename, attachments=None, overwrite=False, file_css='mail_style.css', encoding='utf8', prev_mail=None, next_mail=None, **addition)[source]

Writes a mail, the function assumes the attachments were already dumped.

@param location location @param mail instance of @see cl EmailMessage @param attachments list of attachments (see @see me dump_attachments) @param overwrite the function does not overwrite @param file_css css file (where it is supposed to be stored) @param encoding encoding @param addition additional parameter sent to Jinja2 @param prev_mail previous mail (or None if there is none) @param next_mail next mail (or None if there is none) @return list of written local files, attachements