function zpa_zarafa_admin_setup($mapi, $user, $pass)
{
    require PHP_MAPI_PATH . 'mapi.util.php';
    require PHP_MAPI_PATH . 'mapidefs.php';
    require PHP_MAPI_PATH . 'mapicode.php';
    require PHP_MAPI_PATH . 'mapitags.php';
    require PHP_MAPI_PATH . 'mapiguid.php';
    $session = @mapi_logon_zarafa($user, $pass, $mapi);
    if (!$session) {
        echo "User '{$user}' could not login. The script will exit. Errorcode: 0x" . sprintf("%x", mapi_last_hresult()) . "\n";
        exit(1);
    }
    $stores = @mapi_getmsgstorestable($session);
    $storeslist = @mapi_table_queryallrows($stores);
    $adminStore = @mapi_openmsgstore($session, $storeslist[0][PR_ENTRYID]);
    if (!$stores || !$storeslist || !$adminStore) {
        echo "There was error trying to log in as admin or retrieving admin info. The script will exit.\n";
        exit(1);
    }
    return array("session" => $session, "adminStore" => $adminStore);
}
 /**
  * Translate ($addressBookId, $cardUri) to entry id
  * @param $addressBookId address book to search contact in
  * @param $cardUri name of contact card to retrieve
  */
 protected function getContactEntryId($addressBookId, $cardUri)
 {
     // Update object properties
     $this->logger->trace("getContactEntryId({$cardUri})");
     $folder = mapi_msgstore_openentry($this->bridge->getStore($addressBookId), $addressBookId);
     $contactsTable = mapi_folder_getcontentstable($folder);
     $contacts = mapi_table_queryallrows($contactsTable, array(PR_ENTRYID, PR_CARDDAV_URI, PR_SUBJECT));
     $entryId = 0;
     foreach ($contacts as $c) {
         if (isset($c[PR_CARDDAV_URI])) {
             if ($c[PR_CARDDAV_URI] == $cardUri) {
                 $entryId = $c[PR_ENTRYID];
                 break;
             }
         } else {
             // CardURI can be PR_ENTRYID .vcf
             if ($this->bridge->entryIdToStr($c[PR_ENTRYID]) == substr($cardUri, 0, -4)) {
                 $entryId = $c[PR_ENTRYID];
                 break;
             }
         }
     }
     return $entryId;
 }
}
if ($argv[1] == "-t") {
    $trans_array = translate($argv[2], 1);
    foreach ($trans_array as $key => $value) {
        echo str_pad($key, 20, " ");
        echo "{$value}\n";
    }
    exit(0);
}
$socket = "file:///var/run/zarafa";
if (preg_match("#--socket=([0-9]+)#", @implode(" ", $argv), $re)) {
    $socket = "file:///var/run/zarafa-{$re[1]}";
}
$session = mapi_logon_zarafa("SYSTEM", "", $socket);
$msgstorestable = mapi_getmsgstorestable($session);
$msgstores = mapi_table_queryallrows($msgstorestable, array(PR_DEFAULT_STORE, PR_ENTRYID));
foreach ($msgstores as $row) {
    if ($row[PR_DEFAULT_STORE]) {
        $storeentryid = $row[PR_ENTRYID];
    }
}
if (!$storeentryid) {
    print "Can't find default store\n";
    exit(1);
}
$store = mapi_openmsgstore($session, $storeentryid);
if (!$store) {
    print "Unable to open system store\n";
    exit(1);
}
$userstoreentryid = mapi_msgstore_createentryid($store, $argv[1]);
Esempio n. 4
0
 /**
  * Returns subfolders of given type for a folder or false if there are none.
  *
  * @access public
  *
  * @param MAPIFolder $folder
  * @param string $type
  *
  * @return MAPITable|boolean
  */
 public static function GetSubfoldersForType($folder, $type)
 {
     $subfolders = mapi_folder_gethierarchytable($folder, CONVENIENT_DEPTH);
     mapi_table_restrict($subfolders, MAPIUtils::GetFolderTypeRestriction($type));
     if (mapi_table_getrowcount($subfolders) > 0) {
         return mapi_table_queryallrows($subfolders, array(PR_ENTRYID));
     }
     return false;
 }
Esempio n. 5
0
/**
 * Get all public contact folders
 */
