1: <?php
2:
3: /**
4: * Jyxo PHP Library
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file license.txt.
10: * It is also available through the world-wide-web at this URL:
11: * https://github.com/jyxo/php/blob/master/license.txt
12: */
13:
14: /**
15: * Inline mail attachment created from a string.
16: *
17: * @category Jyxo
18: * @package Jyxo_Mail
19: * @subpackage Email
20: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
21: * @license https://github.com/jyxo/php/blob/master/license.txt
22: * @author Jaroslav HanslĂk
23: */
24: class Jyxo_Mail_Email_Attachment_InlineString extends Jyxo_Mail_Email_Attachment
25: {
26: /**
27: * Type.
28: *
29: * @var string
30: */
31: protected $disposition = Jyxo_Mail_Email_Attachment::DISPOSITION_INLINE;
32:
33: /**
34: * Creates an attachment.
35: *
36: * @param string $content File contents
37: * @param string $name Attachment name
38: * @param string $cid Id
39: * @param string $mimeType Attachment mime-type
40: * @param string $encoding Source encoding
41: */
42: public function __construct($content, $name, $cid, $mimeType = 'application/octet-stream', $encoding = '')
43: {
44: $this->setContent($content);
45: $this->setName($name);
46: $this->setCid($cid);
47: $this->setMimeType($mimeType);
48: $this->setEncoding($encoding);
49: }
50:
51: /**
52: * Sets Id.
53: *
54: * @param string $cid
55: * @return Jyxo_Mail_Email_Attachment_InlineString
56: */
57: public function setCid($cid)
58: {
59: $this->cid = (string) $cid;
60:
61: return $this;
62: }
63:
64: /**
65: * Sets contents encoding.
66: * If none is set, assume no encoding is used.
67: *
68: * @param string $encoding Encoding name
69: * @return Jyxo_Mail_Email_Attachment_InlineString
70: * @throws InvalidArgumentException If an incompatible encoding was provided
71: */
72: public function setEncoding($encoding)
73: {
74: if ((!empty($encoding)) && (!Jyxo_Mail_Encoding::isCompatible($encoding))) {
75: throw new InvalidArgumentException(sprintf('Incompatible encoding %s', $encoding));
76: }
77:
78: $this->encoding = (string) $encoding;
79:
80: return $this;
81: }
82: }
83: