Name

General Functions — Functions that are not directly MAPI related.

Synopsis

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_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);

Details

mapi_is_error ()

long mapi_is_error(long $hresult)

Checks if the high bit of the passed error is set.

$hresult
The error value to check
Returns
Returns TRUE if the specified value has the high bit set (0x80000000), indicating a error.

Example 3.1. Checking an error

if (mapi_is_error(mapi_last_hresult())) {
	echo "error!\n";
}
		

mapi_last_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.

Returns
the last occurred HRESULT from a MAPI function.

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";
	}
}
		

mapi_make_scode ()

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
The severity value, 0 or 1.
$code
The actual error value

Example 3.3. Creating an SCODE error value

$error_not_found = mapi_make_scode(1, 0x010f);
		

mapi_prop_id ()

long mapi_prop_id(long $proptag)

Returns the ID part of the property tag (the high 16 bits).

$proptag
The propertytag

Example 3.4. Getting the ID of a propertytag

// Get the ID
$id = mapi_prop_id(PR_SUBJECT);	// $id is now 0x0037
		

mapi_prop_type ()

long mapi_prop_type(long $proptag)

Returns the type part of the property tag (the low 16 bits).

$proptag
The propertytag

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
		

mapi_prop_tag ()

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
The type of the propertytag that must be made. Should be one of the PT_* constants.
$propid
The unique ID for the propertytag.

Example 3.6. Making a PR_SUBJECT

// Make a PR_SUBJECT
define('PR_SUBJECT', mapi_prop_tag(PT_STRING8,   0x0037));
		

mapi_getidsfromnames ()

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
The store that the ID's are being requested for
$names
The names being requested.
$guids (Optional)
The guids of the names being requested

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);
		

mapi_getnamesfromids ()

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
The store that the ID's are being requested for
$proptags
a list of named proptags for which names should be looked up. The prop_type is not important, and is mostly PT_NULL.

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
        )

)
		

mapi_getprops ()

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
The object which you are requesting the properties of.
$properties (optional)
The properties that you want to read from the object.

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];
		

mapi_setprops ()

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
The object you want to set the properties of.
$properties
Array of properties you want to set.

Example 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);
		

mapi_savechanges ()

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
The object you wish to save. Can be a message, attachment, folder or store.

Example 3.11. Saving changes to a message

// Set the subject
mapi_setprops($message, Array(PR_SUBJECT) => "New subject"));
mapi_savechanges($message);
		

mapi_deleteprops ()

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
The object which you are deleting the properties of.
$properties (optional)
The properties that you want to delete from the object.

Example 3.12. 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);
		

mapi_openproperty ()

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
The object from which the property should be opened, this object can be one of the following (Mapimessage, Mapifolder, Mapiattachment, Messagestore)
$propertytag
The specific tag that should be opened.
$interface
The interface that should be used to open the property. This is normally any of the IID_I* interface definitions that are available.
$interfaceflags
Flags that should be passed to the interface which are specific to that interface. For example, you could specify STGM_TRANSACTED when opening an IID_IStream interface. Normally just 0.
$flags
The MAPI flags to use when opening this property. Most useful flags are MAPI_CREATE and MAPI_MODIFY, which must both be specified (ORed together) when creating a new property using mapi_openproperty.

Example 3.13. Getting a property

// Open a property from a folder
$viewliststream = mapi_openproperty($inbox, PR_FOLDER_VIEWLIST, IID_IStream, 0, 0);
		

mapi_createoneoff ()

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
The display name of the recipient to create a One-Off entryid for.
$type
The type of the recipient's address (mostly "SMTP").
$emailaddress
The e-mail address of the recipient.
$flags (optional)

Bitmask of flags that affects the one-off recipient.

MAPI_UNICODE

The display name, address type, and address are in Unicode format.

MAPI_SEND_NO_RICH_INFO

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.14. Creating a one-off entry identifier

// Creating a one-off entry identifier
$oneoffentryid = mapi_createoneoff("John Doe", "SMTP", "john@example.com");
		

mapi_parseoneoff ()

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
The input string with the one-off entryid to parse.

Example 3.15. 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'];