Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: 
  3: /*
  4:  * This file is part of SwiftMailer.
  5:  * (c) 2004-2009 Chris Corbyn
  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:  * The default email message class.
 13:  * @package Swift
 14:  * @subpackage Mime
 15:  * @author Chris Corbyn
 16:  */
 17: class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime_Message
 18: {
 19:     /**
 20:      * Create a new SimpleMessage with $headers, $encoder and $cache.
 21:      * @param Swift_Mime_HeaderSet      $headers
 22:      * @param Swift_Mime_ContentEncoder $encoder
 23:      * @param Swift_KeyCache            $cache
 24:      * @param Swift_Mime_Grammar        $grammar
 25:      * @param string                    $charset
 26:      */
 27:     public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar, $charset = null)
 28:     {
 29:         parent::__construct($headers, $encoder, $cache, $grammar, $charset);
 30:         $this->getHeaders()->defineOrdering(array(
 31:             'Return-Path',
 32:             'Sender',
 33:             'Message-ID',
 34:             'Date',
 35:             'Subject',
 36:             'From',
 37:             'Reply-To',
 38:             'To',
 39:             'Cc',
 40:             'Bcc',
 41:             'MIME-Version',
 42:             'Content-Type',
 43:             'Content-Transfer-Encoding'
 44:             ));
 45:         $this->getHeaders()->setAlwaysDisplayed(
 46:             array('Date', 'Message-ID', 'From')
 47:             );
 48:         $this->getHeaders()->addTextHeader('MIME-Version', '1.0');
 49:         $this->setDate(time());
 50:         $this->setId($this->getId());
 51:         $this->getHeaders()->addMailboxHeader('From');
 52:     }
 53: 
 54:     /**
 55:      * Always returns {@link LEVEL_TOP} for a message instance.
 56:      * @return int
 57:      */
 58:     public function getNestingLevel()
 59:     {
 60:         return self::LEVEL_TOP;
 61:     }
 62: 
 63:     /**
 64:      * Set the subject of this message.
 65:      * @param  string                   $subject
 66:      * @return Swift_Mime_SimpleMessage
 67:      */
 68:     public function setSubject($subject)
 69:     {
 70:         if (!$this->_setHeaderFieldModel('Subject', $subject)) {
 71:             $this->getHeaders()->addTextHeader('Subject', $subject);
 72:         }
 73: 
 74:         return $this;
 75:     }
 76: 
 77:     /**
 78:      * Get the subject of this message.
 79:      * @return string
 80:      */
 81:     public function getSubject()
 82:     {
 83:         return $this->_getHeaderFieldModel('Subject');
 84:     }
 85: 
 86:     /**
 87:      * Set the date at which this message was created.
 88:      * @param  int                      $date
 89:      * @return Swift_Mime_SimpleMessage
 90:      */
 91:     public function setDate($date)
 92:     {
 93:         if (!$this->_setHeaderFieldModel('Date', $date)) {
 94:             $this->getHeaders()->addDateHeader('Date', $date);
 95:         }
 96: 
 97:         return $this;
 98:     }
 99: 