function getPublicContactFolders($session, $publicstore)
{
    $pub_folder = mapi_msgstore_openentry($publicstore);
    $h_table = mapi_folder_gethierarchytable($pub_folder, CONVENIENT_DEPTH);
    $contact_properties = getContactProperties($publicstore);
    $subfolders = mapi_table_queryallrows($h_table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_DISPLAY_TYPE, PR_CONTAINER_CLASS, PR_SUBFOLDERS));
    $pub_list2 = array();
    $contacts = array();
    foreach ($subfolders as $folder) {
        // check if folder contains PR_CONTAINER_CLASS and if its a contact
        if (isset($folder[907214878]) && $folder[907214878] == "IPF.Contact" && $folder[805371934] != "Kontakte") {
            $entryid = $folder[268370178];
            $pub_folder2 = mapi_msgstore_openentry($publicstore, $entryid);
            $pub_table2 = mapi_folder_getcontentstable($pub_folder2);
            $pub_list2 = mapi_table_queryallrows($pub_table2, $contact_properties);
            for ($j = 0; $j < sizeof($pub_list2); $j++) {
                $pub_list2[$j][268370178] = md5($pub_list2[$j][268370178]);
            }
            for ($k = 0; $k < sizeof($pub_list2); $k++) {
                foreach ($pub_list2[$k] as $key => $value) {
                    $attribute = mapKey($key);
                    if ($attribute != "") {
                        $contacts[$k][$attribute] = $value;
                    }
                }
            }
            //$contactFolders[$folder[805371934]] = $pub_list2;
            $contactFolders[] = array("foldername" => $folder[805371934], "contacts" => $contacts);
        }
    }
    //print_r($contactFolders);
    return $contactFolders;
}
Esempio n. 6
0
function buildEMLAttachment($attach)
{
    $msgembedded = mapi_attach_openobj($attach);
    $msgprops = mapi_getprops($msgembedded, array(PR_MESSAGE_CLASS, PR_CLIENT_SUBMIT_TIME, PR_DISPLAY_TO, PR_SUBJECT, PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS));
    $msgembeddedrcpttable = mapi_message_getrecipienttable($msgembedded);
    $msgto = $msgprops[PR_DISPLAY_TO];
    if ($msgembeddedrcpttable) {
        $msgembeddedrecipients = mapi_table_queryrows($msgembeddedrcpttable, array(PR_ADDRTYPE, PR_ENTRYID, PR_DISPLAY_NAME, PR_EMAIL_ADDRESS, PR_SMTP_ADDRESS, PR_RECIPIENT_TYPE, PR_RECIPIENT_FLAGS, PR_PROPOSEDNEWTIME, PR_PROPOSENEWTIME_START, PR_PROPOSENEWTIME_END, PR_RECIPIENT_TRACKSTATUS), 0, 99999999);
        foreach ($msgembeddedrecipients as $rcpt) {
            if ($rcpt[PR_DISPLAY_NAME] == $msgprops[PR_DISPLAY_TO]) {
                $msgto = $rcpt[PR_DISPLAY_NAME];
                if (isset($rcpt[PR_EMAIL_ADDRESS]) && $rcpt[PR_EMAIL_ADDRESS] != $msgprops[PR_DISPLAY_TO]) {
                    $msgto .= " <" . $rcpt[PR_EMAIL_ADDRESS] . ">";
                }
                break;
            }
        }
    }
    $msgsubject = $msgprops[PR_SUBJECT];
    $msgfrom = $msgprops[PR_SENT_REPRESENTING_NAME];
    if (isset($msgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS]) && $msgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS] != $msgprops[PR_SENT_REPRESENTING_NAME]) {
        $msgfrom .= " <" . $msgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS] . ">";
    }
    $msgtime = $msgprops[PR_CLIENT_SUBMIT_TIME];
    $msgembeddedbody = eml_ReadMessage($msgembedded);
    $msgembeddedattachtable = mapi_message_getattachmenttable($msgembedded);
    $msgembeddedattachtablerows = mapi_table_queryallrows($msgembeddedattachtable, array(PR_ATTACH_NUM, PR_ATTACH_METHOD));
    if ($msgembeddedattachtablerows) {
        $boundary = '=_zpush_static';
        $headercontenttype = "multipart/mixed";
        $msgembeddedbody['body'] = "Unfortunately your mobile is not able to handle MIME Messages\n" . "--" . $boundary . "\n" . "Content-Type: " . $msgembeddedbody['content'] . "; charset=utf-8\n" . "Content-Transfer-Encoding: quoted-printable\n\n" . $msgembeddedbody['body'] . "\n";
        foreach ($msgembeddedattachtablerows as $msgembeddedattachtablerow) {
            $msgembeddedattach = mapi_message_openattach($msgembedded, $msgembeddedattachtablerow[PR_ATTACH_NUM]);
            if (!$msgembeddedattach) {
                debugLog("Unable to open attachment number {$attachnum}");
            } else {
                $msgembeddedattachprops = mapi_getprops($msgembeddedattach, array(PR_ATTACH_MIME_TAG, PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME, PR_DISPLAY_NAME));
                if (isset($msgembeddedattachprops[PR_ATTACH_LONG_FILENAME])) {
                    $attachfilename = w2u($msgembeddedattachprops[PR_ATTACH_LONG_FILENAME]);
                } else {
                    if (isset($msgembeddedattachprops[PR_ATTACH_FILENAME])) {
                        $attachfilename = w2u($msgembeddedattachprops[PR_ATTACH_FILENAME]);
                    } else {
                        if (isset($msgembeddedattachprops[PR_DISPLAY_NAME])) {
                            $attachfilename = w2u($msgembeddedattachprops[PR_DISPLAY_NAME]);
                        } else {
                            $attachfilename = w2u("untitled");
                        }
                    }
                }
                if ($msgembeddedattachtablerow[PR_ATTACH_METHOD] == ATTACH_EMBEDDED_MSG) {
                    $attachfilename .= w2u(".eml");
                }
                $msgembeddedbody['body'] .= "--" . $boundary . "\n" . "Content-Type: " . $msgembeddedattachprops[PR_ATTACH_MIME_TAG] . ";\n" . " name=\"" . $attachfilename . "\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . " filename=\"" . $attachfilename . "\"\n\n";
                $msgembeddedattachstream = mapi_openpropertytostream($msgembeddedattach, PR_ATTACH_DATA_BIN);
                $msgembeddedattachment = "";
                while (1) {
                    $msgembeddedattachdata = mapi_stream_read($msgembeddedattachstream, 4096);
                    if (byte_strlen($msgembeddedattachdata) == 0) {
                        break;
                    }
                    $msgembeddedattachment .= $msgembeddedattachdata;
                }
                $msgembeddedbody['body'] .= chunk_split(base64_encode($msgembeddedattachment)) . "\n";
                unset($msgembeddedattachment);
            }
        }
        $msgembeddedbody['body'] .= "--" . $boundary . "--\n";
    } else {
        $headercontenttype = $msgembeddedbody['content'] . "; charset=utf-8";
        $boundary = '';
    }
    $msgembeddedheader = "Subject: " . $msgsubject . "\n" . "From: " . $msgfrom . "\n" . "To: " . $msgto . "\n" . "Date: " . gmstrftime("%a, %d %b %Y %T +0000", $msgprops[PR_CLIENT_SUBMIT_TIME]) . "\n" . "MIME-Version: 1.0\n" . "Content-Type: " . $headercontenttype . ";\n" . ($boundary ? " boundary=\"" . $boundary . "\"\n" : "") . "\n";
    $stream = mapi_stream_create();
    mapi_stream_setsize($stream, byte_strlen($msgembeddedheader . $msgembeddedbody['body']));
    mapi_stream_write($stream, $msgembeddedheader . $msgembeddedbody['body']);
    mapi_stream_seek($stream, 0, STREAM_SEEK_SET);
    return $stream;
}
Esempio n. 7
0
 /**
  * Function which applies the provided recipients to the exception, also checks for deleted recipients.
  *
  * The $exception_recips should be an array containing all recipients which must be applied
  * to the exception. This will copy all recipients from the original message and then start filter
  * out all recipients which are not provided by the $exception_recips list.
  *
  * @param resource $message exception attachment of recurring item
  * @param array $exception_recips list of recipients
  */
 function setAllExceptionRecipients($message, $exception_recips)
 {
     $deletedRecipients = array();
     $useMessageRecipients = false;
     $recipientTable = mapi_message_getrecipienttable($message);
     $recipientRows = mapi_table_queryallrows($recipientTable, $this->recipprops);
     if (empty($recipientRows)) {
         $useMessageRecipients = true;
         $recipientTable = mapi_message_getrecipienttable($this->message);
         $recipientRows = mapi_table_queryallrows($recipientTable, $this->recipprops);
     }
     // Add organizer to meeting only if it is not organized.
     $msgprops = mapi_getprops($message, array(PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_EMAIL_ADDRESS, PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_ADDRTYPE, $this->proptags['responsestatus']));
     if (isset($msgprops[$this->proptags['responsestatus']]) && $msgprops[$this->proptags['responsestatus']] != olResponseOrganized) {
         $this->addOrganizer($msgprops, $exception_recips);
     }
     if (!empty($exception_recips)) {
         foreach ($recipientRows as $key => $recipient) {
             $found = false;
             foreach ($exception_recips as $excep_recip) {
                 if (isset($recipient[PR_SEARCH_KEY]) && isset($excep_recip[PR_SEARCH_KEY]) && $recipient[PR_SEARCH_KEY] == $excep_recip[PR_SEARCH_KEY]) {
                     $found = true;
                 }
             }
             if (!$found) {
                 $foundInDeletedRecipients = false;
                 // Look if the $recipient is in the list of deleted recipients
                 if (!empty($deletedRecipients)) {
                     foreach ($deletedRecipients as $recip) {
                         if ($recip[PR_SEARCH_KEY] == $recipient[PR_SEARCH_KEY]) {
                             $foundInDeletedRecipients = true;
                             break;
                         }
                     }
                 }
                 // If recipient is not in list of deleted recipient, add him
                 if (!$foundInDeletedRecipients) {
                     if (!isset($recipient[PR_RECIPIENT_FLAGS]) || $recipient[PR_RECIPIENT_FLAGS] != (recipReserved | recipExceptionalDeleted | recipSendable)) {
                         $recipient[PR_RECIPIENT_FLAGS] = recipSendable | recipExceptionalDeleted;
                     } else {
                         $recipient[PR_RECIPIENT_FLAGS] = recipReserved | recipExceptionalDeleted | recipSendable;
                     }
                     $recipient[PR_RECIPIENT_TRACKSTATUS] = olRecipientTrackStatusNone;
                     // No Response required
                     $deletedRecipients[] = $recipient;
                 }
             }
             // When $message contains a non-empty recipienttable, we must delete the recipients
             // before re-adding them. However, when $message is doesn't contain any recipients,
             // we are using the recipient table of the original message ($this->message)
             // rather then $message. In that case, we don't need to remove the recipients
             // from the $message, as the recipient table is already empty, and
             // mapi_message_modifyrecipients() will throw an error.
             if ($useMessageRecipients === false) {
                 mapi_message_modifyrecipients($message, MODRECIP_REMOVE, array($recipient));
             }
         }
         $exception_recips = array_merge($exception_recips, $deletedRecipients);
     } else {
         $exception_recips = $recipientRows;
     }
     if (!empty($exception_recips)) {
         // Set the new list of recipients on the exception message, this also removes the existing recipients
         mapi_message_modifyrecipients($message, 0, $exception_recips);
     }
 }
    return $id;
}
// Log on to zarafa as admin user
$session = mapi_logon_zarafa('SYSTEM', '', SERVER);
if (!$session) {
    print "Unable to logon\n";
    return;
}
// Get our stores table
$storetable = mapi_getmsgstorestable($session);
if (!$storetable) {
    print "Unable to get stores list\n";
    return;
}
// Find our default store
$stores = mapi_table_queryallrows($storetable, array(PR_DISPLAY_NAME, PR_ENTRYID, PR_DEFAULT_STORE));
$storenentryid = false;
// Set default to false
foreach ($stores as $row) {
    if (isset($row[PR_DEFAULT_STORE]) && $row[PR_DEFAULT_STORE]) {
        $storeentryid = $row[PR_ENTRYID];
        //print "Found store " . $row[PR_DISPLAY_NAME] . "\n";
        break;
    }
}
if (!$storeentryid) {
    print "Unable to find default store\n";
    return;
}
// We now have the store entryid for the admin store, so open the store
$store = mapi_openmsgstore($session, $storeentryid);
// mapping for the csv column number to contact field (first field is 0)
$csv_mapping = array("given_name" => 0, "middle_name" => 1, "surname" => 2, "display_name_prefix" => 3, "webpage" => 6, "birthday" => 8, "wedding_anniversary" => 9, "notes" => 13, "email_address_1" => 14, "email_address_2" => 15, "email_address_3" => 16, "home_telephone_number" => 18, "home2_telephone_number" => 19, "cellular_telephone_number" => 20, "pager_telephone_number" => 21, "home_fax_number" => 22, "home_address" => 23, "home_address_street" => 24, "home_address_street2" => 25, "home_address_street3" => 26, "home_address_pobox" => 27, "home_address_city" => 28, "home_address_state" => 29, "home_address_postal_code" => 30, "home_address_country" => 31, "spouse_name" => 32, "manager_name" => 34, "assistant" => 35, "company_telephone_number" => 37, "office_telephone_number" => 38, "business2_telephone_number" => 39, "business_fax_number" => 40, "assistant_telephone_number" => 41, "company_name" => 42, "job_title" => 43, "department_name" => 44, "office_location" => 45, "profession" => 47, "business_address" => 49, "business_address_street" => 50, "business_address_street2" => 51, "business_address_street3" => 52, "business_address_pobox" => 53, "business_address_city" => 54, "business_address_state" => 55, "business_address_postal_code" => 56, "business_address_country" => 57, "other_telephone_number" => 58, "other_address" => 60, "other_address_street" => 61, "other_address_street2" => 62, "other_address_street3" => 63, "other_address_pobox" => 64, "other_address_city" => 65, "other_address_state" => 66, "other_address_postal_code" => 67, "other_address_country" => 68, "callback_telephone_number" => 69, "car_telephone_number" => 70, "isdn_number" => 71, "radio_telephone_number" => 72, "ttytdd_telephone_number" => 73, "telex_telephone_number" => 74, "sensitivity" => 84, "categories" => 87);
##########################
## end of configuration ##
##########################
error_reporting(E_ALL);
ini_set("display_errors", true);
ini_set("html_errors", false);
mapidefs();
mapitags();
$session = mapi_logon_zarafa($username, $password, SERVER);
if (mapi_last_hresult() != 0) {
    trigger_error(sprintf("MAPI Error: 0x%x", mapi_last_hresult()), E_USER_ERROR);
}
$storesTable = mapi_getmsgstorestable($session);
$stores = mapi_table_queryallrows($storesTable, array(PR_ENTRYID, PR_MDB_PROVIDER));
for ($i = 0; $i < count($stores); $i++) {
    if ($stores[$i][PR_MDB_PROVIDER] == ZARAFA_SERVICE_GUID) {
        $storeEntryid = $stores[$i][PR_ENTRYID];
        break;
    }
}
if (!isset($storeEntryid)) {
    trigger_error("Default store not found", E_USER_ERROR);
}
$store = mapi_openmsgstore($session, $storeEntryid);
$root = mapi_msgstore_openentry($store, null);
$rootProps = mapi_getprops($root, array(PR_IPM_CONTACT_ENTRYID));
$folder = mapi_msgstore_openentry($store, $rootProps[PR_IPM_CONTACT_ENTRYID]);
isUnicodeStore($store);
// open the csv file and start reading
Esempio n. 10
0
require MAPI_PATH . "mapicode.php";
require MAPI_PATH . "mapidefs.php";
require MAPI_PATH . "mapitags.php";
require MAPI_PATH . "mapiguid.php";
$supported_classes = array("IPF.Note" => "SYNC_FOLDER_TYPE_USER_MAIL", "IPF.Task" => "SYNC_FOLDER_TYPE_USER_TASK", "IPF.Appointment" => "SYNC_FOLDER_TYPE_USER_APPOINTMENT", "IPF.Contact" => "SYNC_FOLDER_TYPE_USER_CONTACT", "IPF.StickyNote" => "SYNC_FOLDER_TYPE_USER_NOTE");
$session = @mapi_logon_zarafa(ZARAFA_USER, ZARAFA_PASS, ZARAFA_SERVER);
if (!$session) {
    die("Login to Zarafa failed\n");
}
$storetable = @mapi_getmsgstorestable($session);
$storeslist = @mapi_table_queryallrows($storetable, array(PR_ENTRYID, PR_MDB_PROVIDER));
for ($i = 0; $i < count($storeslist); $i++) {
    if ($storeslist[$i][PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
        $publicstore = @mapi_openmsgstore($session, $storeslist[$i][PR_ENTRYID]);
        break;
    }
}
if (!isset($publicstore)) {
    die("Public folder not available");
}
$pub_folder = @mapi_msgstore_openentry($publicstore);
$h_table = @mapi_folder_gethierarchytable($pub_folder, CONVENIENT_DEPTH);
$subfolders = @mapi_table_queryallrows($h_table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_CONTAINER_CLASS, PR_SOURCE_KEY));
echo "Available folders in public folder:\n" . str_repeat("-", 50) . "\n";
foreach ($subfolders as $folder) {
    if (isset($folder[PR_CONTAINER_CLASS]) && array_key_exists($folder[PR_CONTAINER_CLASS], $supported_classes)) {
        echo "Name:\t\t" . $folder[PR_DISPLAY_NAME] . "\n";
        echo "Sync-class:\t" . $supported_classes[$folder[PR_CONTAINER_CLASS]] . "\n";
        echo "PUID:\t\t" . bin2hex($folder[PR_SOURCE_KEY]) . "\n\n";
    }
}
Esempio n. 11
0
 /**
  * Assign a contact picture to a contact
  * @param entryId contact entry id
  * @param contactPicture must be a valid jpeg file. If contactPicture is NULL will remove contact picture from contact if exists
  */
 public function setContactPicture(&$contact, $contactPicture)
 {
     $this->logger->trace("setContactPicture");
     // Find if contact picture is already set
     $contactAttachment = -1;
     $hasattachProp = mapi_getprops($contact, array(PR_HASATTACH));
     if ($hasattachProp) {
         $attachmentTable = mapi_message_getattachmenttable($contact);
         $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD, PR_ATTACH_CONTENT_ID, PR_ATTACH_MIME_TAG, PR_ATTACHMENT_CONTACTPHOTO, PR_EC_WA_ATTACHMENT_HIDDEN_OVERRIDE));
         foreach ($attachments as $attachmentRow) {
             if (isset($attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) && $attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) {
                 $contactAttachment = $attachmentRow[PR_ATTACH_NUM];
                 break;
             }
         }
     }
     // Remove existing attachment if necessary
     if ($contactAttachment != -1) {
         $this->logger->trace("removing existing contact picture");
         $attach = mapi_message_deleteattach($contact, $contactAttachment);
     }
     if ($contactPicture !== NULL) {
         $this->logger->debug("Saving contact picture as attachment");
         // Create attachment
         $attach = mapi_message_createattach($contact);
         // Update contact attachment properties
         $properties = array(PR_ATTACH_SIZE => strlen($contactPicture), PR_ATTACH_LONG_FILENAME => 'ContactPicture.jpg', PR_ATTACHMENT_HIDDEN => false, PR_DISPLAY_NAME => 'ContactPicture.jpg', PR_ATTACH_METHOD => ATTACH_BY_VALUE, PR_ATTACH_MIME_TAG => 'image/jpeg', PR_ATTACHMENT_CONTACTPHOTO => true, PR_ATTACH_DATA_BIN => $contactPicture, PR_ATTACHMENT_FLAGS => 1, PR_ATTACH_EXTENSION_A => '.jpg', PR_ATTACH_NUM => 1);
         mapi_setprops($attach, $properties);
         mapi_savechanges($attach);
     }
     // Test
     if (mapi_last_hresult() > 0) {
         $this->logger->warn("Error saving contact picture: " . get_mapi_error_name());
     } else {
         $this->logger->trace("contact picture done");
     }
 }
 /**
  * open_zarafa
  *
  * @param	descriptor	An open Zarafa session id.
  * @return	array		Array with session and store information.
  */
 function open_zarafa($session)
 {
     $ret = array("root" => "/");
     $storesTable = mapi_getmsgstorestable($session);
     $stores = mapi_table_queryallrows($storesTable, array(PR_ENTRYID, PR_MDB_PROVIDER));
     for ($i = 0; $i < count($stores); $i++) {
         if ($stores[$i][PR_MDB_PROVIDER] == ZARAFA_SERVICE_GUID) {
             $storeEntryid = $stores[$i][PR_ENTRYID];
             break;
         }
     }
     if (!isset($storeEntryid)) {
         trigger_error("Default store not found", PR_USER_ERROR);
     }
     $store = mapi_openmsgstore($session, $storeEntryid);
     $root = mapi_msgstore_openentry($store, null);
     $rootProps = mapi_getprops($root, array(PR_IPM_CONTACT_ENTRYID));
     $folder = mapi_msgstore_openentry($store, $rootProps[PR_IPM_CONTACT_ENTRYID]);
     $table = mapi_folder_getcontentstable($folder);
     $contacts = mapi_table_queryallrows($table);
     $ret["session"] = $session;
     $ret["store"] = $store;
     $ret["contacts"] = $contacts;
     // ZCP 7 and up know unicode...
     $supportmask = mapi_getprops($store, array(PR_STORE_SUPPORT_MASK));
     if (isset($supportmask[PR_STORE_SUPPORT_MASK]) && $supportmask[PR_STORE_SUPPORT_MASK] & STORE_UNICODE_OK) {
         $ret["unicode_store"] = true;
         setlocale(LC_CTYPE, 'en_US.utf-8');
     }
     // END ZCP7 and up know unicode
     return $ret;
 }
