MailMimeParser 2.3

UUEncodedPart extends NonMimePart
in package
implements IUUEncodedPart

Implementation of a non-mime message's uuencoded attachment part.

Tags
author

Zaahid Bateson

Interfaces, Classes, Traits and Enums

IUUEncodedPart
An interface representing a non-mime uuencoded part.

Table of Contents

$charsetOverride  : string|null
$filename  : string
$ignoreTransferEncoding  : bool
$mode  : int
$observers  : SplObjectStorage
$parent  : IMimePart|null
$partStreamContainer  : PartStreamContainer
__construct()  : mixed
__toString()  : string
Returns the message/part as a string, containing its headers, content and children.
attach()  : void
attachContentStream()  : static
Attaches the stream or resource handle for the part's content. The stream is closed when another stream is attached, or the MimePart is destroyed.
detach()  : void
detachContentStream()  : static
Detaches the content stream.
getBinaryContentResourceHandle()  : resource|null
Returns a resource handle for the content's raw data stream, or null if the part doesn't have a content stream.
getBinaryContentStream()  : StreamInterface|null
Returns the raw data stream for the current part, if it exists, or null if there's no content associated with the stream.
getCharset()  : string
Returns null
getContent()  : string|null
Shortcut to reading stream content and assigning it to a string. Returns null if the part doesn't have a content stream.
getContentDisposition()  : string
Returns 'attachment'.
getContentId()  : string|null
Returns the Content ID of the part.
getContentStream()  : StreamInterface|null
Returns the StreamInterface for the part's content or null if the part doesn't have a content section.
getContentTransferEncoding()  : string
Returns 'x-uuencode'.
getContentType()  : string
Returns 'application/octet-stream'.
getFilename()  : string
Returns the filename included in the uuencoded 'begin' line for this part.
getParent()  : IMimePart
Returns this part's parent.
getResourceHandle()  : resource
Returns a resource handle for the string representation of this part, containing its headers, content and children. For an IMessage, this would be the entire RFC822 (or greater) email.
getStream()  : StreamInterface
Returns a Psr7 StreamInterface for the string representation of this part, containing its headers, content and children.
getUnixFileMode()  : int|null
Returns the file mode included in the uuencoded 'begin' line for this part.
hasContent()  : bool
Returns true if the part contains a 'body' (content).
isMime()  : bool
Returns false.
isTextPart()  : false
Returns false.
notify()  : void
save()  : static
Writes a string representation of this part, including its headers, content and children to the passed file, resource, or stream.
saveContent()  : self
Saves the binary content of the stream to the passed file, resource or stream.
setCharsetOverride()  : static
Overrides the default character set used for reading content from content streams in cases where a user knows the source charset is not what is specified.
setContent()  : static
Sets the content of the part to the passed string, resource, or stream.
setFilename()  : static
Sets the filename included in the uuencoded 'begin' line.
setUnixFileMode()  : static
Sets the unix file mode for the uuencoded 'begin' line.

Properties

$charsetOverride

protected string|null $charsetOverride

can be used to set an override for content's charset in cases where a user knows the charset on the content is not what it claims to be.

$filename

protected string $filename = null

the name of the file in the uuencoding 'header'.

$ignoreTransferEncoding

protected bool $ignoreTransferEncoding

set to true when a user attaches a stream manually, it's assumed to already be decoded or to have relevant transfer encoding decorators attached already.

$observers

protected SplObjectStorage $observers

attached observers that need to be notified of modifications to this part.

Methods

__construct()

public __construct([int|null $mode = null ][, string|null $filename = null ][, IMimePart|null $parent = null ][, PartStreamContainer|null $streamContainer = null ]) : mixed
Parameters
$mode : int|null = null
$filename : string|null = null
$parent : IMimePart|null = null
$streamContainer : PartStreamContainer|null = null
Return values
mixed

__toString()

Returns the message/part as a string, containing its headers, content and children.

public __toString() : string

Convenience method for calling getContents() on IMessagePart::getStream().

Return values
string

attach()

public attach(SplObserver $observer) : void
Parameters
$observer : SplObserver
Return values
void