100:     /**
101:      * Get the date at which this message was created.
102:      * @return int
103:      */
104:     public function getDate()
105:     {
106:         return $this->_getHeaderFieldModel('Date');
107:     }
108: 
109:     /**
110:      * Set the return-path (the bounce address) of this message.
111:      * @param  string                   $address
112:      * @return Swift_Mime_SimpleMessage
113:      */
114:     public function setReturnPath($address)
115:     {
116:         if (!$this->_setHeaderFieldModel('Return-Path', $address)) {
117:             $this->getHeaders()->addPathHeader('Return-Path', $address);
118:         }
119: 
120:         return $this;
121:     }
122: 
123:     /**
124:      * Get the return-path (bounce address) of this message.
125:      * @return string
126:      */
127:     public function getReturnPath()
128:     {
129:         return $this->_getHeaderFieldModel('Return-Path');
130:     }
131: 
132:     /**
133:      * Set the sender of this message.
134:      * This does not override the From field, but it has a higher significance.
135:      * @param  string                   $sender
136:      * @param  string                   $name   optional
137:      * @return Swift_Mime_SimpleMessage
138:      */
139:     public function setSender($address, $name = null)
140:     {
141:         if (!is_array($address) && isset($name)) {
142:             $address = array($address => $name);
143:         }
144: 
145:         if (!$this->_setHeaderFieldModel('Sender', (array) $address)) {
146:             $this->getHeaders()->addMailboxHeader('Sender', (array) $address);
147:         }
148: 
149:         return $this;
150:     }
151: 
152:     /**
153:      * Get the sender of this message.
154:      * @return string
155:      */
156:     public function getSender()
157:     {
158:         return $this->_getHeaderFieldModel('Sender');
159:     }
160: 
161:     /**
162:      * Add a From: address to this message.
163:      *
164:      * If $name is passed this name will be associated with the address.
165:      *
166:      * @param string $address
167:      * @param string $name    optional
168:      */
169:     public function addFrom($address, $name = null)
170:     {
171:         $current = $this->getFrom();
172:         $current[$address] = $name;
173: 
174:         return $this->setFrom($current);
175:     }
176: 
177:     /**
178:      * Set the from address of this message.
179:      *
180:      * You may pass an array of addresses if this message is from multiple people.
181:      *
182:      * If $name is passed and the first parameter is a string, this name will be
183:      * associated with the address.
184:      *
185:      * @param  string                   $addresses
186:      * @param  string                   $name      optional
187:      * @return Swift_Mime_SimpleMessage
188:      */
189:     public function setFrom($addresses, $name = null)
190:     {
191:         if (!is_array($addresses) && isset($name)) {
192:             $addresses = array($addresses => $name);
193:         }
194: 
195:         if (!$this->_setHeaderFieldModel('From', (array) $addresses)) {
196:             $this->getHeaders()->addMailboxHeader('From', (array) $addresses);
197:         }
198: 
199:         return $this;
200:     }
201: 
202:     /**
203:      * Get the from address of this message.
204:      *
205:      * @return string
206:      */
207:     public function getFrom()
208:     {
209:         return $this->_getHeaderFieldModel('From');
210:     }
211: 
212:     /**
213:      * Add a Reply-To: address to this message.
214:      *
215:      * If $name is passed this name will be associated with the address.
216:      *
217:      * @param  string                   $address
218:      * @param  string                   $name    optional
219:      * @return Swift_Mime_SimpleMessage
220:      */
221:     public function addReplyTo($address, $name = null)
222:     {
223:         $current = $this->getReplyTo();
224:         $current[$address] = $name;
225: 
226:         return $this->setReplyTo($current);
227:     }
228: 
229:     /**
230:      * Set the reply-to address of this message.
231:      *
232:      * You may pass an array of addresses if replies will go to multiple people.
233:      *
234:      * If $name is passed and the first parameter is a string, this name will be
235:      * associated with the address.
236:      *
237:      * @param  string                   $addresses
238:      * @param  string                   $name      optional
239:      * @return Swift_Mime_SimpleMessage
240:      */
241:     public function setReplyTo($addresses, $name = null)
242:     {
243:         if (!is_array($addresses) && isset($name)) {
244:             $addresses = array($addresses => $name);
245:         }
246: 
247:         if (!$this->_setHeaderFieldModel('Reply-To', (array) $addresses)) {
248:             $this->getHeaders()->addMailboxHeader('Reply-To', (array) $addresses);
249:         }
250: 
251:         return $this;
252:     }
253: 
254:     /**
255:      * Get the reply-to address of this message.
256:      *
257:      * @return string
258:      */
259:     public function getReplyTo()
260:     {
261:         return $this->_getHeaderFieldModel('Reply-To');
262:     }
263: 
264:     /**
265:      * Add a To: address to this message.
266:      *
267:      * If $name is passed this name will be associated with the address.
268:      *
269:      * @param  string                   $address
270:      * @param  string                   $name    optional
271:      * @return Swift_Mime_SimpleMessage
272:      */
273:     public function addTo($address, $name = null)
274:     {
275:         $current = $this->getTo();
276:         $current[$address] = $name;
277: 
278:         return $this->setTo($current);
279:     }
280: 
281:     /**
282:      * Set the to addresses of this message.
283:      *
284:      * If multiple recipients will receive the message and array should be used.
285:      *
286:      * If $name is passed and the first parameter is a string, this name will be
287:      * associated with the address.
288:      *
289:      * @param  array                    $addresses
290:      * @param  string                   $name      optional
291:      * @return Swift_Mime_SimpleMessage
292:      */
293:     public function setTo($addresses, $name = null)
294:     {
295:         if (!is_array($addresses) && isset($name)) {
296:             $addresses = array($addresses => $name);
297:         }
298: 
299:         if (!$this->_setHeaderFieldModel('To', (array) $addresses)) {
300:             $this->getHeaders()->addMailboxHeader('To', (array) $addresses);
301:         }
302: 
303:         return $this;
304:     }
305: 
306:     /**
307:      * Get the To addresses of this message.
308:      *
309:      * @return array
310:      */
311:     public function getTo()
312:     {
313:         return $this->_getHeaderFieldModel('To');
314:     }
315: 
316:     /**
317:      * Add a Cc: address to this message.
318:      *
319:      * If $name is passed this name will be associated with the address.
320:      *
321:      * @param  string                   $address
322:      * @param  string                   $name    optional
323:      * @return Swift_Mime_SimpleMessage
324:      */
325:     public function addCc($address, $name = null)
326:     {
327:         $current = $this->getCc();
328:         $current[$address] = $name;
329: 
330:         return $this->setCc($current);
331:     }
332: 
333:     /**
334:      * Set the Cc addresses of this message.
335:      *
336:      * If $name is passed and the first parameter is a string, this name will be
337:      * associated with the address.
338:      *
339:      * @param  array                    $addresses
340:      * @param  string                   $name      optional
341:      * @return Swift_Mime_SimpleMessage
342:      */
343:     public function setCc($addresses, $name = null)
344:     {
345:         if (!is_array($addresses) && isset($name)) {
346:             $addresses = array($addresses => $name);
347:         }
348: 
349:         if (!$this->_setHeaderFieldModel('Cc', (array) $addresses)) {
350:             $this->getHeaders()->addMailboxHeader('Cc', (array) $addresses);
351:         }
352: 
353:         return $this;
354:     }
355: 
356:     /**
357:      * Get the Cc address of this message.
358:      *
359:      * @return array
360:      */
361:     public function getCc()
362:     {
363:         return $this->_getHeaderFieldModel('Cc');
364:     }
365: 
366:     /**
367:      * Add a Bcc: address to this message.
368:      *
369:      * If $name is passed this name will be associated with the address.
370:      *
371:      * @param  string                   $address
372:      * @param  string                   $name    optional
373:      * @return Swift_Mime_SimpleMessage
374:      */
375:     public function addBcc($address, $name = null)
376:     {
377:         $current = $this->getBcc();
378:         $current[$address] = $name;
379: 
380:         return $this->setBcc($current);
381:     }
382: 
383:     /**
384:      * Set the Bcc addresses of this message.
385:      *
386:      * If $name is passed and the first parameter is a string, this name will be
387:      * associated with the address.
388:      *
389:      * @param  array                    $addresses
390:      * @param  string                   $name      optional
391:      * @return Swift_Mime_SimpleMessage
392:      */
393:     public function setBcc($addresses, $name = null)
394:     {
395:         if (!is_array($addresses) && isset($name)) {
396:             $addresses = array($addresses => $name);
397:         }
398: 
399:         if (!$this->_setHeaderFieldModel('Bcc', (array) $addresses)) {
400:             $this->getHeaders()->addMailboxHeader('Bcc', (array) $addresses);
401:         }
402: 
403:         return $this;
404:     }
405: 
406:     /**
407:      * Get the Bcc addresses of this message.
408:      *
409:      * @return array
410:      */
411:     public function getBcc()
412:     {
413:         return $this->_getHeaderFieldModel('Bcc');
414:     }
415: 
416:     /**
417:      * Set the priority of this message.
418:      * The value is an integer where 1 is the highest priority and 5 is the lowest.
419:      * @param  int                      $priority
420:      * @return Swift_Mime_SimpleMessage
421:      */
422:     public function setPriority($priority)
423:     {
424:         $priorityMap = array(
425:             1 => 'Highest',
426:             2 => 'High',
427:             3 => 'Normal',
428:             4 => 'Low',
429:             5 => 'Lowest'
430:             );
431:         $pMapKeys = array_keys($priorityMap);
432:         if ($priority > max($pMapKeys)) {
433:             $priority = max($pMapKeys);
434:         } elseif ($priority < min($pMapKeys)) {
435:             $priority = min($pMapKeys);
436:         }
437:         if (!$this->_setHeaderFieldModel('X-Priority',
438:             sprintf('%d (%s)', $priority, $priorityMap[$priority])))
439:         {
440:             $this->getHeaders()->addTextHeader('X-Priority',
441:                 sprintf('%d (%s)', $priority, $priorityMap[$priority]));
442:         }
443: 
444:         return $this;
445:     }
446: 
447:     /**
448:      * Get the priority of this message.
449:      * The returned value is an integer where 1 is the highest priority and 5
450:      * is the lowest.
451:      * @return int
452:      */
453:     public function getPriority()
454:     {
455:         list($priority) = sscanf($this->_getHeaderFieldModel('X-Priority'),
456:             '%[1-5]'
457:             );
458: 
459:         return isset($priority) ? $priority : 3;
460:     }
461: 
462:     /**
463:      * Ask for a delivery receipt from the recipient to be sent to $addresses
464:      * @param  array                    $addresses
465:      * @return Swift_Mime_SimpleMessage
466:      */
467:     public function setReadReceiptTo($addresses)
468:     {
469:         if (!$this->_setHeaderFieldModel('Disposition-Notification-To', $addresses)) {
470:             $this->getHeaders()
471:                 ->addMailboxHeader('Disposition-Notification-To', $addresses);
472:         }
473: 
474:         return $this;
475:     }
476: 
477:     /**
478:      * Get the addresses to which a read-receipt will be sent.
479:      * @return string
480:      */
481:     public function getReadReceiptTo()
482:     {
483:         return $this->_getHeaderFieldModel('Disposition-Notification-To');
484:     }
485: 
486:     /**
487:      * Attach a {@link Swift_Mime_MimeEntity} such as an Attachment or MimePart.
488:      * @param  Swift_Mime_MimeEntity    $entity
489:      * @return Swift_Mime_SimpleMessage
490:      */
491:     public function attach(Swift_Mime_MimeEntity $entity)
492:     {
493:         $this->setChildren(array_merge($this->getChildren(), array($entity)));
494: 
495:         return $this;
496:     }
497: 
498:     /**
499:      * Remove an already attached entity.
500:      * @param  Swift_Mime_MimeEntity    $entity
501:      * @return Swift_Mime_SimpleMessage
502:      */
503:     public function detach(Swift_Mime_MimeEntity $entity)
504:     {
505:         $newChildren = array();
506:         foreach ($this->getChildren() as $child) {
507:             if ($entity !== $child) {
508:                 $newChildren[] = $child;
509:             }
510:         }
511:         $this->setChildren($newChildren);
512: 
513:         return $this;
514:     }
515: 
516:     /**
517:      * Attach a {@link Swift_Mime_MimeEntity} and return it's CID source.
518:      * This method should be used when embedding images or other data in a message.
519:      * @param  Swift_Mime_MimeEntity $entity
520:      * @return string
521:      */
522:     public function embed(Swift_Mime_MimeEntity $entity)
523:     {
524:         $this->attach($entity);
525: 
526:         return 'cid:' . $entity->getId();
527:     }
528: 
529:     /**
530:      * Get this message as a complete string.
531:      * @return string
532:      */
533:     public function toString()
534:     {
535:         if (count($children = $this->getChildren()) > 0 && $this->getBody() != '') {
536:             $this->setChildren(array_merge(array($this->_becomeMimePart()), $children));
537:             $string = parent::toString();
538:             $this->setChildren($children);
539:         } else {
540:             $string = parent::toString();
541:         }
542: 
543:         return $string;
544:     }
545: 
546:     /**
547:      * Returns a string representation of this object.
548:      *
549:      * @return string
550:      *
551:      * @see toString()
552:      */
553:     public function __toString()
554:     {
555:         return $this->toString();
556:     }
557: 
558:     /**
559:      * Write this message to a {@link Swift_InputByteStream}.
560:      * @param Swift_InputByteStream $is
561:      */
562:     public function toByteStream(Swift_InputByteStream $is)
563:     {
564:         if (count($children = $this->getChildren()) > 0 && $this->getBody() != '') {
565:             $this->setChildren(array_merge(array($this->_becomeMimePart()), $children));
566:             parent::toByteStream($is);
567:             $this->setChildren($children);
568:         } else {
569:             parent::toByteStream($is);
570:         }
571:     }
572: 
573:     // -- Protected methods
574: 
575:     /** @see Swift_Mime_SimpleMimeEntity::_getIdField() */
576:     protected function _getIdField()
577:     {
578:         return 'Message-ID';
579:     }
580: 
581:     // -- Private methods
582: 
583:     /** Turn the body of this message into a child of itself if needed */
584:     private function _becomeMimePart()
585:     {
586:         $part = new parent($this->getHeaders()->newInstance(), $this->getEncoder(),
587:             $this->_getCache(), $this->_getGrammar(), $this->_userCharset
588:             );
589:         $part->setContentType($this->_userContentType);
590:         $part->setBody($this->getBody());
591:         $part->setFormat($this->_userFormat);
592:         $part->setDelSp($this->_userDelSp);
593:         $part->_setNestingLevel($this->_getTopNestingLevel());
594: 
595:         return $part;
596:     }
597: 
598:     /** Get the highest nesting level nested inside this message */
599:     private function _getTopNestingLevel()
600:     {
601:         $highestLevel = $this->getNestingLevel();
602:         foreach ($this->getChildren() as $child) {
603:             $childLevel = $child->getNestingLevel();
604:             if ($highestLevel < $childLevel) {
605:                 $highestLevel = $childLevel;
606:             }
607:         }
608: 
609:         return $highestLevel;
610:     }
611: }
612: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen