Name

Folder Functions — This section describes functions which are performed on MAPI Folder objects.

Synopsis

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

Details

mapi_folder_gethierarchytable ()

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.

$folder
The folder from which the hierarchytable should be opened.
$flags (optional)

Bitmask of flags that controls how information is returned in the table. The following flags can be set:

SHOW_SOFT_DELETES

Get a list of Soft Deleted Folders of the subfolder pointed to by $entryid.

Example 3.28. Getting the hierarchytable

// Get a the messagestore $inbox is a valid MAPI Folder
$table = mapi_folder_gethierarchytable($inbox);
		

mapi_folder_getcontentstable ()

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.

$folder
The folder from which the contentstable should be opened.
$flags (optional)

Bitmask of flags that controls how information is returned in the table. The following flags can be set:

MAPI_ASSOCIATED

Get a list of associated messages of the subfolder pointed to by $folder.

SHOW_SOFT_DELETES

Get a list of Soft Deleted messages of the subfolder pointed to by $folder.

Example 3.29. Getting the getcontentstable

// Get the messages of $inbox
$table = mapi_folder_getcontentstable($inbox);
		

mapi_folder_createmessage ()

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.

$folder
The folder from in which the message should be created.
$flags (optional)

A bitmask of flags that control the creation of a folder. The following flags can be set:

MAPI_DEFERRED_ERRORS

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.

MAPI_ASSOCIATED

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.30. Creating a new message

// Create a new message into the inbox
$viewlist = mapi_folder_createmessage($inbox);
		

mapi_folder_deletemessages ()

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.

$folder
The folder containing the messages to be deleted
$entryids
An array of binary entryID's to be removed from the folder
$flags (optional)

Bitmask of flags that controls how information is returned in the table. The following flags can be set:

DELETE_HARD_DELETE

Hard Delete the messages given by $entryid.

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

mapi_folder_copymessages ()

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.

$srcfolder
The folder which you want to copy the messages from.
$messageArray
An array with the entryid's from the message you want to copy.
$destfolder
The folder which you want to copy the messages to.
$flags (optional)
Some flags you can set. (Only MESSAGE_MOVE will work)

See Also

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

mapi_folder_emptyfolder ()

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.

$folder
The folder which you want to copy the messages from.
$flags (optional)

Bitmask of flags that controls how the folder is emptied. The following flags can be set:

DEL_ASSOCIATED

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.

DELETE_HARD_DELETE

Hard Delete the messages and/or folders

See Also

Example 3.33. 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. 
		

mapi_folder_copyfolder ()

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.

$srcfolder
The parent folder which you want to copy the messages from.
$entryid
An array with the entryid's from the message you want to copy.
$destfolder
The folder which you want to copy the messages to.
$new_foldername (optional)
The new foldername of the copy of the source folder in the destination folder.
$flags (optional)

A bitmask of flags that control the setting of a message's read flag. The following flags can be set:

COPY_SUBFOLDERS

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.

FOLDER_MOVE

The folder is to be moved rather than copied. If FOLDER_MOVE is not set, the folder is copied.

Example 3.34. 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.";
}
		

mapi_folder_deletefolder ()

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.

$srcfolder
The folder which you want to delete the folder from.
$entryid
The entryid of the folder you want to delete.
$flags (optional)

A bitmask of flags that control the setting of a message's read flag. The following flags can be set:

DEL_FOLDERS

All subfolders of the subfolder pointed to by $entryid should be soft deleted.

DEL_MESSAGES

All messages in the subfolder pointed to by $entryid should be soft deleted.

DELETE_HARD_DELETE

All messages in the subfolder pointed to by $entryid should be hard deleted.

Example 3.35. Deleting a folder

// Delete a folder
$result = mapi_folder_deletefolder($parent, $folderid);
		

mapi_folder_createfolder ()

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.

$parentfolder
The folder in which you want to create a new folder.
$name
The name of the folder to create.
$description
A description of the folder.
$flags (optional)

A bitmask of flags that control the creation of a folder. The following flags can be set:

MAPI_DEFERRED_ERRORS

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.

MAPI_UNICODE

The passed-in strings are in Unicode format. If the MAPI_UNICODE flag is not set, the strings are in ANSI format.

OPEN_IF_EXISTS

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.

$foldertype (optional)

Specify the type of the folder to create.

FOLDER_GENERIC

Create a generic folder.

FOLDER_SEARCH

Create a search folder.

Example 3.36. Creating a folder

// Create a folder
$result = mapi_folder_createfolder($folder, "New folder", "Description for new folder");
		

mapi_folder_setreadflags ()

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.

$folder
The folder in which you want mark a number of messages read.
$entryids
A list of entryids of messages that are in the given folder. When this array is empty, all the messages in the folder will be marked.
$flags (optional)

A bitmask of flags that control the creation of a folder. The following flags can be set:

CLEAR_READ_FLAG

In stead of marking the messages read, the messages are marked Unread.

Example 3.37. Marking messages in a folder read

// Mark all messages read in the inbox
$result = mapi_folder_createfolder($inbox, array());
		

mapi_folder_openmodifytable ()

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.

$inbox
The rules table is only available on the default delivery folder.

Example 3.38. Requesting the IExchangeModifyTable interface

// Requesting the IExchangeModifyTable interface
$inbox = mapi_msgstore_getreceivefolder($store);
$emt = mapi_folder_openmodifytable($inbox);
		

mapi_folder_setsearchcriteria ()

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.

$folder
The folder to set the search criteria on. This must be a search folder, ie it must have been created with type FOLDER_SEARCH
$restriction
The restriction that items in the search folder must match.
$folderlist
$flags
Valid values are BACKGROUND_SEARCH, FOREGROUND_SEARCH, RECURSIVE_SEARCH, RESTART_SEARCH, SHALLOW_SEARCH and STOP_SEARCH. Background and foreground searching is currently not implemented in Zarafa.

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 searchstatus flag. These are stored respectively in the 'restriction', 'folderlist' and 'searchstatus' keys in the returned associative array. The searchstatus 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.

$folder
The search folder to query.
$flags (optional)
These flags are currently unused.