attachContentStream()

Attaches the stream or resource handle for the part's content. The stream is closed when another stream is attached, or the MimePart is destroyed.

public attachContentStream(StreamInterface $stream[, string $streamCharset = MailMimeParser::DEFAULT_CHARSET ]) : static
Parameters
$stream : StreamInterface

the content

$streamCharset : string = MailMimeParser::DEFAULT_CHARSET

the charset of $stream

Return values
static

detach()

public detach(SplObserver $observer) : void
Parameters
$observer : SplObserver
Return values
void

detachContentStream()

Detaches the content stream.

public detachContentStream() : static
Return values
static

getBinaryContentResourceHandle()

Returns a resource handle for the content's raw data stream, or null if the part doesn't have a content stream.

public getBinaryContentResourceHandle() : resource|null

The method wraps a call to IMessagePart::getBinaryContentStream() and returns a resource handle for the returned Stream.

Return values
resource|null

the resource

getBinaryContentStream()

Returns the raw data stream for the current part, if it exists, or null if there's no content associated with the stream.

public getBinaryContentStream() : StreamInterface|null

This is basically the same as calling IMessagePart::getContentStream(), except no automatic charset conversion is done. Note that for non-text streams, this doesn't have an effect, as charset conversion is not performed in that case, and is useful only when:

  • The charset defined is not correct, and the conversion produces errors; or
  • You'd like to read the raw contents without conversion, for instance to save it to file or allow a user to download it as-is (in a download link for example).
Return values
StreamInterface|null

the stream

getCharset()

Returns null

public getCharset() : string
Return values
string

getContent()

Shortcut to reading stream content and assigning it to a string. Returns null if the part doesn't have a content stream.

public getContent([string $charset = MailMimeParser::DEFAULT_CHARSET ]) : string|null

The returned string is encoded to the passed $charset character encoding.

Parameters
$charset : string = MailMimeParser::DEFAULT_CHARSET

the target charset for the returned string

Return values
string|null

the content

getContentDisposition()

Returns 'attachment'.

public getContentDisposition([string|null $default = 'attachment' ]) : string
Parameters
$default : string|null = 'attachment'
Return values
string

getContentId()

Returns the Content ID of the part.

public getContentId() : string|null

NonMimeParts do not have a Content ID, and so this simply returns null.

Return values
string|null

getContentStream()

Returns the StreamInterface for the part's content or null if the part doesn't have a content section.

public getContentStream([string $charset = MailMimeParser::DEFAULT_CHARSET ]) : StreamInterface|null

To get a stream without charset conversion if you know the part's content contains a binary stream, call self::getBinaryContentStream() instead.

The library automatically handles decoding and charset conversion (to the target passed $charset) based on the part's transfer encoding as returned by IMessagePart::getContentTransferEncoding() and the part's charset as returned by IMessagePart::getCharset(). The returned stream is ready to be read from directly.

Note that the returned Stream is a shared object. If called multiple times with the same $charset, and the value of the part's Content-Transfer-Encoding header has not changed, the stream will be rewound. This would affect other existing variables referencing the stream, for example:

// assuming $part is a part containing the following
// string for its content: '12345678'
$stream = $part->getContentStream();
$someChars = $part->read(4);

$stream2 = $part->getContentStream();
$moreChars = $part->read(4);
echo ($someChars === $moreChars);    //1

In this case the Stream was rewound, and $stream's second call to read 4 bytes reads the same first 4.

Parameters
$charset : string = MailMimeParser::DEFAULT_CHARSET

Optional charset for the returned stream.

Return values
StreamInterface|null

the stream

getContentTransferEncoding()

Returns 'x-uuencode'.

public getContentTransferEncoding([string|null $default = 'x-uuencode' ]) : string
Parameters
$default : string|null = 'x-uuencode'
Return values
string

getContentType()

Returns 'application/octet-stream'.

public getContentType([string $default = 'application/octet-stream' ]) : string
Parameters
$default : string = 'application/octet-stream'
Return values
string

getFilename()

Returns the filename included in the uuencoded 'begin' line for this part.

