Name

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

Synopsis

boolean mapi_message_setreadflag(mapimessage $message,
                                 long $flag);

mapitable mapi_message_getattachmenttable(mapimessage $message);
mapitable mapi_message_getrecipienttable(mapimessage $message);
boolean mapi_message_modifyrecipients(mapimessage $message,
                                      long $flag,
                                      array $recipients);

mapiattach mapi_message_openattach(mapimessage $message,
                                   long $attachnum);

mapiattach mapi_message_createattach(mapimessage $message);
boolean mapi_message_deleteattach(mapimessage $message,
                                  long $attachnum);

boolean mapi_message_submitmessage(mapimessage $message);

Details

mapi_message_setreadflag ()

boolean mapi_message_setreadflag(mapimessage $message, long $flag)

Sets the readflag of a specific message.

This function changes or sets the PR_MESSAGE_FLAGS property and controls the processing of read reports.

$message
The message you are requesting the properties of.
$flag

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

CLEAR_READ_FLAG

The MSGFLAG_READ flag should be cleared in PR_MESSAGE_FLAGS and no read report should be sent.

CLEAR_NRN_PENDING

The MSGFLAG_NRN_PENDING flag should be cleared in PR_MESSAGE_FLAGS and a nonread report should not be sent.

CLEAR_RN_PENDING

The MSGFLAG_RN_PENDING flag should be cleared in PR_MESSAGE_FLAGS and no read report should be sent.

GENERATE_RECEIPT_ONLY

A read report should be sent if one is pending, but there should be no change in the state of the MSGFLAG_READ flag.

SUPPRESS_RECEIPT

A pending read report should be canceled if a read report had been requested and this call changes the state of the message from unread to read. If this call does not change the state of the message, the message store provider can ignore this flag.

Example 3.46. Marking all messages as read in the inbox

$inbox = mapi_msgstore_getreceivefolder($userstore);
$contents = mapi_folder_getcontentstable($inbox);

// Loop through all the messages in the inbox and open them one by one,
// each time, marking the message read
for ($i = 0; $i < mapi_table_getrowcount($contents); $i++) {
	$props = mapi_table_queryrows($contents, array(PR_ENTRYID), $i, 1);
	$message = mapi_msgstore_openentry($userstore, $props[PR_ENTRYID]);
	mapi_message_setreadflag($message);
}

// Note: you should actually do this with mapi_folder_setreadflags()
		

mapi_message_getattachmenttable ()

mapitable mapi_message_getattachmenttable(mapimessage $message)

Retrieve attachment table of a message

Returns a table of the attachments of a message. This table contains information about each attachment, most notably PR_ATTACH_NUM which can be passed to mapi_message_openattach to open the attachment object. The table is automatically updated when a new attachment is added or an attachment is removed (even if the attachment table is still open). Returns a mapitable object on success, FALSE on failure.

$message
The message you are requesting the attachment table of.

Example 3.47. Opening the attachmenttable of a message

$inbox = mapi_msgstore_getreceivefolder($userstore);
$contents = mapi_folder_getcontentstable($inbox);

// Loop through all the messages in the inbox and open them one by one,
// each time retrieving their attachment table
for ($i = 0; $i < mapi_table_getrowcount($contents); $i++) {
	$props = mapi_table_queryrows($contents, array(PR_ENTRYID), $i, 1);
	$message = mapi_msgstore_openentry($store, $props[PR_ENTRYID]);
	$attachtable = mapi_message_getattachmenttable($message);
	// the attachement table can be processed with the mapi_table_* functions aswell
}
		

mapi_message_getrecipienttable ()

