$oMessage->setFlag(['Seen', 'Spam']);
$oMessage->unsetFlag('Spam');
// Mark all messages as "read" while fetching:
$aMessage = $oFolder->query()->text('Hello world')->markAsRead()->get();
// Don't mark all messages as "read" while fetching:
$aMessage = $oFolder->query()->text('Hello world')->leaveUnread()->get();