public getFilename() : string
Return values
string

getResourceHandle()

Returns a resource handle for the string representation of this part, containing its headers, content and children. For an IMessage, this would be the entire RFC822 (or greater) email.

public getResourceHandle() : resource

If the part has not been modified and represents a parsed part, the original stream should be returned. Otherwise a stream representation of the part including its modifications should be returned. This insures that an unmodified, signed message could be passed on that way even after parsing and reading.

The returned stream is not guaranteed to be RFC822 (or greater) compliant for the following reasons:

  • The original email or part, if not modified, is returned as-is and may not be compliant.
  • Although certain parts may have been modified, an original unmodified header from the original email or part may not be compliant.
  • A user may set headers in a non-compliant format.
Return values
resource

the resource handle containing the part.

getStream()

Returns a Psr7 StreamInterface for the string representation of this part, containing its headers, content and children.

public getStream() : StreamInterface

If the part has not been modified and represents a parsed part, the original stream should be returned. Otherwise a stream representation of the part including its modifications should be returned. This insures that an unmodified, signed message could be passed on that way even after parsing and reading.

The returned stream is not guaranteed to be RFC822 (or greater) compliant for the following reasons:

  • The original email or part, if not modified, is returned as-is and may not be compliant.
  • Although certain parts may have been modified, an original unmodified header from the original email or part may not be compliant.
  • A user may set headers in a non-compliant format.
Return values
StreamInterface

the stream containing the part.

getUnixFileMode()

Returns the file mode included in the uuencoded 'begin' line for this part.

public getUnixFileMode() : int|null
Return values
int|null

hasContent()

Returns true if the part contains a 'body' (content).

public hasContent() : bool
Return values
bool

isMime()

Returns false.

public isMime() : bool
Return values
bool

isTextPart()

Returns false.

public isTextPart() : false

Although the part may be plain text, there is no reliable way of determining its type since uuencoded 'begin' lines only include a file name and no mime type. The file name's extension may be a hint.

Return values
false

notify()

public notify() : void
Return values
void

save()

Writes a string representation of this part, including its headers, content and children to the passed file, resource, or stream.

public save(mixed $filenameResourceOrStream[, string $filemode = 'w+' ]) : static
Parameters
$filenameResourceOrStream : mixed

the file, resource, or stream to write to.

$filemode : string = 'w+'

Optional filemode to open a file in (if $filenameResourceOrStream is a string)

Return values
static

saveContent()

Saves the binary content of the stream to the passed file, resource or stream.

public saveContent(mixed $filenameResourceOrStream) : self

Note that charset conversion is not performed in this case, and the contents of the part are saved in their binary format as transmitted (but after any content-transfer decoding is performed). IMessagePart::getBinaryContentStream() for a more detailed description of the stream.

If the passed parameter is a string, it's assumed to be a filename to write to. The file is opened in 'w+' mode, and closed before returning.

When passing a resource or Psr7 Stream, the resource is not closed, nor rewound.

Parameters
$filenameResourceOrStream : mixed
Return values
self

setCharsetOverride()

Overrides the default character set used for reading content from content streams in cases where a user knows the source charset is not what is specified.

public setCharsetOverride(string $charsetOverride[, bool $onlyIfNoCharset = false ]) : static
Parameters
$charsetOverride : string

the actual charset of the content.

$onlyIfNoCharset : bool = false

if true, $charsetOverride is used only if getCharset returns null.

Return values
static

setContent()

Sets the content of the part to the passed string, resource, or stream.

public setContent(mixed $resource[, string $charset = MailMimeParser::DEFAULT_CHARSET ]) : static
Parameters
$resource : mixed

the content.

$charset : string = MailMimeParser::DEFAULT_CHARSET
Return values
static

setFilename()

Sets the filename included in the uuencoded 'begin' line.

public setFilename(string $filename) : static
Parameters
$filename : string
Return values
static

setUnixFileMode()

Sets the unix file mode for the uuencoded 'begin' line.

public setUnixFileMode(int $mode) : static
Parameters
$mode : int
Return values
static

Search results