Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Message often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Message, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class Message extends MimePart |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var string unique ID used to identify the object to |
||
| 31 | * $this->partStreamRegistry when registering the stream. The ID is |
||
| 32 | * used for opening stream parts with the mmp-mime-message "protocol". |
||
| 33 | * |
||
| 34 | * @see \ZBateson\MailMimeParser\SimpleDi::registerStreamExtensions |
||
| 35 | * @see \ZBateson\MailMimeParser\Stream\PartStream::stream_open |
||
| 36 | */ |
||
| 37 | protected $objectId; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var \ZBateson\MailMimeParser\Message\MimePart represents the content portion of |
||
| 41 | * the email message. It is assigned either a text or HTML part, or a |
||
| 42 | * MultipartAlternativePart |
||
| 43 | */ |
||
| 44 | protected $contentPart; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var \ZBateson\MailMimeParser\Message\MimePart contains the body of the signature |
||
| 48 | * for a multipart/signed message. |
||
| 49 | */ |
||
| 50 | protected $signedSignaturePart; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var \ZBateson\MailMimeParser\Message\MimePart[] array of non-content parts in |
||
| 54 | * this message |
||
| 55 | */ |
||
| 56 | protected $attachmentParts = []; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var \ZBateson\MailMimeParser\Message\MimePartFactory a MimePartFactory to create |
||
| 60 | * parts for attachments/content |
||
| 61 | */ |
||
| 62 | protected $mimePartFactory; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var \ZBateson\MailMimeParser\Message\Writer\MessageWriter the part |
||
| 66 | * writer for this Message. The same object is assigned to $partWriter |
||
| 67 | * but as an AbstractWriter -- not really needed in PHP but helps with |
||
| 68 | * auto-complete and code analyzers. |
||
| 69 | */ |
||
| 70 | protected $messageWriter = null; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var bool set to true if a newline should be inserted before the next |
||
| 74 | * boundary (signed messages are finicky) |
||
| 75 | */ |
||
| 76 | private $insertNewLineBeforeBoundary = false; |
||
|
|
|||
| 77 | |||
| 78 | /** |
||
| 79 | * Convenience method to parse a handle or string into a Message without |
||
| 80 | * requiring including MailMimeParser, instantiating it, and calling parse. |
||
| 81 | * |
||
| 82 | * @param resource|string $handleOrString the resource handle to the input |
||
| 83 | * stream of the mime message, or a string containing a mime message |
||
| 84 | */ |
||
| 85 | 1 | public static function from($handleOrString) |
|
| 86 | { |
||
| 87 | 1 | $mmp = new MailMimeParser(); |
|
| 88 | 1 | return $mmp->parse($handleOrString); |
|
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Constructs a Message. |
||
| 93 | * |
||
| 94 | * @param HeaderFactory $headerFactory |
||
| 95 | * @param MessageWriter $messageWriter |
||
| 96 | * @param MimePartFactory $mimePartFactory |
||
| 97 | */ |
||
| 98 | 89 | public function __construct( |
|
| 99 | HeaderFactory $headerFactory, |
||
| 100 | MessageWriter $messageWriter, |
||
| 101 | MimePartFactory $mimePartFactory |
||
| 102 | ) { |
||
| 103 | 89 | parent::__construct($headerFactory, $messageWriter); |
|
| 104 | 89 | $this->messageWriter = $messageWriter; |
|
| 105 | 89 | $this->mimePartFactory = $mimePartFactory; |
|
| 106 | 89 | $this->objectId = uniqid(); |
|
| 107 | 89 | } |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Returns the unique object ID registered with the PartStreamRegistry |
||
| 111 | * service object. |
||
| 112 | * |
||
| 113 | * @return string |
||
| 114 | */ |
||
| 115 | 84 | public function getObjectId() |
|
| 116 | { |
||
| 117 | 84 | return $this->objectId; |
|
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Returns true if the $part should be assigned as this message's main |
||
| 122 | * content part. |
||
| 123 | * |
||
| 124 | * @param \ZBateson\MailMimeParser\Message\MimePart $part |
||
| 125 | * @return bool |
||
| 126 | */ |
||
| 127 | 84 | private function addContentPartFromParsed(MimePart $part) |
|
| 128 | { |
||
| 129 | 84 | $type = strtolower($part->getHeaderValue('Content-Type', 'text/plain')); |
|
| 130 | // separate if statements for clarity |
||
| 131 | if ($type === 'multipart/alternative' |
||
| 132 | 84 | || $type === 'text/plain' |
|
| 133 | 84 | || $type === 'text/html') { |
|
| 134 | 81 | if ($this->contentPart === null) { |
|
| 135 | 81 | $this->contentPart = $part; |
|
| 136 | 81 | } |
|
| 137 | 81 | return true; |
|
| 138 | } |
||
| 139 | 51 | return false; |
|
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Adds the passed part to the message with the passed position, or at the |
||
| 144 | * end if not passed. |
||
| 145 | * |
||
| 146 | * This should not be used by a user directly and will be set 'protected' in |
||
| 147 | * the future. Instead setTextPart, setHtmlPart and addAttachment should be |
||
| 148 | * used. |
||
| 149 | * |
||
| 150 | * @param \ZBateson\MailMimeParser\Message\MimePart $part |
||
| 151 | * @param int $position |
||
| 152 | */ |
||
| 153 | 87 | public function addPart(MimePart $part, $position = null) |
|
| 154 | { |
||
| 155 | 87 | parent::addPart($part, $position); |
|
| 156 | 87 | $disposition = $part->getHeaderValue('Content-Disposition'); |
|
| 157 | 87 | $mtype = $this->getHeaderValue('Content-Type'); |
|
| 158 | 87 | $protocol = $this->getHeaderParameter('Content-Type', 'protocol'); |
|
| 159 | 87 | $type = $part->getHeaderValue('Content-Type'); |
|
| 160 | 87 | if (strcasecmp($mtype, 'multipart/signed') === 0 && $protocol !== null && $part->getParent() === $this && strcasecmp($protocol, $type) === 0) { |
|
| 161 | 12 | $this->signedSignaturePart = $part; |
|
| 162 | 87 | } else if (($disposition !== null || !$this->addContentPartFromParsed($part)) && !$part->isMultiPart()) { |
|
| 163 | 53 | $this->attachmentParts[] = $part; |
|
| 164 | 53 | } |
|
| 165 | 87 | } |
|
| 166 | |||
| 167 | /** |
||
| 168 | * Returns the content part (or null) for the passed mime type looking at |
||
| 169 | * the assigned content part, and if it's a multipart/alternative part, |
||
| 170 | * looking to find an alternative part of the passed mime type. |
||
| 171 | * |
||
| 172 | * @param string $mimeType |
||
| 173 | * @return \ZBateson\MailMimeParser\Message\MimePart or null if not |
||
| 174 | * available |
||
| 175 | */ |
||
| 176 | 74 | protected function getContentPartByMimeType($mimeType) |
|
| 177 | { |
||
| 178 | 74 | if (!isset($this->contentPart)) { |
|
| 179 | 2 | return null; |
|
| 180 | } |
||
| 181 | 73 | $type = strtolower($this->contentPart->getHeaderValue('Content-Type', 'text/plain')); |
|
| 182 | 73 | if ($type === 'multipart/alternative') { |
|
| 183 | 22 | return $this->getPartByMimeType($mimeType); |
|
| 184 | 55 | } elseif ($type === $mimeType) { |
|
| 185 | 53 | return $this->contentPart; |
|
| 186 | } |
||
| 187 | 11 | return null; |
|
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Sets the content of the message to the content of the passed part, for a |
||
| 192 | * message with a multipart/alternative content type where the other part |
||
| 193 | * has been removed, and this is the only remaining part. |
||
| 194 | * |
||
| 195 | * @param \ZBateson\MailMimeParser\Message\MimePart $part |
||
| 196 | */ |
||
| 197 | 2 | private function overrideAlternativeMessageContentFromContentPart(MimePart $part) |
|
| 198 | { |
||
| 199 | 2 | $contentType = $part->getHeaderValue('Content-Type'); |
|
| 200 | 2 | if ($contentType === null) { |
|
| 201 | $contentType = 'text/plain; charset="us-ascii"'; |
||
| 202 | } |
||
| 203 | 2 | $this->setRawHeader( |
|
| 204 | 2 | 'Content-Type', |
|
| 205 | $contentType |
||
| 206 | 2 | ); |
|
| 207 | 2 | $this->setRawHeader( |
|
| 208 | 2 | 'Content-Transfer-Encoding', |
|
| 209 | 'quoted-printable' |
||
| 210 | 2 | ); |
|
| 211 | 2 | $this->attachContentResourceHandle($part->getContentResourceHandle()); |
|
| 212 | 2 | $part->detachContentResourceHandle(); |
|
| 213 | 2 | $this->removePart($part); |
|
| 214 | 2 | } |
|
| 215 | |||
| 216 | /** |
||
| 217 | * Removes the passed MimePart as a content part. If there's a remaining |
||
| 218 | * part, either sets the content on this message if the message itself is a |
||
| 219 | * multipart/alternative message, or overrides the contentPart with the |
||
| 220 | * remaining part. |
||
| 221 | * |
||
| 222 | * @param \ZBateson\MailMimeParser\Message\MimePart $part |
||
| 223 | */ |
||
| 224 | 3 | private function removePartFromAlternativeContentPart(MimePart $part) |
|
| 225 | { |
||
| 226 | 3 | $this->removePart($part); |
|
| 227 | 3 | if ($this->contentPart === $this) { |
|
| 228 | 2 | $this->overrideAlternativeMessageContentFromContentPart($this->getPart(0)); |
|
| 229 | 3 | } elseif ($this->contentPart->getPartCount() === 1) { |
|
| 230 | 1 | $this->removePart($this->contentPart); |
|
| 231 | 1 | $contentPart = $this->contentPart->getChild(0); |
|
| 232 | 1 | $contentPart->setParent($this); |
|
| 233 | 1 | $this->contentPart = null; |
|
| 234 | 1 | $this->addPart($contentPart, 0); |
|
| 235 | 1 | } |
|
| 236 | 3 | } |
|
| 237 | |||
| 238 | /** |
||
| 239 | * Loops over children of the content part looking for a part with the |
||
| 240 | * passed mime type, then proceeds to remove it by calling |
||
| 241 | * removePartFromAlternativeContentPart. |
||
| 242 | * |
||
| 243 | * @param string $contentType |
||
| 244 | * @return boolean true on success |
||
| 245 | */ |
||
| 246 | 3 | private function removeContentPartFromAlternative($contentType) |
|
| 247 | { |
||
| 248 | 3 | $parts = $this->contentPart->getAllParts(); |
|
| 249 | 3 | foreach ($parts as $part) { |
|
| 250 | 3 | $type = $part->getHeaderValue('Content-Type', 'text/plain'); |
|
| 251 | 3 | if (strcasecmp($type, $contentType) === 0) { |
|
| 252 | 3 | $this->removePartFromAlternativeContentPart($part); |
|
| 253 | 3 | return true; |
|
| 254 | } |
||
| 255 | 2 | } |
|
| 256 | return false; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Removes the content part of the message with the passed mime type. If |
||
| 261 | * there is a remaining content part and it is an alternative part of the |
||
| 262 | * main message, the content part is moved to the message part. |
||
| 263 | * |
||
| 264 | * If the content part is part of an alternative part beneath the message, |
||
| 265 | * the alternative part is replaced by the remaining content part. |
||
| 266 | * |
||
| 267 | * @param string $contentType |
||
| 268 | * @return boolean true on success |
||
| 269 | */ |
||
| 270 | 3 | protected function removeContentPart($contentType) |
|
| 271 | { |
||
| 272 | 3 | if (!isset($this->contentPart)) { |
|
| 273 | return false; |
||
| 274 | } |
||
| 275 | 3 | $type = $this->contentPart->getHeaderValue('Content-Type', 'text/plain'); |
|
| 276 | 3 | if (strcasecmp($type, $contentType) === 0) { |
|
| 277 | if ($this->contentPart === $this) { |
||
| 278 | return false; |
||
| 279 | } |
||
| 280 | $this->removePart($this->contentPart); |
||
| 281 | $this->contentPart = null; |
||
| 282 | return true; |
||
| 283 | } |
||
| 284 | 3 | return $this->removeContentPartFromAlternative($contentType); |
|
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Returns the text part (or null if none is set.) |
||
| 289 | * |
||
| 290 | * @return \ZBateson\MailMimeParser\Message\MimePart |
||
| 291 | */ |
||
| 292 | 64 | public function getTextPart() |
|
| 293 | { |
||
| 294 | 64 | return $this->getContentPartByMimeType('text/plain'); |
|
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Returns the HTML part (or null if none is set.) |
||
| 299 | * |
||
| 300 | * @return \ZBateson\MailMimeParser\Message\MimePart |
||
| 301 | */ |
||
| 302 | 36 | public function getHtmlPart() |
|
| 303 | { |
||
| 304 | 36 | return $this->getContentPartByMimeType('text/html'); |
|
| 305 | } |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Returns the content MimePart, which could be a text/plain, text/html or |
||
| 309 | * multipart/alternative part or null if none is set. |
||
| 310 | * |
||
| 311 | * @return \ZBateson\MailMimeParser\Message\MimePart |
||
| 312 | */ |
||
| 313 | 1 | public function getContentPart() |
|
| 314 | { |
||
| 315 | 1 | return $this->contentPart; |
|
| 316 | } |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Returns an open resource handle for the passed string or resource handle. |
||
| 320 | * |
||
| 321 | * For a string, creates a php://temp stream and returns it. |
||
| 322 | * |
||
| 323 | * @param resource|string $stringOrHandle |
||
| 324 | * @return resource |
||
| 325 | */ |
||
| 326 | 5 | private function getHandleForStringOrHandle($stringOrHandle) |
|
| 337 | |||
| 338 | /** |
||
| 339 | * Creates and returns a unique boundary. |
||
| 340 | * |
||
| 341 | * @param string $mimeType first 3 characters of a multipart type are used, |
||
| 342 | * e.g. REL for relative or ALT for alternative |
||
| 343 | * @return string |
||
| 344 | */ |
||
| 345 | 14 | private function getUniqueBoundary($mimeType) |
|
| 346 | { |
||
| 347 | 14 | $type = ltrim(strtoupper(preg_replace('/^(multipart\/(.{3}).*|.*)$/i', '$2-', $mimeType)), '-'); |
|
| 348 | 14 | return uniqid('----=MMP-' . $type . $this->objectId . '.', true); |
|
| 349 | } |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Creates a unique mime boundary and assigns it to the passed part's |
||
| 353 | * Content-Type header with the passed mime type. |
||
| 354 | * |
||
| 355 | * @param \ZBateson\MailMimeParser\Message\MimePart $part |
||
| 356 | * @param string $mimeType |
||
| 357 | */ |
||
| 358 | 7 | private function setMimeHeaderBoundaryOnPart(MimePart $part, $mimeType) |
|
| 366 | |||
| 367 | /** |
||
| 368 | * Sets this message to be a multipart/alternative message, making space for |
||
| 369 | * another alternative content part. |
||
| 370 | * |
||
| 371 | * Creates a content part and assigns the content stream from the message to |
||
| 372 | * that newly created part. |
||
| 373 | */ |
||
| 374 | 2 | private function setMessageAsAlternative() |
|
| 392 | |||
| 393 | /** |
||
| 394 | * Creates a new mime part as a multipart/alternative, assigning it to |
||
| 395 | * $this->contentPart. Adds the current contentPart below the newly created |
||
| 396 | * alternative part. |
||
| 397 | */ |
||
| 398 | 2 | View Code Duplication | private function createAlternativeContentPart() |
| 410 | |||
| 411 | /** |
||
| 412 | * Copies Content-Type, Content-Disposition and Content-Transfer-Encoding |
||
| 413 | * headers from the $from header into the $to header. If the Content-Type |
||
| 414 | * header isn't defined in $from, defaults to text/plain and |
||
| 415 | * quoted-printable. |
||
| 416 | * |
||
| 417 | * @param \ZBateson\MailMimeParser\Message\MimePart $from |
||
| 418 | * @param \ZBateson\MailMimeParser\Message\MimePart $to |
||
| 419 | */ |
||
| 420 | 11 | private function copyTypeHeadersFromPartToPart(MimePart $from, MimePart $to) |
|
| 438 | |||
| 439 | /** |
||
| 440 | * Creates a new content part from the passed part, allowing the part to be |
||
| 441 | * used for something else (e.g. changing a non-mime message to a multipart |
||
| 442 | * mime message). |
||
| 443 | */ |
||
| 444 | 4 | private function createNewContentPartFromPart(MimePart $part) |
|
| 452 | |||
| 453 | /** |
||
| 454 | * Creates a new part out of the current contentPart and sets the message's |
||
| 455 | * type to be multipart/mixed. |
||
| 456 | */ |
||
| 457 | 4 | private function setMessageAsMixed() |
|
| 465 | |||
| 466 | /** |
||
| 467 | * This function makes space by moving the main message part down one level. |
||
| 468 | * |
||
| 469 | * The content-type, content-disposition and content-transfer-encoding |
||
| 470 | * headers are copied from this message to the newly created part, the |
||
| 471 | * resource handle is moved and detached, any attachments and content parts |
||
| 472 | * with parents set to this message get their parents set to the newly |
||
| 473 | * created part. |
||
| 474 | */ |
||
| 475 | 8 | private function makeSpaceForMultipartSignedMessage() |
|
| 496 | |||
| 497 | /** |
||
| 498 | * Creates and returns a new MimePart for the signature part of a |
||
| 499 | * multipart/signed message and assigns it to $this->signedSignaturePart. |
||
| 500 | * |
||
| 501 | * @param string $body |
||
| 502 | */ |
||
| 503 | 8 | View Code Duplication | public function createSignaturePart($body) |
| 518 | |||
| 519 | /** |
||
| 520 | * Loops over parts of this message and sets the content-transfer-encoding |
||
| 521 | * header to quoted-printable for text/* mime parts, and to base64 |
||
| 522 | * otherwise for parts that are '8bit' encoded. |
||
| 523 | * |
||
| 524 | * Used for multipart/signed messages which doesn't support 8bit transfer |
||
| 525 | * encodings. |
||
| 526 | */ |
||
| 527 | 8 | private function overwrite8bitContentEncoding() |
|
| 540 | |||
| 541 | /** |
||
| 542 | * Ensures a non-text part comes first in a signed multipart/alternative |
||
| 543 | * message as some clients seem to prefer the first content part if the |
||
| 544 | * client doesn't understand multipart/signed. |
||
| 545 | */ |
||
| 546 | 8 | private function ensureHtmlPartFirstForSignedMessage() |
|
| 560 | |||
| 561 | /** |
||
| 562 | * Turns the message into a multipart/signed message, moving the actual |
||
| 563 | * message into a child part, sets the content-type of the main message to |
||
| 564 | * multipart/signed and adds a signature part as well. |
||
| 565 | * |
||
| 566 | * @param string $micalg The Message Integrity Check algorithm being used |
||
| 567 | * @param string $protocol The mime-type of the signature body |
||
| 568 | */ |
||
| 569 | 8 | public function setAsMultipartSigned($micalg, $protocol) |
|
| 585 | |||
| 586 | /** |
||
| 587 | * Returns the signed part or null if not set. |
||
| 588 | * |
||
| 589 | * @return \ZBateson\MailMimeParser\Message\MimePart |
||
| 590 | */ |
||
| 591 | 12 | public function getSignaturePart() |
|
| 595 | |||
| 596 | /** |
||
| 597 | * Enforces the message to be a mime message for a non-mime (e.g. uuencoded |
||
| 598 | * or unspecified) message. If the message has uuencoded attachments, sets |
||
| 599 | * up the message as a multipart/mixed message and creates a content part. |
||
| 600 | */ |
||
| 601 | 12 | private function enforceMime() |
|
| 612 | |||
| 613 | /** |
||
| 614 | * Creates a new content part for the passed mimeType and charset, making |
||
| 615 | * space by creating a multipart/alternative if needed |
||
| 616 | * |
||
| 617 | * @param string $mimeType |
||
| 618 | * @param string $charset |
||
| 619 | * @return \ZBateson\MailMimeParser\Message\MimePart |
||
| 620 | */ |
||
| 621 | 4 | private function createContentPartForMimeType($mimeType, $charset) |
|
| 645 | |||
| 646 | /** |
||
| 647 | * Either creates a mime part or sets the existing mime part with the passed |
||
| 648 | * mimeType to $strongOrHandle. |
||
| 649 | * |
||
| 650 | * @param string $mimeType |
||
| 651 | * @param string|resource $stringOrHandle |
||
| 652 | * @param string $charset |
||
| 653 | */ |
||
| 654 | 4 | protected function setContentPartForMimeType($mimeType, $stringOrHandle, $charset) |
|
| 667 | |||
| 668 | /** |
||
| 669 | * Sets the text/plain part of the message to the passed $stringOrHandle, |
||
| 670 | * either creating a new part if one doesn't exist for text/plain, or |
||
| 671 | * assigning the value of $stringOrHandle to an existing text/plain part. |
||
| 672 | * |
||
| 673 | * The optional $charset parameter is the charset for saving to. |
||
| 674 | * $stringOrHandle is expected to be in UTF-8. |
||
| 675 | * |
||
| 676 | * @param string|resource $stringOrHandle |
||
| 677 | * @param string $charset |
||
| 678 | */ |
||
| 679 | 1 | public function setTextPart($stringOrHandle, $charset = null) |
|
| 683 | |||
| 684 | /** |
||
| 685 | * Sets the text/html part of the message to the passed $stringOrHandle, |
||
| 686 | * either creating a new part if one doesn't exist for text/html, or |
||
| 687 | * assigning the value of $stringOrHandle to an existing text/html part. |
||
| 688 | * |
||
| 689 | * The optional $charset parameter is the charset for saving to. |
||
| 690 | * $stringOrHandle is expected to be in UTF-8. |
||
| 691 | * |
||
| 692 | * @param string|resource $stringOrHandle |
||
| 693 | * @param string $charset |
||
| 694 | */ |
||
| 695 | 4 | public function setHtmlPart($stringOrHandle, $charset = null) |
|
| 699 | |||
| 700 | /** |
||
| 701 | * Removes the text part of the message if one exists. Returns true on |
||
| 702 | * success. |
||
| 703 | * |
||
| 704 | * @return bool true on success |
||
| 705 | */ |
||
| 706 | 2 | public function removeTextPart() |
|
| 710 | |||
| 711 | /** |
||
| 712 | * Removes the html part of the message if one exists. Returns true on |
||
| 713 | * success. |
||
| 714 | * |
||
| 715 | * @return bool true on success |
||
| 716 | */ |
||
| 717 | 1 | public function removeHtmlPart() |
|
| 721 | |||
| 722 | /** |
||
| 723 | * Returns the non-content part at the given 0-based index, or null if none |
||
| 724 | * is set. |
||
| 725 | * |
||
| 726 | * @param int $index |
||
| 727 | * @return \ZBateson\MailMimeParser\Message\MimePart |
||
| 728 | */ |
||
| 729 | 7 | public function getAttachmentPart($index) |
|
| 736 | |||
| 737 | /** |
||
| 738 | * Returns all attachment parts. |
||
| 739 | * |
||
| 740 | * @return \ZBateson\MailMimeParser\Message\MimePart[] |
||
| 741 | */ |
||
| 742 | 47 | public function getAllAttachmentParts() |
|
| 746 | |||
| 747 | /** |
||
| 748 | * Returns the number of attachments available. |
||
| 749 | * |
||
| 750 | * @return int |
||
| 751 | */ |
||
| 752 | 48 | public function getAttachmentCount() |
|
| 756 | |||
| 757 | /** |
||
| 758 | * Removes the attachment with the given index |
||
| 759 | * |
||
| 760 | * @param int $index |
||
| 761 | */ |
||
| 762 | 2 | public function removeAttachmentPart($index) |
|
| 768 | |||
| 769 | /** |
||
| 770 | * Creates and returns a MimePart for use with a new attachment part being |
||
| 771 | * created. |
||
| 772 | * |
||
| 773 | * @return \ZBateson\MailMimeParser\Message\MimePart |
||
| 774 | */ |
||
| 775 | 2 | protected function createPartForAttachment() |
|
| 789 | |||
| 790 | /** |
||
| 791 | * Adds an attachment part for the passed raw data string or handle and |
||
| 792 | * given parameters. |
||
| 793 | * |
||
| 794 | * @param string|handle $stringOrHandle |
||
| 795 | * @param strubg $mimeType |
||
| 796 | * @param string $filename |
||
| 797 | * @param string $disposition |
||
| 798 | */ |
||
| 799 | 1 | public function addAttachmentPart($stringOrHandle, $mimeType, $filename = null, $disposition = 'attachment') |
|
| 812 | |||
| 813 | /** |
||
| 814 | * Adds an attachment part using the passed file. |
||
| 815 | * |
||
| 816 | * Essentially creates a file stream and uses it. |
||
| 817 | * |
||
| 818 | * @param string $file |
||
| 819 | * @param string $mimeType |
||
| 820 | * @param string $filename |
||
| 821 | * @param string $disposition |
||
| 822 | */ |
||
| 823 | 2 | public function addAttachmentPartFromFile($file, $mimeType, $filename = null, $disposition = 'attachment') |
|
| 837 | |||
| 838 | /** |
||
| 839 | * Returns a resource handle where the text content can be read or null if |
||
| 840 | * unavailable. |
||
| 841 | * |
||
| 842 | * @return resource |
||
| 843 | */ |
||
| 844 | 60 | public function getTextStream() |
|
| 852 | |||
| 853 | /** |
||
| 854 | * Returns the text content as a string. |
||
| 855 | * |
||
| 856 | * Reads the entire stream content into a string and returns it. Returns |
||
| 857 | * null if the message doesn't have a text part. |
||
| 858 | * |
||
| 859 | * @return string |
||
| 860 | */ |
||
| 861 | 1 | public function getTextContent() |
|
| 869 | |||
| 870 | /** |
||
| 871 | * Returns a resource handle where the HTML content can be read or null if |
||
| 872 | * unavailable. |
||
| 873 | * |
||
| 874 | * @return resource |
||
| 875 | */ |
||
| 876 | 30 | public function getHtmlStream() |
|
| 884 | |||
| 885 | /** |
||
| 886 | * Returns the HTML content as a string. |
||
| 887 | * |
||
| 888 | * Reads the entire stream content into a string and returns it. Returns |
||
| 889 | * null if the message doesn't have an HTML part. |
||
| 890 | * |
||
| 891 | * @return string |
||
| 892 | */ |
||
| 893 | public function getHtmlContent() |
||
| 901 | |||
| 902 | /** |
||
| 903 | * Returns true if either a Content-Type or Mime-Version header are defined |
||
| 904 | * in this Message. |
||
| 905 | * |
||
| 906 | * @return bool |
||
| 907 | */ |
||
| 908 | 84 | public function isMime() |
|
| 914 | |||
| 915 | /** |
||
| 916 | * Saves the message as a MIME message to the passed resource handle. |
||
| 917 | * |
||
| 918 | * @param resource $handle |
||
| 919 | */ |
||
| 920 | 80 | public function save($handle) |
|
| 924 | |||
| 925 | /** |
||
| 926 | * Returns the content part of a signed message for a signature to be |
||
| 927 | * calculated on the message. |
||
| 928 | * |
||
| 929 | * @return string |
||
| 930 | */ |
||
| 931 | 8 | public function getSignableBody() |
|
| 935 | |||
| 936 | /** |
||
| 937 | * Shortcut to call Message::save with a php://temp stream and return the |
||
| 938 | * written email message as a string. |
||
| 939 | * |
||
| 940 | * @return string |
||
| 941 | */ |
||
| 942 | public function __toString() |
||
| 951 | } |
||
| 952 |
This check marks private properties in classes that are never used. Those properties can be removed.