Name

Logon Functions — This section describes the various logon functions.

Synopsis

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

Details

mapi_logon ()

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.

$profile
The profile name to log on to. Profiles must be pre-created to be used. If $profile is empty, the default profile is used.
$password
The password to open the profile. Note: this is not the password to open a specific store or folder, just the password on the actual profile.

Example 3.17. Logging on to the default profile

// Log on to the default profile with no password
$session = mapi_logon('','');
		

mapi_logon_zarafa ()

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.

$username
The name of the user to log with.
$password
The password of the user.
$server (optional)
The location of the server. If not given, this will default to 'http://localhost:236/zarafa'. To connect over the unix socket (fastest method), use 'file:///var/run/zarafa' here.

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

mapi_logon_pst ()

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.

$filename
The name of the PST-file to be used. When the file does not exist MAPI will create one.

Example 3.19. Logging on to a PST-file

// Log on to a PST files
$session = mapi_logon_pst('C:\outlook.pst');
			

mapi_openmsgstore ()

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

$session
The session that is opened before.
$entryID
The unique identifier that is used to identify the messagestore.

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

mapi_openentry ()

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.

$session
The session that is opened before.
$entryID
A unique identifier that is used to identify an item.
$flags
Usually 0, can be: MAPI_MODIFY (?).

mapi_getmsgstorestable ()

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.

$session
The opened session

Example 3.21. Getting the table with the stores

// Get the table
$session = mapi_logon_zarafa($username, $password, $serverlocation);
$table = mapi_getmsgstorestable($session);
		  

mapi_openmsgstore_zarafa ()

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

This function is depricated. Please use the mapi_logon_zarafa() function. This function will be removed in the future.

$username
The username of the store that needs to be opened.
$password
The password of the user that corresponds to the store.
$server (optional)
This value defaults to 'http://localhost:236/zarafa'.

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

mapi_openmsgstore_zarafa_other ()

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

This function is depricated and will be removed in the future.

$username
The username of the store that needs to be opened.
$username
The username as whom we would like to open the store of another user as. Read/write rights apply from this user.
$password
The password of the user that corresponds to the username parameter.
$server (optional)
This value defaults to 'http://localhost:236/zarafa'.

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