mapitable mapi_message_getrecipienttable(mapimessage $message

Retrieve recipient table of a message

Each message has a number of recipients (including 0). This function returns a table of recipients for the message. Each row in the table represents one recipient, usually with an e-mail adress in the PR_EMAIL_ADDRESS and 'SMTP' in the PR_ADDRTYPE. Returns a mapitable object on success, FALSE on failure.

$message
The message you are requesting the recipient table of.

Example 3.48. Opening a recipienttable

$recipienttable = mapi_message_getrecipienttable ($message);
print "Number of recipients: " . mapi_table_getrowcount($recipienttable);
		

mapi_message_modifyrecipients ()

boolean mapi_message_modifyrecipients(mapimessage $message, long $flag, array $recipients)

Add or remove recipients to a message

With this function the recipients of a message can be added, modified or deleted. With the flag the needed action is selected.

The value of the flag can be:

MODRECIP_ADD

The recipients in the recipients array are added to the recipients in the message.

MODRECIP_MODIFY

The recipients in the recipients array should replace existing recipients.

MODRECIP_REMOVE

The recipients in the recipients array should be removed from the recipient list. The PR_ROWID should be used as a index for the rows to remove.

The recipient array should be formed like the following example:

$recipient[] = array {    
	  PR_DISPLAY_NAME=>"John Doe",
	  PR_EMAIL_ADDRESS=>"jdoe@example.com",
	  PR_ADDRTYPE => "SMTP",
	  PR_RECIPIENT_TYPE=> MAPI_BCC
}
	  
$message
The message the recipients should be modified.
$flag
A flag that can be set to specify what action should be performed with the recipients.
$recipients
An array with the properties of the recipients of the message.

Example 3.49. Modifying recipients

$message = mapi_folder_createmessage($folder);

mapi_message_modifyrecipients($message, MODRECIP_ADD,
	array( array(
			PR_DISPLAY_NAME=>"Pete",
			PR_EMAIL_ADDRESS=>"pete@example.com",
			PR_ADDRTYPE => "SMTP",
			PR_RECIPIENT_TYPE=> MAPI_TO
		)
);
		

mapi_message_openattach ()

mapiattach mapi_message_openattach(mapimessage $message, long $attachnum

Open an attachment from a message

This function returns a mapiattach object by opening an existing attachment in a message. You must specify which attachment to open with the $attachnum parameter. This parameter can be retrieved by looking at the attachment table retrieved with mapi_message_getattachmenttable(). Returns a mapiattach object on success, FALSE on failure.

$message
The message you are requesting the recipient table of.
$attachnum
The attachment number of the attachment you wish to open.

Example 3.50. Opening an attachment

// Open attachment number 0
$attach = mapi_message_openattach ($message, 0);

// Dump properties of the attachment (filename, etc)
print_r(mapi_attach_getprops($attach));
		

mapi_message_createattach ()

mapiattach mapi_message_createattach(mapimessage $message)

Open an attachment from a message

This function returns a mapiattach object by creating a new attachment in a message. Returns a mapiattach object on success, FALSE on failure.

$message
The message you are createing an attachment on.

Example 3.51. Creating an attachment

// Open attachment number 0
$attach = mapi_message_createattach ($message);

// Set properties of the attachment
$props = Array(PR_DISPLAY_NAME => "testname.txt",
			PR_FILENAME => "testname.txt",
			PR_ATTACH_METHOD => ATTACH_BY_VALUE,
			PR_ATTACH_DATA_BIN => "Hello world!");

mapi_setprops($attach, $props);
mapi_savechanges($attach);

// Dump properties of the attachment (filename, etc)
print_r(mapi_attach_getprops($attach));
		

mapi_message_deleteattach ()

boolean mapi_message_deleteattach(mapimessage $message, long $attachnum)

Open an attachment from a message

This function deletes an existing attachment in a message. You must specify which attachment to delete with the $attachnum parameter. This parameter can be retrieved by looking at the attachment table retrieved with mapi_message_getattachmenttable(). Returns a mapiattach object on success, FALSE on failure.

$message
The message you are deleting the attachment from.
$attachnum
The attachment number of the attachment you wish to delete.

Example 3.52. Deleting an attachment

// Delete attachment number 0
if (mapi_message_deleteattach($message, 0) == true) {
	print("successfully removed attachment");
} else {
	print("unable to remove attachment");
}
		

mapi_message_submitmessage ()

boolean mapi_message_submitmessage(mapimessage $message)

Submits a message for sending

The message is marked ready for sending when this function is called. MAPI passes messages to the underlying messaging system in the order in which they are marked for sending. Because of this functionality, a message might stay in a message store for some time before the underlying messaging system can take responsibility for it.

$message
The message you wish to submit

Example 3.53. Submitting a message

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

mapi_message_submitmessage($message);