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
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 require_once('Mail.php');
22 require_once('Mail/mime.php');
24 // {{{ class HermesMailer
25 /** Class for sending inline or multipart-emails.
27 class HermesMailer
extends Mail_Mime
{
36 function HermesMailer() {
37 $this->Mail_Mime("\n");
38 $this->_mail
=& Mail
::factory('sendmail', Array('-oi'));
42 // {{{ function _correct_emails()
45 * converts all : Foo Bar Baz <quux@foobar.org> into "Foo Bar Baz" <quux@foobar.org> wich is RFC compliant
48 function _correct_emails($email)
50 return preg_replace('!(^|, *)([^<"][^<"]*[^< "]) *(<[^>]*>)!', '\1"\2" \3', $email);
54 // {{{ function addTo()
56 function addTo($email)
58 $email = $this->_correct_emails($email);
59 if (isset($this->_headers
['To'])) {
60 $this->_headers
['To'] .= ", $email";
62 $this->_headers
['To'] = $email;
67 // {{{ function addCc()
69 function addCc($email)
71 return parent
::addCc($this->_correct_emails($email));
75 // {{{ function addBcc()
77 function addBcc($email)
79 return parent
::addBcc($this->_correct_emails($email));
83 // {{{ function setFrom()
85 function setFrom($email)
87 return parent
::setFrom($this->_correct_emails($email));
91 // {{{ function addHeader()
93 function addHeader($hdr,$val)
101 unset($this->_headers
[$hdr]);
106 unset($this->_headers
[$hdr]);
111 unset($this->_headers
[$hdr]);
116 $this->headers(Array($hdr=>$val));
121 // {{{ function send()
125 foreach(Array('To', 'Cc', 'Bcc') as $hdr) {
126 if(isset($this->_headers
[$hdr])) {
127 require_once 'Mail/RFC822.php';
128 $addrs = array_merge($addrs, Mail_RFC822
::parseAddressList($this->_headers
[$hdr]));
131 if(empty($addrs)) return false
;
134 foreach($addrs as $a) $dests[] = "{$a->mailbox}@{$a->host}";
136 // very important to do it in THIS order very precisely.
137 $body = $this->get();
138 $hdrs = $this->headers();
139 return $this->_mail
->send($dests, $hdrs, $body);