Table of Contents
List of Examples
Table of Contents
Summary — An introduction to the PHP MAPI Extension
The PHP-MAPI extension provides access to MS MAPI function from php. Although not all MAPI functions and interfaces are supported, most functions have a php counterpart in this extension. Using PHP-MAPI, users can create webbased e-mail and calendaring systems and interfaces with existing php projects, using the mapi functions like a normal mapi program.
The complete PHP-MAPI extension was based on the MAPI specification by Microsoft, which can be downloaded from MSDN at no charge. The functions defined in chapter 2, the php-mapi reference, are usually directly related to their MAPI counterpart and most information provided by the Microsoft MAPI specification is also applicable to the functions defined in the reference.
Also, general MAPI practices, hierarchies and properties apply to the PHP-MAPI extension. You are assumed to have basic knowledge of MAPI and its object structure before reading this reference manual.
Current unsupported features of MAPI are:
The IProfAdmin interface and related interfaces
Notifications, interfaces and related functions
Search folders: creation and use of
Unicode string properties (read/write, except for named properties which are always Unicode)
Folder and message operations: copyTo etc.
Additional features since 4.1 are:
Selected Addressbook functions (IAddrBook and others)
SetReadFlags function on a MAPI folder was added
GetNamesFromIDs function for named properties was added
IExchangeModifyTable interface support
Zarafa specific admin functions to create users, groups and adminster them
Zarafa specific permission functions to get and set permissions on items
Ability to get the last occurred HRESULT from the called mapi functions
The latest version of this document can be downloaded from http://developer.zarafa.com/
Table of Contents
This chapter will describe the PHP-MAPI API and how to use it. It will describe also some tricks that can be applied to make programming easier.
Properties — Explanation of MAPI properties.
Every object in MAPI has several properties set. The properties contains information about the object like the name, the unique id, etc... A property tag consists of a type and a unique id, the property type and the property id. A property tag is made as in the following example:
Example 2.1. Property definitions
define ('PR_SUBJECT', mapi_prop_tag(PT_TSTRING, 0x0037);
// This will result in a constant PR_SUBJECT with the value 0x001E0037
Within the PHP-code all of the properties are defined with a PR_ prefix to indicatie it is a PRoperty. All type codes are prefixed with PT_ (Property Type).
The function mapi_prop_tag accepts the
property type and the property id and returns a unique code that
indicates the property tag. This code is a simple long where the first
16 bits are the type and the last 16 bits are the ID.
Possible property types are:
PT_NULL, PT_ERROR Single properties PT_I2, PT_LONG, PT_FLOAT, PT_DOUBLE, PT_APPTIME, PT_BOOLEAN, PT_STRING8, PT_SYSTIME, PT_BINARY, PT_CLSID Multi value properties PT_MV_I2, PT_MV_LONG, PT_MV_R4, PT_MV_DOUBLE, PT_MV_APPTIME PT_MV_SYSTIME, PT_MV_STRING8, PT_MV_BINARY, PT_MV_CLSID Not support: PT_CURRENCY, PT_UNICODE, PT_OBJECT, PT_I8 PT_MV_CURRENCY, PT_MV_UNICODE, PT_MV_I8 Special properties for rules table: PT_ACTIONS and PT_SRESTRICTION
Checking Errors — How to handle errors from the extension.
When an array of properties is retrieved with the function
mapi_getprops by example there could some
problems with the properties. Because of optimalization MAPI has a
restricition on the size of a property. When by example a PR_BODY is
too big the error MAPI_E_NOT_ENOUGH_MEMORY will be returned instead of
the actual data.
The type of this property will be set to PT_ERROR instead of PT_TSTRING. The value of the property will be the code of the error that occured. The numeric value of the property tag will be 0x000A0037 which is different from 0x001E0037. This requires a special way to check if there is an error and find out what the error code is.
The following program listing gives an example how to check the property on an error and how to get the error from the property:
Example 2.2. Checking property errors in an object
// get properties
$msg_props = mapi_getprops($message);
if (array_key_exists($msg_props, PR_BODY) {
// there is a body with no error, display body here
} else {
$pr_body_error = mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_BODY));
if (array_key_exists($msg_props, $pr_body_error)) {
// found an error, now check which
switch($msg_props[$pr_body_error]) {
case MAPI_E_NOT_ENOUGH_MEMORY:
// found but too big, use mapi_openproperty the get the data.
break;
default:
// other error.
break;
}
} else {
// No error found, the body doesn't exist in this object.
}
}
Also, when checking error values (such as 0x80040107, MAPI_E_NOT_FOUND), you must use the mapi_is_error function to check whether the valus is actually an error. This is due to the fact that 0x800xxxxx numbers are not handed as unsigned numbers within PHP.
Example 2.3. Checking for errors or warnings
if(mapi_is_error($msg_props[$pr_body_error])) {
echo "error!\n";
}
When a function returns the value 'false', it means the function has failed. To retrieve the MAPI error, you can use the mapi_last_hresult() function, to get the last returned HRESULT value of a MAPI function. Example:
Example 2.4. Checking last MAPI returned error code
$inbox = mapi_msgstore_getreceivefolder($store);
if ($inbox == false) {
print "no inbox available!\n";
printf("last result: %x\n",mapi_last_hresult());
}
Restrictions — Using restrictions on tables.
Restrictions limit the rows queried using a set of conditions. This way messages can be selected on specific properties, such as the existance of a certain property, a property's value larger than a certain value, etc..
A restriction is specified with an array with one value with the restriction type and one value with an array with the restriction specific properties.
Restriction types:
Takes an array with restrictions that must all be valid.
Expects an array with restrictions of which either one can be valid.
Wants an array with a single restriction that must not be valid.
Fuzzy search a property. The array must contain: FUZZYLEVEL, ULPROPTAG and VALUE. VALUE must be a string or binary. VALUE => array (tag => value)
Takes an array with properties of a property which must be valid. This array must contain: RELOP, ULPROPTAG and VALUE. The property and VALUE can have different types. VALUE => array (tag => value)
Compares two props. Expects an array with the indexes: RELOP, ULPROPTAG1 and ULPROPTAG2.
Applies a bitmask. The given array must contain: ULPROPTAG, ULTYPE and ULMASK.
Measures the size of a property. The array must have: ULPROPTAG, RELOP and CB.
Checks whether a property exists. Takes only ULPROPTAG in its array.
Places a restriction on a property. This is used on PR_MESSAGE_RECIPIENT properties with an RES_COMMENT restriction.
A comment restriction can be used to add comments to the restriction structure, or in a special case with the RES_SUBRESTRICTION. The RES_COMMENT structure holds a RES_PROPERTY restriction, which applies on the given properties list in the structure.
RELOP can be:
Less than.
Less than or equal to.
Greater than.
Greater than or equal to.
Equal to.
Not equal to.
The attachment has just been created.
FUZZYLEVEL can be one or bitwise more of these:
The property must be equal to this exact string.
Full text search for substring.
The value must start with this string.
Case should be ignored.
Non-spaces should be ignored.
The string is allowed to match loosely.
Example 2.5. Simple restriction example
// Example for restrictions
$testrestriction = Array(RES_OR,
Array(Array(RES_PROPERTY,
Array(RELOP => RELOP_LE,
ULPROPTAG => PR_BODY,
VALUE => array(PR_BODY =>"test") )),
Array(RES_PROPERTY,
Array(RELOP => RELOP_LE,
ULPROPTAG => PR_SUBJECT,
VALUE => array(PR_SUBJECT => "bericht")))));
$contents = mapi_table_queryallrows($table, $props, $sizerestriction);
foreach ($contents as $row)
{
echo $row[PR_SUBJECT];
echo "\n";
}
Example 2.6. RES_SUBRESTRICTION + RES_COMMENT example
$restriction = array(RES_SUBRESTRICTION, array(ULPROPTAG => PR_MESSAGE_RECIPIENTS, // this is the subobject RESTRICTION => array(RES_COMMENT, array(PROPS => array(), // probably need to add outlook data RESTRICTION => array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_SEARCH_KEY, VALUE => array(PR_SEARCH_KEY => "one-off entryid") ) ) ) ) ) );
Attachments — Adding attachments to messages.
Attachments are used to send a binary file with a email message. There are a few different attachments types.
| ATTACH_BY_VALUE, the attachment data is stored within the message object. |
| ATTACH_EMBEDDED_MSG, the attachment is stored as a message object within the message object. |
| ATTACH_BY_REFERENCE, ATTACH_BY_REF_RESOLVE and ATTACH_BY_REF_ONLY are references to a file by name. Since the PHP code runs on the server, these types are unsupported. |
All of these types use different ways to store the name and to
store the attachement data. with
mapi_message_getattachmenttable() the table with
all the attachments can be read from the message. Every row in this
table has a property PR_ATTACH_METHOD which defines with which method
the attachment was stored (see the values above). The property to read
from an attachment or the function to call depends on the method an
attachment has:
The attachment has just been created.
The PR_ATTACH_FILENAME and PR_ATTACH_LONG_FILENAME contains
the name of the attachment. When the attachment is opened with
mapi_message_openattach() the data can be read with
mapi_attach_openbin().
The PR_DISPLAY_NAME contains the name of the attachment
(This is mostly the PR_SUBJECT of the message that has been
attached). With mapi_attach_openobj() the
attachment can be read from the message. This function returns a
message object.
These types are unsupported and should never be used.
When created, all attachment objects have an initial PR_ATTACH_METHOD value of NO_ATTACHMENT. Client applications and service providers are only required to support the attachment method represented by the ATTACH_BY_VALUE value. The other attachment methods are optional.
The message store does not enforce any consistency between the value of PR_ATTACH_METHOD and the values of the other attachment properties.
Messages — Reading messages.
The reading of the contents from a message can be done in a generic way. All messages contain all types of bodies. The different body types are kept in sync automatically, and the version which is written last wins, and updates the other versions. The following body types are available:
There are 3 ways in which the body of a message can be stored:
The content of the message is stored in the PR_RTF_COMPRESSED property.
The content of the message is stored in the PR_RTF_COMPRESSED property. This is a special type of RTF that has an embedded HTML content. This version has been depricated by normal HTML.
The content of the message is stored in the PR_HTML property. This is normal HTML formatted text.
The content of the body is stored in the PR_BODY property, and only contains the plain text.
The PR_RTF_COMPRESSED property can hold RTF of HTML embedded text. If you use this property, you can convert it to HTML with the mapi_rtf2html function. Therefore, this property is only usefull to detect if the original message was sent in TRF or HTML.
The RTF-text may be used when messages are stored within Outlook. RTF text can only be sent through the TNEF data in a winmail.dat attachment.
The messages that are sent in HTML will be stored as RTF in the
PR_RTF_COMPRESSED property. The HTML is converted from plain HTML to
Embedded HTML. With the function mapi_rtf2html
this type of RTF can be converted back to HTML to be shown in a
browser. The function will return false when the RTF is not of the
correct type.
While this is still true, this method of reading the body is depricated. If you want the HTML version of the body, use the normal HTML property.
Recipients — Using the recipient table.
Recipients are used to specify the receiving entities for a specific message.
The structure of a recipient array in PHP is as follows. When recipients are set, you should use mapi_createoneoff() to create the right PR_ENTRYIDs:
Example 2.7. Recipient table
// Create array of recipients usable by the PHP MAPI functions
$recipientarray = Array(Array(PR_ENTRYID => mapi_createoneoff("John Doe", "SMTP", "john@example.com"),
PR_DISPLAY_NAME => "John Doe",
PR_ADDRTYPE => "SMTP",
PR_EMAIL_ADDRESS => "john@example.com"
PR_RECIPIENT_TYPE => MAPI_TO),
Array(PR_ENTRYID => mapi_createoneoff("Steve Ballmer", "SMTP", "ballmer@microsoft.com"),
PR_DISPLAY_NAME => "Steve Ballmer",
PR_ADDRTYPE => "SMTP",
PR_EMAIL_ADDRESS => "ballmer@microsoft.com"
PR_RECIPIENT_TYPE => MAPI_CC),
Array(PR_ENTRYID => mapi_createoneoff("ConnecTUX", "SMTP", "info@connectux.com"),
PR_DISPLAY_NAME => "ConnecTUX",
PR_ADDRTYPE => "SMTP",
PR_EMAIL_ADDRESS => "info@connectux.com"
PR_RECIPIENT_TYPE => MAPI_BCC));
To set or get recipients, use the mapi_message_modifyrecipients and mapi_message_getrecipienttable methods.
Table of Contents
General Functions — Functions that are not directly MAPI related.
long mapi_is_error(long $hresult);long mapi_last_hresult();long mapi_make_scode(long $severity,
long $code);long mapi_prop_id(long $proptag);long mapi_prop_type(long $proptag);long mapi_prop_tag(long $proptype,
long $propid);array mapi_getidsfromnames(mapimsgstore $store,
array $names,
array $guids);array mapi_getnamesfromids(mapimsgstore $store,
array $proptags);array mapi_getprops(mapiobject $obj,
array $properties);boolean mapi_setprops(mapiobject $obj,
array $properties);boolean mapi_copyto(mapiobject $srcobj,
array $excludeiids,
array $excludeprops,
mapiobject $dstobj,
long $flags);boolean mapi_savechanges(mapiobj $object);boolean mapi_deleteprops(mapiobject $obj,
array $properties);string mapi_openproperty(mapipropObj $mapipropObj,
long $propertytag,
string $interface,
long $interfaceflags,
long $flags);string mapi_createoneoff(string $displayname,
string $type,
string $emailaddress,
long $flags);array mapi_parseoneoff(string $oneoff);long mapi_is_error(long $hresult)
Checks if the high bit of the passed error is set.
$hresultlong mapi_last_hresult()
Returns 0 if last call succeeded. Otherwise, this value contains the MAPI error code. MAPI error codes are defined in include/php/mapicode.php.
Example 3.2. Checking the last MAPI HRESULT
$inbox = mapi_msgstore_getreceivefolder($store);
if($inbox == false) {
if (mapi_last_hresult() == MAPI_E_NO_ACCESS) {
print "Access was denied to the inbox!\n";
}
}
long mapi_make_scode(long $severity, long $code)
This function returns the SCODE value of the specified error. Refer to MSDN for further information on SCODEs.
$severity$codelong mapi_prop_id(long $proptag)
Returns the ID part of the property tag (the high 16 bits).
$proptagExample 3.4. Getting the ID of a propertytag
// Get the ID $id = mapi_prop_id(PR_SUBJECT); // $id is now 0x0037
long mapi_prop_type(long $proptag)
Returns the type part of the property tag (the low 16 bits).
$proptagExample 3.5. Getting the type of a propertytag
// Get the type $id = mapi_prop_type(PR_SUBJECT); // $id is now equal to PT_STRING8
long mapi_prop_tag(long $proptype, long $propid)
A propertytag is a unique identifier of a property. The property ID and property type are stores into the propertytag. Returns the property tag.
The default MAPI function is used.
![]() | Note |
|---|---|
Because PHP can't handle unsigned longs some of the propertytags look like this -2129461248. |
$proptype$propidExample 3.6. Making a PR_SUBJECT
// Make a PR_SUBJECT
define('PR_SUBJECT', mapi_prop_tag(PT_STRING8, 0x0037));
array mapi_getidsfromnames(mapimsgstore $store, array $names, array $guids)
Returns an array of mapped properties for the names specified. If $guids is not specified, then the default GUID {00062002-0000-0000-C000-000000000046} is used for all names. The returned properties are all of type PT_UNSPECIFIED so they have to be converted to the correct property types before being passed to mapi_setprops or mapi_getprops. Returns an array on success, FALSE on failure.
$store$names$guids (Optional)Example 3.7. Mapping start and end named properties for calendar items
// Get the ID's of the named properties for 'Start' and 'End' of calendar items
$ids = mapi_getidsfromnames($store, Array(0x820d, 0x820e), Array("{00062002-0000-0000-C000-000000000046}","{00062002-0000-0000-C000-000000000046}"});
// Create actual proptags by adding the type of the properties
$ids[0] = mapi_prop_tag(PT_SYSTIME, mapi_prop_id($ids[0]);
$ids[1] = mapi_prop_tag(PT_SYSTIME, mapi_prop_id($ids[1]);
$startend = mapi_message_getprops($message, $ids);
array mapi_getnamesfromids(mapimsgstore $store, array $proptags)
Returns an array of mapped properties for the ids specified. Returns an array on success, FALSE on failure. The array contains a name or id and a guid for each found property.
$store$proptagsExample 3.8. Get names from IDs
// Get the ID's of the named properties for 'Start' and 'End' of calendar items $ids = mapi_getidsfromnames($store, Array(0x820d, 0x820e)); // Re-read the names from the ids we just got. $names = mapi_getnamesfromids($store, $ids); print_r($names); // or create a new array list of ids $names = mapi_getnamesfromids($store, array(mapi_prop_tag(PT_NULL, 0x8503), mapi_prop_tag(PT_NULL, 0x8001))); print_r($names);
Output:
Array
(
[-2146631680] => Array
(
[guid] => guid...
[id] => 33293
)
[-2146566144] => Array
(
[guid] => guid...
[id] => 33294
)
[-2146959360] => Array
(
[guid] => guid...
[id] => 33288
)
[-2146238464] => Array
(
[guid] => guid...
[id] => 33299
)
[-2144010240] => Array
(
[guid] => guid...
[id] => 33333
)
)
Array
(
[-2063400959] => Array
(
[guid] => guid...
[name] => ...
)
[-2147418111] => Array
(
[guid] => guid...
[id] => 33281
)
)
array mapi_getprops(mapiobject $obj, array $properties)
This function returns an associative array of the requested properties and their values. If the value is not available, the value is not added to the associative array. Returns an array on success, FALSE on failure.
$obj$properties (optional)Example 3.9. Getting the properties of a store
// Get the properties of the message store $storeprops = mapi_getprops($userstore, array(PR_DISPLAY_NAME)); print "Store: " . $storeprops[PR_DISPLAY_NAME];
boolean mapi_setprops(mapiobject $obj, array $properties)
This function will set the properties for a MAPI object. It will work for all objects that inherit from IMAPIProp.
$obj$propertiesExample 3.10. Setting the properties of a message
// Create a message and set some props. $message = mapi_message_createmessage($inbox); // Create an array with some props $props = Array(PR_SUBJECT => "Testsubject", PR_BODY => "Hello world!"); // Set props mapi_setprops($message, $props); // Save changes mapi_savechanges($message);
boolean mapi_copyto(mapiobject $srcobj, array $excludeiids, array $excludeprops, mapiobject $dstobj, long $flags)
This function will copy the properties for a MAPI object. It will work for all objects that inherit from IMAPIProp.
$srcobj$excludeiids$excludeprops$dstobj$flagsExample 3.11. Copying the properties of a message
// Create a message $newmessage = mapi_message_createmessage($inbox); // Copy message mapi_copyto($message, array(), array(), $newmessage); // Save changes mapi_savechanges($newmessage);
boolean mapi_savechanges(mapiobj $object)
Save changes on a MAPI Object. This is mostly used on a message or attachment to push the property changes to the server.
Changes to a MAPI resource are not actually sent to the server until a mapi_savechanges is called. When creating new messages, the message wil be deleted if a mapi_savechanges call is not sent to the newly created message object. Returns TRUE on success, FALSE on failure.
$objectExample 3.12. Saving changes to a message
// Set the subject mapi_setprops($message, Array(PR_SUBJECT) => "New subject")); mapi_savechanges($message);
boolean mapi_deleteprops(mapiobject $obj, array $properties)
Delete properties from a mapi object.
This function deletes the properties given from a object. This works for all object that are derived from IMAPIProp.
Returns true when the deletion has been successful or false when something got wrong.
$obj$properties (optional)Example 3.13. Deleting a property of a message
// Deleting a property of a message $message = mapi_msgstore_openentry($userstore, $message_entryid); // remove subject from a message mapi_deleteprops($message, array(PR_SUBJECT)); mapi_savechanges($message);
string mapi_openproperty(mapipropObj $mapipropObj, long $propertytag, string $interface, long $interfaceflags, long $flags)
Opens a property from an object.
Some properties are not shown when a mapi_getprops is executed, and return MAPI_E_NOT_ENOUGH_MEMORY. With mapi_openproperty these properties can be read, and are returned as a string. Returns a string on success, FALSE on failure.
$mapipropObj$propertytag$interface$interfaceflags$flagsExample 3.14. Getting a property
// Open a property from a folder $viewliststream = mapi_openproperty($inbox, PR_FOLDER_VIEWLIST, IID_IStream, 0, 0);
string mapi_createoneoff(string $displayname, string $type, string $emailaddress, long $flags)
Creates a One-Off entry identifier.
This function creates a One-Off entry identifier. These are used in recipient tables (for PR_ENTRYID) and in message properties. These are also used in flatentrylists. Returned is a binary string with the entry identifier.
$displayname$type$emailaddress$flags (optional)Bitmask of flags that affects the one-off recipient.
The display name, address type, and address are in Unicode format.
The recipient cannot handle formatted message content. If MAPI_SEND_NO_RICH_INFO is set, MAPI sets the recipient's PR_SEND_RICH_INFO property to FALSE. If MAPI_SEND_NO_RICH_INFO is not set, MAPI sets this property to TRUE unless the recipient's messaging address pointed to by lpszAddress is interpreted to be an Internet address. In this case, MAPI sets PR_SEND_RICH_INFO to FALSE.
Example 3.15. Creating a one-off entry identifier
// Creating a one-off entry identifier
$oneoffentryid = mapi_createoneoff("John Doe", "SMTP", "john@example.com");
array mapi_parseoneoff(string $oneoff)
Parses a one-off entryid to an array with meaningful values.
This function takes a one-off entryid and parses it. Given back is an array with indexes 'name', 'type' and 'value'.
$oneoffExample 3.16. Listing the Zarafa users
$props = mapi_getprops($message, Array(PR_ENTRYID)); $result = mapi_parseoneoff($props[PR_ENTRYID]); echo "Display name: ".$result['name']; echo "Type: ".$result['type']; echo "E-mail address: ".$result['address'];
Logon Functions — This section describes the various logon functions.
mapisession mapi_logon(string $profile,
string $password);mapisession mapi_logon_zarafa(string $username,
string $password,
string $server);mapisession mapi_logon_pst(string $filename);mapimsgstore mapi_openmsgstore(mapisession $session,
string $entryID);resource mapi_openentry(mapisession $session,
string $entryID,
long $flags);mapitable mapi_getmsgstorestable(mapisession $session);array mapi_openmsgstore_zarafa(string $username,
string $password,
string $server);mapimsgstore mapi_openmsgstore_zarafa_other(string $entryid,
string $username,
string $password,
string $server);mapisession mapi_logon(string $profile, string $password)
Logon to a MAPI profile
mapi_logon uses the MAPI calls MAPILogonEx(). Returns a mapisession object on success, FALSE on failure.
Example 3.17. Logging on to the default profile
// Log on to the default profile with no password
$session = mapi_logon('','');
mapisession mapi_logon_zarafa(string $username, string $password, string $server)
Logon to a Zarafa server
mapi_logon_zarafa logs a user on to the server. A MAPI Session object is returned, which is required for further calls. This is the preferred method to logon to Zarafa. On failure, FALSE is returned.
Example 3.18. Logging on to the Zarafa server using the unix socket
$session = mapi_logon_zarafa('user','password','file:///var/run/zarafa');
if ($session == false) {
print "logon failed with error ".mapi_last_hresult()."\n";
}
mapisession mapi_logon_pst(string $filename)
Logon to a local MAPI PST-file
mapi_logon_pst makes a profile and uses the filename to store the information in a PST-file. You can open a specific PST file with this function, however, remember that only one process at a time can access a PST file. However, because the php-mapi extension shares sessions accross requests, you can open the same PST file across multiple PHP requests. Returns a mapisession object on success, FALSE on failure.
Example 3.19. Logging on to a PST-file
// Log on to a PST files
$session = mapi_logon_pst('C:\outlook.pst');
mapimsgstore mapi_openmsgstore(mapisession $session, string $entryID)
Opens a messagestore
The session is used to open a messagestore with the entryID given. Returns a mapimsgstore object on success, FALSE on failure.
![]() | Note |
|---|---|
When the entryid is a hexadecimal string, the function hex2bin must be used to convert the string to binary. Also the function bin2hex can be used to convert from binary to hexadecimal. |
Example 3.20. Opening the stores of a Zarafa session
// $serverlocation is optional, default http://localhost:236/zarafa $session = mapi_logon_zarafa($username, $password, $serverlocation); $stores = mapi_getmsgstorestable($session); $storeslist = mapi_table_queryallrows($stores); $userstore = mapi_openmsgstore($session, $storeslist[0][PR_ENTRYID]); $publicstore = mapi_openmsgstore($session, $storeslist[1][PR_ENTRYID]);
resource mapi_openentry(mapisession $session, string $entryID, long $flags)
Opens an entry from a messagestore or addressbook.
This function works as mapi_msgstore_openentry but automatically detects from which store the message should be opened. It can also be used for EntryIDs in the addressbook and one-off EntryIDs. Because this function must open a store to get the item in that store, it is more efficient to use the mapi_msgstore_openentry function.
mapitable mapi_getmsgstorestable(mapisession $session)
Gets a table with the messagestores within the session.
Gets a table with the messagestores defined in the profile. The profile should be opened first with the function mapi_logon_zarafa. The table can be read with a mapi_table_* functions. Internally, this function calls the MAPI function GetMsgStoreTable(). Returns a mapitable object on success, FALSE on failure.
Example 3.21. Getting the table with the stores
// Get the table $session = mapi_logon_zarafa($username, $password, $serverlocation); $table = mapi_getmsgstorestable($session);
array mapi_openmsgstore_zarafa(string $username, string $password, string $server)
Opens an store for an existing Zarafa user.
Opens a store of a user on the Zarafa server. The result is either false, or an array of valid php resource id's which point to the userstore and the public store.
![]() | Warning |
|---|---|
This function is depricated. Please use the mapi_logon_zarafa() function. This function will be removed in the future. |
Example 3.22. Opening a Zarafa message store
$stores = mapi_openmsgstore_zarafa("user","password");
// print properties of the userstore
print_r(mapi_getprops($stores[0]));
mapimsgstore mapi_openmsgstore_zarafa_other(string $entryid, string $username, string $password, string $server)
Opens an store for an existing Zarafa user. This function is depricated, and will be removed in the future.
Opens a store of a different user on the Zarafa server than which is known with username and password combination. This is actually a hack at the moment because of the limitations of mapi4linux (see source for more documentation). The result is either false, or a valid php resource id.
![]() | Warning |
|---|---|
This function is depricated and will be removed in the future. |
Example 3.23. Opening multiple Zarafa message stores
// usage example of depricated mapi_openmsgstore_zarafa_other();
$store = mapi_openmsgstore_zarafa("user","password");
$user2_entryid = mapi_msgstore_createentryid($store, "user2");
$user2_store = mapi_openmsgstore_zarafa_other($user2_entryid, "user", "password");
print_r(mapi_getprops($user2_store));
Example 3.24. Opening multiple Zarafa message stores
// normal MAPI way of opening other users store $session = mapi_logon_zarafa($username, $password, $serverlocation); $stores = mapi_getmsgstorestable($session); $storeslist = mapi_table_queryallrows($stores); $userstore = mapi_openmsgstore($session, $storeslist[0][PR_ENTRYID]); $publicstore = mapi_openmsgstore($session, $storeslist[1][PR_ENTRYID]); $user2_entryid = mapi_msgstore_createentryid($userstore, "user2"); $user2_store = mapi_openmsgstore($session, $user2_entryid);
Store Functions — This section describes functions which are performed on MAPI Store objects.
mapifolder mapi_msgstore_getreceivefolder(mapimsgstore $store);resource mapi_msgstore_openentry(mapimsgstore $messagestore,
string $entryID,
long $flags);string mapi_msgstore_createentryid(resource $store,
string $username);mapitable mapi_msgstore_openmultistoretable(mapimsgstore $store,
array $entryids,
long $flags);mapifolder mapi_msgstore_getreceivefolder(mapimsgstore $store)
Open the inbox for the specified store.
This function requests the EntryID for the inbox of the given store and opens the folder. Returns a mapifolder object on success, FALSE on failure.
Example 3.25. Opening the inbox of a store
// Open the inbox for a user $store = mapi_logon_zarafa($username, $password, $serverlocation); $stores = mapi_getmsgstorestable($session); $storeslist = mapi_table_queryallrows($stores); $userstore = mapi_openmsgstore($session, $storeslist[0][PR_ENTRYID]); $inbox = mapi_msgstore_getreceivefolder($userstore);
resource mapi_msgstore_openentry(mapimsgstore $messagestore, string $entryID, long $flags
Opens an entry from the messagestore.
This function opens an entry from the messagestore. The function will return a mapifolder or a mapimessage, depending on the entryID. Returns a mapimessage or mapifolder object on success, FALSE on failure.
Bitmask of flags that controls how information is returned in the table. The following flags can be set:
Requests that the object be opened with the maximum network permissions allowed for the user and the maximum client application access. For example, if the client has read/write access, the object should be opened with read/write access; if the client has read-only access, the object should be opened with read-only access.
Requests read/write access. By default, objects are opened with read-only access, and clients should not work on the assumption that read/write access has been granted.
Open a Soft Deleted Message or Folder.
Example 3.26. Opening an entry from a messagestore
// Open a folder from a store $folder = mapi_msgstore_openentry($store, $folder_entryid); // Open a message from a store $message = mapi_msgstore_openentry($store, $message_entryid);
string mapi_msgstore_createentryid(resource $store, string $username)
Returns an entryid string to an arbitrary user store which exists on the Zarafa server.
Creates an EntryID to use with mapi_openmsgstore() function. Result is false if the store was not found, otherwise it will return a valid entryid.
Example 3.27. Opening a Zarafa message store
$user2_entryid = mapi_msgstore_createentryid($userstore, "user2"); $user2_store = mapi_openmsgstore($session, $user2_entryid);
mapitable mapi_msgstore_openmultistoretable(mapimsgstore $store, array $entryids, long $flags
Open a special table that may contain items from different stores. The items you wish the table to contain is passed to this function.
This function opens a special table which contains items the user sets. The return value can be treated a normal table, using the mapi_table_* functions to handle it.. Returns a mapitable object on success, FALSE on failure.
Example 3.28. Opening the special multistore table
// Open the inbox for a user $store = mapi_logon_zarafa($username, $password, $serverlocation); $stores = mapi_getmsgstorestable($session); $storeslist = mapi_table_queryallrows($stores); $userstore = mapi_openmsgstore($session, $storeslist[0][PR_ENTRYID]); // array() should be replaced with an array of entry id's of messages $mst = mapi_msgstore_openmultistoretable($userstore, array());
Folder Functions — This section describes functions which are performed on MAPI Folder objects.
mapitable mapi_folder_gethierarchytable(mapifolder $folder,
long $flags);mapitable mapi_folder_getcontentstable(mapifolder $folder,
long $flags);mapimessage mapi_folder_createmessage(mapifolder $folder,
long $flags);boolean mapi_folder_deletemessages(mapifolder $folder,
array $entryids,
long $flags);boolean mapi_folder_copymessages(mapifolder $srcFolder,
array $messageArray,
mapifolder $destFolder,
long $Flags);boolean mapi_folder_emptyfolder(mapifolder $folder,
long $flags);boolean mapi_folder_copyfolder(mapifolder $srcfolder,
string $entryid,
mapifolder $destfolder,
string $new_foldername,
long $flags);boolean mapi_folder_deletefolder(mapifolder $srcfolder,
long $entryid,
long $flags);boolean mapi_folder_createfolder(mapifolder $parentfolder,
string $name,
string $description,
long $flags,
long $foldertype);boolean mapi_folder_setreadflags(mapifolder $folder,
array $entryids,
long $flags);resource mapi_folder_openmodifytable(mapifolder $inbox);bool mapi_folder_setsearchcriteria(mapifolder $folder,
array $restriction,
array $folderlistr,
long $flags);bool mapi_folder_getsearchcriteria(mapifolder $folder,
long $flags);mapitable mapi_folder_gethierarchytable(mapifolder $folder, long $flags)
Gets the hierarchytable
Opens the hierarchytable of the folder. The hierarchytable contains the subfolders of the folder. Returns a mapitable object on success, FALSE on failure.
Bitmask of flags that controls how information is returned in the table. The following flags can be set:
Get a list of Soft Deleted Folders of the subfolder pointed to by $entryid.
Example 3.29. Getting the hierarchytable
// Get a the messagestore $inbox is a valid MAPI Folder $table = mapi_folder_gethierarchytable($inbox);
mapitable mapi_folder_getcontentstable(mapifolder $folder, long $flags)
Gets the contentstable
Opens the contentstable of the folder. The contentstable contains the messages of the folder. Returns a mapitable object on success, FALSE on failure.
Bitmask of flags that controls how information is returned in the table. The following flags can be set:
Get a list of associated messages of the subfolder pointed to by $folder.
Get a list of Soft Deleted messages of the subfolder pointed to by $folder.
Example 3.30. Getting the getcontentstable
// Get the messages of $inbox $table = mapi_folder_getcontentstable($inbox);
mapimessage mapi_folder_createmessage(mapifolder $folder, long $flags)
Creates a new message in the folder
This function makes a new message in the folder. It returns the newly created message and with mapi_setprops properties can be stored into the message. The message is not visible to other users until the mapi_savechanges function is called. Returns a mapimessage object on success, FALSE on failure.
A bitmask of flags that control the creation of a folder. The following flags can be set:
Allows CreateMessage to return successfully, possibly before the new folder is fully accessible to the calling client. If the new message is not accessible, making a subsequent call to it can result in an error.
The message to be created should be included in the associated contents table rather than the standard contents table. Associated messages typically contain invisible data, such as view descriptors.
Example 3.31. Creating a new message
// Create a new message into the inbox $viewlist = mapi_folder_createmessage($inbox);
boolean mapi_folder_deletemessages(mapifolder $folder, array $entryids, long $flags)
Deletes messages from a folder
This function removes a message with the given entryid's from the specified folder. Note that normally in Outlook, messages are simply moved to the 'Deleted items' folder when a 'delete' is requested, and messages are only really deleted when they are removed from the 'Deleted items' folder. Returns TRUE for success, FALSE for failure.
Bitmask of flags that controls how information is returned in the table. The following flags can be set:
Hard Delete the messages given by $entryid.
Example 3.32. Creating and removing a message
// Create a new message into the inbox $msg = mapi_folder_createmessage($inbox); mapi_savechanges($msg); // Get the EntryID $props = mapi_message_getprops($msg); // Remove it mapi_folder_deletemessages(array($props[PR_ENTRYID]));
boolean mapi_folder_copymessages(mapifolder $srcFolder, array $messageArray, mapifolder $destFolder, long $Flags)
Copies one or more messages from one folder to another.
This function moves or copies the one or more messages given with the messageArray. The function will return true when the copying was succesfull.
The messagearray must be in following structure:
$messageArray = array (
[0] => {entryid}
[1] => {entryid}
...
);
The optional flag can be MESSAGE_MOVE when the messages must be moved from the sourcefolder to the destination folder, when no flag is provided the messages will be copied.
Example 3.33. Moving messages to the wastebasket
$storeprops = mapi_msgstore_getprops($userstore);
$wastebasket = mapi_msgstore_openentry($userstore, $storeprops[PR_IPM_WASTEBASKET_ENTRYID]);
$inbox = mapi_msgstore_getreceivefolder($userstore);
$contentstable = mapi_folder_getcontentstable($inbox);
$contents = mapi_table_queryallrows($contentstable);
foreach($contents as $row) {
$msg[] = $row[PR_ENTRYID];
}
mapi_folder_copymessages($inbox, $msg, $wastebasket, MESSAGE_MOVE);
boolean mapi_folder_emptyfolder(mapifolder $folder, long $flags)
Deletes all the messages in a folder.
This function deletes all the messages and subfolders in the folder. But without deleting itself.
The followin flag can be set: DEL_ASSOCIATED With this flag set the function deletes all subfolders, including subfolders containing messages with associated content. The DEL_ASSOCIATED flag only has meaning for the top-level folder the call acts on.
Bitmask of flags that controls how the folder is emptied. The following flags can be set:
Deletes all subfolders, including subfolders containing messages with associated content. The DEL_ASSOCIATED flag only has meaning for the top-level folder the call acts on.
Hard Delete the messages and/or folders
Example 3.34. Emptying a folder
$storeprops = mapi_msgstore_getprops($userstore); $wastebasket = mapi_msgstore_openentry($userstore, $storeprops[PR_IPM_WASTEBASKET_ENTRYID]); mapi_folder_emptyfolder($wastebasket); // wastebasket is empty now.
boolean mapi_folder_copyfolder(mapifolder $srcfolder, string $entryid, mapifolder $destfolder, string $new_foldername, long $flags)
Copies a folder from one parent folder to another.
This function moves or copies the folder given with entryid. The function will return true when the copy/move was successful.
A bitmask of flags that control the setting of a message's read flag. The following flags can be set:
All of the subfolders in the folder to be copied should also be copied. When COPY_SUBFOLDERS is not set for a copy operation, only the folder identified by $entryid is copied. With a move operation, the COPY_SUBFOLDERS behavior is the default regardless of whether the flag is set.
The folder is to be moved rather than copied. If FOLDER_MOVE is not set, the folder is copied.
Example 3.35. Move a complete folder, with subtree, to a new destination
$res = mapi_folder_copyfolder($inbox, $tocopy_folder_entryid, $dest_folder, "New folder name", COPY_SUBFOLDERS | FOLDER_MOVE);
if ($res == false) {
print "mapi_folder_copyfolder() failed.";
}
boolean mapi_folder_deletefolder(mapifolder $srcfolder, long $entryid, long $flags)
Deletes a folder.
This function deletes the folder given with the entryid. The function will return true when the deletion was successful.
A bitmask of flags that control the setting of a message's read flag. The following flags can be set:
All subfolders of the subfolder pointed to by $entryid should be soft deleted.
All messages in the subfolder pointed to by $entryid should be soft deleted.
All messages in the subfolder pointed to by $entryid should be hard deleted.
Example 3.36. Deleting a folder
// Delete a folder $result = mapi_folder_deletefolder($parent, $folderid);
boolean mapi_folder_createfolder(mapifolder $parentfolder, string $name, string $description, long $flags, long $foldertype)
Creates a folder.
This function creates a folder within the given folder; with the given name and description. It returns true on success, false on failure.
A bitmask of flags that control the creation of a folder. The following flags can be set:
Allows CreateFolder to return successfully, possibly before the new folder is fully accessible to the calling client. If the new folder is not accessible, making a subsequent call to it can result in an error.
The passed-in strings are in Unicode format. If the MAPI_UNICODE flag is not set, the strings are in ANSI format.
Allows the method to succeed even if the folder named in the lpszFolderName parameter already exists by opening the existing folder with that name. Note that message store providers that allow sibling folders to have the same name might fail to open an existing folder if more than one exists with the supplied name.
Specify the type of the folder to create.
Create a generic folder.
Create a search folder.
Example 3.37. Creating a folder
// Create a folder $result = mapi_folder_createfolder($folder, "New folder", "Description for new folder");
boolean mapi_folder_setreadflags(mapifolder $folder, array $entryids, long $flags)
Mark a list of messages in a folder as read.
This function markes selected messages in a given folder. All the messages can be set read or unread in the folder. It returns true on success, false on failure.
A bitmask of flags that control the creation of a folder. The following flags can be set:
In stead of marking the messages read, the messages are marked Unread.
Example 3.38. Marking messages in a folder read
// Mark all messages read in the inbox $result = mapi_folder_createfolder($inbox, array());
resource mapi_folder_openmodifytable(mapifolder $inbox)
Returns the IExchangeModifyTable interface.
The IExchangeModifyTable interface is used for the rules table. Use this interface to read and write rules which are applied on incoming e-mails.
It returns the IExchangeModifyTable on success, false on failure.
Example 3.39. Requesting the IExchangeModifyTable interface
// Requesting the IExchangeModifyTable interface $inbox = mapi_msgstore_getreceivefolder($store); $emt = mapi_folder_openmodifytable($inbox);
bool mapi_folder_setsearchcriteria(mapifolder $folder, array $restriction, array $folderlistr, long $flags)
Set/reset search criteria of a search folder.
mapi_folder_setsearchcriteria can be used to setup a search folder. Once setsearchcriteria has been successfully called, the server will start running the search. A contents table for this folder with show only those items that match the search and will be dynamically built in the background.
Note that after setsearchcriteria has been called, the contents table will not directly show all matches, but will start to build them slowly. You can see if the search is still running by calling mapi_folder_getsearchcriteria.
bool mapi_folder_getsearchcriteria(mapifolder $folder, long $flags)
Get search criteria and status of a search folder.
mapi_folder_getsearchcriteria returns an associative array with three values: the restriction and folder list from setsearchcriteria, and a searchstate flag. These are stored respectively in the 'restriction', 'folderlist' and 'searchstate' keys in the returned associative array. The searchstate value may be any combination of SEARCH_REBUILD, SEARCH_RUNNING, SEARCH_FOREGROUND and SEARCH_RECURSIVE.
When a folder first starts the search process (after mapi_folder_setsearchcriteria), it will return SEARCH_REBUILD | SEARCH_RUNNING until the search has completed. After this, it will return SEARCH_RUNNING, until the search is restarted or stopped. If the search has stopped, neither SEARCH_REBUILD or SEARCH_RUNNING will be set.
Table Functions — This section describes functions which are performed on MAPI Table objects.
array mapi_table_queryallrows(mapitable $table,
array $tagarray,
array $restriction);array mapi_table_queryrows(mapitable $table,
array $tagarray,
long $start,
long $limit);long mapi_table_getrowcount(mapitable $table);boolean mapi_table_sort(mapitable $table,
array $sortcolumns);boolean mapi_table_restrict(mapitable $table,
array $restriction);array mapi_table_queryallrows(mapitable $table, array $tagarray, array $restriction)
Queries all the rows in a table and returns a PHP Array
This function reads all the rows of a table and returns the properties specified with the second parameter. Returns an array on success, FALSE on failure. An array with properties that should be queried can be given. Also, an array with restrictions can be given as third argument.
Example 3.40. Reading the rows from a table
// Read the rows with properties PR_ENTRYID and PR_SUBJECT // Restriction which should restrict messages smaller than or equal to 100 bytes $restriction = Array(RES_PROPERTY, Array(RELOP => RELOP_LE, ULPROPTAG => PR_MESSAGE_SIZE, VALUE => array (PR_MESSAGE_SIZE => 100) )); $array = mapi_table_queryallrows($table, array(PR_ENTRYID, PR_SUBJECT), $restriction);
array mapi_table_queryrows(mapitable $table, array $tagarray, long $start, long $limit)
Queries the rows in a table and returns a PHP Array
This function reads at most $limit rows the rows of a table, starting at row $start and returns the properties specified with the second parameter. Returns the array on success, FALSE on failure.
Example 3.41. Reading the rows from a table
// Read the rows with properties PR_ENTRYID and PR_SUBJECT $array = mapi_table_queryrows($table, array(PR_ENTRYID, PR_SUBJECT), 10, 10);
long mapi_table_getrowcount(mapitable $table)
Get the amount of rows in a table
Returns the total amount of rows in the table, however, the table may change while processing the rows in the table after retrieving the amount of rows, so you cannot rely on mapi_table_queryrows() to return data for a row which should have existed according to mapi_table_getrowcount(). Returns the amount of rows on success, FALSE on failure.
Example 3.42. Getting the the rows one by one from a table
// Read the rows with properties PR_ENTRYID and PR_SUBJECT
for ($i = 0; $i < mapi_table_getrowcount($table); $i++) {
$array = mapi_table_queryrows($table, array(PR_ENTRYID, PR_SUBJECT), $i, 1);
}
boolean mapi_table_sort(mapitable $table, array $sortcolumns)
Sort the given table according to columns.
This function sets the sort order of a table to the given sorting columns. The MAPI provider may or may not actually perform the sort operation at the time of the call, but usually the actual sort is performed when the data is retrieved from the table from mapi_table_queryrows or mapi_table_queryallrows. Returns TRUE on success, FALSE on failure.
Example 3.43. Sorting and retrieving the rows of a table by subject
// Read the rows with properties PR_ENTRYID and PR_SUBJECT
mapi_table_sort($table, array(PR_SUBJECT => TABLE_SORT_ASCEND));
for ($i = 0; $i < mapi_table_getrowcount($table); $i++) {
$array = mapi_table_queryrows($table, array(PR_ENTRYID, PR_SUBJECT), $i, 1);
}
boolean mapi_table_restrict(mapitable $table, array $restriction
Restrict the data in a table to certain rules.
This function sets a restriction on the table, narrowing the data in the table.
Example 3.44. Restriction on a mapitable
$restriction = array(RES_CONTENT, array( FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, ULPROPTAG => PR_SUBJECT, VALUE => array(PR_SUBJECT=>'spam')) ); mapi_table_restrict($table, $restriction); // all mapi_table_queryrows() calls here after only return rows that match the restriction // if the result was false, mapi_last_hresult() will probably be set to MAPI_E_TOO_COMPLEX mapi_table_restrict($table, array()); // this clears the restriction
Rules Functions — This section describes functions which are performed on the rules table.
array mapi_rules_gettable(resource $emt);boolean mapi_rules_modifytable(resource $emt,
array $rows,
long $flags);array mapi_rules_gettable(resource $emt)
Returns the rules table from an IExchangeModifyTable interface.
This function opens a table view on the rules table from the IExchangeModifyTable interface. Returns an mapi table object on success, or FALSE on failure.
Example 3.45. Retrieving the rules table
// Get the current rules $emt = mapi_folder_openmodifytable($inbox); $rtable = mapi_rules_gettable($emt); $rules = mapi_table_queryallrows($rtable); print_r($rules);
boolean mapi_rules_modifytable(resource $emt, array $rows, long $flags)
Modifies the rules table using the IExchangeModifyTable interface.
This function alters the rules table with the current row set. The previous table can be cleared when the ROWLIST_REPLACE is passed in the flags parameter. Returns an TRUE on success, or FALSE on failure.
Example 3.46. Modifying the rules table
// Get the interface $emt = mapi_folder_openmodifytable($inbox); $restriction = array(RES_CONTENT, array( FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, ULPROPTAG => PR_SUBJECT, VALUE => array(PR_SUBJECT=>'spam')) ); $action = array( array ( 'action' => OP_MOVE, 'storeentryid' => $publicstore_entryid, 'folderentryid' => $public_folder_entryid ), ); $rule = array( PR_RULE_ACTIONS => $action, PR_RULE_CONDITION => $restriction, PR_RULE_PROVIDER => 'RuleOrganizer', PR_RULE_STATE => ST_ENABLED, PR_RULE_NAME => 'move "spam" mails to "important" folder in the public store', ); $rows = array( 0 => array( 'rowflags' => ROW_ADD, 'properties' => $rule ) ); $result = mapi_rules_modifytable($emt, $rows); $rtable = mapi_rules_gettable($emt); $rules = mapi_table_queryallrows($rtable); print_r($rules);
Message Functions — This section describes functions which are performed on MAPI Message objects.
boolean mapi_message_setreadflag(mapimessage $message,
long $flag);mapitable mapi_message_getattachmenttable(mapimessage $message);mapitable mapi_message_getrecipienttable(mapimessage $message);boolean mapi_message_modifyrecipients(mapimessage $message,
long $flag,
array $recipients);mapiattach mapi_message_openattach(mapimessage $message,
long $attachnum);mapiattach mapi_message_createattach(mapimessage $message);boolean mapi_message_deleteattach(mapimessage $message,
long $attachnum);boolean mapi_message_submitmessage(mapimessage $message);boolean mapi_message_setreadflag(mapimessage $message, long $flag)
Sets the readflag of a specific message.
This function changes or sets the PR_MESSAGE_FLAGS property and controls the processing of read reports.
A bitmask of flags that control the setting of a message's read flag. The following flags can be set:
The MSGFLAG_READ flag should be cleared in PR_MESSAGE_FLAGS and no read report should be sent.
The MSGFLAG_NRN_PENDING flag should be cleared in PR_MESSAGE_FLAGS and a nonread report should not be sent.
The MSGFLAG_RN_PENDING flag should be cleared in PR_MESSAGE_FLAGS and no read report should be sent.
A read report should be sent if one is pending, but there should be no change in the state of the MSGFLAG_READ flag.
A pending read report should be canceled if a read report had been requested and this call changes the state of the message from unread to read. If this call does not change the state of the message, the message store provider can ignore this flag.
Example 3.47. Marking all messages as read in the inbox
$inbox = mapi_msgstore_getreceivefolder($userstore);
$contents = mapi_folder_getcontentstable($inbox);
// Loop through all the messages in the inbox and open them one by one,
// each time, marking the message read
for ($i = 0; $i < mapi_table_getrowcount($contents); $i++) {
$props = mapi_table_queryrows($contents, array(PR_ENTRYID), $i, 1);
$message = mapi_msgstore_openentry($userstore, $props[PR_ENTRYID]);
mapi_message_setreadflag($message);
}
// Note: you should actually do this with mapi_folder_setreadflags()
mapitable mapi_message_getattachmenttable(mapimessage $message)
Retrieve attachment table of a message
Returns a table of the attachments of a message. This table contains information about each attachment, most notably PR_ATTACH_NUM which can be passed to mapi_message_openattach to open the attachment object. The table is automatically updated when a new attachment is added or an attachment is removed (even if the attachment table is still open). Returns a mapitable object on success, FALSE on failure.
Example 3.48. Opening the attachmenttable of a message
$inbox = mapi_msgstore_getreceivefolder($userstore);
$contents = mapi_folder_getcontentstable($inbox);
// Loop through all the messages in the inbox and open them one by one,
// each time retrieving their attachment table
for ($i = 0; $i < mapi_table_getrowcount($contents); $i++) {
$props = mapi_table_queryrows($contents, array(PR_ENTRYID), $i, 1);
$message = mapi_msgstore_openentry($store, $props[PR_ENTRYID]);
$attachtable = mapi_message_getattachmenttable($message);
// the attachement table can be processed with the mapi_table_* functions aswell
}
mapitable mapi_message_getrecipienttable(mapimessage $message
Retrieve recipient table of a message
Each message has a number of recipients (including 0). This function returns a table of recipients for the message. Each row in the table represents one recipient, usually with an e-mail adress in the PR_EMAIL_ADDRESS and 'SMTP' in the PR_ADDRTYPE. Returns a mapitable object on success, FALSE on failure.
Example 3.49. Opening a recipienttable
$recipienttable = mapi_message_getrecipienttable ($message); print "Number of recipients: " . mapi_table_getrowcount($recipienttable);
boolean mapi_message_modifyrecipients(mapimessage $message, long $flag, array $recipients)
Add or remove recipients to a message
With this function the recipients of a message can be added, modified or deleted. With the flag the needed action is selected.
The value of the flag can be:
The recipients in the recipients array are added to the recipients in the message.
The recipients in the recipients array should replace existing recipients.
The recipients in the recipients array should be removed from the recipient list. The PR_ROWID should be used as a index for the rows to remove.
The recipient array should be formed like the following example:
$recipient[] = array {
PR_DISPLAY_NAME=>"John Doe",
PR_EMAIL_ADDRESS=>"jdoe@example.com",
PR_ADDRTYPE => "SMTP",
PR_RECIPIENT_TYPE=> MAPI_BCC
}
Example 3.50. Modifying recipients
$message = mapi_folder_createmessage($folder); mapi_message_modifyrecipients($message, MODRECIP_ADD, array( array( PR_DISPLAY_NAME=>"Pete", PR_EMAIL_ADDRESS=>"pete@example.com", PR_ADDRTYPE => "SMTP", PR_RECIPIENT_TYPE=> MAPI_TO ) );
mapiattach mapi_message_openattach(mapimessage $message, long $attachnum
Open an attachment from a message
This function returns a mapiattach object by opening an existing attachment in a message. You must specify which attachment to open with the $attachnum parameter. This parameter can be retrieved by looking at the attachment table retrieved with mapi_message_getattachmenttable(). Returns a mapiattach object on success, FALSE on failure.
Example 3.51. Opening an attachment
// Open attachment number 0 $attach = mapi_message_openattach ($message, 0); // Dump properties of the attachment (filename, etc) print_r(mapi_attach_getprops($attach));
mapiattach mapi_message_createattach(mapimessage $message)
Open an attachment from a message
This function returns a mapiattach object by creating a new attachment in a message. Returns a mapiattach object on success, FALSE on failure.
Example 3.52. Creating an attachment
// Open attachment number 0 $attach = mapi_message_createattach ($message); // Set properties of the attachment $props = Array(PR_DISPLAY_NAME => "testname.txt", PR_FILENAME => "testname.txt", PR_ATTACH_METHOD => ATTACH_BY_VALUE, PR_ATTACH_DATA_BIN => "Hello world!"); mapi_setprops($attach, $props); mapi_savechanges($attach); // Dump properties of the attachment (filename, etc) print_r(mapi_attach_getprops($attach));
boolean mapi_message_deleteattach(mapimessage $message, long $attachnum)
Open an attachment from a message
This function deletes an existing attachment in a message. You must specify which attachment to delete with the $attachnum parameter. This parameter can be retrieved by looking at the attachment table retrieved with mapi_message_getattachmenttable(). Returns a mapiattach object on success, FALSE on failure.
Example 3.53. Deleting an attachment
// Delete attachment number 0
if (mapi_message_deleteattach($message, 0) == true) {
print("successfully removed attachment");
} else {
print("unable to remove attachment");
}
boolean mapi_message_submitmessage(mapimessage $message)
Submits a message for sending
The message is marked ready for sending when this function is called. MAPI passes messages to the underlying messaging system in the order in which they are marked for sending. Because of this functionality, a message might stay in a message store for some time before the underlying messaging system can take responsibility for it.
Example 3.54. Submitting a message
// Set the subject mapi_setprops($message, Array(PR_SUBJECT) => "New subject")); mapi_savechanges($message); mapi_message_submitmessage($message);
Attachment Functions — This section describes functions which are performed on MAPI Attachment objects.
string mapi_attach_openbin(mapiattach $attach,
long $proptag);mapimessage mapi_attach_openobj(mapiattach $attach,
long $flags);string mapi_attach_openbin(mapiattach $attach, long $proptag
Read binary contents of attachment
Retrieves the actual attachment data in the attachment when the attachment has PR_ATTACH_METHOD is 1 (ATTACH_BY_VALUE). Returns a binary string on success, FALSE on failure.
Example 3.55. Getting attachment data
// Open attachment number 0 $attach = mapi_message_openattach ($message, 0); // Output attachment data print(mapi_attach_openbin($attach, PR_ATTACH_DATA_BIN));
mapimessage mapi_attach_openobj(mapiattach $attach, long $flags
Read message contents of attachment
Returns a message object which is embedded in an attachment. This can be done for attachment which have PR_ATTACH_METHOD 5 (ATTACH_EMBEDDED_MSG). Returns a mapimessage object on success, FALSE on failure.
Bitmask of flags that controls access to the property. The following flags can be set:
If the property does not exist, it should be created. If the property does exist, the current value of the property should be discarded. When a caller sets the MAPI_CREATE flag, it should also set the MAPI_MODIFY flag.
Requests read/write access to the property. The default access is read-only. MAPI_MODIFY must be set when MAPI_CREATE is set.
Example 3.56. Getting the attachment message
// Open attachment number 0 $attach = mapi_message_openattach($message, 0); // Open embedded message $message = mapi_attach_openobj($attach); // Show message contents print_r(mapi_message_getprops($message);
Stream Functions — This section describes functions to create streams to objects and how to use these streams.
stream mapi_openpropertytostream(mapipropobj $mapiProp,
ulong $propertytag,
int $flags);resource mapi_stream_create();string mapi_stream_read(stream $stream,
int $lbytes);boolean mapi_stream_seek(stream $stream,
int $bytes,
int $flags);boolean mapi_stream_setsize(stream $stream,
int $newsize);boolean mapi_stream_commit(stream $stream);boolean mapi_stream_write(stream $stream,
string $data);array mapi_stream_stat(stream $stream);stream mapi_openpropertytostream(mapipropobj $mapiProp, ulong $propertytag, int $flags)
Opens a property to a stream object
![]() | Warning |
|---|---|
| (DEPRECATED: use mapi_openproperty instead) |
This functions opens a stream on a specific property. It returns a stream that can be used with other stream functions to read and write the data.
The default access is read-only. Flags you can give:
If the property does not exist, it should be created. If the property does exist, the current value of the property should be discarded. When a caller sets the MAPI_CREATE flag, it should also set the MAPI_MODIFY flag.
Requests read/write access to the property. The default access is read-only. MAPI_MODIFY must be set when MAPI_CREATE is set.
Example 3.57. Reading a stream
$bodyStream = mapi_openpropertytostream($message, PR_BODY); $stat = mapi_stream_stat($bodyStream)
resource >mapi_stream_create()
Create a new in-memory stream object
This function can be used to create an in-memory stream object. Any data written to this object can subsequently be read from the same stream with mapi_stream_read().
Example 3.58. Creating a new stream
$stream = mapi_stream_create(); mapi_stream_write($stream, "Hello, world!");
string mapi_stream_read(stream $stream, int $lbytes)
Reads data from a stream
This functions read a specific ammount of data from a stream.
mapi_openpropertytostream, mapi_stream_stat, mapi_stream_write, mapi_stream_setsize, mapi_stream_seek
Example 3.59. Reading from a stream
$body = mapi_stream_read($stream, 100); echo $body; // will echo the first 100 bytes of the body
boolean mapi_stream_seek(stream $stream, int $bytes, int $flags)
Moves the internal pointer the given bytes.
This functions seek in a stream. It can move the pointer with the given bytes. The function will return true when the seeking was succesful or false when it wasn't. If no flag is given, STREAM_SEEK_CUR will be assumed.
A flag that can be given:
TThe new seek pointer is an offset relative to the beginning of the stream.
The new seek pointer is an offset relative to the current seek pointer location.
The new seek pointer is an offset relative to the end of the stream.
mapi_openpropertytostream, mapi_stream_stat, mapi_stream_write, mapi_stream_setsize, mapi_stream_read
Example 3.60. Seeking in a stream
mapi_stream_seek($stream, 100); // will move the pointer 100 bytes
boolean mapi_stream_setsize(stream $stream, int $newsize)
Resizes a stream
This functions resizes the stream. With this function it is possible to preallocate space to use with the stream.
mapi_openpropertytostream, mapi_stream_stat, mapi_stream_write, mapi_stream_commit, mapi_stream_read
Example 3.61. Setting the size of a stream
mapi_stream_setsize($stream, 100); // will resize the stream to a size of 100 bytes
boolean mapi_stream_commit(stream $stream)
Commits the stream
This functions commits the stream. Now all changes are saved. Will return true when everything is oke or false when an error has occured.
mapi_openpropertytostream, mapi_stream_stat, mapi_stream_write, mapi_stream_setsize, mapi_stream_read
Example 3.62. Committing a stream
mapi_stream_commit($stream); // commit the stream, all data is saved.
boolean mapi_stream_write(stream $stream, string $data)
Write data to a stream
This functions writes data to the stream. The pointer will also moved the places that is needed. Use mapi_stream_commit to save the stream.
Example 3.63. Writing data into a stream
mapi_stream_write($stream, "data"); // will write "data" into the stream and moves the pointer 4 bytes.
array mapi_stream_stat(stream $stream)
Gets the statistics of the stream.
This functions reads the statistics from a stream and returns this in an assoc array. For now only the element 'cb' is supported, this gives the size of the stream.
Example 3.64. Getting the statistics from a stream
$stat = mapi_stream_stat($stream); echo "Size :" . $stat['cb']; // will read the stats from the stream.
Addressbook Functions — This section describes functions to use the addressbook for user and e-mail address lookups.
resource mapi_openaddressbook(mapisession $session);resource mapi_ab_openentry(resource $addrbook,
string $entryid,
long $flags);array mapi_ab_resolvename(resource $addrbook,
array $name_entry);string mapi_ab_getdefaultdir(resource $addrbook);resource mapi_openaddressbook(mapisession $session)
Opens the MAPI Addressbook. On Zarafa, this only is the Global Addressbook, containing the Zarafa users.
This function will return a MAPI Addressbook resource when successfull, or FALSE on failure.
Example 3.65. Open the Addressbook
// First, logon to zarafa to get a session $session = mapi_logon_zarafa($username, $password, $server); // Now we can open the addressbook $addrbook = mapi_openaddressbook($session);
resource mapi_ab_openentry(resource $addrbook, string $entryid, long $flags)
Calls the OpenEntry() function on the Addressbook object.
This function performs the OpenEntry() call on the AddressBook interface. Returns FALSE on failure, otherwise an MailUser, DistList or ABContainer is returned as resource.
Example 3.66. Requesting the top-level AddressBook container
$addrbook = mapi_openaddressbook($session); $abcontainer = mapi_ab_openentry($addrbook);
array mapi_ab_resolvename(resource $addrbook, array $name_entry)
Calls the ResolveName() function on the Addressbook object.
This function performs the ResolveName() call on the AddressBook interface.
This function returns MAPI_E_AMBIGUOUS_RECEIP or MAPI_E_NOT_FOUND when these errors occurred, or FALSE on any other error. When the user is found, the array returned has the full information of the user requested.
Example 3.67. Resolving a user to e-mail address
$addrbook = mapi_openaddressbook($session); $user = array( array( PR_DISPLAY_NAME => 'steve' ), array( PR_DISPLAY_NAME => 'milo' ) ); $user = mapi_ab_resolvename($addrbook, $user); print_r($user);
Output:
Array
(
[0] => Array
(
[805437470] => SMTP
[805371934] => Steve Hardy
[956301315] => 0
[805503006] => steve@connectux.com
[268370178] => ...
[267780354] => ...
[268304387] => 6
[267976962] => ...
[806027522] => SMTP:STEVE@CONNECTUX.COM
)
[1] => Array
(
[805437470] => SMTP
[805371934] => Milo Oostergo
[956301315] => 0
[805503006] => milo@connectux.com
[268370178] => ...
[267780354] => ...
[268304387] => 6
[267976962] => ...
[806027522] => SMTP:MILO@CONNECTUX.COM
)
)
string mapi_ab_getdefaultdir(resource $addrbook)
Calls the GetDefaultDir() function on the Addressbook object.
This function performs the GetDefaultDir() call on the AddressBook interface.
This function returns an EntryID on success, FALSE on error.
Example 3.68. Opening the default Addressbook Directory
$addrbook = mapi_openaddressbook($session); #entryid = mapi_ab_getdefaultdir($addrbook);
Freebusy Functions — This section describes freebusy specific functions to see the freebusy data of the users.
resource IFreeBusySupport mapi_freebusysupport_open(resource $session,
resource $messagestore);boolean mapi_freebusysupport_close(resource $freebusysupport);array freebusydata mapi_freebusysupport_loaddata(resource $freebusysupport,
array $fbusers);array freebusydata mapi_freebusysupport_loadupdate(resource $freebusysupport,
array $fbusers);resource freebusyenumblock mapi_freebusydata_enumblocks(resource $freebusydata,
long $starttime,
long $endtime);array mapi_freebusydata_getpublishrange(resource $freebusydata);boolean mapi_freebusydata_setrange(resource $freebusydata,
long $starttime,
long $endtime);boolean mapi_freebusyenumblock_reset(resource $freebusyenumblock);boolean mapi_freebusyenumblock_skip(resource $freebusyenumblock);boolean mapi_freebusyenumblock_restrict(resource $freebusyenumblock,
long $starttime,
long $endtime);boolean mapi_freebusyenumblock_next(resource $freebusyenumblock,
long $celt,
long $endtime);boolean mapi_freebusyupdate_reset(resource $freebusyupdate);boolean mapi_freebusyupdate_publish(resource $freebusyupdate,
array $freebusyblocks);boolean mapi_freebusyupdate_savechanges(resource $freebusyupdate,
long $starttime,
long $endtime);resource mapi_freebusysupport_open(resource $session, resource $messagestore)
Retreive freebusy support object
Example 3.69. Open a freebusysupport object
$fbsupport = mapi_freebusysupport_open($session);
resource $fbsupport, freebusysupport
boolean mapi_freebusysupport_close(resource $freebusysupport)
Close the freebusy support object
Example 3.70. Close a freebusysupport object
$fbsupport = mapi_freebusysupport_open($session); // Do something $result = mapi_freebusysupport_close($fbsupport);
true is succeeded
array mapi_freebusysupport_loaddata(resource $freebusysupport, array $fbusers)
Get a freebusydata object for one of more users.
Example 3.71. Get freebusydata object of one user
$fbsupport = mapi_freebusysupport_open($session);
$fbDataArray = mapi_freebusysupport_loaddata($fbsupport, array($userentrid1, $userentrid2) );
if(isset($fbDataArray[0]))
{
$rangeuser1 = mapi_freebusydata_getpublishrange($fbDataArray[0]);
print_r($rangeuser1);
}else {
echo "No freebusy for User 1\n";
}
if(isset($fbDataArray[1]))
{
$rangeuser2 = mapi_freebusydata_getpublishrange($fbDataArray[1]);
print_r($rangeuser2);
}else {
echo "No freebusy for User 2\n";
}
mapi_freebusysupport_close($fbsupport);
Array(
[start] => 1157061600
[end] => 1162335600
)
No freebusy for User 2
Get freebusy write objects for one of more users.
array freebusydata mapi_freebusysupport_loadupdate(resource $freebusysupport,
array $fbusers);Example 3.72. Get freebusyupdate object of one user
$fbupdate = mapi_freebusysupport_loadupdate($fbsupport, array($userentryid));
$result = mapi_freebusyupdate_reset($fbupdate[0]);
$fbblocks = array(
array("start" => 1157439600, "end" => 1157468400, "status" => 2),
array("start" => 1157526000, "end" => 1157554800, "status" => 2)
);
// Add fbblocks
$result = mapi_freebusyupdate_publish($fbupdate[0], $fbblocks);
// Save data
$result = mapi_freebusyupdate_savechanges($fbupdate[0], 1157061600, 1162335600);
resource mapi_freebusydata_enumblocks(resource $freebusydata, long $starttime, long $endtime)
Get an interface to supports accessing and enumerating free/busy blocks of data for a user within a time range.
Example 3.73. Get freebusy enumblock object of one user and read some data
$enumblock = mapi_freebusydata_enumblocks($fbData, 0, 0xFFFFFFFF);
// Set the cursur on the begining
$result = mapi_freebusyenumblock_reset($enumblock);
//Read the free/busy blocks in a cycles of 2 blocks
while(true)
{
$blocks = mapi_freebusyenumblock_next($enumblock, 2);
if($blocks == false)
break;
print_r($blocks);
}
Array
(
[0] => Array
(
[start] => 1157439600
[end] => 1157468400
[status] => 2
)
[1] => Array
(
[start] => 1157526000
[end] => 1157554800
[status] => 2
)
)
Gets a preset time range for an enumeration of free/busy blocks of data for a user
Get free/busy publish range, start and end time in unixtimestamp format
array mapi_freebusydata_getpublishrange(resource $freebusydata);boolean mapi_freebusydata_setrange(resource $freebusydata, long $starttime, long $endtime)
Sets the range of time for an enumeration of free/busy block of data for a user.
Sets the freebusy range of time
Example 3.75. Sets the freebusy range of time.
$result = mapi_freebusydata_setrange($freebusydata, 1157061600, 1162335600);
return $result, false or true
boolean mapi_freebusyenumblock_reset(resource $freebusyenumblock)
Resets the enumerator by setting the cursor to the beginning.
mapi_freebusysupport_open, mapi_freebusysupport_close, mapi_freebusysupport_loaddata, mapi_freebusydata_enumblocks
boolean mapi_freebusyenumblock_skip(resource $freebusyenumblock)
Skips a specified number of blocks of free/busy data.
mapi_freebusysupport_open, mapi_freebusysupport_close, mapi_freebusysupport_loaddata, mapi_freebusydata_enumblocks
Example 3.77. Skips 2 blocks of free/busy data.
$enumblock = mapi_freebusydata_enumblocks($fbData, 0, 0xFFFFFFFF); // Set the cursur on the begining $result = mapi_freebusyenumblock_reset($enumblock); // Skip 2 free/busy blocks $result = mapi_freebusyenumblock_skip($enumblock, 2); // Read the 2 free/busy blocks $blocks = mapi_freebusyenumblock_next($enumblock, 2);
boolean mapi_freebusyenumblock_restrict(resource $freebusyenumblock, long $starttime, long $endtime)
Restricts the enumeration to a specified time period.
mapi_freebusysupport_open, mapi_freebusysupport_close, mapi_freebusysupport_loaddata, mapi_freebusydata_enumblocks
Example 3.78. Restricts the enumeration to a specified time period.
$enumblock = mapi_freebusydata_enumblocks($fbData, 0, 0xFFFFFFFF); // Set the cursur on the begining $result = mapi_freebusyenumblock_reset($enumblock); //Restrict the free/busy data $result = mapi_freebusyenumblock_restrict($enumblock, 0x12345578, 0xFFFF0000); //Read the 2 free/busy blocks $blocks = mapi_freebusyenumblock_next($enumblock, 2);
-
boolean mapi_freebusyenumblock_next(resource $freebusyenumblock, long $celt, long $endtime)
Gets the next specified number of blocks of free/busy data in an enumeration.
mapi_freebusysupport_open, mapi_freebusysupport_close, mapi_freebusysupport_loaddata, mapi_freebusydata_enumblocks
boolean mapi_freebusyupdate_reset(resource $freebusyupdate)
Remove all current free/busy data
boolean mapi_freebusyupdate_publish(resource $freebusyupdate, array $freebusyblocks)
Publish a specified number of blocks of free/busy data. May be called more than once successively.
boolean mapi_freebusyupdate_savechanges(resource $freebusyupdate, long $starttime, long $endtime)
Save the free/busy data with time frame between the begintime and endtime.
Zarafa specific text functions — This section describes special functions used to handle texts of a mailbody.
string mapi_decompressrtf(string $compressedRTF);string mapi_rtf2html(string $RTF);string mapi_html2rtf(string $HTML);string mapi_compressrtf(string $uncompressedRTF);>string mapi_decompressrtf(string $compressedRTF)
Decompresses a compressed RTF stream from the PR_RTF_COMPRESSED property.
This function will decompress the RTF Body from a message and return the decompressed RTF.
Example 3.83. Decompress a RTF body
$rtf = mapi_openproperty($inbox, PR_RTF_COMPRESSED); echo mapi_decompressrtf($rtf); // will echo the raw rtf data
string mapi_rtf2html(string $RTF)
Decodes the raw RTF data to readable HTML.
This function will read the embedded HTML from an RTF stream. When the RTF Stream is not of the embedded HTML RTF type the function will return false indicating that the body must be read as plaintext.
Example 3.84. Decoding RTF
$rtf = mapi_openproperty($inbox, PR_RTF_COMPRESSED); echo mapi_rtf2html(mapi_decompressrtf($rtf)); // will echo the html data.
string mapi_html2rtf(string $HTML)
Encodes the HTML as RTF.
This function encodes the given HTML into an RTF document, which can subsequently be passed to mapi_compressrtf to be included in MAPI messages. The HTML is encoded so that when it is decoded, the exact HTML source is again readable.
Compresses an uncompressed RTF stream for the PR_RTF_COMPRESSED property.
This function will compress the RTF Body for a message and return the compressed RTF.
string mapi_compressrtf(string $uncompressedRTF);Example 3.86. Compress an RTF body
$rtf = mapi_openproperty($inbox, PR_RTF_COMPRESSED); $decompressedRTF = mapi_decompressrtf($rtf); // will echo the raw rtf data, uncompressed echo $decompressedRTF; // will echo compressed RTF data, usable for streaming (back) to PR_RTF_COMPRESSED echo mapi_compressrtf($decompressedRTF);
Zarafa specific functions — This section describes Zarafa specific functions to manage users and groups and get and set permissions on folders.
long mapi_zarafa_createuser(store $storeid,
string $username,
string $password,
string $fullname,
string $emailaddress,
long $isnonactive,
long $isadmin);boolean mapi_zarafa_setuser(store $store,
long $userid,
string $username,
string $fullname,
string $emailaddress,
string $password,
long $isnonactive,
long $isadmin);boolean mapi_zarafa_createstore(store $storeid,
long $storetype,
long $userid);boolean mapi_zarafa_deleteuser(resource $store,
string $username);array mapi_zarafa_getuserlist(resource $messagestore,
int $companyid);array mapi_zarafa_getuser_by_id(resource $messagestore,
int $userid);array mapi_zarafa_getuser_by_name(resource $messagestore,
string $username);array mapi_zarafa_getgroup_by_id(resource $messagestore,
int $groupid);array mapi_zarafa_getgroup_by_name(resource $messagestore,
string $group);boolean mapi_zarafa_setgroup(resource $messagestore,
long $groupid,
string $groupname);array mapi_zarafa_getgrouplist(resource $messagestore,
int $companyid);long mapi_zarafa_creategroup(resource $messagestore,
string $groupname);boolean mapi_zarafa_deletegroup(resource $messagestore,
string $groupname);boolean mapi_zarafa_addgroupmember(resource $messagestore,
int $groupid,
int $userid);boolean mapi_zarafa_deletegroupmember(resource $messagestore,
int $groupid,
int $userid);array mapi_zarafa_getgrouplistofuser(resource $messagestore,
long $userid);array mapi_zarafa_getuserlistofgroup(resource $messagestore,
long $groupid);long mapi_zarafa_createcompany(resource $messagestore,
string $companyname);boolean mapi_zarafa_deletecompany(resource $messagestore,
string $companyname);array mapi_zarafa_getcompany_by_id(resource $messagestore,
int $companyid);array mapi_zarafa_getcompany_by_name(resource $messagestore,
string $company);array mapi_zarafa_getcompanylist(resource $messagestore);boolean mapi_zarafa_add_company_remote_viewlist(resource $messagestore,
int $setcompanyid,
int $companyid);boolean mapi_zarafa_del_company_remote_viewlist(resource $messagestore,
int $setcompanyid,
int $companyid);array mapi_zarafa_get_remote_viewlist(resource $messagestore,
int $companyid);boolean mapi_zarafa_add_user_remote_adminlist(resource $messagestore,
int $userid,
int $companyid);boolean mapi_zarafa_del_user_remote_adminlist(resource $messagestore,
int $userid,
int $companyid);array mapi_zarafa_get_remote_adminlist(resource $messagestore,
int $companyid);boolean mapi_zarafa_add_quota_recipient(resource $messagestore,
int $companyid,
int $recipient,
int $type);boolean mapi_zarafa_del_quota_recipient(resource $messagestore,
int $companyid,
int $recipientid,
int $type);array mapi_zarafa_get_quota_recipientlist(resource $messagestore,
int $userid);array mapi_zarafa_getpermissionrules(resource $mapiobject,
long $acl_type);boolean mapi_zarafa_setpermissionrules(resource $mapiobject,
array $acls);boolean mapi_inetmap_imtoinet(resource $session,
resource $addrbook,
resource $message,
array $flags);long mapi_zarafa_createuser(store $storeid, string $username, string $password, string $fullname, string $emailaddress, long $isnonactive, long $isadmin)
Creates a new user on an Zarafa server
Creates a new user on the Zarafa server. This can only be done when a store is specified which is logged on to a server with administration rights. The user is then created, but is initially 'nonactive' after being created. If the username existed before the call to mapi_zarafa_createstore(), an error is generated. The returned value can be used in a call to mapi_zarafa_setuser to set user settings of the created user.
Example 3.87. Creating a user
$session = mapi_logon_zarafa($admin_user, $password, $serverlocation);
$stores = mapi_getmsgstorestable($session);
$storeslist = mapi_table_queryallrows($stores);
$adminstore = mapi_openmsgstore($session, $storeslist[0][PR_ENTRYID]);
$userid = mapi_zarafa_createuser($adminstore, "newuser", "pass", "New User Name", "new@test.com");
if($userid == false) {
print "Error creating user\n";
}
Sets user information for a specific user on a Zarafa server
This function sets the user information on a user previously created (with mapi_zarafa_createuser). This call can only be done by users with administration rights on the server.
boolean mapi_zarafa_setuser(store $store,
long $userid,
string $username,
string $fullname,
string $emailaddress,
string $password,
long $isnonactive,
long $isadmin);Example 3.88. Setting user information
$store = mapi_openmsgstore_zarafa("user","password");
$userid = mapi_zarafa_createuser($store, "newuser", "pass", "New User Name", "new@test.com");
if($userid == false)
print "Error creating user\n";
else
mapi_zarafa_setuser($store, $userid, 'John Doe', 'john.doe@domain.com', 'password', 0);
Creates a store on a Zarafa server
Creates a complete store either for a specific user or creates a public store. When creating a user store, the standard folders 'Inbox', 'Outbox', etc. are all created and added to the store.
boolean mapi_zarafa_createstore(store $storeid,
long $storetype,
long $userid);Example 3.89. Creating a store
$store = mapi_openmsgstore_zarafa("user","password");
$userid = mapi_zarafa_createuser($store, "newuser");
if($userid == false)
print "Error creating user\n";
mapi_zarafa_setuser($store, $userid, 'John Doe', 'john.doe@domain.com', 'password', 0);
mapi_zarafa_createstore($store, 0, $userid);
Deletes a Zarafa user.
This function deletes a user from the Zarafa
server. The deleted store will be moved to an Admin folder
in the toplevel of the public
store. true is returned on
success.
boolean mapi_zarafa_deleteuser(resource $store,
string $username);Example 3.90. Deleting a user
// Deleting a user, deleting store with it. $result = mapi_zarafa_deleteuser($store, "john");
Retreive a list of Zarafa users.
Returns an associative array of all users, with the username as key, and the full name as value.
array mapi_zarafa_getuserlist(resource $messagestore,
int $companyid);Example 3.91. Listing the Zarafa users
$tempStoreslist = mapi_openmsgstore_zarafa($username, "password", "http://localhost:236/zarafa"); $msgstore = $tempStoreslist[0]; $users = mapi_zarafa_getuserlist($msgstore); print_r($users);
Array ( [SYSTEM] => SYSTEM User [username] => Fullname )
Retreive user information for zarafa user.
Returns an associative array of information for the specified user, or FALSE of the user does not exist or an other error occurred. The associative array contains 'userid', 'username', 'fullname', 'emailaddress', 'nonactive' and 'admin'.
array mapi_zarafa_getuser_by_id(resource $messagestore,
int $userid);Example 3.92. Getting user information
$info = mapi_zarafa_getuser_by_id($msgstore, 10); print $info["userid"]; print $info["username"]; print $info["fullname"]; print $info["emailaddress"]; print $info["admin"]; print $info["nonactive"];
Retreive user information for zarafa user.
Returns an associative array of information for the specified user, or FALSE of the user does not exist or an other error occurred. The associative array contains 'userid', 'username', 'fullname', 'emailaddress', 'nonactive' and 'admin'.
array mapi_zarafa_getuser_by_name(resource $messagestore,
string $username);Example 3.93. Getting user information
$info = mapi_zarafa_getuser($msgstore, "username"); print $info["userid"]; print $info["username"]; print $info["fullname"]; print $info["emailaddress"]; print $info["admin"]; print $info["nonactive"];
Retrieve group information for zarafa group.
Returns an associative array of information for the specified group, or FALSE of the group does not exist or an other error occurred. The associative array contains 'groupid' and 'groupname'.
array mapi_zarafa_getgroup_by_id(resource $messagestore,
int $groupid);Example 3.94. Getting group information
$info = mapi_zarafa_getgroup_by_id($msgstore, 2); print $info["groupid"]; print $info["groupname"];
Retrieve group information for zarafa group.
Returns an associative array of information for the specified group, or FALSE of the group does not exist or an other error occurred. The associative array contains 'groupid' and 'groupname'.
array mapi_zarafa_getgroup_by_name(resource $messagestore,
string $group);Example 3.95. Getting group information
$info = mapi_zarafa_getgroup($msgstore, "Everyone"); print $info["groupid"]; print $info["groupname"];
Set group information for a specific Zarafa group.
Modifies the given group, setting the groupname. Basically, this is a 'rename' of a group, as groups currently have no other information apart from their name. Returns TRUE on success, FALSE on error.
boolean mapi_zarafa_setgroup(resource $messagestore,
long $groupid,
string $groupname);Get list of all groups
Returns an array of all groups. Each list item is an associative array with the keys 'groupname' and 'groupid'. There are as many items in the returned array as there are groups that are viewable by the user
array mapi_zarafa_getgrouplist(resource $messagestore,
int $companyid);Create a new group.
This function creates a new group with the specified name on the server. After creation, the group will contain no users. Returns TRUE if the group was created successfully, FALSE if the creation failed. You cannot create a group which already exists.
long mapi_zarafa_creategroup(resource $messagestore,
string $groupname);Delete an existing group.
This function deletes a group on the server. Any users within this group are left untouched. Returns TRUE if the deletion was successful, FALSE if the group could not be deleted (not found).
boolean mapi_zarafa_deletegroup(resource $messagestore,
string $groupname);Add a user to a group.
This function adds a user to an existing group. Returns TRUE on success, FALSE on failure (ie unknown user or unknown group)
boolean mapi_zarafa_addgroupmember(resource $messagestore,
int $groupid,
int $userid);Delete a user from a group.
This function deletes a user from an existing group. Returns TRUE on success, FALSE on failure (ie unknown user or unknown group)
boolean mapi_zarafa_deletegroupmember(resource $messagestore,
int $groupid,
int $userid);Example 3.101. Deleting a user from a group
mapi_zarafa_deletegroupmember($msgstore,$groupid,$userid);
Get a list of groups for a specific user.
This function returns a list of groups in the same way as mapi_zarafa_getgrouplist, but only returns the groups of which the specified user is a member.
array mapi_zarafa_getgrouplistofuser(resource $messagestore,
long $userid);Get a list of users for a specific group.
This function returns a list of users in the same way as mapi_zarafa_getuserlist, but only returns the users that are members of the specified group.
array mapi_zarafa_getuserlistofgroup(resource $messagestore,
long $groupid);Create a new company.
This function creates a new company with the specified name on the server. After creation, the company will contain no users. Returns TRUE if the company was created successfully, FALSE if the creation failed. You cannot create a company which already exists.
long mapi_zarafa_createcompany(resource $messagestore,
string $companyname);Delete an existing company.
This function deletes a company on the server. Any users within this company are left untouched. Returns TRUE if the deletion was successful, FALSE if the company could not be deleted (not found).
boolean mapi_zarafa_deletecompany(resource $messagestore,
string $companyname);Retrieve company information for zarafa company.
Returns an associative array of information for the specified company, or FALSE of the company does not exist or an other error occurred. The associative array contains 'companyid' and 'companyname'.
array mapi_zarafa_getcompany_by_id(resource $messagestore,
int $companyid);Example 3.106. Getting company information
$info = mapi_zarafa_getcompany_by_id($msgstore, 2); print $info["companyid"]; print $info["companyname"];
Retrieve company information for zarafa company.
Returns an associative array of information for the specified company, or FALSE of the company does not exist or an other error occurred. The associative array contains 'companyid' and 'companyname'.
array mapi_zarafa_getcompany_by_name(resource $messagestore,
string $company);Example 3.107. Getting company information
$info = mapi_zarafa_getcompany_by_name($msgstore, "default"); print $info["companyid"]; print $info["companyname"];
Get list of all companies
Returns an array of all companies on the server.Each list item is an associative array with the keys 'companyname' and 'companyid'. There are as many items in the returned array as there are companies
array mapi_zarafa_getcompanylist(resource $messagestore);Add a company to the remote view list of a different company
This will add a company (setcompanyid) to the remote view list of a different company (companyid). This will allow the members of company 'companyid' to view the members of company 'setcompanyid'.
boolean mapi_zarafa_add_company_remote_viewlist(resource $messagestore,
int $setcompanyid,
int $companyid);Example 3.109. Add a company to the remote view list of a different company
mapi_zarafa_add_company_remote_viewlist($msgstore, $setcompanyid, $companyid);
Delete a company from the remote view list of a different company
This will delete a company (setcompanyid) from the remote view list of a different company (companyid). This will prevent the members of company 'companyid' to view the members of company 'setcompanyid'.
boolean mapi_zarafa_del_company_remote_viewlist(resource $messagestore,
int $setcompanyid,
int $companyid);Example 3.110. Delete a company from the remote view list of a different company
mapi_zarafa_del_company_remote_viewlist($msgstore, $setcompanyid, $companyid);
List all companies in the remote view list
This will return the remote view list for the specified company.
array mapi_zarafa_get_remote_viewlist(resource $messagestore,
int $companyid);Example 3.111. List all companies in the remote view list
$companies = mapi_zarafa_get_remote_viewlist($msgstore, $companyid); print_r($companies);
Add a user to the remote admin list of a company
This will add a user to the remote admin list of a company. This will allow the user to perform administrator tasks over the specified company.
boolean mapi_zarafa_add_user_remote_adminlist(resource $messagestore,
int $userid,
int $companyid);Example 3.112. Add a user to the remote admin list of a different company
mapi_zarafa_add_user_remote_adminlist($msgstore, $userid, $companyid);
Delete a user from the remote admin list of a company
This will delete an user from the remote admin list of a company. This will strip the administrator rights for the user on the specified company.
boolean mapi_zarafa_del_user_remote_adminlist(resource $messagestore,
int $userid,
int $companyid);Example 3.113. Delete a user from the admin list of a company
mapi_zarafa_del_user_remote_adminlist($msgstore, $userid, $companyid);
List all users in the remote admin list
This will return the remote admin list for the specified company.
array mapi_zarafa_get_remote_adminlist(resource $messagestore,
int $companyid);Example 3.114. List all users in the remote admin list
$users = mapi_zarafa_get_remote_adminlist($msgstore, $companyid); print_r($users);
Add a recipient to the recipient list of a company
When a user exceeds his quota, he will receive a warning email. With this function you can edit the list of additional recipients for this email. With the type argument you can set if the recipient list of userquota or companyquota warnings should be edited.
boolean mapi_zarafa_add_quota_recipient(resource $messagestore,
int $companyid,
int $recipient,
int $type);Example 3.115. Add a recipient to the recipient list of a company
mapi_zarafa_add_quota_recipient($msgstore, $companyid, $recipientid, USEROBJECT_TYPE_COMPANY);
Delete a recipient from the recipient list of a company
When a user exceeds his quota, he will receive a warning email. With this function you can edit the list of additional recipients for this email. With the type argument you can set if the recipient list of userquota or companyquota warnings should be edited.
boolean mapi_zarafa_del_quota_recipient(resource $messagestore,
int $companyid,
int $recipientid,
int $type);Example 3.116. Delete a recipient from the recipient list of a company
mapi_zarafa_del_quota_recipient($msgstore, $companyid, $userid, USEROBJECT_TYPE_COMPANY);
List all users in the recipient list
When a user exceeds his quota, he will receive a warning email. With this function you can request the list of additional recipients for this email. The userid as argument can either be a userid or companyid.
array mapi_zarafa_get_quota_recipientlist(resource $messagestore,
int $userid);Example 3.117. List all users in the recipient list
$users = mapi_zarafa_get_quota_recipientlist($msgstore, $userid); print_r($users);
Get a list of ACLs from an object.
This function returns an array of set ACLs of the requested type.
The type field is one of: ACCESS_TYPE_DENIED, ACCESS_TYPE_GRANT, ACCESS_TYPE_BOTH
The 'rights' field in the array is the access value. These values are defined in the ecRights* defines, found in include/mapidefs.php. The values are bitwise OR-ed. 1531 == 0x5FB == ecRightsAll.
The state field is one of: RIGHT_NORMAL, RIGHT_NEW, RIGHT_MODIFY, RIGHT_DELETED, RIGHT_AUTOUPDATE_DENIED. In the mapi_zarafa_getpermissionrules(), only RIGHT_NORMAL is returned.
array mapi_zarafa_getpermissionrules(resource $mapiobject,
long $acl_type);This is a mapi object. It can be a store, folder, message or attachment.
Note: Only ACLs on the store and on a folder work.
Example 3.118. Getting the ACL list of the store.
$acls = mapi_zarafa_getpermissionrules($msgstore, ACCESS_TYPE_GRANT); print_r($acls);
Output:
Array
(
[0] => Array
(
[userid] => 4
[type] => 2
[rights] => 1531
[state] => 0
)
)
Set a list of ACLs on an object.
This function sets returns an array of set ACLs of the requested type.
Each entry contains the following fields: userid, type, rights, state.
boolean mapi_zarafa_setpermissionrules(resource $mapiobject,
array $acls);This is a mapi object. It can be a store, folder, message or attachment.
Note: Only ACLs on the store and on a folder work.
Example 3.119. Setting the ACL list on the inbox.
$acls = array( 0 => array( 'userid' => 3, 'type' => ACCESS_TYPE_GRANT, 'rights' => ecRightsFullControl, 'state' => RIGHT_NEW | RIGHT_AUTOUPDATE_DENIED ) ); $ret = mapi_zarafa_setpermissionrules($inbox, $acls);
Converts a MAPI Message into an RFC822-formatted e-mail stream.
stream mapi_inetmapi_imtoinet(resource $session,
resource $addrbook,
resource $message,
array $flags);