Files
jmc/tests/email_generator.py
David Rousselie e02cde5c93 Finish french translation
darcs-hash:20060129142403-86b55-840b288b57bb61ead3f81f14c7a3c8ffba053012.gz
2006-01-29 15:24:03 +01:00

66 lines
2.3 KiB
Python

##
# -*- coding: iso-8859-1 -*-
## email_generator.py
## Login : David Rousselie <david.rousselie@happycoders.org>
## Started on Tue May 17 15:33:35 2005
## $Id: email_generator.py,v 1.1 2005/07/11 20:39:31 dax Exp $
##
## Copyright (C) 2005
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
from email.Header import Header
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
def _create_multipart(encoded):
msg = MIMEMultipart()
if encoded:
part1 = MIMEText("Encoded multipart1 with 'iso-8859-15' charset (éàê)", \
_charset = "iso-8859-15")
msg.attach(part1)
part2 = MIMEText("Encoded multipart2 with 'iso-8859-15' charset (éàê)", \
_charset = "iso-8859-15")
msg.attach(part2)
else:
part1 = MIMEText("Not encoded multipart1")
msg.attach(part1)
part2 = MIMEText("Not encoded multipart2")
msg.attach(part2)
return msg
def _create_singlepart(encoded):
if encoded:
return MIMEText("Encoded single part with 'iso-8859-15' charset (éàê)", \
_charset = "iso-8859-15")
else:
return MIMEText("Not encoded single part")
def generate(encoded, multipart, header):
msg = None
if multipart:
msg = _create_multipart(encoded)
else:
msg = _create_singlepart(encoded)
if header:
if encoded:
msg['Subject'] = Header("encoded subject (éàê)", "iso-8859-15")
msg['From'] = Header("encoded from (éàê)", "iso-8859-15")
else:
msg['Subject'] = Header("not encoded subject")
msg['From'] = Header("not encoded from")
return msg