| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|---|
| 4 | |
|---|
| 5 | // +-------------------------------------------------------------------+ |
|---|
| 6 | // | WiFiDog Authentication Server | |
|---|
| 7 | // | ============================= | |
|---|
| 8 | // | | |
|---|
| 9 | // | The WiFiDog Authentication Server is part of the WiFiDog captive | |
|---|
| 10 | // | portal suite. | |
|---|
| 11 | // +-------------------------------------------------------------------+ |
|---|
| 12 | // | PHP version 5 required. | |
|---|
| 13 | // +-------------------------------------------------------------------+ |
|---|
| 14 | // | Homepage: http://www.wifidog.org/ | |
|---|
| 15 | // | Source Forge: http://sourceforge.net/projects/wifidog/ | |
|---|
| 16 | // +-------------------------------------------------------------------+ |
|---|
| 17 | // | This program is free software; you can redistribute it and/or | |
|---|
| 18 | // | modify it under the terms of the GNU General Public License as | |
|---|
| 19 | // | published by the Free Software Foundation; either version 2 of | |
|---|
| 20 | // | the License, or (at your option) any later version. | |
|---|
| 21 | // | | |
|---|
| 22 | // | This program is distributed in the hope that it will be useful, | |
|---|
| 23 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 24 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 25 | // | GNU General Public License for more details. | |
|---|
| 26 | // | | |
|---|
| 27 | // | You should have received a copy of the GNU General Public License | |
|---|
| 28 | // | along with this program; if not, contact: | |
|---|
| 29 | // | | |
|---|
| 30 | // | Free Software Foundation Voice: +1-617-542-5942 | |
|---|
| 31 | // | 59 Temple Place - Suite 330 Fax: +1-617-542-2652 | |
|---|
| 32 | // | Boston, MA 02111-1307, USA gnu@gnu.org | |
|---|
| 33 | // | | |
|---|
| 34 | // +-------------------------------------------------------------------+ |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * This a wrapper class conforming RFC822 capable of sending valid UTF-8 MIME |
|---|
| 38 | * headers |
|---|
| 39 | * |
|---|
| 40 | * @package WiFiDogAuthServer |
|---|
| 41 | * @author Francois Proulx <francois.proulx@gmail.com> |
|---|
| 42 | * @copyright 2005 Francois Proulx <francois.proulx@gmail.com> - Technologies |
|---|
| 43 | * Coeus inc. |
|---|
| 44 | * @version CVS: $Id$ |
|---|
| 45 | * @link http://sourceforge.net/projects/wifidog/ |
|---|
| 46 | */ |
|---|
| 47 | |
|---|
| 48 | class Mail |
|---|
| 49 | { |
|---|
| 50 | // Business domain attributes |
|---|
| 51 | private $from_name; |
|---|
| 52 | private $from_email; |
|---|
| 53 | private $to_name; |
|---|
| 54 | private $to_email; |
|---|
| 55 | private $subject; |
|---|
| 56 | private $body; |
|---|
| 57 | |
|---|
| 58 | public function __construct() |
|---|
| 59 | { |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | private function encodeMimeHeader($header) |
|---|
| 63 | { |
|---|
| 64 | // BASE 64 according to the RFC |
|---|
| 65 | // Taken from : www.php.net mb_send_mail comments |
|---|
| 66 | $header = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $header); |
|---|
| 67 | $header = str_replace(' ', '_', $header); |
|---|
| 68 | return "=?utf-8?Q?$header?="; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | public function getMessageBody() |
|---|
| 72 | { |
|---|
| 73 | return $this->body; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | public function getMessageSubject() |
|---|
| 77 | { |
|---|
| 78 | return $this->subject; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | public function getRecipientName() |
|---|
| 82 | { |
|---|
| 83 | return $this->to_name; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | public function getRecipientEmail() |
|---|
| 87 | { |
|---|
| 88 | return $this->to_email; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | public function getSenderName() |
|---|
| 92 | { |
|---|
| 93 | return $this->from_name; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | public function getSenderEmail() |
|---|
| 97 | { |
|---|
| 98 | return $this->from_email; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | // Packs e-mail and send it according to RFC822 |
|---|
| 102 | public function send() |
|---|
| 103 | { |
|---|
| 104 | $headers = "From: \"".$this->getSenderName()."\" <".$this->getSenderEmail().">\r\n"; |
|---|
| 105 | $headers .= "Reply-To: ".$this->getSenderEmail()."\r\n"; |
|---|
| 106 | $headers .= "Content-Type: text/plain; charset=utf-8"; |
|---|
| 107 | $args = "-f".$this->getSenderEmail(); |
|---|
| 108 | return mail($this->getRecipientEmail(), $this->getMessageSubject(), $this->getMessageBody(), $headers, $args); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | public function setMessageBody($body) |
|---|
| 112 | { |
|---|
| 113 | $this->body = $body; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | public function setMessageSubject($subject) |
|---|
| 117 | { |
|---|
| 118 | $this->subject = $this->encodeMimeHeader($subject); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | public function setRecipientEmail($mail) |
|---|
| 122 | { |
|---|
| 123 | $this->to_email = $mail; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | public function setSenderName($name) |
|---|
| 127 | { |
|---|
| 128 | // Encode header |
|---|
| 129 | $this->from_name = $this->encodeMimeHeader($name); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | public function setSenderEmail($mail) |
|---|
| 133 | { |
|---|
| 134 | $this->from_email = $mail; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | /* |
|---|
| 139 | * Local variables: |
|---|
| 140 | * tab-width: 4 |
|---|
| 141 | * c-basic-offset: 4 |
|---|
| 142 | * c-hanging-comment-ender-p: nil |
|---|
| 143 | * End: |
|---|
| 144 | */ |
|---|
| 145 | |
|---|
| 146 | ?> |
|---|