Example #1
0
<?php

/*
   OpenChange PHP bindings examples

   Copyright (C) 2013-2014 Javier Amor Garcia

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
include './test-helpers.php';
is(PidLidEmail1OriginalDisplayName, 2156134431, "PidLidEmail1OriginalDisplayName constant");
is(PidTagBody, 268435487, "PidTagBody constant");
is(MAPIMessage::RW, 1, "Class constant MAPIMessage::RW");
endTestSuite("constant.php");
Example #2
0
diag("Inbox item type " . $inbox->getFolderType());
$inboxId = $inbox->getID();
$table1 = $inbox->getFolderTable();
ok($table1, "Get folder table for inbox");
$parentFolder = $table1->getParentFolder();
ok($parentFolder, "Get parent folder for table");
is($parentFolder->getID(), $inboxId, "Checking by ID that parent is the inbox");
ok($table1->count() > 0, "Check that table is not empty");
# XXX continue whern we have folders..
$folders = $table1->getFolders();
var_dump($folders);
echo "First folder ID " . $folders[0]->getID() . "\n";
echo "Get othe folder table\n";
$table2 = $inbox->getFolderTable();
var_dump($table2);
echo "Folder table summary\n";
var_dump($table2->summary());
unset($table2);
foreach ($folders as $one_folder) {
    unset($one_folder);
}
unset($folders);
unset($table1);
unset($info);
unset($parentFolder);
unset($mailbox);
unset($session);
unset($mapiProfile);
unset($mapi);
endTestSuite("folder-table.php");
Example #3
0
<?php

/*
   OpenChange PHP bindings examples

   Copyright (C) 2013-2014 Javier Amor Garcia

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
include './test-helpers.php';
include './config.php';
$mapiDB = new MAPIProfileDB($dbPath);
ok($mapiDB, "MAPIProfileDB opened for {$dbPath}");
$profile = $mapiDB->createAndGetProfile($profileName, $username, $password, $domain, $realm, $server);
ok($profile, "createAndGet profile for {$profileName}");
$session = $profile->logon();
ok($session, "Check logon with profile {$profileName}");
endTestSuite("create-get-profile.php");
Example #4
0
is(get_class($twoMessages[1]), 'MAPIContact', 'Check that second retrieved value is a MAPIContact');
foreach ($twoMessages as $msg) {
    unset($msg);
}
unset($twoMessages);
$remainingMessages = $table1->getMessages();
ok(count($remainingMessages) > 0, "Check the retrieval of remainig from the table");
is(get_class($remainingMessages[0]), 'MAPIContact', 'Check that we have retrieved a MAPIContact');
foreach ($remainingMessages as $msg) {
    unset($msg);
}
unset($remainingMessages);
$parentFolder = $table1->getParentFolder();
ok($parentFolder, "Getting parent folder");
is($parentFolder->getID(), $contactsId, "Checking that ID of parent fodler is the correct one");
echo "Contacts getMessageTable with properties PidLidFileUnder, PidLidEmail1EmailAddress \n";
$table2 = $contacts->getMessageTable(PidLidEmail1EmailAddress, PidTagDisplayName);
ok($table2, "Contacts getMessageTable with properties PidLidEmail1EmailAddress and PidTagDisplayName");
$oneSummaryContact = $table2->summary(1);
is(count($oneSummaryContact), 1, "Get one summary contact");
ok($oneSummaryContact[0] . PidLidEmail1EmailAddress, "Checking PidLidEmail1EmailAddress attribute for contact");
$remainingSummary = $table2->summary();
ok(count($remainingSummary) > 0, "Getting remaining sumamries");
foreach ($oneSummaryContact as $msg) {
    unset($msg);
}
foreach ($remainingSummary as $msg) {
    unset($msg);
}
endTestSuite("message-table.php");
Example #5
0
*/
include './test-helpers.php';
include './config.php';
$mapi = new MAPIProfileDB($pathDB);
ok($mapi, "MAPIProfileDB open for path {$pathDB}");
is($mapi->path(), $pathDB, "MAPI DB correct path");
$inexistent = $mapi->getProfile("idonotexist_232");
ok(is_null($inexistent), "Checking that trying to get inexistent profile return NULL");
$mapiProfile = $mapi->getProfile($profileName);
ok($mapiProfile, "Getting profile {$profileName}");
$session = $mapiProfile->logon();
ok($session, "Logon with profile {$profileName}");
$mailbox = $session->mailbox();
ok($mailbox, "Get default mailbox");
diag("Mailbox name " . $mailbox->getName());
$contacts = $mailbox->contacts();
ok($contacts, "Get contacts folder");
$messageTable = $contacts->getMessageTable();
ok($messageTable, "Get message table from contacts folder");
ok($messageTable->count() > 0, "Checking that message table contains messages");
$message = $contacts->openMessage($messageId);
ok($message, "Get message with ID {$messageId}");
is($message->getID(), $messageId, "Check opened message Id (must be {$messageId})");
#unset($mapi); # do not work..
#unset($profile);
#unset($session);
#unset($mailbox);
#unset($contacts);
#unset($messages);
endTestSuite("simple-hierarchy.php");
Example #6
0
diag("Changing PidTagBody to '{$tagBody1}'");
$message->set(PidTagBody, $tagBody1);
diag("Changing  PidLidAppointmentEndWhole to {$unixtime1} (09/26/2013 @ 10:02am in EST.)");
$message->set(PidLidAppointmentEndWhole, $unixtime1);
$message->save();
unset($message);
diag("--After saving changes:");
$message = $calendar->openMessage($appointmentId, MAPIMessage::RW);
ok($message, "Reopen message in RW mode after saving changes");
is($message->get(PidTagBody), $tagBody1, "Checking that PidTagBody has correctly been changed");
is($message->get(PidLidAppointmentEndWhole), $unixtime1, "Checking that PidLidAppointmentEndWhole has correctly been changed");
diag("Changing PidTagBody again to {$tagBody2}");
$message->set(PidTagBody, $tagBody2);
diag("Changing  PidLidAppointmentEndWhole to 100 seconds more");
$message->set(PidLidAppointmentEndWhole, $unixtime2);
$message->save();
unset($message);
diag("--After last changes:");
$message = $calendar->openMessage($appointmentId, MAPIMessage::RO);
ok($message, "Reopen message in RO mode after saving the last changes");
is($message->get(PidTagBody), $tagBody2, "Checking that PidTagBody has changed again");
is($message->get(PidLidAppointmentEndWhole), $unixtime2, "Checking that PidLidAppointmentEndWhole has changed again");
# workaround against shutdown problem
unset($message);
#unset($calendar);
#unset($mailbox);
#unset($session);
#unset($mapiProfile);
#unset($mapi);
endTestSuite("appointment.php");
Example #7
0
is($message->getID(), $taskId, "Check opened message Id (must be {$taskId})");
dumpTask($message);
diag("Changing PidTagBody to '{$tagBody1}'");
diag("Changing PidLidTaskComplete to '{$tagComplete}'");
diag("Changing PidLidTaskComplete to '{$dateFinished}'");
diag("Changing PidLidTaskStatus to '{$status}'");
echo "\n";
$message->set(PidTagBody, $tagBody1, PidLidTaskStatus, $status, PidLidTaskDateCompleted, $dateFinished, PidLidTaskComplete, $tagComplete);
echo "\n";
diag("Changing PidLidPercentComplete to {$percent}\n");
$message->set(PidLidPercentComplete, $percent);
$message->set($PidNameKeywords, $keywords);
$message->save();
unset($message);
diag("--After saving changes:");
$message = $ocFolder->openMessage($taskId, MAPIMessage::RW);
ok($message, "Reopen message in RW mode after saving changes");
is($message->get(PidTagBody), $tagBody1, "Checking change in PidTagBody");
is($message->get(PidLidTaskStatus), $status, "Checking change in PidLidTaskStatus");
is($message->get(PidLidTaskComplete), $tagComplete, "Checking change in PidLidTaskComplete");
echo "PidLidTaskDateCompleted: " . $message->get(PidLidTaskDateCompleted) . " NOT WORKING PROPERLY. USING WORKAROUND IN ROUNDCUBE " . "\n";
is($message->get(PidLidPercentComplete), $percent, "Checking change in PidLidPercentComplete");
var_dump($message->get($PidNameKeywords));
diag("-- Reverting changes");
$message->set(PidTagBody, $undoTagBody1, PidLidTaskStatus, $undoStatus, PidLidTaskDateCompleted, $undoDateFinished, PidLidTaskComplete, $undoTagComplete);
$message->set(PidLidPercentComplete, $undoPercent);
$message->set($PidNameKeywords, $undoKeywords);
$message->save();
unset($message);
endTestSuite("task.php");
Example #8
0
is($message->getBodyContentFormat(), "txt", "Checking body content format");
diag("Setting multiple messages properties to first set");
$message->set(PidTagBody, $pidTagBody1, PidLidWorkAddressStreet, $pidLidWorkAddressStreet1, PidLidEmail1EmailAddress, $pidLidEmail1EmailAddress1);
diag("Setting one property PidTagDisplayName to first set");
$message->set(PidTagDisplayName, $pidTagDisplayName1);
$message->save();
unset($message);
diag("- Saving changes");
$message = $contacts->openMessage($contactMessageId, MAPIMessage::RW);
ok($message, "Reopening message in RW mode");
is($message->get(PidTagDisplayName), $pidTagDisplayName1, "Checking PidTagDisplayName1 has changed properly");
$multipleValues = $message->get(PidTagBody, PidLidWorkAddressStreet, PidLidEmail1EmailAddress);
is($multipleValues[PidTagBody], $pidTagBody1, "Checking value as PidTagBody (retrieved in a multiple value get)");
is($multipleValues[PidLidWorkAddressStreet], $pidLidWorkAddressStreet1, "Checking value as PidLidWorkAddressStreet (retrieved in a multiple value get)");
is($multipleValues[PidLidEmail1EmailAddress], $pidLidEmail1EmailAddress1, "Checking value as PidLidEmail1EmailAddress (retrieved in a multiple value get)");
diag("Setting values again");
$message->set(PidTagBody, $pidTagBody2, PidLidWorkAddressStreet, $pidLidWorkAddressStreet2, PidLidEmail1EmailAddress, $pidLidEmail1EmailAddress2);
$message->set(PidTagDisplayName, $pidTagDisplayName2);
$message->save();
unset($message);
diag("- Saving last changes");
$message = $contacts->openMessage($contactMessageId, MAPIMessage::RO);
ok($message, "Reopening message in RO mode");
is($message->get(PidTagDisplayName), $pidTagDisplayName2, "Checking PidTagDisplayName2 has changed properly");
$multipleValues = $message->get(PidTagBody, PidLidWorkAddressStreet, PidLidEmail1EmailAddress);
is($multipleValues[PidTagBody], $pidTagBody2, "Checking value as PidTagBody (retrieved in a multiple value get)");
is($multipleValues[PidLidWorkAddressStreet], $pidLidWorkAddressStreet2, "Checking value as PidLidWorkAddressStreet (retrieved in a multiple value get)");
is($multipleValues[PidLidEmail1EmailAddress], $pidLidEmail1EmailAddress2, "Checking value as PidLidEmail2EmailAddress (retrieved in a multiple value get)");
unset($message);
endTestSuite("message.php");
Example #9
0
$mapi = new MAPIProfileDB($dbPath);
ok($mapi, "Open MAPIProfileDB with path {$dbPath}");
$mapiProfile = $mapi->getProfile($profileName);
ok($mapiProfile, "Get profile {$profileName}");
$session = $mapiProfile->logon();
ok($session, "Logon with profile {$profileName}");
$mailbox = $session->mailbox();
ok($mailbox, "Get default mailbox");
is($mailbox->getName(), $mailboxName, "Get mailbox name");
$inbox = $mailbox->inbox();
ok($inbox, "Get inbox folder");
is($inbox->getFolderType(), "IPF.Note", "Get inbox folder type");
is($inbox->getName(), $inboxName, "Get inbox folder name");
$calendar = $mailbox->calendar();
ok($calendar, "Get calendar folder");
is($calendar->getFolderType(), "IPF.Appointment", "Get calendar folder type");
is($calendar->getName(), $calendarName, "Get calendar folder name");
unset($calendar);
$tasks = $mailbox->tasks();
ok($tasks, "Get tasks folder");
is($tasks->getFolderType(), "IPF.Task", "Get tasks folder type");
is($tasks->getName(), $tasksName, "Get tasks folder name");
$contacts = $mailbox->contacts();
ok($contacts, "Get contacts folder");
is($contacts->getFolderType(), "IPF.Contact", "Get contacts folder type");
is($contacts->getName(), $contactsName, "Get contacts folder name");
$drafts = $mailbox->openFolder($draftFolderId, "IPF.Note");
ok($drafts, "Open by ID draft folder");
ok(is_null($mailbox->openFolder($inexistentFolderId, "IPF.Note")), "Open folder with inexistent ID returns NULL");
endTestSuite("mailbox.php");
Example #10
0
ok($mailbox, "Default mailbox");
$contacts = $mailbox->contacts();
ok($contacts, "Open contacts folder");
$ids = array();
$newContact = $contacts->createMessage(PidLidEmail1EmailAddress, '*****@*****.**', PidTagCompanyName, 'to_delete_org', PidTagDisplayName, 'first');
ok($newContact, "Created new contact");
is(get_class($newContact), "MAPIContact", "Check returned new class type");
$ids[] = $newContact->getID();
unset($newContact);
$newContact = $contacts->createMessage(PidLidEmail1EmailAddress, '*****@*****.**', PidTagCompanyName, 'to_delete_org', PidTagDisplayName, 'second');
ok($newContact, "Created a second new contact");
is(get_class($newContact), "MAPIContact", "Check returned new class type for second new contact");
$ids[] = $newContact->getID();
unset($newContact);
foreach ($ids as $newId) {
    $retrieved = $contacts->openMessage($newId);
    ok($retrieved, "Check that we can retrieve a new created contact by its ID={$newId}");
    is(get_class($retrieved), "MAPIContact", "Check class type for retrieved contact");
    is($retrieved->getID(), $newId, "Check ID for retrieved contact");
    unset($retrieved);
}
diag("Delete created contacts");
call_user_func_array(array($contacts, 'deleteMessages'), $ids);
foreach ($ids as $newId) {
    $retrieved = $contacts->openMessage($newId);
    ok(is_null($retrieved), "Check that removed contact {$newId} has been removed");
}
diag("Try to delete inexistent contact. XXX does not return error because SOGO limitation");
$contacts->deleteMessages($inexistentContactId);
endTestSuite("new_message.php");