Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

Copyright 1999-2017 Horde LLC (http://www.horde.org/) See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Copyright: 1999-2017 Horde LLC
License: http://www.horde.org/licenses/lgpl21 LGPL 2.1
File Size: 2548 lines (77 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Horde_Mime_Part:: (90 methods):
  __construct()
  __clone()
  setDisposition()
  getDisposition()
  setDispositionParameter()
  getDispositionParameter()
  getAllDispositionParameters()
  setName()
  getName()
  setContents()
  appendContents()
  clearContents()
  getContents()
  _transferDecode()
  _transferEncode()
  setType()
  getType()
  getDefaultType()
  getPrimaryType()
  getSubType()
  setCharset()
  getCharset()
  setHeaderCharset()
  getHeaderCharset()
  setLanguage()
  getLanguage()
  setDuration()
  getDuration()
  setDescription()
  getDescription()
  setTransferEncoding()
  getParts()
  setContentTypeParameter()
  getContentTypeParameter()
  getAllContentTypeParameters()
  setEOL()
  getEOL()
  addMimeHeaders()
  toString()
  _getTransferEncoding()
  replaceEOL()
  getBytes()
  setBytes()
  getSize()
  setContentId()
  getContentId()
  setMimeId()
  getMimeId()
  buildMimeIds()
  isBasePart()
  isAttachment()
  setMetadata()
  getMetadata()
  send()
  findBody()
  partIterator()
  getPartByIndex()
  _reindex()
  _writeStream()
  _readStream()
  _scanStream()
  parseMessage()
  _getStructure()
  getRawPartText()
  _findHeader()
  _findBoundary()
  _sanityCheckRfc822Attachments()
  _reEncodeMessageAttachment()
  offsetExists()
  offsetGet()
  offsetSet()
  offsetUnset()
  count()
  current()
  key()
  next()
  rewind()
  valid()
  hasChildren()
  getChildren()
  serialize()
  __serialize()
  __unserialize()
  unserialize()
  clearContentTypeParameter()
  contentTypeMap()
  addPart()
  getPart()
  alterPart()
  removePart()


Class: Horde_Mime_Part  - X-Ref

Object-oriented representation of a MIME part (RFC 2045-2049).

__construct()   X-Ref
Constructor.


__clone()   X-Ref
Function to run on clone.


setDisposition($disposition = null)   X-Ref
Set the content-disposition of this part.

param: string $disposition  The content-disposition to set ('inline',

getDisposition()   X-Ref
Get the content-disposition of this part.

return: string  The part's content-disposition.  An empty string means

setDispositionParameter($label, $data)   X-Ref
Add a disposition parameter to this part.

param: string $label  The disposition parameter label.
param: string $data   The disposition parameter data. If null, removes

getDispositionParameter($label)   X-Ref
Get a disposition parameter from this part.

param: string $label  The disposition parameter label.
return: string  The data requested.

getAllDispositionParameters()   X-Ref
Get all parameters from the Content-Disposition header.

return: array  An array of all the parameters

setName($name)   X-Ref
Set the name of this part.

param: string $name  The name to set.

getName($default = false)   X-Ref
Get the name of this part.

param: boolean $default  If the name parameter doesn't exist, should we
return: string  The name of the part.

setContents($contents, $options = array()   X-Ref
Set the body contents of this part.

param: mixed $contents  The part body. Either a string or a stream
param: array $options   Additional options:

appendContents($contents, $options = array()   X-Ref
Add to the body contents of this part.

param: mixed $contents  The part body. Either a string or a stream

clearContents()   X-Ref
Clears the body contents of this part.


getContents($options = array()   X-Ref
Return the body of the part.

param: array $options  Additional options:
return: mixed  The body text (string) of the part, null if there is no

_transferDecode($fp, $encoding)   X-Ref
Decodes the contents of the part to binary encoding.

param: resource $fp      A stream containing the data to decode.
param: string $encoding  The original file encoding.
return: resource  A new file resource with the decoded data.

_transferEncode($fp, $encoding)   X-Ref
Encodes the contents of the part as necessary for transport.

param: resource $fp      A stream containing the data to encode.
param: string $encoding  The encoding to use.
return: resource  A new file resource with the encoded data.

setType($type)   X-Ref
Set the MIME type of this part.

param: string $type  The MIME type to set (ex.: text/plain).

getType($charset = false)   X-Ref
Get the full MIME Content-Type of this part.

param: boolean $charset  Append character set information to the end
return: string  The MIME type of this part.

getDefaultType()   X-Ref
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.

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

getPrimaryType()   X-Ref
Get the primary type of this part.

return: string  The primary MIME type of this part.

getSubType()   X-Ref
Get the subtype of this part.

return: string  The MIME subtype of this part.

setCharset($charset)   X-Ref
Set the character set of this part.

param: string $charset  The character set of this part.

getCharset()   X-Ref
Get the character set to use for this part.

return: string  The character set of this part (lowercase). Returns

setHeaderCharset($charset)   X-Ref
Set the character set to use when outputting MIME headers.

param: string $charset  The character set.

getHeaderCharset()   X-Ref
Get the character set to use when outputting MIME headers.

return: string  The character set. If no preferred character set has

setLanguage($lang)   X-Ref
Set the language(s) of this part.

param: mixed $lang  A language string, or an array of language

getLanguage()   X-Ref
Get the language(s) of this part.

param: array  The list of languages.

setDuration($duration)   X-Ref
Set the content duration of the data contained in this part (see RFC
3803).

param: integer $duration  The duration of the data, in seconds. If

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

return: integer  The duration of the data, in seconds. Returns null if

setDescription($description)   X-Ref
Set the description of this part.

param: string $description  The description of this part. If null,

getDescription($default = false)   X-Ref
Get the description of this part.

param: boolean $default  If the description parameter doesn't exist,
return: string  The description of this part.

setTransferEncoding($encoding, $options = array()   X-Ref
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).

param: string $encoding  The transfer encoding to use.
param: array $options    Additional options:

getParts()   X-Ref
Get a list of all MIME subparts.

return: array  An array of the Horde_Mime_Part subparts.

setContentTypeParameter($label, $data)   X-Ref
Add/remove a content type parameter to this part.

param: string $label  The content-type parameter label.
param: string $data   The content-type parameter data. If null, removes

getContentTypeParameter($label)   X-Ref
Get a content type parameter from this part.

param: string $label  The content type parameter label.
return: string  The data requested.

getAllContentTypeParameters()   X-Ref
Get all parameters from the Content-Type header.

return: array  An array of all the parameters

setEOL($eol)   X-Ref
Sets a new string to use for EOLs.

param: string $eol  The string to use for EOLs.

getEOL()   X-Ref
Get the string to use for EOLs.

return: string  The string to use for EOLs.

addMimeHeaders($options = array()   X-Ref
Returns a Horde_Mime_Header object containing all MIME headers needed
for the part.

param: array $options  Additional options:
return: Horde_Mime_Headers  A Horde_Mime_Headers object.

toString($options = array()   X-Ref
Return the entire part in MIME format.

param: array $options  Additional options:
return: mixed  The MIME string (returned as a resource if $stream is

_getTransferEncoding($encode = self::ENCODE_7BIT)   X-Ref
Get the transfer encoding for the part based on the user requested
transfer encoding and the current contents of the part.

param: integer $encode  A mask of allowable encodings.
return: string  The transfer-encoding of this part.

replaceEOL($text, $eol = null, $stream = false)   X-Ref
Replace newlines in this part's contents with those specified by either
the given newline sequence or the part's current EOL setting.

param: mixed $text      The text to replace. Either a string or a
param: string $eol      The EOL sequence to use. If not present, uses
param: boolean $stream  If true, returns a stream resource.
return: string  The text with the newlines replaced by the desired

getBytes($approx = false)   X-Ref
Determine the size of this MIME part and its child members.

param: boolean $approx  If true, determines an approximate size for
return: integer  Size of the part, in bytes.

setBytes($bytes)   X-Ref
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).

param: integer $bytes  The size of this part in bytes.

getSize($approx = false)   X-Ref
Output the size of this MIME part in KB.

param: boolean $approx  If true, determines an approximate size for
return: string  Size of the part in KB.

setContentId($cid = null)   X-Ref
Sets the Content-ID header for this part.

param: string $cid  Use this CID (if not already set). Else, generate
return: string  The Content-ID for this part.

getContentId()   X-Ref
Returns the Content-ID for this part.

return: string  The Content-ID for this part (null if not set).

setMimeId($mimeid)   X-Ref
Alter the MIME ID of this part.

param: string $mimeid  The MIME ID.

getMimeId()   X-Ref
Returns the MIME ID of this part.

return: string  The MIME ID.

buildMimeIds($id = null, $rfc822 = false)   X-Ref
Build the MIME IDs for this part and all subparts.

param: string $id       The ID of this part.
param: boolean $rfc822  Is this a message/rfc822 part?

isBasePart($base)   X-Ref
Is this the base MIME part?

param: boolean $base  True if this is the base MIME part.

isAttachment()   X-Ref
Determines if this MIME part is an attachment for display purposes.

return: boolean  True if this part should be considered an attachment.

setMetadata($key, $data = null)   X-Ref
Set a piece of metadata on this object.

param: string $key  The metadata key.
param: mixed $data  The metadata. If null, clears the key.

getMetadata($key)   X-Ref
Retrieves metadata from this object.

param: string $key  The metadata key.
return: mixed  The metadata, or null if it doesn't exist.

send($email, $headers, Horde_Mail_Transport $mailer,array $opts = array()   X-Ref
Sends this message.

param: string $email                 The address list to send to.
param: Horde_Mime_Headers $headers   The Horde_Mime_Headers object
param: Horde_Mail_Transport $mailer  A Horde_Mail_Transport object.
param: array $opts                   Additional options:

findBody($subtype = null)   X-Ref
Finds the main "body" text part (if any) in a message.
"Body" data is the first text part under this part.

param: string $subtype  Specifically search for this subtype.
return: mixed  The MIME ID of the main body part, or null if a body

partIterator($current = true)   X-Ref
Returns the recursive iterator needed to iterate through this part.

param: boolean $current  Include the current part as the base?
return: Iterator  Recursive iterator.

getPartByIndex($index)   X-Ref
Returns a subpart by index.

return: Horde_Mime_Part  Part, or null if not found.

_reindex($force = false)   X-Ref
Reindexes the MIME IDs, if necessary.

param: boolean $force  Reindex if the current part doesn't have an ID.

_writeStream($data, $options = array()   X-Ref
Write data to a stream.

param: array $data     The data to write. Either a stream resource or
param: array $options  Additional options:
return: resource  The stream resource.

_readStream($fp, $close = false)   X-Ref
Read data from a stream.

param: resource $fp    An active stream.
param: boolean $close  Close the stream when done reading?
return: string  The data from the stream.

_scanStream($fp)   X-Ref
Scans a stream for content type.

param: resource $fp  A stream resource.
return: mixed  Either 'binary', '8bit', or false.

parseMessage($text, array $opts = array()   X-Ref
Attempts to build a Horde_Mime_Part object from message text.

param: string $text  The text of the MIME message.
param: array $opts   Additional options:
return: Horde_Mime_Part  A MIME Part object.

_getStructure($header, $body,array $opts = array()   X-Ref
Creates a MIME object from the text of one part of a MIME message.

param: string $header  The header text.
param: string $body    The body text.
param: array $opts     Additional options:
return: Horde_Mime_Part  The MIME part object.

getRawPartText($text, $type, $id)   X-Ref
Attempts to obtain the raw text of a MIME part.

param: mixed $text   The full text of the MIME message. The text is
param: string $type  Either 'header' or 'body'.
param: string $id    The MIME ID.
return: string  The raw text.

_findHeader($text, $eol)   X-Ref
Find the location of the end of the header text.

param: string $text  The text to search.
param: string $eol   The EOL string.
return: integer  Header position.

_findBoundary($text, $pos, $boundary,$end = null)   X-Ref
Find the location of the next boundary string.

param: string $text      The text to search.
param: integer $pos      The current position in $text.
param: string $boundary  The boundary string.
param: integer $end      If set, return after matching this many
return: array  Keys are the boundary number, values are an array with

_sanityCheckRfc822Attachments()   X-Ref
Re-enocdes message/rfc822 parts in case there was e.g., some broken
line length in the headers of the message in the part. Since we shouldn't
alter the original message in any way, we simply reset cause the part to
be encoded as base64 and sent as a application/octet part.


_reEncodeMessageAttachment(Horde_Mime_Part $part)   X-Ref
Rebuilds $part and forces it to be a base64 encoded
application/octet-stream part.

param: Horde_Mime_Part $part   The MIME part.

offsetExists($offset)   X-Ref
No description

offsetGet($offset)   X-Ref
No description

offsetSet($offset, $value)   X-Ref
No description

offsetUnset($offset)   X-Ref
No description

count()   X-Ref
Returns the number of child message parts (doesn't include
grandchildren or more remote ancestors).

return: integer  Number of message parts.

current()   X-Ref


key()   X-Ref


next()   X-Ref


rewind()   X-Ref


valid()   X-Ref


hasChildren()   X-Ref


getChildren()   X-Ref


serialize()   X-Ref
Serialization.

return: string  Serialized data.

__serialize()   X-Ref
No description

__unserialize(array $data)   X-Ref
No description

unserialize($data)   X-Ref
Unserialization.

param: string $data  Serialized data.

clearContentTypeParameter($label)   X-Ref


contentTypeMap($sort = true)   X-Ref


addPart($mime_part)   X-Ref


getPart($id)   X-Ref


alterPart($id, $mime_part)   X-Ref


removePart($id)   X-Ref