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.