Development

/branches/1.1/lib/plugins/sfCompat10Plugin/lib/sfMail.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/plugins/sfCompat10Plugin/lib/sfMail.class.php

Revision 10270, 7.7 kB (checked in by Carl.Vondrick, 6 years ago)

1.1: added deprecated warnings to all sfCompatPlugin classes (closes #3882)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  *
13  * sfMail class.
14  *
15  * WARNING: This class is deprecated and will be removed in symfony 1.2.
16  *
17  * @package    symfony
18  * @subpackage addon
19  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
20  * @version    SVN: $Id$
21  */
22 class sfMail
23 {
24   protected $mailer;
25
26   public function __construct()
27   {
28     require_once(dirname(__FILE__).'/vendor/phpmailer/class.phpmailer.php');
29     require_once(dirname(__FILE__).'/vendor/phpmailer/class.smtp.php');
30
31     $this->mailer = new PHPMailer();
32   }
33
34   public function initialize()
35   {
36   }
37
38   public function setCharset($charset)
39   {
40     $this->mailer->CharSet = $charset;
41   }
42
43   public function getCharset()
44   {
45     return $this->mailer->CharSet;
46   }
47
48   public function setContentType($content_type)
49   {
50     $this->mailer->ContentType = $content_type;
51   }
52
53   public function getContentType()
54   {
55     return $this->mailer->ContentType;
56   }
57
58   public function setPriority($priority)
59   {
60     $this->mailer->Priority = $priority;
61   }
62
63   public function getPriority()
64   {
65     return $this->mailer->Priority;
66   }
67
68   public function setEncoding($encoding)
69   {
70     $this->mailer->Encoding = $encoding;
71   }
72
73   public function getEncoding()
74   {
75     return $this->mailer->Encoding;
76   }
77
78   public function setSubject($subject)
79   {
80     $this->mailer->Subject = $subject;
81   }
82
83   public function getSubject()
84   {
85     return $this->mailer->Subject;
86   }
87
88   public function setBody($body)
89   {
90     $this->mailer->Body = $body;
91   }
92
93   public function getBody()
94   {
95     return $this->mailer->Body;
96   }
97
98   public function setMailer($type = 'mail', $options = array())
99   {
100     switch ($type)
101     {
102       case 'smtp':
103         $this->mailer->IsSMTP();
104         if (isset($options['keep_alive'])) $this->mailer->SMTPKeepAlive = true;
105         break;
106       case 'sendmail':
107         $this->mailer->IsSendmail();
108         break;
109       default:
110         $this->mailer->IsMail();
111         break;
112     }
113   }
114  
115   public function getMailer()
116   {
117     return $this->mailer->Mailer;
118   }
119
120   public function setSender($address, $name = null)
121   {
122     if (!$address)
123     {
124       return;
125     }
126
127     if ($name == null)
128     {
129       list($address, $name) = $this->splitAddress($address);
130     }
131     $this->mailer->Sender = $address;
132   }
133
134   public function getSender()
135   {
136     return $this->mailer->Sender;
137   }
138
139   public function setFrom($address, $name = null)
140   {
141     if (!$address)
142     {
143       return;
144     }
145
146     if ($name == null)
147     {
148       list($address, $name) = $this->splitAddress($address);
149     }
150     $this->mailer->From     = $address;
151     $this->mailer->FromName = $name;
152   }
153
154   public function getFrom()
155   {
156     return $this->mailer->From;
157   }
158
159   /*
160    * $recipents:
161    * test@example.com
162    * Example email <test@example.com>
163    * array('test@example.com', 'test1@example.com')
164    * array('Example email <test@example.com>', 'test1@example.com')
165    */
166   public function addAddresses($addresses)
167   {
168     if (!$addresses)
169     {
170       return;
171     }
172
173     if (is_array($addresses))
174     {
175       foreach ($addresses as $address)
176       {
177         list($address, $name) = $this->splitAddress($address);
178         $this->mailer->AddAddress($address, $name);
179       }
180     }
181     else
182     {
183       list($address, $name) = $this->splitAddress($addresses);
184       $this->mailer->AddAddress($address, $name);
185     }
186   }
187
188   private function splitAddress($address)
189   {
190     if (preg_match('/^(.+)\s<(.+?)>$/', $address, $matches))
191     {
192       return array($matches[2], $matches[1]);
193     }
194     else
195     {
196       return array($address, '');
197     }
198   }
199
200   public function addAddress($address, $name = null)
201   {
202     if ($name == null)
203     {
204       list($address, $name) = $this->splitAddress($address);
205     }
206     $this->mailer->AddAddress($address, $name);
207   }
208
209   public function addCc($address, $name = null)
210   {
211     if ($name == null)
212     {
213       list($address, $name) = $this->splitAddress($address);
214     }
215     $this->mailer->AddCc($address, $name);
216   }
217
218   public function addBcc($address, $name = null)
219   {
220     if ($name == null)
221     {
222       list($address, $name) = $this->splitAddress($address);
223     }
224     $this->mailer->AddBcc($address, $name);
225   }
226
227   public function addReplyTo($address, $name = null)
228   {
229     if (!$address)
230     {
231       return;
232     }
233
234     if ($name == null)
235     {
236       list($address, $name) = $this->splitAddress($address);
237     }
238     $this->mailer->AddReplyTo($address, $name);
239   }
240
241   public function clearAddresses()
242   {
243     $this->mailer->ClearAddresses();
244   }
245
246   public function clearCcs()
247   {
248     $this->mailer->ClearCcs();
249   }
250
251   public function clearBccs()
252   {
253     $this->mailer->ClearBccs();
254   }
255
256   public function clearReplyTos()
257   {
258     $this->mailer->ClearReplyTos();
259   }
260
261   public function clearAllRecipients()
262   {
263     $this->mailer->ClearAllRecipients();
264   }
265
266   public function addAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream')
267   {
268     $this->mailer->AddAttachment($path, $name, $encoding, $type);
269   }
270
271   public function addStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream')
272   {
273     $this->mailer->AddStringAttachment($string, $filename, $encoding, $type);
274   }
275
276   public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream')
277   {
278     $this->mailer->AddEmbeddedImage($path, $cid, $name, $encoding, $type);
279   }
280
281   public function setAttachments($attachments)
282   {
283     if ($attachments instanceof sfMailAttachments)
284     {
285       $this->mailer->setAttachments($attachments->getAttachments());
286     }
287   }
288
289   public function clearAttachments()
290   {
291     $this->mailer->ClearAttachments();
292   }
293
294   function addCustomHeader($name, $value)
295   {
296     $this->mailer->AddCustomHeader("$name: $value");
297   }
298
299   function clearCustomHeaders()
300   {
301     $this->mailer->ClearCustomHeaders();
302   }
303
304   public function prepare()
305   {
306     // Set whether the message is multipart/alternative
307     if (!empty($this->mailer->AltBody))
308     {
309       $this->mailer->ContentType = "multipart/alternative";
310     }
311
312     $this->mailer->SetMessageType();
313   }
314
315   public function send()
316   {
317     if (!$this->mailer->Send())
318     {
319       throw new sfException($this->mailer->ErrorInfo);
320     }
321   }
322
323   public function smtpClose()
324   {
325     $this->mailer->SmtpClose();
326   }
327  
328   public function getRawHeader()
329   {
330     return $this->mailer->CreateHeader();
331   }
332
333   public function getRawBody()
334   {
335     return $this->mailer->CreateBody();
336   }
337
338   public function setDomain($hostname)
339   {
340     $this->mailer->Hostname = $hostname;
341   }
342
343   public function getDomain()
344   {
345     return $this->mailer->Hostname;
346   }
347
348   public function setHostname($hostname)
349   {
350     $this->mailer->Host = $hostname;
351   }
352
353   public function getHostname()
354   {
355     return $this->mailer->Host;
356   }
357
358   public function setPort($port)
359   {
360     $this->mailer->Port = $port;
361   }
362
363   public function getPort()
364   {
365     return $this->mailer->Port;
366   }
367
368   public function setUsername($username)
369   {
370     $this->mailer->Username = $username;
371     $this->mailer->SMTPAuth = $username ? true : false;
372   }
373
374   public function getUsername()
375   {
376     return $this->mailer->Username;
377   }
378
379   public function setPassword($password)
380   {
381     $this->mailer->Password = $password;
382   }
383
384   public function getPassword()
385   {
386     return $this->mailer->Password;
387   }
388
389   public function setWordWrap($wordWrap)
390   {
391     $this->mailer->WordWrap = $wordWrap;
392   }
393
394   public function getWordWrap()
395   {
396     return $this->mailer->WordWrap;
397   }
398
399   public function setAltBody($text)
400   {
401     $this->mailer->AltBody = $text;
402   }
403
404   public function getAltBody()
405   {
406     return $this->mailer->AltBody;
407   }
408 }
409
Note: See TracBrowser for help on using the browser.