Esempio n. 13
0
function listfolders_getlist($adminStore, $session, $user)
{
    global $supported_classes;
    if (strtoupper($user) == 'SYSTEM') {
        // Find the public store store
        $storestables = @mapi_getmsgstorestable($session);
        $result = @mapi_last_hresult();
        if ($result == NOERROR) {
            $rows = @mapi_table_queryallrows($storestables, array(PR_ENTRYID, PR_MDB_PROVIDER));
            foreach ($rows as $row) {
                if (isset($row[PR_MDB_PROVIDER]) && $row[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
                    if (!isset($row[PR_ENTRYID])) {
                        echo "Public folder are not available.\nIf this is a multi-tenancy system, use -u and -p and login with an admin user of the company.\nThe script will exit.\n";
                        exit(1);
                    }
                    $entryid = $row[PR_ENTRYID];
                    break;
                }
            }
        }
    } else {
        $entryid = @mapi_msgstore_createentryid($adminStore, $user);
    }
    $userStore = @mapi_openmsgstore($session, $entryid);
    $hresult = mapi_last_hresult();
    // Cache the store for later use
    if ($hresult != NOERROR) {
        echo "Could not open store for '{$user}'. The script will exit.\n";
        exit(1);
    }
    if (strtoupper($user) != 'SYSTEM') {
        $inbox = mapi_msgstore_getreceivefolder($userStore);
        if (mapi_last_hresult() != NOERROR) {
            printf("Could not open inbox for %s (0x%08X). The script will exit.\n", $user, mapi_last_hresult());
            exit(1);
        }
        $inboxProps = mapi_getprops($inbox, array(PR_SOURCE_KEY));
    }
    $storeProps = mapi_getprops($userStore, array(PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID, PR_IPM_WASTEBASKET_ENTRYID));
    $root = @mapi_msgstore_openentry($userStore, null);
    $h_table = @mapi_folder_gethierarchytable($root, CONVENIENT_DEPTH);
    $subfolders = @mapi_table_queryallrows($h_table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_CONTAINER_CLASS, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_FOLDER_TYPE, PR_ATTR_HIDDEN));
    echo "Available folders in store '{$user}':\n" . str_repeat("-", 50) . "\n";
    foreach ($subfolders as $folder) {
        // do not display hidden and search folders
        if (isset($folder[PR_ATTR_HIDDEN]) && $folder[PR_ATTR_HIDDEN] || isset($folder[PR_FOLDER_TYPE]) && $folder[PR_FOLDER_TYPE] == FOLDER_SEARCH) {
            continue;
        }
        // handle some special folders
        if (strtoupper($user) != 'SYSTEM' && (isset($inboxProps[PR_SOURCE_KEY]) && $folder[PR_SOURCE_KEY] == $inboxProps[PR_SOURCE_KEY] || $folder[PR_ENTRYID] == $storeProps[PR_IPM_SENTMAIL_ENTRYID] || $folder[PR_ENTRYID] == $storeProps[PR_IPM_WASTEBASKET_ENTRYID])) {
            $folder[PR_CONTAINER_CLASS] = "IPF.Note";
        }
        if (isset($folder[PR_CONTAINER_CLASS]) && array_key_exists($folder[PR_CONTAINER_CLASS], $supported_classes)) {
            echo "Folder name:\t" . $folder[PR_DISPLAY_NAME] . "\n";
            echo "Folder ID:\t" . bin2hex($folder[PR_SOURCE_KEY]) . "\n";
            echo "Type:\t\t" . $supported_classes[$folder[PR_CONTAINER_CLASS]] . "\n";
            echo "\n";
        }
    }
}
function export($store, $csv_file)
{
    $folder = getContactsFolder($store);
    // open the csv file and start reading
    $fh = fopen($csv_file, "w");
    if (!$fh) {
        trigger_error("Can't write CSV file \"" . $csv_file . "\".", E_USER_ERROR);
    }
    $properties = getProperties();
    $properties = replaceStringPropertyTags($store, $properties);
    $table = mapi_folder_getcontentstable($folder);
    $list = mapi_table_queryallrows($table, $properties);
    $special_properties = array();
    // currently no special values, thus empty array.
    $csv_mapping = getMapping();
    $csv_mapping = convertToGaplessMapping($csv_mapping);
    fputcsv($fh, array_keys($csv_mapping), CSV_DELIMITER, CSV_ENCLOSURE);
    foreach ($list as $item) {
        printf("Contact read: \"%s\".\n", $item[$properties["display_name"]]);
        $attributeValues = array();
        foreach ($csv_mapping as $property => $cnt) {
            $attributeValue = "?????";
            if (substr($property, 0, 3) == "N/A") {
                $attributeValue = "";
            } else {
                if (!in_array($property, $special_properties)) {
                    $attributeValue = array_key_exists($properties[$property], $item) ? $item[$properties[$property]] : "";
                    if (is_array($attributeValue)) {
                        $attributeValue = implode(";", $attributeValue);
                    }
                } else {
                    $attributeValue = "Special value.";
                }
            }
            $attributeValues[] = $attributeValue;
        }
        fputcsv($fh, $attributeValues, CSV_DELIMITER, CSV_ENCLOSURE);
    }
    fclose($fh);
}
Esempio n. 15
0
/**
 * Note: Static function, more like a utility function.
 *
 * Gets all the items (including recurring items) in the specified calendar in the given timeframe. Items are
 * included as a whole if they overlap the interval <$start, $end> (non-inclusive). This means that if the interval
 * is <08:00 - 14:00>, the item [6:00 - 8:00> is NOT included, nor is the item [14:00 - 16:00>. However, the item
 * [7:00 - 9:00> is included as a whole, and is NOT capped to [8:00 - 9:00>.
 *
 * @param $store resource The store in which the calendar resides
 * @param $calendar resource The calendar to get the items from
 * @param $viewstart int Timestamp of beginning of view window
 * @param $viewend int Timestamp of end of view window
 * @param $propsrequested array Array of properties to return
 * @param $rows array Array of rowdata as if they were returned directly from mapi_table_queryrows. Each recurring item is
 *                    expanded so that it seems that there are only many single appointments in the table.
 */
