2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once('diogenes/diogenes.hermes.inc.php');
23 require_once('Smarty.class.php');
25 // {{{ class XOrgMailer
27 /** Classe de mail avec corps en templates.
29 class XOrgMailer
extends Smarty
33 /** Directory used to store mails_templates.
34 * Smarty::template_dir subdir used to sotre the mails templates.
35 * The body of the message is taken from a tsmarty template
37 var $mail_dir = "mails";
38 /** stores the mail template name */
41 /** stores the mail From: header */
43 /** stores the recipients of the mail */
45 /** stores the Cc recipients of the mail */
47 /** stores the Bcc recipients of the mail */
49 /** stores the subject of the mail */
55 function XorgMailer($tpl)
60 $this->compile_check
=true
;
62 $this->template_dir
= $globals->root
. "/templates/";
63 $this->compile_dir
= $globals->root
. "/spool/templates_c/";
64 $this->config_dir
= $globals->root
. "/configs/";
66 $this->register_outputfilter('mail_format');
67 $this->register_function('from', 'set_from');
68 $this->register_function('to', 'set_to');
69 $this->register_function('cc', 'set_cc');
70 $this->register_function('bcc', 'set_bcc');
71 $this->register_function('subject', 'set_subject');
75 // {{{ function send()
79 // do not try to optimize, in the templates, some function can modify our object, then we
80 // have to fetch in the first time, and only then send the mail.
81 $body = $this->fetch($this->mail_dir
."/".$this->_tpl
);
82 $mailer = new HermesMailer();
83 $mailer->setFrom($this->_from
);
84 $mailer->addTo(implode(',',$this->_to
));
85 $mailer->setSubject($this->_subject
);
86 if (!empty($this->_cc
)) {
87 $mailer->addCc(implode(',',$this->_cc
));
89 if (!empty($this->_bcc
)) {
90 $mailer->addBcc(implode(',',$this->_bcc
));
92 $mailer->setTxtBody($body);
100 // {{{ function mail_format()
102 /** used to remove the empty lines due to {from ...}, {to ...} ... functions */
103 function mail_format($output, &$smarty)
105 return wordwrap("\n".trim($output)."\n",75);
109 // {{{ function format_addr()
111 function format_addr(&$params)
113 if (isset($params['full'])) {
114 return $params['full'];
115 } elseif (empty($params['text'])) {
116 return $params['addr'];
118 return $params['text'].' <'.$params['addr'].'>';
123 // {{{ function set_from()
125 /** template function : from.
126 * {from full=...} for an already formatted address
127 * {from addr=... [text=...]} else
129 function set_from($params, &$smarty)
130 { $smarty->_from
= format_addr($params); }
133 // {{{ function set_to()
135 /** template function : to.
136 * {to full=...} for an already formatted address
137 * {to addr=... [text=...]} else
139 function set_to($params, &$smarty)
140 { $smarty->_to
[] = format_addr($params); }
143 // {{{ function set_cc()
145 /** template function : cc.
146 * {cc full=...} for an already formatted address
147 * {cc addr=... [text=...]} else
149 function set_cc($params, &$smarty)
150 { $smarty->_cc
[] = format_addr($params); }
153 // {{{ function set_bcc()
155 /** template function : bcc.
156 * {bcc full=...} for an already formatted address
157 * {bcc addr=... [text=...]} else
159 function set_bcc($params, &$smarty)
160 { $smarty->_bcc
[] = format_addr($params); }
163 // {{{ function set_subject()
165 /** template function : subject.
168 function set_subject($params, &$smarty)
170 $smarty->_subject
= $params['text'];
175 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: