1 # Patchwork - automated patch tracking system
2 # Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
4 # This file is part of the Patchwork package.
6 # Patchwork is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # Patchwork is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Patchwork; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 from patchwork.models import Project, Person
24 from email.mime.text import MIMEText
25 from email.mime.multipart import MIMEMultipart
27 # Python 2.4 compatibility
28 from email.MIMEText import MIMEText
29 from email.MIMEMultipart import MIMEMultipart
31 # helper functions for tests
32 _test_mail_dir = 'patchwork/tests/mail'
33 _test_patch_dir = 'patchwork/tests/patches'
35 class defaults(object):
36 project = Project(linkname = 'test-project', name = 'Test Project')
38 patch_author = 'Patch Author <patch-author@example.com>'
39 patch_author_person = Person(name = 'Patch Author',
40 email = 'patch-author@example.com')
42 comment_author = 'Comment Author <comment-author@example.com>'
44 sender = 'Test Author <test-author@example.com>'
46 subject = 'Test Subject'
48 patch_name = 'Test Patch'
51 def read_patch(filename, encoding = None):
52 file_path = os.path.join(_test_patch_dir, filename)
53 if encoding is not None:
54 f = codecs.open(file_path, encoding = encoding)
60 def create_email(content, subject = None, sender = None, multipart = False,
61 project = None, content_encoding = None):
63 subject = defaults.subject
65 sender = defaults.sender
67 project = defaults.project
71 body = MIMEText(content, _subtype = 'plain')
72 if content_encoding is not None:
73 body.set_charset(content_encoding)
76 msg = MIMEText(content)
77 if content_encoding is not None:
78 msg.set_charset(content_encoding)
80 msg['Subject'] = subject
82 msg['List-Id'] = project.linkname