function getCalendarItems($store, $calendar, $viewstart, $viewend, $propsrequested)
{
    $result = array();
    $properties = getPropIdsFromStrings($store, array("duedate" => "PT_SYSTIME:PSETID_Appointment:0x820e", "startdate" => "PT_SYSTIME:PSETID_Appointment:0x820d", "enddate_recurring" => "PT_SYSTIME:PSETID_Appointment:0x8236", "recurring" => "PT_BOOLEAN:PSETID_Appointment:0x8223", "recurring_data" => "PT_BINARY:PSETID_Appointment:0x8216", "timezone_data" => "PT_BINARY:PSETID_Appointment:0x8233", "label" => "PT_LONG:PSETID_Appointment:0x8214"));
    // Create a restriction that will discard rows of appointments that are definitely not in our
    // requested time frame
    $table = mapi_folder_getcontentstable($calendar);
    $restriction = array(RES_OR, array(array(RES_AND, array(array(RES_PROPERTY, array(RELOP => RELOP_GT, ULPROPTAG => $properties["duedate"], VALUE => $viewstart)), array(RES_PROPERTY, array(RELOP => RELOP_LT, ULPROPTAG => $properties["startdate"], VALUE => $viewend)))), array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => $properties["recurring"], VALUE => true))));
    // global OR
    // Get requested properties, plus whatever we need
    $proplist = array(PR_ENTRYID, $properties["recurring"], $properties["recurring_data"], $properties["timezone_data"]);
    $proplist = array_merge($proplist, $propsrequested);
    $propslist = array_unique($proplist);
    $rows = mapi_table_queryallrows($table, $proplist, $restriction);
    // $rows now contains all the items that MAY be in the window; a recurring item needs expansion before including in the output.
    foreach ($rows as $row) {
        $items = array();
        if (isset($row[$properties["recurring"]]) && $row[$properties["recurring"]]) {
            // Recurring item
            $rec = new Recurrence($store, $row);
            // GetItems guarantees that the item overlaps the interval <$viewstart, $viewend>
            $occurrences = $rec->getItems($viewstart, $viewend);
            foreach ($occurrences as $occurrence) {
                // The occurrence takes all properties from the main row, but overrides some properties (like start and end obviously)
                $item = $occurrence + $row;
                array_push($items, $item);
            }
        } else {
            // Normal item, it matched the search criteria and therefore overlaps the interval <$viewstart, $viewend>
            array_push($items, $row);
        }
        $result = array_merge($result, $items);
    }
    // All items are guaranteed to overlap the interval <$viewstart, $viewend>. Note that we may be returning a few extra
    // properties that the caller did not request (recurring, etc). This shouldn't be a problem though.
    return $result;
}
Esempio n. 16
0
 /**
  * Returns contacts matching given email address from a folder.
  *
  * @param MAPIStore $store
  * @param binary $folderEntryid
  * @param string $email
  *
  * @return array|boolean
  */
 private function getContactsFromFolder($store, $folderEntryid, $email)
 {
     $folder = mapi_msgstore_openentry($store, $folderEntryid);
     $folderContent = mapi_folder_getcontentstable($folder);
     mapi_table_restrict($folderContent, MAPIUtils::GetEmailAddressRestriction($store, $email));
     // TODO max limit
     if (mapi_table_getrowcount($folderContent) > 0) {
         return mapi_table_queryallrows($folderContent, array(PR_DISPLAY_NAME, PR_USER_X509_CERTIFICATE));
     }
     return false;
 }
 function run()
 {
     $retval = RESULT_ERROR_GET_USER;
     $this->checkcommandline();
     $this->logon();
     $this->getdefaultstore();
     $this->opendefaultstore();
     $this->getuserlist();
     $this->openaddressbook();
     $this->openglobaladdressbook();
     $this->getgabfolder();
     $rows = mapi_table_queryallrows($this->gabtable, array(PR_ENTRYID, PR_MDB_PROVIDER, PR_DISPLAY_NAME, PR_OBJECT_TYPE));
     if (is_array($rows)) {
         $retval = RESULT_OK;
         $anythingdone = false;
         foreach ($rows as $row) {
             if ($row[PR_OBJECT_TYPE] == MAPI_MAILUSER && $row[PR_DISPLAY_NAME] != "SYSTEM") {
                 $mustprocess = $this->options->all;
                 $storename = $this->getusernamebyfullname($row[PR_DISPLAY_NAME]);
                 if (!$mustprocess) {
                     $mustprocess = $storename == $this->options->user;
                 }
                 if ($mustprocess) {
                     printf("Processing user '%s'\n", $storename);
                     if (!$this->UpdateFB($this->addressbook, $this->session, $this->defaultstore, $row[PR_ENTRYID])) {
                         print "Unable to update F/B for user " . $storename . "\n";
                     } else {
                         $anythingdone = true;
                     }
                 }
             }
         }
         if (!$anythingdone) {
             print "No applicable users found.\n";
             $retval = RESULT_WARNING_NOTHINGDONE;
         }
     } else {
         print "No applicable users found.\n";
     }
     return $retval;
 }
