Path

ez components / documentation / api reference / 2007.1 / mail


eZ Components 2007.1

Mail: ezcMailTools

[ Tutorial ] [ Display-example ] [ Mail-listing-example ] [ Rfcs ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcMailTools

This class contains static convenience methods for composing addresses and ensuring correct line-breaks in the mail. [source]

Constants

REPLY_ALL = 1 Reply to all.
REPLY_SENDER = 1 Reply to sender.

Method Summary

public static string composeEmailAddress( $item )
Returns ezcMailAddress $item as a RFC822 compliant address string.
public static string composeEmailAddresses( $items, [$foldLength = null] )
Returns the array $items consisting of ezcMailAddress objects as one RFC822 compliant address string.
public static string generateContentId( [$partName = "part"] )
Returns an unique ID to be used for Content-ID headers.
public static string generateMessageId( $hostname )
Returns an unique message ID to be used for a mail message.
public static void guessContentType( $fileName, &$contentType, &$mimeType, $contentType, $mimeType )
Guesses the content and mime type by using the file extension.
public static string lineBreak( )
Returns one endLine character.
public static string mimeDecode( $text, [$charset = 'utf-8'] )
Decodes mime encoded fields and tries to recover from errors.
public static ezcMailAddress parseEmailAddress( $address, [$encoding = "mime"] )
Returns an ezcMailAddress object parsed from the address string $address.
public static array(ezcMailAddress) parseEmailAddresses( $addresses, [$encoding = "mime"] )
Returns an array of ezcMailAddress objects parsed from the address string $addresses.
public static ezcMail replyToMail( $mail, $from, [$type = self::REPLY_SENDER], [$subjectPrefix = "Re: "], [$mailClass = "ezcMail"] )
Returns a new mail object that is a reply to the current object.
public static void setLineBreak( $characters )
Sets the endLine $character(s) to use when generating mail.

Methods

composeEmailAddress

string composeEmailAddress( ezcMailAddress $item )
Returns ezcMailAddress $item as a RFC822 compliant address string.
Example:
1.  composeEmailAddressnew ezcMailAddress'sender@example.com''John Doe' ) );
Returns:
 John Doe 

Parameters

Name Type Description
$item ezcMailAddress  

composeEmailAddresses

string composeEmailAddresses( $items, [int $foldLength = null] )
Returns the array $items consisting of ezcMailAddress objects as one RFC822 compliant address string.
Set foldLength to control how many characters each line can have before a line break is inserted according to the folding rules specified in RFC2822.

Parameters

Name Type Description
$items array(ezcMailAddress)  
$foldLength int  

generateContentId

string generateContentId( [string $partName = "part"] )
Returns an unique ID to be used for Content-ID headers.
The part $partName is default set to "part". Another value can be used to provide, for example, a file name of a part. $partName will be encoded with base64 to be compliant with the RFCs.
The formula used is [base64( $partName )]."@".[time].[counter]

Parameters

Name Type Description
$partName string  

generateMessageId

string generateMessageId( string $hostname )
Returns an unique message ID to be used for a mail message.
The hostname $hostname will be added to the unique ID as required by RFC822. If an e-mail address is provided instead, the hostname is extracted and used.
The formula to generate the message ID is: [time_and_date].[process_id].[counter]

Parameters

Name Type Description
$hostname string  

guessContentType

void guessContentType( string $fileName, &$contentType, &$mimeType, string $contentType, string $mimeType )
Guesses the content and mime type by using the file extension.
The content and mime types are returned through the $contentType and $mimeType arguments. For the moment only for image files.

Parameters

Name Type Description
$fileName string  
$contentType string  
$mimeType string  
&$contentType  
&$mimeType  

lineBreak

string lineBreak( )
Returns one endLine character.
The default is to use "\n\r" as specified by RFC 2045.

mimeDecode

string mimeDecode( string $text, [string $charset = 'utf-8'] )
Decodes mime encoded fields and tries to recover from errors.
Decodes the $text encoded as a MIME string to the $charset. In case the strict conversion fails this method tries to workaround the issues by trying to "fix" the original $text before trying to convert it.

Parameters

Name Type Description
$text string  
$charset string  

parseEmailAddress

ezcMailAddress parseEmailAddress( string $address, [string $encoding = "mime"] )
Returns an ezcMailAddress object parsed from the address string $address.
You can set the encoding of the name part with the $encoding parameter. If $encoding is omitted or set to "mime" parseEmailAddress will asume that the name part is mime encoded.
This method does not perform validation. It will also accept slightly malformed addresses.
If the mail address given can not be decoded null is returned.
Example:
1.  ezcMailTools::parseEmailAddress'John Doe <john@example.com>' );

Parameters

Name Type Description
$address string  
$encoding string  

parseEmailAddresses

array(ezcMailAddress) parseEmailAddresses( string $addresses, [string $encoding = "mime"] )
Returns an array of ezcMailAddress objects parsed from the address string $addresses.
You can set the encoding of the name parts with the $encoding parameter. If $encoding is omitted or set to "mime" parseEmailAddresses will asume that the name parts are mime encoded.
Example:
1.  ezcMailTools::parseEmailAddresses'John Doe <john@example.com>' );

Parameters

Name Type Description
$addresses string  
$encoding string  

replyToMail

ezcMail replyToMail( ezcMail $mail, ezcMailAddress $from, [int $type = self::REPLY_SENDER], [string $subjectPrefix = "Re: "], [string $mailClass = "ezcMail"] )
Returns a new mail object that is a reply to the current object.
The new mail will have the correct to, cc, bcc and reference headers set. It will not have any body set.
By default the reply will only be sent to the sender of the original mail. If $type is set to REPLY_ALL, all the original recipients will be included in the reply.
Use $subjectPrefix to set the prefix to the subject of the mail. The default is to prefix with 'Re: '.

Parameters

Name Type Description
$mail ezcMail  
$from ezcMailAddress  
$type int REPLY_SENDER or REPLY_ALL
$subjectPrefix string  
$mailClass string  

setLineBreak

void setLineBreak( string $characters )
Sets the endLine $character(s) to use when generating mail.
The default is to use "\r\n" as specified by RFC 2045.

Parameters

Name Type Description
$characters string  

Last updated: Thu, 01 Nov 2007