Overview

Packages

  • Mime

Classes

  • Horde_Mime
  • Horde_Mime_Address
  • Horde_Mime_Exception
  • Horde_Mime_Headers
  • Horde_Mime_Magic
  • Horde_Mime_Mail
  • Horde_Mime_Mdn
  • Horde_Mime_Part
  • Horde_Mime_Translation
  • Overview
  • Package
  • Class
  • Tree

Class Horde_Mime_Part

This class provides an object-oriented representation of a MIME part (defined by RFC 2045).

Copyright 1999-2012 Horde LLC (http://www.horde.org/)

See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Horde_Mime_Part implements ArrayAccess, Countable, Serializable
Package: Mime
Category: Horde
License: LGPL 2.1
Author: Chuck Hagenbuch chuck@horde.org
Author: Michael Slusarz slusarz@horde.org
Located at Horde/Mime/Part.php
Methods summary
public
# __clone( )

Function to run on clone.

Function to run on clone.

public
# setDisposition( string $disposition = null )

Set the content-disposition of this part.

Set the content-disposition of this part.

Parameters

$disposition
<p>The content-disposition to set ('inline', 'attachment', or an empty value).</p>
public string
# getDisposition( )

Get the content-disposition of this part.

Get the content-disposition of this part.

Returns

string

The part's content-disposition. An empty string means q no desired disposition has been set for this part.

public
# setDispositionParameter( string $label, string $data )

Add a disposition parameter to this part.

Add a disposition parameter to this part.

Parameters

$label
The disposition parameter label.
$data
The disposition parameter data.
public string
# getDispositionParameter( string $label )

Get a disposition parameter from this part.

Get a disposition parameter from this part.

Parameters

$label
The disposition parameter label.

Returns

string

The data requested. Returns null if $label is not set.

public array
# getAllDispositionParameters( )

Get all parameters from the Content-Disposition header.

Get all parameters from the Content-Disposition header.

Returns

array

An array of all the parameters Returns the empty array if no parameters set.

public
# setName( string $name )

Set the name of this part.

Set the name of this part.

Parameters

$name
The name to set.
public string
# getName( boolean $default = false )

Get the name of this part.

Get the name of this part.

Parameters

$default
<p>If the name parameter doesn't exist, should we use the default name from the description parameter?</p>

Returns

string
The name of the part.
public
# setContents( mixed $contents, array $options = array() )

Set the body contents of this part.

Set the body contents of this part.

Parameters

$contents
<p>The part body. Either a string or a stream resource, or an array containing both.</p>
$options
Additional options: <pre><span class="php-quote">'encoding'</span> - (string) The encoding of <span class="php-var">$contents</span>. <span class="php-keyword1">DEFAULT</span>: <span class="php-keyword2">Current</span> transfer encoding value. <span class="php-quote">'usestream'</span> - (boolean) <span class="php-keyword1">If</span> <span class="php-var">$contents</span> is a stream, should we directly <span class="php-keyword1">use</span> that stream? <span class="php-keyword1">DEFAULT</span>: <span class="php-var">$contents</span> copied to a <span class="php-keyword1">new</span> stream.</pre>
public
# appendContents( mixed $contents, mixed $options = array() )

Add to the body contents of this part.

Add to the body contents of this part.

Parameters

$contents
<p>The part body. Either a string or a stream resource, or an array containing both.</p> <pre><span class="php-quote">'encoding'</span> - (string) The encoding of <span class="php-var">$contents</span>. <span class="php-keyword1">DEFAULT</span>: <span class="php-keyword2">Current</span> transfer encoding value. <span class="php-quote">'usestream'</span> - (boolean) <span class="php-keyword1">If</span> <span class="php-var">$contents</span> is a stream, should we directly <span class="php-keyword1">use</span> that stream? <span class="php-keyword1">DEFAULT</span>: <span class="php-var">$contents</span> copied to a <span class="php-keyword1">new</span> stream.</pre>
$options
public
# clearContents( )

Clears the body contents of this part.

Clears the body contents of this part.

public mixed
# getContents( array $options = array() )

Return the body of the part.

Return the body of the part.

Parameters

$options
Additional options: <pre><span class="php-quote">'canonical'</span> - (boolean) Returns the contents in strict RFC <span class="php-num">822</span> &amp; <span class="php-num">2045</span> output - namely, all newlines <span class="php-keyword2">end</span> with the canonical &lt;CR&gt;&lt;LF&gt; sequence. <span class="php-keyword1">DEFAULT</span>: No <span class="php-quote">'stream'</span> - (boolean) <span class="php-keyword1">Return</span> the body <span class="php-keyword1">as</span> a stream resource. <span class="php-keyword1">DEFAULT</span>: No</pre>

Returns

mixed

The body text of the part, or a stream resource if 'stream' is true.

public
# setType( string $type )

Set the MIME type of this part.

Set the MIME type of this part.

Parameters

$type
The MIME type to set (ex.: text/plain).
public string
# getType( boolean $charset = false )

Get the full MIME Content-Type of this part.

Get the full MIME Content-Type of this part.

Parameters

$charset
<p>Append character set information to the end of the content type if this is a text/* part?</p>

Returns

string

The mimetype of this part (ex.: text/plain; charset=us-ascii) or false.

public string
# getDefaultType( )

If the subtype of a MIME part is unrecognized by an application, the default type should be used instead (See RFC 2046). This method returns the default subtype for a particular primary MIME type.

If the subtype of a MIME part is unrecognized by an application, the default type should be used instead (See RFC 2046). This method returns the default subtype for a particular primary MIME type.

Returns

string
The default MIME type of this part (ex.: text/plain).
public string
# getPrimaryType( )

Get the primary type of this part.

Get the primary type of this part.

Returns

string
The primary MIME type of this part.
public string
# getSubType( )

Get the subtype of this part.

Get the subtype of this part.

Returns

string
The MIME subtype of this part.
public
# setCharset( string $charset )

Set the character set of this part.

Set the character set of this part.

Parameters

$charset
The character set of this part.
public string
# getCharset( )

Get the character set to use for this part.

Get the character set to use for this part.

Returns

string

The character set of this part. Returns null if there is no character set.

public
# setHeaderCharset( string $charset )

Set the character set to use when outputting MIME headers.

Set the character set to use when outputting MIME headers.

Parameters

$charset
The character set.
public string
# getHeaderCharset( )

Get the character set to use when outputting MIME headers.

Get the character set to use when outputting MIME headers.

Returns

string
The character set.
public
# setLanguage( mixed $lang )

Set the language(s) of this part.

Set the language(s) of this part.

Parameters

$lang
<p>A language string, or an array of language strings.</p>
public
# getLanguage( )

Get the language(s) of this part.

Get the language(s) of this part.

public
# setDuration( integer $duration )

Set the content duration of the data contained in this part (see RFC 3803).

Set the content duration of the data contained in this part (see RFC 3803).

Parameters

$duration
<p>The duration of the data, in seconds. If null, clears the duration information.</p>
public integer
# getDuration( )

Get the content duration of the data contained in this part (see RFC 3803).

Get the content duration of the data contained in this part (see RFC 3803).

Returns

integer

The duration of the data, in seconds. Returns null if there is no duration information.

public
# setDescription( string $description )

Set the description of this part.

Set the description of this part.

Parameters

$description
The description of this part.
public string
# getDescription( boolean $default = false )

Get the description of this part.

Get the description of this part.

Parameters

$default
<p>If the description parameter doesn't exist, should we use the name of the part?</p>

Returns

string
The description of this part.
public
# setTransferEncoding( string $encoding, array $options = array() )

Set the transfer encoding to use for this part. Only needed in the following circumstances: 1.) Indicate what the transfer encoding is if the data has not yet been set in the object (can only be set if there presently are not any contents). 2.) Force the encoding to a certain type on a toString() call (if 'send' is true).

Set the transfer encoding to use for this part. Only needed in the following circumstances: 1.) Indicate what the transfer encoding is if the data has not yet been set in the object (can only be set if there presently are not any contents). 2.) Force the encoding to a certain type on a toString() call (if 'send' is true).

Parameters

$encoding
The transfer encoding to use.
$options
Additional options: <pre><span class="php-quote">'send'</span> - (boolean) <span class="php-keyword1">If</span> <span class="php-keyword1">true</span>, <span class="php-keyword1">use</span> <span class="php-var">$encoding</span> <span class="php-keyword1">as</span> the sending encoding. <span class="php-keyword1">DEFAULT</span>: <span class="php-var">$encoding</span> is used to change the base encoding.</pre>
public
# addPart( Horde_Mime_Part $mime_part )

Add a MIME subpart.

Add a MIME subpart.

Parameters

$mime_part
Add a subpart to the current object.
public array
# getParts( )

Get a list of all MIME subparts.

Get a list of all MIME subparts.

Returns

array
An array of the Horde_Mime_Part subparts.
public Horde_Mime_Part
# getPart( string $id )

Retrieve a specific MIME part.

Retrieve a specific MIME part.

Parameters

$id
The MIME ID to get.

Returns

Horde_Mime_Part

The part requested or null if the part doesn't exist.

public
# removePart( string $id )

Remove a subpart.

Remove a subpart.

Parameters

$id
The MIME ID to delete.
public
# alterPart( string $id, Horde_Mime_Part $mime_part )

Alter a current MIME subpart.

Alter a current MIME subpart.

Parameters

$id
The MIME ID to alter.
$mime_part
The MIME part to store.
public
# setContentTypeParameter( string $label, string $data )

Add a content type parameter to this part.

Add a content type parameter to this part.

Parameters

$label
The disposition parameter label.
$data
The disposition parameter data.
public
# clearContentTypeParameter( string $label )

Clears a content type parameter from this part.

Clears a content type parameter from this part.

Parameters

$label
The disposition parameter label.
public string
# getContentTypeParameter( string $label )

Get a content type parameter from this part.

Get a content type parameter from this part.

Parameters

$label
The content type parameter label.

Returns

string

The data requested. Returns null if $label is not set.

public array
# getAllContentTypeParameters( )

Get all parameters from the Content-Type header.

Get all parameters from the Content-Type header.

Returns

array

An array of all the parameters Returns the empty array if no parameters set.

public
# setEOL( string $eol )

Sets a new string to use for EOLs.

Sets a new string to use for EOLs.

Parameters

$eol
The string to use for EOLs.
public string
# getEOL( )

Get the string to use for EOLs.

Get the string to use for EOLs.

Returns

string
The string to use for EOLs.
public Horde_Mime_Headers
# addMimeHeaders( array $options = array() )

Returns a Horde_Mime_Header object containing all MIME headers needed for the part.

Returns a Horde_Mime_Header object containing all MIME headers needed for the part.

Parameters

$options
Additional options: <pre><span class="php-quote">'encode'</span> - (integer) A mask of allowable encodings. <span class="php-keyword1">DEFAULT</span>: See self::_getTransferEncoding() <span class="php-quote">'headers'</span> - (Horde_Mime_Headers) The object to add the MIME headers to. <span class="php-keyword1">DEFAULT</span>: Add headers to a <span class="php-keyword1">new</span> object</pre>

Returns

Horde_Mime_Headers
A Horde_Mime_Headers object.
public mixed
# toString( array $options = array() )

Return the entire part in MIME format.

Return the entire part in MIME format.

Parameters

$options
Additional options: <pre><span class="php-quote">'canonical'</span> - (boolean) Returns the encoded part in strict RFC <span class="php-num">822</span> &amp; <span class="php-num">2045</span> output - namely, all newlines <span class="php-keyword2">end</span> with the canonical &lt;CR&gt;&lt;LF&gt; sequence. <span class="php-keyword1">DEFAULT</span>: <span class="php-keyword1">false</span> <span class="php-quote">'defserver'</span> - (string) The <span class="php-keyword1">default</span> server to <span class="php-keyword1">use</span> when creating the <span class="php-keyword2">header</span> string. <span class="php-keyword1">DEFAULT</span>: none <span class="php-quote">'encode'</span> - (integer) A mask of allowable encodings. <span class="php-keyword1">DEFAULT</span>: self::ENCODE_7BIT <span class="php-quote">'headers'</span> - (mixed) <span class="php-keyword1">Include</span> the MIME headers? <span class="php-keyword1">If</span> <span class="php-keyword1">true</span>, create a <span class="php-keyword1">new</span> headers object. <span class="php-keyword1">If</span> a Horde_Mime_Headers object, add MIME headers to this object. <span class="php-keyword1">If</span> a string, <span class="php-keyword1">use</span> the string verbatim. <span class="php-keyword1">DEFAULT</span>: <span class="php-keyword1">true</span> <span class="php-quote">'id'</span> - (string) <span class="php-keyword1">Return</span> only this MIME ID part. <span class="php-keyword1">DEFAULT</span>: Returns the base part. <span class="php-quote">'stream'</span> - (boolean) <span class="php-keyword1">Return</span> a stream resource. <span class="php-keyword1">DEFAULT</span>: <span class="php-keyword1">false</span></pre>

Returns

mixed

The MIME string (returned as a resource if $stream is true).

public string
# replaceEOL( mixed $text, string $eol = null, boolean $stream = false )

Replace newlines in this part's contents with those specified by either the given newline sequence or the part's current EOL setting.

Replace newlines in this part's contents with those specified by either the given newline sequence or the part's current EOL setting.

Parameters

$text
<p>The text to replace. Either a string or a stream resource. If a stream, and returning a string, will close the stream when done.</p>
$eol
<p>The EOL sequence to use. If not present, uses the part's current EOL setting.</p>
$stream
If true, returns a stream resource.

Returns

string

The text with the newlines replaced by the desired newline sequence (returned as a stream resource if $stream is true).

public integer
# getBytes( boolean $approx = false )

Determine the size of this MIME part and its child members.

Determine the size of this MIME part and its child members.

Parameters

$approx
<p>If true, determines an approximate size for parts consisting of base64 encoded data (since 1.1.0).</p>

Returns

integer
Size of the part, in bytes.
public
# setBytes( integer $bytes )

Explicitly set the size (in bytes) of this part. This value will only be returned (via getBytes()) if there are no contents currently set. This function is useful for setting the size of the part when the contents of the part are not fully loaded (i.e. creating a Horde_Mime_Part object from IMAP header information without loading the data of the part).

Explicitly set the size (in bytes) of this part. This value will only be returned (via getBytes()) if there are no contents currently set. This function is useful for setting the size of the part when the contents of the part are not fully loaded (i.e. creating a Horde_Mime_Part object from IMAP header information without loading the data of the part).

Parameters

$bytes
The size of this part in bytes.
public string
# getSize( boolean $approx = false )

Output the size of this MIME part in KB.

Output the size of this MIME part in KB.

Parameters

$approx
<p>If true, determines an approximate size for parts consisting of base64 encoded data (since 1.1.0).</p>

Returns

string
Size of the part in KB.
public string
# setContentId( string $cid = null )

Sets the Content-ID header for this part.

Sets the Content-ID header for this part.

Parameters

$cid
<p>Use this CID (if not already set). Else, generate a random CID.</p>

Returns

string
The Content-ID for this part.
public string
# getContentId( )

Returns the Content-ID for this part.

Returns the Content-ID for this part.

Returns

string
The Content-ID for this part.
public
# setMimeId( string $mimeid )

Alter the MIME ID of this part.

Alter the MIME ID of this part.

Parameters

$mimeid
The MIME ID.
public string
# getMimeId( )

Returns the MIME ID of this part.

Returns the MIME ID of this part.

Returns

string
The MIME ID.
public
# buildMimeIds( string $id = null, boolean $rfc822 = false )

Build the MIME IDs for this part and all subparts.

Build the MIME IDs for this part and all subparts.

Parameters

$id
The ID of this part.
$rfc822
Is this a message/rfc822 part?
public array
# contentTypeMap( boolean $sort = true )

Returns a mapping of all MIME IDs to their content-types.

Returns a mapping of all MIME IDs to their content-types.

Parameters

$sort
Sort by MIME ID?

Returns

array
Keys: MIME ID; values: content type.
public
# isBasePart( boolean $base )

Is this the base MIME part?

Is this the base MIME part?

Parameters

$base
True if this is the base MIME part.
public
# setMetadata( string $key, mixed $data = null )

Set a piece of metadata on this object.

Set a piece of metadata on this object.

Parameters

$key
The metadata key.
$data
The metadata. If null, clears the key.
public mixed
# getMetadata( string $key )

Retrieves metadata from this object.

Retrieves metadata from this object.

Parameters

$key
The metadata key.

Returns

mixed
The metadata, or null if it doesn't exist.
public
# send( string $email, Horde_Mime_Headers $headers, Horde_Mail_Transport $mailer, array $opts = array() )

Sends this message.

Sends this message.

Parameters

$email
The address list to send to.
$headers
<p>The Horde_Mime_Headers object holding this message's headers.</p>
$mailer
A Horde_Mail_Transport object.
$opts
<p>Additional options: - encode: (integer) The encoding to use. A mask of self::ENCODE_* values. DEFAULT: Auto-determined based on transport driver.</p>

Throws

Horde_Mime_Exception
InvalidArgumentException
public mixed
# findBody( string $subtype = null )

Finds the main "body" text part (if any) in a message. "Body" data is the first text part under this part.

Finds the main "body" text part (if any) in a message. "Body" data is the first text part under this part.

Parameters

$subtype
Specifically search for this subtype.

Returns

mixed

The MIME ID of the main body part, or null if a body part is not found.

public static Horde_Mime_Part
# parseMessage( string $text, array $options = array() )

Attempts to build a Horde_Mime_Part object from message text. This function can be called statically via: $mime_part = Horde_Mime_Part::parseMessage();

Attempts to build a Horde_Mime_Part object from message text. This function can be called statically via: $mime_part = Horde_Mime_Part::parseMessage();

Parameters

$text
The text of the MIME message.
$options
Additional options: <pre><span class="php-quote">'forcemime'</span> - (boolean) <span class="php-keyword1">If</span> <span class="php-keyword1">true</span>, the message data is assumed to be MIME data. <span class="php-keyword1">If</span> not, a MIME-Version <span class="php-keyword2">header</span> must exist (RFC <span class="php-num">2045</span> [<span class="php-num">4</span>]) to be parsed <span class="php-keyword1">as</span> a MIME message. <span class="php-keyword1">DEFAULT</span>: <span class="php-keyword1">false</span></pre>

Returns

Horde_Mime_Part
A MIME Part object.

Throws

Horde_Mime_Exception
public static string
# getRawPartText( mixed $text, string $type, string $id )

Attempts to obtain the raw text of a MIME part. This function can be called statically via: $data = Horde_Mime_Part::getRawPartText();

Attempts to obtain the raw text of a MIME part. This function can be called statically via: $data = Horde_Mime_Part::getRawPartText();

Parameters

$text
<p>The full text of the MIME message. The text is assumed to be MIME data (no MIME-Version checking is performed). It can be either a stream or a string.</p>
$type
Either 'header' or 'body'.
$id
The MIME ID.

Returns

string
The raw text.

Throws

Horde_Mime_Exception
public
# offsetExists( mixed $offset )

Implementation of

ArrayAccess::offsetExists()
public
# offsetGet( mixed $offset )

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( mixed $offset, mixed $value )

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( mixed $offset )

Implementation of

ArrayAccess::offsetUnset()
public integer
# count( )

Returns the number of message parts.

Returns the number of message parts.

Returns

integer
Number of message parts.

Implementation of

Countable::count()
public string
# serialize( )

Serialization.

Serialization.

Returns

string
Serialized data.

Implementation of

Serializable::serialize()
public
# unserialize( string $data )

Unserialization.

Unserialization.

Parameters

$data
Serialized data.

Throws

Exception

Implementation of

Serializable::unserialize()
Constants summary
integer VERSION
# 1
string EOL
# "\n"
string RFC_EOL
# "\r\n"
string DEFAULT_ENCODING
# 'binary'
integer ENCODE_7BIT
# 1
integer ENCODE_8BIT
# 2
integer ENCODE_BINARY
# 4
string UNKNOWN
# 'x-unknown'
Properties summary
public static string $defaultCharset

The default charset to use when parsing text parts with no charset information.

The default charset to use when parsing text parts with no charset information.

# 'us-ascii'
public static array $encodingTypes

Valid encoding types.

Valid encoding types.

# array( '7bit', '8bit', 'base64', 'binary', 'quoted-printable', // Non-RFC types, but old mailers may still use 'uuencode', 'x-uuencode', 'x-uue' )
public static integer $memoryLimit

The memory limit for use with the PHP temp stream.

The memory limit for use with the PHP temp stream.

# 2097152
public static array $mimeTypes

Valid MIME types.

Valid MIME types.

# array( 'text', 'multipart', 'message', 'application', 'audio', 'image', 'video', 'model' )
API documentation generated by ApiGen