if ($l_bbnEntryID) {
    // Open msg store by using the entryID
    $l_rDefaultStore = mapi_openmsgstore($l_rSession, $l_bbnEntryID);
    echo 'Opening default store result (0=success): ' . mapi_last_hresult() . "\n";
    // Get inbox
    $l_rInbox = mapi_msgstore_getreceivefolder($l_rDefaultStore);
    echo 'Getting entryID of inbox folder result (0=success): ' . mapi_last_hresult() . "\n";
    // Check if folder has been opened
    if ($l_rInbox) {
        // Open contents table
        $l_rInboxTable = mapi_folder_getcontentstable($l_rInbox);
        echo 'Opening contents table result (0=success): ' . mapi_last_hresult() . "\n";
        // Find the item by restricting all items to the correct ID
        $restrict = array(RES_AND, array(array(RES_PROPERTY, array(RELOP => RELOP_NE, ULPROPTAG => PR_PROCESSED, VALUE => array(PR_PROCESSED => true))), array(RES_CONTENT, array(FUZZYLEVEL => FL_PREFIX, ULPROPTAG => PR_MESSAGE_CLASS, VALUE => array(PR_SUBJECT => 'IPM.Schedule.Meeting'))), array(RES_BITMASK, array(ULTYPE => BMR_EQZ, ULMASK => MSGFLAG_READ, ULPROPTAG => PR_MESSAGE_FLAGS))));
        // Just get all items from table
        $l_aRows = mapi_table_queryallrows($l_rInboxTable, array(PR_ENTRYID, PR_MESSAGE_CLASS, PR_SUBJECT, PR_PROCESSED), $restrict);
        echo 'Querying contents table result (0=success): ' . mapi_last_hresult() . "\n";
        //print_r(count($l_aRows));
        //exit;
        echo 'Processing messages' . "\n";
        $l_iCounter = 0;
        for ($i = 0; $i < count($l_aRows); $i++) {
            $l_sMsgClassSearch = 'IPM.Schedule.Meeting';
            $l_rMessage = mapi_msgstore_openentry($l_rDefaultStore, $l_aRows[$i][PR_ENTRYID]);
            $req = new Meetingrequest($l_rDefaultStore, $l_rMessage, $l_rSession);
            if ($req->isMeetingRequest() && !$req->isLocalOrganiser()) {
                // Put the item in the calendar 'tentatively'
                $req->doAccept(true, false, false);
                $l_iCounter++;
            } elseif ($req->isMeetingCancellation()) {
                // Let's do some processing of this Meeting Cancellation Object we received
Esempio n. 19
0
 function _getFoldersRecursive($mapifolder, $parent, &$list)
 {
     $hierarchytable = mapi_folder_gethierarchytable($mapifolder);
     $folderprops = mapi_getprops($mapifolder, array(PR_ENTRYID));
     if (!$hierarchytable) {
         return false;
     }
     $rows = mapi_table_queryallrows($hierarchytable, array(PR_DISPLAY_NAME, PR_SUBFOLDERS, PR_ENTRYID));
     foreach ($rows as $row) {
         $folder = array();
         $folder["mod"] = $row[PR_DISPLAY_NAME];
         $folder["id"] = bin2hex($row[PR_ENTRYID]);
         $folder["parent"] = $parent;
         array_push($list, $folder);
         if (isset($row[PR_SUBFOLDERS]) && $row[PR_SUBFOLDERS]) {
             $this->_getFoldersRecursive(mapi_msgstore_openentry($this->_defaultstore, $row[PR_ENTRYID]), $folderprops[PR_ENTRYID], $list);
         }
     }
     return true;
 }
Esempio n. 20
0
 /**
  * Convert vObject to an array of properties
  * @param array $properties 
  * @param object $vCard
  */
 public function propertiesToVObject($contact, &$vCard)
 {
     $this->logger->debug("Generating contact vCard from properties");
     $p = $this->bridge->getExtendedProperties();
     $contactProperties = mapi_getprops($contact);
     // $this->bridge->getProperties($contactId);
     $dump = print_r($contactProperties, true);
     $this->logger->trace("Contact properties:\n{$contactProperties}");
     // Version check
     switch ($this->version) {
         case 2:
             $vCard->add('VERSION', '2.1');
             break;
         case 3:
             $vCard->add('VERSION', '3.0');
             break;
         case 4:
             $vCard->add('VERSION', '4.0');
             break;
         default:
             $this->logger->fatal("Unrecognised VCard version: " . $this->version);
             return;
     }
     // Private contact ?
     if (isset($contactProperties[$p['private']]) && $contactProperties[$p['private']]) {
         $vCard->add('CLASS', 'PRIVATE');
         // Not in VCARD 4.0 but keep it for compatibility
     }
     // Mandatory FN
     $this->setVCard($vCard, 'FN', $contactProperties, $p['display_name']);
     // Contact name and pro information
     // N property
     /*
        Special note:  The structured property value corresponds, in
     	  sequence, to the Family Names (also known as surnames), Given
     	  Names, Additional Names, Honorific Prefixes, and Honorific
     	  Suffixes.  The text components are separated by the SEMICOLON
     	  character (U+003B).  Individual text components can include
     	  multiple text values separated by the COMMA character (U+002C).
     	  This property is based on the semantics of the X.520 individual
     	  name attributes [CCITT.X520.1988].  The property SHOULD be present
     	  in the vCard object when the name of the object the vCard
     	  represents follows the X.520 model.
     
     	  The SORT-AS parameter MAY be applied to this property.
     */
     $contactInfos = array();
     $contactInfos[] = isset($contactProperties[$p['surname']]) ? $contactProperties[$p['surname']] : '';
     $contactInfos[] = isset($contactProperties[$p['given_name']]) ? $contactProperties[$p['given_name']] : '';
     $contactInfos[] = isset($contactProperties[$p['middle_name']]) ? $contactProperties[$p['middle_name']] : '';
     $contactInfos[] = isset($contactProperties[$p['display_name_prefix']]) ? $contactProperties[$p['display_name_prefix']] : '';
     $contactInfos[] = isset($contactProperties[$p['generation']]) ? $contactProperties[$p['generation']] : '';
     $element = new Sabre_VObject_Property("N");
     $element->setValue(implode(';', $contactInfos));
     // $element->offsetSet("SORT-AS", '"' . $contactProperties[$p['fileas']] . '"');
     $vCard->add($element);
     $this->setVCard($vCard, 'SORT-AS', $contactProperties, $p['fileas']);
     $this->setVCard($vCard, 'NICKNAME', $contactProperties, $p['nickname']);
     $this->setVCard($vCard, 'TITLE', $contactProperties, $p['title']);
     $this->setVCard($vCard, 'ROLE', $contactProperties, $p['profession']);
     $this->setVCard($vCard, 'ORG', $contactProperties, $p['company_name']);
     $this->setVCard($vCard, 'OFFICE', $contactProperties, $p['office_location']);
     if ($this->version >= 4) {
         if (isset($contactProperties[$p['assistant']])) {
             if (!empty($contactProperties[$p['assistant']])) {
                 $element = new Sabre_VObject_Property('RELATED');
                 $element->setValue($contactProperties[$p['assistant']]);
                 $element->offsetSet('TYPE', 'assistant');
                 // Not RFC compliant
                 $vCard->add($element);
             }
         }
         if (isset($contactProperties[$p['manager_name']])) {
             if (!empty($contactProperties[$p['manager_name']])) {
                 $element = new Sabre_VObject_Property('RELATED');
                 $element->setValue($contactProperties[$p['manager_name']]);
                 $element->offsetSet('TYPE', 'manager');
                 // Not RFC compliant
                 $vCard->add($element);
             }
         }
         if (isset($contactProperties[$p['spouse_name']])) {
             if (!empty($contactProperties[$p['spouse_name']])) {
                 $element = new Sabre_VObject_Property('RELATED');
                 $element->setValue($contactProperties[$p['spouse_name']]);
                 $element->offsetSet('TYPE', 'spouse');
                 $vCard->add($element);
             }
         }
     }
     // older syntax - may be needed by some clients so keep it!
     $this->setVCard($vCard, 'X-MS-ASSISTANT', $contactProperties, $p['assistant']);
     $this->setVCard($vCard, 'X-MS-MANAGER', $contactProperties, $p['manager_name']);
     $this->setVCard($vCard, 'X-MS-SPOUSE', $contactProperties, $p['spouse_name']);
     // Dates
     if (isset($contactProperties[$p['birthday']]) && $contactProperties[$p['birthday']] > 0) {
         $vCard->add('BDAY', date(DATE_PATTERN, $contactProperties[$p['birthday']]));
     }
     if (isset($contactProperties[$p['wedding_anniversary']]) && $contactProperties[$p['wedding_anniversary']] > 0) {
         if ($this->version >= 4) {
             $vCard->add('ANNIVERSARY', date(DATE_PATTERN, $contactProperties[$p['wedding_anniversary']]));
         } else {
             $vCard->add('X-ANNIVERSARY', date(DATE_PATTERN, $contactProperties[$p['wedding_anniversary']]));
         }
     }
     // Telephone numbers
     // webaccess can handle 19 telephone numbers...
     $this->setVCard($vCard, 'TEL;TYPE=HOME,VOICE', $contactProperties, $p['home_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=HOME,VOICE', $contactProperties, $p['home2_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=CELL', $contactProperties, $p['cellular_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=WORK,VOICE', $contactProperties, $p['office_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=WORK,VOICE', $contactProperties, $p['business2_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=WORK,FAX', $contactProperties, $p['business_fax_number']);
     $this->setVCard($vCard, 'TEL;TYPE=HOME,FAX', $contactProperties, $p['home_fax_number']);
     $this->setVCard($vCard, 'TEL;TYPE=PAGER', $contactProperties, $p['pager_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=ISDN', $contactProperties, $p['isdn_number']);
     $this->setVCard($vCard, 'TEL;TYPE=WORK', $contactProperties, $p['company_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=CAR', $contactProperties, $p['car_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=SECR', $contactProperties, $p['assistant_telephone_number']);
     // There are unmatched telephone numbers in zarafa, use them!
     $unmatchedProperties = array("callback_telephone_number", "other_telephone_number", "primary_fax_number", "primary_telephone_number", "radio_telephone_number", "telex_telephone_number", "ttytdd_telephone_number");
     if (in_array(DEFAULT_TELEPHONE_NUMBER_PROPERTY, $unmatchedProperties)) {
         // unmatched found a match!
         $this->setVCard($vCard, 'TEL', $contactProperties, $p[DEFAULT_TELEPHONE_NUMBER_PROPERTY]);
     }
     $this->setVCardAddress($vCard, 'HOME', $contactProperties, 'home');
     $this->setVCardAddress($vCard, 'WORK', $contactProperties, 'business');
     $this->setVCardAddress($vCard, 'OTHER', $contactProperties, 'other');
     // emails
     for ($i = 1; $i <= 3; $i++) {
         if (isset($contactProperties[$p["email_address_{$i}"]])) {
             // Zarafa needs an email display name
             $emailProperty = new Sabre_VObject_Property('EMAIL', $contactProperties[$p["email_address_{$i}"]]);
             // Get display name
             $dn = isset($contactProperties[$p["email_address_display_name_{$i}"]]) ? $contactProperties[$p["email_address_display_name_{$i}"]] : $contactProperties[$p['display_name']];
             $emailProperty->offsetSet("X-CN", '"' . $dn . '"');
             $vCard->add($emailProperty);
         }
     }
     // URL and Instant Messenging (vCard 3.0 extension)
     $this->setVCard($vCard, 'URL', $contactProperties, $p["webpage"]);
     $this->setVCard($vCard, 'IMPP', $contactProperties, $p["im"]);
     // Categories
     $contactCategories = '';
     if (isset($contactProperties[$p['categories']])) {
         if (is_array($contactProperties[$p['categories']])) {
             $contactCategories = implode(',', $contactProperties[$p['categories']]);
         } else {
             $contactCategories = $contactProperties[$p['categories']];
         }
     }
     if ($contactCategories != '') {
         $vCard->add('CATEGORIES', $contactCategories);
     }
     // Contact picture?
     $hasattachProp = mapi_getprops($contact, array(PR_HASATTACH));
     $photo = NULL;
     $photoMime = '';
     if (isset($hasattachProp[PR_HASATTACH]) && $hasattachProp[PR_HASATTACH]) {
         $attachmentTable = mapi_message_getattachmenttable($contact);
         $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD, PR_ATTACH_CONTENT_ID, PR_ATTACH_MIME_TAG, PR_ATTACHMENT_CONTACTPHOTO, PR_EC_WA_ATTACHMENT_HIDDEN_OVERRIDE));
         $dump = print_r($attachments, true);
         $this->logger->trace("Contact attachments:\n{$dump}");
         foreach ($attachments as $attachmentRow) {
             if (isset($attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) && $attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) {
                 $attach = mapi_message_openattach($contact, $attachmentRow[PR_ATTACH_NUM]);
                 $photo = mapi_attach_openbin($attach, PR_ATTACH_DATA_BIN);
                 if (isset($attachmentRow[PR_ATTACH_MIME_TAG])) {
                     $photoMime = $attachmentRow[PR_ATTACH_MIME_TAG];
                 } else {
                     $photoMime = 'image/jpeg';
                 }
                 break;
             }
         }
     }
     if ($photo != NULL) {
         // SogoConnector does not like image/jpeg
         if ($photoMime == 'image/jpeg') {
             $photoMime = 'JPEG';
         }
         $this->logger->trace("Adding contact picture to VCard");
         $photoEncoded = base64_encode($photo);
         $photoProperty = new Sabre_VObject_Property('PHOTO', $photoEncoded);
         $photoProperty->offsetSet('TYPE', $photoMime);
         $photoProperty->offsetSet('ENCODING', 'b');
         $vCard->add($photoProperty);
     }
     // Misc
     $vCard->add('UID', "urn:uuid:" . substr($contactProperties[PR_CARDDAV_URI], 0, -4));
     // $this->entryIdToStr($contactProperties[PR_ENTRYID]));
     $this->setVCard($vCard, 'NOTE', $contactProperties, $p['notes']);
     $vCard->add('PRODID', VCARD_PRODUCT_ID);
     $vCard->add('REV', date('c', $contactProperties[$p['last_modification_time']]));
 }
Esempio n. 21
0
 /**
  * Copies attachments from one message to another.
  *
  * @param MAPIMessage $toMessage
  * @param MAPIMessage $fromMessage
  *
  * @return void
  */
 private function copyAttachments(&$toMessage, $fromMessage)
 {
     $attachtable = mapi_message_getattachmenttable($fromMessage);
     $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
     foreach ($rows as $row) {
         if (isset($row[PR_ATTACH_NUM])) {
             $attach = mapi_message_openattach($fromMessage, $row[PR_ATTACH_NUM]);
             $newattach = mapi_message_createattach($toMessage);
             // Copy all attachments from old to new attachment
             $attachprops = mapi_getprops($attach);
             mapi_setprops($newattach, $attachprops);
             if (isset($attachprops[mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_ATTACH_DATA_BIN))])) {
                 // Data is in a stream
                 $srcstream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
                 $dststream = mapi_openpropertytostream($newattach, PR_ATTACH_DATA_BIN, MAPI_MODIFY | MAPI_CREATE);
                 while (1) {
                     $data = mapi_stream_read($srcstream, 4096);
                     if (strlen($data) == 0) {
                         break;
                     }
                     mapi_stream_write($dststream, $data);
                 }
                 mapi_stream_commit($dststream);
             }
             mapi_savechanges($newattach);
         }
     }
 }
Esempio n. 22
0
// Either boolean or binary
// Loop through returned rows
for ($i = 0; $i < count($l_aTableRows); $i++) {
    // Check to see if this entry is the default store
    if (isset($l_aTableRows[$i][PR_DEFAULT_STORE]) && $l_aTableRows[$i][PR_DEFAULT_STORE] == true) {
        $storeEntryId = $l_aTableRows[$i][PR_ENTRYID];
        break;
    }
}
// check if default root store's entry id found
if ($storeEntryId) {
    $store = mapi_openmsgstore($l_rSession, $storeEntryId);
    $delStoreProps = mapi_getprops($store, array(PR_IPM_WASTEBASKET_ENTRYID));
    $deletedFolder = mapi_msgstore_openentry($store, $delStoreProps[PR_IPM_WASTEBASKET_ENTRYID]);
    $table = mapi_folder_getcontentstable($deletedFolder);
    $delRows = mapi_table_queryallrows($table, array(PR_ENTRYID, PR_CREATION_TIME));
    echo (mapi_last_hresult() == 0 ? "Fetching messages from Deleted Folder..." : "Some error in fetching...") . "\n";
    if (count($delRows) > 0) {
        $delEntryIds = array();
        echo 'Total messages in deleted folder found are : ' . count($delRows) . "\n";
        for ($i = 0; $i < count($delRows); $i++) {
            if (greaterDate(date("Y-m-d G:i:s", $delRows[$i][PR_CREATION_TIME]), $daysBeforeDeleted)) {
                array_push($delEntryIds, $delRows[$i][PR_ENTRYID]);
            }
        }
        if (count($delEntryIds) > 0) {
            echo "\nDeleting all " . count($delEntryIds) . " messages...\n";
            mapi_folder_deletemessages($deletedFolder, $delEntryIds);
            echo "" . (mapi_last_hresult() == 0 ? "Successfully deleted all messages" : "Some error in deleting... please try again later") . "\n";
        } else {
            echo "\nNo message found before " . $daysBeforeDeleted . " days in Deleted Folder.";
 /**
  * Function which clones current occurrence and sets appropriate properties.
  * The original recurring item is moved to next occurrence.
  *@param boolean $markComplete true if existing occurrence has to be mark complete else false.
  */
 function regenerateTask($markComplete)
 {
     // Get all properties
     $taskItemProps = mapi_getprops($this->message);
     if (isset($this->action["subject"])) {
         $taskItemProps[$this->proptags["subject"]] = $this->action["subject"];
     }
     if (isset($this->action["importance"])) {
         $taskItemProps[$this->proptags["importance"]] = $this->action["importance"];
     }
     if (isset($this->action["startdate"])) {
         $taskItemProps[$this->proptags["startdate"]] = $this->action["startdate"];
         $taskItemProps[$this->proptags["commonstart"]] = $this->action["startdate"];
     }
     if (isset($this->action["duedate"])) {
         $taskItemProps[$this->proptags["duedate"]] = $this->action["duedate"];
         $taskItemProps[$this->proptags["commonend"]] = $this->action["duedate"];
     }
     $folder = mapi_msgstore_openentry($this->store, $taskItemProps[PR_PARENT_ENTRYID]);
     $newMessage = mapi_folder_createmessage($folder);
     $taskItemProps[$this->proptags["status"]] = $markComplete ? olTaskComplete : olTaskNotStarted;
     $taskItemProps[$this->proptags["complete"]] = $markComplete;
     $taskItemProps[$this->proptags["percent_complete"]] = $markComplete ? 1 : 0;
     // This occurrence has been marked as 'Complete' so disable reminder
     if ($markComplete) {
         $taskItemProps[$this->proptags["reset_reminder"]] = false;
         $taskItemProps[$this->proptags["reminder"]] = false;
         $taskItemProps[$this->proptags["datecompleted"]] = $this->action["datecompleted"];
         unset($this->action[$this->proptags['datecompleted']]);
     }
     // Recurrence ends for this item
     $taskItemProps[$this->proptags["dead_occurrence"]] = true;
     $taskItemProps[$this->proptags["task_f_creator"]] = true;
     //OL props
     $taskItemProps[$this->proptags["side_effects"]] = 1296;
     $taskItemProps[$this->proptags["icon_index"]] = 1280;
     // Copy recipients
     $recipienttable = mapi_message_getrecipienttable($this->message);
     $recipients = mapi_table_queryallrows($recipienttable, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_EMAIL_ADDRESS, PR_RECIPIENT_ENTRYID, PR_RECIPIENT_TYPE, PR_SEND_INTERNET_ENCODING, PR_SEND_RICH_INFO, PR_RECIPIENT_DISPLAY_NAME, PR_ADDRTYPE, PR_DISPLAY_TYPE, PR_RECIPIENT_TRACKSTATUS, PR_RECIPIENT_TRACKSTATUS_TIME, PR_RECIPIENT_FLAGS, PR_ROWID));
     $copy_to_recipientTable = mapi_message_getrecipienttable($newMessage);
     $copy_to_recipientRows = mapi_table_queryallrows($copy_to_recipientTable, array(PR_ROWID));
     foreach ($copy_to_recipientRows as $recipient) {
         mapi_message_modifyrecipients($newMessage, MODRECIP_REMOVE, array($recipient));
     }
     mapi_message_modifyrecipients($newMessage, MODRECIP_ADD, $recipients);
     // Copy attachments
     $attachmentTable = mapi_message_getattachmenttable($this->message);
     if ($attachmentTable) {
         $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD));
         foreach ($attachments as $attach_props) {
             $attach_old = mapi_message_openattach($this->message, (int) $attach_props[PR_ATTACH_NUM]);
             $attach_newResourceMsg = mapi_message_createattach($newMessage);
             mapi_copyto($attach_old, array(), array(), $attach_newResourceMsg, 0);
             mapi_savechanges($attach_newResourceMsg);
         }
     }
     mapi_setprops($newMessage, $taskItemProps);
     mapi_savechanges($newMessage);
     // Update body of original message
     $msgbody = mapi_message_openproperty($this->message, PR_BODY);
     $msgbody = trim($this->windows1252_to_utf8($msgbody), "");
     $separator = "------------\r\n";
     if (!empty($msgbody) && strrpos($msgbody, $separator) === false) {
         $msgbody = $separator . $msgbody;
         $stream = mapi_openpropertytostream($this->message, PR_BODY, MAPI_CREATE | MAPI_MODIFY);
         mapi_stream_setsize($stream, strlen($msgbody));
         mapi_stream_write($stream, $msgbody);
         mapi_stream_commit($stream);
     }
     // We need these properties to notify client
     return mapi_getprops($newMessage, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID));
 }
Esempio n. 24
0
function listfolders_getlist($adminStore, $session, $user)
{
    global $supported_classes;
    if (strtoupper($user) == 'SYSTEM') {
        // Find the public store store
        $storestables = @mapi_getmsgstorestable($session);
        $result = @mapi_last_hresult();
        if ($result == NOERROR) {
            $rows = @mapi_table_queryallrows($storestables, array(PR_ENTRYID, PR_MDB_PROVIDER));
            foreach ($rows as $row) {
                if (isset($row[PR_MDB_PROVIDER]) && $row[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
                    if (!isset($row[PR_ENTRYID])) {
                        echo "Public folder are not available.\nIf this is a multi-tenancy system, use -u and -p and login with an admin user of the company.\nThe script will exit.\n";
                        exit(1);
                    }
                    $entryid = $row[PR_ENTRYID];
                    break;
                }
            }
        }
    } else {
        $entryid = @mapi_msgstore_createentryid($adminStore, $user);
    }
    $userStore = @mapi_openmsgstore($session, $entryid);
    $hresult = mapi_last_hresult();
    // Cache the store for later use
    if ($hresult != NOERROR) {
        echo "Could not open store for '{$user}'. The script will exit.\n";
        exit(1);
    }
    $folder = @mapi_msgstore_openentry($userStore);
    $h_table = @mapi_folder_gethierarchytable($folder, CONVENIENT_DEPTH);
    $subfolders = @mapi_table_queryallrows($h_table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_CONTAINER_CLASS, PR_SOURCE_KEY));
    echo "Available folders in store '{$user}':\n" . str_repeat("-", 50) . "\n";
    foreach ($subfolders as $folder) {
        if (isset($folder[PR_CONTAINER_CLASS]) && array_key_exists($folder[PR_CONTAINER_CLASS], $supported_classes)) {
            echo "Folder name:\t" . $folder[PR_DISPLAY_NAME] . "\n";
            echo "Folder ID:\t" . bin2hex($folder[PR_SOURCE_KEY]) . "\n";
            echo "Type:\t\t" . $supported_classes[$folder[PR_CONTAINER_CLASS]] . "\n";
            echo "\n";
        }
    }
}
Esempio n. 25
0
function parse_messages($store, $entryid)
{
    global $total_deleted;
    $folder = mapi_msgstore_openentry($store, $entryid);
    if (!$folder) {
        print "Unable to open folder.";
        return false;
    }
    $table = mapi_folder_getcontentstable($folder);
    if (!$table) {
        print "Unable to open table.";
        return false;
    }
    $org_hash = null;
    $dup_messages = array();
    $dup_count = 0;
    $result = mapi_table_sort($table, array(PR_CLIENT_SUBMIT_TIME => TABLE_SORT_DESCEND));
    if ($result == false) {
        echo "Could not sort table\n";
        return;
    }
    while (1) {
        // query messages from folders content table
        $filters = array(PR_MESSAGE_SIZE, PR_CLIENT_SUBMIT_TIME, PR_MESSAGE_RECIPIENTS, PR_EMAIL_ADDRESS, PR_BODY, PR_HTML, PR_ENTRYID, PR_SUBJECT, PR_SMTP_ADDRESS);
        $rows = mapi_table_queryrows($table, $filters, 0, 50);
        if (count($rows) == 0) {
            break;
        }
        // we got the messages
        foreach ($rows as $row) {
            // hash message body (plaintext + html + subject)
            $md5_subject = md5($row[PR_SUBJECT]);
            $md5_body = md5($row[PR_BODY]);
            $md5_html = md5($row[PR_HTML]);
            $md5_eid = $row[PR_ENTRYID];
            $PR_EMAIL_ADDRESS = $row[PR_EMAIL_ADDRESS];
            $PR_SMTP_ADDRESS = $row[PR_SMTP_ADDRESS];
        }
        $message = mapi_msgstore_openentry($store, $md5_eid);
        $recipTable = mapi_message_getrecipienttable($message);
        $oldRecipients = mapi_table_queryallrows($recipTable, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_EMAIL_ADDRESS, PR_RECIPIENT_ENTRYID, PR_RECIPIENT_TYPE, PR_SEND_INTERNET_ENCODING, PR_SEND_RICH_INFO, PR_RECIPIENT_DISPLAY_NAME, PR_ADDRTYPE, PR_DISPLAY_TYPE, PR_RECIPIENT_TRACKSTATUS, PR_RECIPIENT_FLAGS, PR_ROWID));
        print_r($oldRecipients);
    }
}
    //////////////////////////////////
    $username = $_POST['user'];
    $password = $_POST['pwd'];
    $server = 'http://localhost:236/zarafa';
    ////////////////////////////////
    //connect to the zarafa server
    ///////////////////////////////
    $GLOBALS["mapisession"] = new MAPISession();
    $sess = $GLOBALS["mapisession"]->logon($username, $password, $server);
    $session = mapi_logon_zarafa($username, $password, $server);
    $bus = new Bus();
    // Create global bus object
    $GLOBALS["bus"] = $bus;
    // Make bus global
    $GLOBALS["settings"] = new Settings();
    $storelist = $GLOBALS["mapisession"]->getAllMessageStores();
    $id = "webclient_7";
    //define an id
    $GLOBALS["operations"] = new Operations();
    $datas = $GLOBALS["operations"]->getHierarchyList(array(PR_IPM_APPOINTMENT_ENTRYID));
    $store_idhex = $datas[store][0][attributes][id];
    $entryidhex = $datas[store][0][defaultfolders][calendar];
    $entryid = hex2bin($entryidhex);
    $appointment_id = $_POST['zid'];
    $GLOBALS["properties"] = new Properties();
    $cont = new AppointmentListModule($id, $data);
    $stores = mapi_getmsgstorestable($session);
    $storeslist = mapi_table_queryallrows($stores);
    $store = mapi_openmsgstore($session, $storeslist[0][PR_ENTRYID]);
    $result = $GLOBALS["operations"]->deleteMessages($store, $entryid, hex2bin($appointment_id));
}
 /**
  * Clear responses of all attendees who have replied in past.
  * @param MAPI_MESSAGE $message on which responses should be cleared
  */
 function clearRecipientResponse($message)
 {
     $recipTable = mapi_message_getrecipienttable($message);
     $recipsRows = mapi_table_queryallrows($recipTable, $this->recipprops);
     foreach ($recipsRows as $recipient) {
         if (($recipient[PR_RECIPIENT_FLAGS] & recipOrganizer) != recipOrganizer) {
             // Recipient is attendee, set the trackstatus to "Not Responded"
             $recipient[PR_RECIPIENT_TRACKSTATUS] = olRecipientTrackStatusNone;
         } else {
             // Recipient is organizer, this is not possible, but for safety
             // it is best to clear the trackstatus for him as well by setting
             // the trackstatus to "Organized".
             $recipient[PR_RECIPIENT_TRACKSTATUS] = olRecipientTrackStatusNone;
         }
         mapi_message_modifyrecipients($message, MODRECIP_MODIFY, array($recipient));
     }
 }
 /** Deletes all recipients from given message object
  *
  *@param $message MAPI message from which recipients are to be removed.
  */
 function deleteAllRecipients($message)
 {
     $recipTable = mapi_message_getrecipienttable($message);
     $recipRows = mapi_table_queryallrows($recipTable, array(PR_ROWID));
     foreach ($recipRows as $recipient) {
         mapi_message_modifyrecipients($message, MODRECIP_REMOVE, array($recipient));
     }
 }
Esempio n. 29
0
 /**
  * Writes a SyncContact to MAPI
  *
  * @param mixed             $mapimessage
  * @param SyncContact       $contact
  *
  * @access private
  * @return boolean
  */
 private function setContact($mapimessage, $contact)
 {
     mapi_setprops($mapimessage, array(PR_MESSAGE_CLASS => "IPM.Contact"));
     // normalize email addresses
     if (isset($contact->email1address) && ($contact->email1address = $this->extractEmailAddress($contact->email1address)) === false) {
         unset($contact->email1address);
     }
     if (isset($contact->email2address) && ($contact->email2address = $this->extractEmailAddress($contact->email2address)) === false) {
         unset($contact->email2address);
     }
     if (isset($contact->email3address) && ($contact->email3address = $this->extractEmailAddress($contact->email3address)) === false) {
         unset($contact->email3address);
     }
     $contactmapping = MAPIMapping::GetContactMapping();
     $contactprops = MAPIMapping::GetContactProperties();
     $this->setPropsInMAPI($mapimessage, $contact, $contactmapping);
     ///set display name from contact's properties
     $cname = $this->composeDisplayName($contact);
     //get contact specific mapi properties and merge them with the AS properties
     $contactprops = array_merge($this->getPropIdsFromStrings($contactmapping), $this->getPropIdsFromStrings($contactprops));
     //contact specific properties to be set
     $props = array();
     //need to be set in order to show contacts properly in outlook and wa
     $nremails = array();
     $abprovidertype = 0;
     if (isset($contact->email1address)) {
         $this->setEmailAddress($contact->email1address, $cname, 1, $props, $contactprops, $nremails, $abprovidertype);
     }
     if (isset($contact->email2address)) {
         $this->setEmailAddress($contact->email2address, $cname, 2, $props, $contactprops, $nremails, $abprovidertype);
     }
     if (isset($contact->email3address)) {
         $this->setEmailAddress($contact->email3address, $cname, 3, $props, $contactprops, $nremails, $abprovidertype);
     }
     $props[$contactprops["addressbooklong"]] = $abprovidertype;
     $props[$contactprops["displayname"]] = $props[$contactprops["subject"]] = $cname;
     //pda multiple e-mail addresses bug fix for the contact
     if (!empty($nremails)) {
         $props[$contactprops["addressbookmv"]] = $nremails;
     }
     //set addresses
     $this->setAddress("home", $contact->homecity, $contact->homecountry, $contact->homepostalcode, $contact->homestate, $contact->homestreet, $props, $contactprops);
     $this->setAddress("business", $contact->businesscity, $contact->businesscountry, $contact->businesspostalcode, $contact->businessstate, $contact->businessstreet, $props, $contactprops);
     $this->setAddress("other", $contact->othercity, $contact->othercountry, $contact->otherpostalcode, $contact->otherstate, $contact->otherstreet, $props, $contactprops);
     //set the mailing address and its type
     if (isset($props[$contactprops["businessaddress"]])) {
         $props[$contactprops["mailingaddress"]] = 2;
         $this->setMailingAddress($contact->businesscity, $contact->businesscountry, $contact->businesspostalcode, $contact->businessstate, $contact->businessstreet, $props[$contactprops["businessaddress"]], $props, $contactprops);
     } elseif (isset($props[$contactprops["homeaddress"]])) {
         $props[$contactprops["mailingaddress"]] = 1;
         $this->setMailingAddress($contact->homecity, $contact->homecountry, $contact->homepostalcode, $contact->homestate, $contact->homestreet, $props[$contactprops["homeaddress"]], $props, $contactprops);
     } elseif (isset($props[$contactprops["otheraddress"]])) {
         $props[$contactprops["mailingaddress"]] = 3;
         $this->setMailingAddress($contact->othercity, $contact->othercountry, $contact->otherpostalcode, $contact->otherstate, $contact->otherstreet, $props[$contactprops["otheraddress"]], $props, $contactprops);
     }
     if (isset($contact->picture)) {
         $picbinary = base64_decode($contact->picture);
         $picsize = strlen($picbinary);
         if ($picsize < MAX_EMBEDDED_SIZE) {
             $props[$contactprops["haspic"]] = false;
             // TODO contact picture handling
             // check if contact has already got a picture. delete it first in that case
             // delete it also if it was removed on a mobile
             $picprops = mapi_getprops($mapimessage, array($props[$contactprops["haspic"]]));
             if (isset($picprops[$props[$contactprops["haspic"]]]) && $picprops[$props[$contactprops["haspic"]]]) {
                 ZLog::Write(LOGLEVEL_DEBUG, "Contact already has a picture. Delete it");
                 $attachtable = mapi_message_getattachmenttable($mapimessage);
                 mapi_table_restrict($attachtable, MAPIUtils::GetContactPicRestriction());
                 $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
                 if (isset($rows) && is_array($rows)) {
                     foreach ($rows as $row) {
                         mapi_message_deleteattach($mapimessage, $row[PR_ATTACH_NUM]);
                     }
                 }
             }
             // only set picture if there's data in the request
             if ($picbinary !== false && $picsize > 0) {
                 $props[$contactprops["haspic"]] = true;
                 $pic = mapi_message_createattach($mapimessage);
                 // Set properties of the attachment
                 $picprops = array(PR_ATTACH_LONG_FILENAME_A => "ContactPicture.jpg", PR_DISPLAY_NAME => "ContactPicture.jpg", 0x7fff000b => true, PR_ATTACHMENT_HIDDEN => false, PR_ATTACHMENT_FLAGS => 1, PR_ATTACH_METHOD => ATTACH_BY_VALUE, PR_ATTACH_EXTENSION_A => ".jpg", PR_ATTACH_NUM => 1, PR_ATTACH_SIZE => $picsize, PR_ATTACH_DATA_BIN => $picbinary);
                 mapi_setprops($pic, $picprops);
                 mapi_savechanges($pic);
             }
         }
     }
     if (isset($contact->asbody)) {
         $this->setASbody($contact->asbody, $props, $contactprops);
     }
     //set fileas
     if (defined('FILEAS_ORDER')) {
         $lastname = isset($contact->lastname) ? $contact->lastname : "";
         $firstname = isset($contact->firstname) ? $contact->firstname : "";
         $middlename = isset($contact->middlename) ? $contact->middlename : "";
         $company = isset($contact->companyname) ? $contact->companyname : "";
         $props[$contactprops["fileas"]] = Utils::BuildFileAs($lastname, $firstname, $middlename, $company);
     } else {
         ZLog::Write(LOGLEVEL_DEBUG, "FILEAS_ORDER not defined");
     }
     mapi_setprops($mapimessage, $props);
 }
Esempio n. 30
0
 /**
  * Function will be used to decode smime messages and convert it to normal messages.
  *
  * @param MAPISession       $session
  * @param MAPIStore         $store
  * @param MAPIAdressBook    $addressBook
  * @param MAPIMessage       $message smime message
  *
  * @access public
  * @return void
  */
 public static function ParseSmime($session, $store, $addressBook, &$mapimessage)
 {
     $props = mapi_getprops($mapimessage, array(PR_MESSAGE_CLASS));
     if (isset($props[PR_MESSAGE_CLASS]) && stripos($props[PR_MESSAGE_CLASS], 'IPM.Note.SMIME.MultipartSigned') !== false) {
         // this is a signed message. decode it.
         $attachTable = mapi_message_getattachmenttable($mapimessage);
         $rows = mapi_table_queryallrows($attachTable, array(PR_ATTACH_MIME_TAG, PR_ATTACH_NUM));
         $attnum = false;
         foreach ($rows as $row) {
             if (isset($row[PR_ATTACH_MIME_TAG]) && $row[PR_ATTACH_MIME_TAG] == 'multipart/signed') {
                 $attnum = $row[PR_ATTACH_NUM];
             }
         }
         if ($attnum !== false) {
             $att = mapi_message_openattach($mapimessage, $attnum);
             $data = mapi_openproperty($att, PR_ATTACH_DATA_BIN);
             mapi_message_deleteattach($mapimessage, $attnum);
             mapi_inetmapi_imtomapi($session, $store, $addressBook, $mapimessage, $data, array("parse_smime_signed" => 1));
             ZLog::Write(LOGLEVEL_DEBUG, "Convert a smime signed message to a normal message.");
         }
         mapi_setprops($mapimessage, array(PR_MESSAGE_CLASS => 'IPM.Note.SMIME.MultipartSigned'));
     }
     // TODO check if we need to do this for encrypted (and signed?) message as well
 }