/[qa]/trunk/mia/utils.py
ViewVC logotype

Contents of /trunk/mia/utils.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1121 - (show annotations) (download) (as text)
Wed Nov 9 17:39:00 2005 UTC (7 years, 7 months ago) by tbm
File MIME type: text/x-python
File size: 2206 byte(s)
attach the original message as message/rfc822.  (Oh my god, I'm going
blind!)
1 # Utility functions
2 # Copyright (C) 2000, 2001, 2002 James Troup <james@nocrew.org>
3 # Copyright (C) 2002, 2005 Martin Michlmayr <tbm@cyrius.com>
4 # $Id$
5
6 # This program 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.
10
11 # This program 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.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 import email, email.MIMEMultipart, os, sys
21
22 Error = 'Message Error';
23
24 def send_mail(message):
25 sendmail = os.popen("/usr/sbin/sendmail -t", "w")
26 sendmail.write(message)
27 if sendmail.close():
28 raise Error, "Sendmail gave a non-zero return code";
29
30
31 ################################################################################
32
33 # The following is taken from katie
34
35 ################################################################################
36
37 cant_open_exc = "Can't read file.";
38
39 def open_file(filename, mode='r'):
40 try:
41 f = open(filename, mode);
42 except IOError:
43 raise cant_open_exc, filename
44 return f
45
46 # Perform a substition of template
47 def TemplateSubst(map, filename):
48 file = open_file(filename);
49 template = file.read();
50 for x in map.keys():
51 template = template.replace(x,map[x]);
52 file.close();
53 return template;
54
55 def warn(msg):
56 sys.stderr.write("W: %s\n" % (msg));
57
58 ################################################################################
59
60 def TemplateSubstMIMEMultipart(map, filename):
61 msg = email.message_from_string(TemplateSubst(map, filename))
62 m = email.MIMEMultipart.MIMEMultipart()
63 for key in msg.keys():
64 m[key] = msg[key]
65 m.attach(email.message_from_string(msg.get_payload()))
66 return m
67
68 # vim: ts=4:expandtab:shiftwidth=4:

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5