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.
$hresult
long 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
$code
long mapi_prop_id(long $proptag)
Returns the ID part of the property tag (the high 16 bits).
$proptag
Example 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).
$proptag
Example 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
$propid
Example 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
$proptags
Example 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
$properties
Example 3.10. Setting the properties of a message
// Create a message and set some props. $message = mapi_folder_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
$flags
Example 3.11. Copying the properties of a message
// Create a message $newmessage = mapi_folder_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.
$object
Example 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
$flags
Example 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'.
$oneoff
Example 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'];