Code cleanup in module.contact.php

This commit is contained in:
Christoph Haas 2016-11-30 12:46:19 +01:00
parent 44c0435175
commit cf588a1141
5 changed files with 197 additions and 182 deletions

View File

@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="osboxes">
<words>
<w>guids</w>
</words>
</dictionary>
</component>

View File

@ -2,9 +2,10 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="aae153d8-808f-4371-b0e9-9ee7ff904cab" name="Default" comment=""> <list default="true" id="aae153d8-808f-4371-b0e9-9ee7ff904cab" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/php/helper.php" /> <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/dictionaries/osboxes.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/php/helper.php" afterPath="$PROJECT_DIR$/php/helper.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/php/module.contact.php" afterPath="$PROJECT_DIR$/php/module.contact.php" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/php/module.contact.php" afterPath="$PROJECT_DIR$/php/module.contact.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/php/upload.php" afterPath="$PROJECT_DIR$/php/upload.php" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/php/plugin.contactimporter.php" afterPath="$PROJECT_DIR$/php/plugin.contactimporter.php" />
</list> </list>
<ignored path="contactimporter.iws" /> <ignored path="contactimporter.iws" />
<ignored path=".idea/workspace.xml" /> <ignored path=".idea/workspace.xml" />
@ -25,47 +26,37 @@
</component> </component>
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="download.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/php/download.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="300">
<caret line="41" column="9" selection-start-line="41" selection-start-column="9" selection-end-line="41" selection-end-column="9" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="upload.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/php/upload.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="271">
<caret line="22" column="3" selection-start-line="22" selection-start-column="3" selection-end-line="22" selection-end-column="3" />
<folding>
<element signature="e#7#912#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="module.contact.php" pinned="false" current-in-tab="true"> <file leaf-file-name="module.contact.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/php/module.contact.php"> <entry file="file://$PROJECT_DIR$/php/module.contact.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="234"> <state relative-caret-position="670">
<caret line="275" column="22" selection-start-line="275" selection-start-column="22" selection-end-line="275" selection-end-column="22" /> <caret line="784" column="47" selection-start-line="784" selection-start-column="47" selection-end-line="784" selection-end-column="47" />
<folding> <folding>
<element signature="e#6#919#0#PHP" expanded="true" /> <element signature="e#7#920#0#PHP" expanded="true" />
<element signature="e#1009#1042#0#PHP" expanded="true" /> <element signature="e#1010#1043#0#PHP" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="plugin.contactimporter.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/php/plugin.contactimporter.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="420">
<caret line="28" column="31" selection-start-line="28" selection-start-column="31" selection-end-line="28" selection-end-column="31" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="helper.php" pinned="false" current-in-tab="false"> <file leaf-file-name="helper.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/php/helper.php"> <entry file="file://$PROJECT_DIR$/php/helper.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30"> <state relative-caret-position="15">
<caret line="2" column="55" selection-start-line="2" selection-start-column="55" selection-end-line="2" selection-end-column="55" /> <caret line="1" column="0" selection-start-line="1" selection-start-column="0" selection-end-line="1" selection-end-column="0" />
<folding /> <folding>
<element signature="e#7#912#0#PHP" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -78,7 +69,6 @@
<component name="IdeDocumentHistory"> <component name="IdeDocumentHistory">
<option name="CHANGED_PATHS"> <option name="CHANGED_PATHS">
<list> <list>
<option value="$PROJECT_DIR$/php/plugin.contactimporter.php" />
<option value="$PROJECT_DIR$/config.php" /> <option value="$PROJECT_DIR$/config.php" />
<option value="$PROJECT_DIR$/js/ABOUT.js" /> <option value="$PROJECT_DIR$/js/ABOUT.js" />
<option value="$PROJECT_DIR$/js/dialogs/ImportContentPanel.js" /> <option value="$PROJECT_DIR$/js/dialogs/ImportContentPanel.js" />
@ -90,8 +80,9 @@
<option value="$PROJECT_DIR$/changelog.txt" /> <option value="$PROJECT_DIR$/changelog.txt" />
<option value="$PROJECT_DIR$/manifest.xml" /> <option value="$PROJECT_DIR$/manifest.xml" />
<option value="$PROJECT_DIR$/php/download.php" /> <option value="$PROJECT_DIR$/php/download.php" />
<option value="$PROJECT_DIR$/php/helper.php" />
<option value="$PROJECT_DIR$/php/upload.php" /> <option value="$PROJECT_DIR$/php/upload.php" />
<option value="$PROJECT_DIR$/php/helper.php" />
<option value="$PROJECT_DIR$/php/plugin.contactimporter.php" />
<option value="$PROJECT_DIR$/php/module.contact.php" /> <option value="$PROJECT_DIR$/php/module.contact.php" />
</list> </list>
</option> </option>
@ -323,12 +314,12 @@
<workItem from="1480428199144" duration="44000" /> <workItem from="1480428199144" duration="44000" />
<workItem from="1480428259775" duration="69000" /> <workItem from="1480428259775" duration="69000" />
<workItem from="1480428330068" duration="6691000" /> <workItem from="1480428330068" duration="6691000" />
<workItem from="1480504955898" duration="525000" /> <workItem from="1480504955898" duration="1406000" />
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="7329000" /> <option name="totallyTimeSpent" value="8210000" />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="65" y="24" width="1792" height="999" extended-state="6" /> <frame x="65" y="24" width="1792" height="999" extended-state="6" />
@ -469,13 +460,9 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1200"> <state relative-caret-position="1200">
<caret line="80" column="13" selection-start-line="80" selection-start-column="8" selection-end-line="80" selection-end-column="13" /> <caret line="80" column="13" selection-start-line="80" selection-start-column="8" selection-end-line="80" selection-end-column="13" />
</state> <folding>
</provider> <element signature="n#!!doc" expanded="true" />
</entry> </folding>
<entry file="file://$PROJECT_DIR$/php/plugin.contactimporter.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="675">
<caret line="84" column="83" selection-start-line="84" selection-start-column="83" selection-end-line="84" selection-end-column="83" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -512,14 +499,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/config.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="8" column="75" selection-start-line="8" selection-start-column="75" selection-end-line="8" selection-end-column="75" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/manifest.xml"> <entry file="file://$PROJECT_DIR$/manifest.xml">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="60"> <state relative-caret-position="60">
@ -568,23 +547,15 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/php/download.php"> <entry file="file://$PROJECT_DIR$/php/download.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="300"> <state relative-caret-position="615">
<caret line="41" column="9" selection-start-line="41" selection-start-column="9" selection-end-line="41" selection-end-column="9" /> <caret line="41" column="9" selection-start-line="41" selection-start-column="9" selection-end-line="41" selection-end-column="9" />
<folding /> <folding />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/php/helper.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" column="55" selection-start-line="2" selection-start-column="55" selection-end-line="2" selection-end-column="55" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/php/upload.php"> <entry file="file://$PROJECT_DIR$/php/upload.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="271"> <state relative-caret-position="330">
<caret line="22" column="3" selection-start-line="22" selection-start-column="3" selection-end-line="22" selection-end-column="3" /> <caret line="22" column="3" selection-start-line="22" selection-start-column="3" selection-end-line="22" selection-end-column="3" />
<folding> <folding>
<element signature="e#7#912#0#PHP" expanded="true" /> <element signature="e#7#912#0#PHP" expanded="true" />
@ -592,13 +563,39 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/config.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="75">
<caret line="5" column="38" selection-start-line="5" selection-start-column="8" selection-end-line="5" selection-end-column="38" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/php/helper.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
<caret line="1" column="0" selection-start-line="1" selection-start-column="0" selection-end-line="1" selection-end-column="0" />
<folding>
<element signature="e#7#912#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/php/plugin.contactimporter.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="420">
<caret line="28" column="31" selection-start-line="28" selection-start-column="31" selection-end-line="28" selection-end-column="31" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/php/module.contact.php"> <entry file="file://$PROJECT_DIR$/php/module.contact.php">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="234"> <state relative-caret-position="670">
<caret line="275" column="22" selection-start-line="275" selection-start-column="22" selection-end-line="275" selection-end-column="22" /> <caret line="784" column="47" selection-start-line="784" selection-start-column="47" selection-end-line="784" selection-end-column="47" />
<folding> <folding>
<element signature="e#6#919#0#PHP" expanded="true" /> <element signature="e#7#920#0#PHP" expanded="true" />
<element signature="e#1009#1042#0#PHP" expanded="true" /> <element signature="e#1010#1043#0#PHP" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* helper.php, Kopano Webapp contact to vcf im/exporter * helper.php, Kopano Webapp contact to vcf im/exporter
* *
@ -21,10 +22,8 @@
* *
*/ */
namespace contactimporter; namespace contactimporter;
class Helper class Helper
{ {
/** /**

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* module.contact.php, Kopano Webapp contact to vcf im/exporter * module.contact.php, Kopano Webapp contact to vcf im/exporter
* *
@ -47,6 +48,7 @@ class ContactModule extends Module
/** /**
* Executes all the actions in the $data variable. * Executes all the actions in the $data variable.
* Exception part is used for authentication errors also * Exception part is used for authentication errors also
*
* @return boolean true on success or false on failure. * @return boolean true on success or false on failure.
*/ */
public function execute() public function execute()
@ -98,6 +100,7 @@ class ContactModule extends Module
/** /**
* Add an attachment to the give contact * Add an attachment to the give contact
*
* @param $actionType * @param $actionType
* @param $actionData * @param $actionData
*/ */
@ -105,21 +108,21 @@ class ContactModule extends Module
{ {
// Get uploaded vcf path // Get uploaded vcf path
$vcffile = false; $vcfFile = false;
if (isset($actionData["vcf_filepath"])) { if (isset($actionData["vcf_filepath"])) {
$vcffile = $actionData["vcf_filepath"]; $vcfFile = $actionData["vcf_filepath"];
} }
// Get store id // Get store id
$storeid = false; $storeId = false;
if (isset($actionData["storeid"])) { if (isset($actionData["storeid"])) {
$storeid = $actionData["storeid"]; $storeId = $actionData["storeid"];
} }
// Get folder entryid // Get folder entryid
$folderid = false; $folderId = false;
if (isset($actionData["folderid"])) { if (isset($actionData["folderid"])) {
$folderid = $actionData["folderid"]; $folderId = $actionData["folderid"];
} }
// Get uids // Get uids
@ -130,27 +133,27 @@ class ContactModule extends Module
$response = array(); $response = array();
$error = false; $error = false;
$error_msg = ""; $errorMsg = "";
// parse the vcf file a last time... // parse the vcf file a last time...
$parser = null; $parser = null;
try { try {
$parser = VCardParser::parseFromFile($vcffile); $parser = VCardParser::parseFromFile($vcfFile);
} catch (Exception $e) { } catch (Exception $e) {
$error = true; $error = true;
$error_msg = $e->getMessage(); $errorMsg = $e->getMessage();
} }
$contacts = array(); $contacts = array();
if (!$error && iterator_count($parser) > 0) { if (!$error && iterator_count($parser) > 0) {
$contacts = $this->parseContactsToArray($parser); $contacts = $this->parseContactsToArray($parser);
$store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid)); $store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeId));
$folder = mapi_msgstore_openentry($store, hex2bin($folderid)); $folder = mapi_msgstore_openentry($store, hex2bin($folderId));
$importall = false; $importAll = false;
if (count($uids) == count($contacts)) { if (count($uids) == count($contacts)) {
$importall = true; $importAll = true;
} }
$propValuesMAPI = array(); $propValuesMAPI = array();
@ -160,7 +163,7 @@ class ContactModule extends Module
// iterate through all contacts and import them :) // iterate through all contacts and import them :)
foreach ($contacts as $contact) { foreach ($contacts as $contact) {
if (isset($contact["display_name"]) && ($importall || in_array($contact["internal_fields"]["contact_uid"], $uids))) { if (isset($contact["display_name"]) && ($importAll || in_array($contact["internal_fields"]["contact_uid"], $uids))) {
// parse the arraykeys // parse the arraykeys
// TODO: this is very slow... // TODO: this is very slow...
foreach ($contact as $key => $value) { foreach ($contact as $key => $value) {
@ -223,7 +226,7 @@ class ContactModule extends Module
} else { } else {
$response['status'] = false; $response['status'] = false;
$response['count'] = 0; $response['count'] = 0;
$response['message'] = $error ? $error_msg : dgettext("plugin_contactimporter", "VCF file is empty!"); $response['message'] = $error ? $errorMsg : dgettext("plugin_contactimporter", "VCF file is empty!");
} }
$this->addActionData($actionType, $response); $this->addActionData($actionType, $response);
@ -233,20 +236,20 @@ class ContactModule extends Module
/** /**
* Get a property from the array. * Get a property from the array.
* @param $props * @param $props
* @param $propname * @param $propName
* @return string * @return string
*/ */
private function getProp($props, $propname) private function getProp($props, $propName)
{ {
$p = $this->getProperties(); if (isset($props["props"][$propName])) {
if (isset($props["props"][$propname])) { return $props["props"][$propName];
return $props["props"][$propname];
} }
return ""; return "";
} }
/** /**
* Export selected contacts to vCard. * Export selected contacts to vCard.
*
* @param $actionType * @param $actionType
* @param $actionData * @param $actionData
* @return bool * @return bool
@ -254,9 +257,9 @@ class ContactModule extends Module
private function exportContacts($actionType, $actionData) private function exportContacts($actionType, $actionData)
{ {
// Get store id // Get store id
$storeid = false; $storeId = false;
if (isset($actionData["storeid"])) { if (isset($actionData["storeid"])) {
$storeid = $actionData["storeid"]; $storeId = $actionData["storeid"];
} }
// Get records // Get records
@ -280,13 +283,13 @@ class ContactModule extends Module
$file = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD . "vcf_" . $token . ".vcf"; $file = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD . "vcf_" . $token . ".vcf";
file_put_contents($file, ""); file_put_contents($file, "");
$store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid)); $store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeId));
if ($store) { if ($store) {
// load folder first // load folder first
if ($folder !== false) { if ($folder !== false) {
$mapifolder = mapi_msgstore_openentry($store, hex2bin($folder)); $mapiFolder = mapi_msgstore_openentry($store, hex2bin($folder));
$table = mapi_folder_getcontentstable($mapifolder); $table = mapi_folder_getcontentstable($mapiFolder);
$list = mapi_table_queryallrows($table, array(PR_ENTRYID)); $list = mapi_table_queryallrows($table, array(PR_ENTRYID));
foreach ($list as $item) { foreach ($list as $item) {
@ -295,7 +298,7 @@ class ContactModule extends Module
} }
for ($index = 0, $count = count($records); $index < $count; $index++) { for ($index = 0, $count = count($records); $index < $count; $index++) {
// define vcard // define vcard
$vcard = new VCard(); $vCard = new VCard();
$message = mapi_msgstore_openentry($store, hex2bin($records[$index])); $message = mapi_msgstore_openentry($store, hex2bin($records[$index]));
@ -305,118 +308,118 @@ class ContactModule extends Module
$messageProps = $GLOBALS['operations']->getMessageProps($store, $message, $properties, $plaintext); $messageProps = $GLOBALS['operations']->getMessageProps($store, $message, $properties, $plaintext);
// define variables // define variables
$firstname = $this->getProp($messageProps, "given_name"); $firstName = $this->getProp($messageProps, "given_name");
$lastname = $this->getProp($messageProps, "surname"); $lastName = $this->getProp($messageProps, "surname");
$additional = $this->getProp($messageProps, "middle_name"); $additional = $this->getProp($messageProps, "middle_name");
$prefix = $this->getProp($messageProps, "display_name_prefix"); $prefix = $this->getProp($messageProps, "display_name_prefix");
$suffix = ''; $suffix = '';
// add personal data // add personal data
$vcard->addName($lastname, $firstname, $additional, $prefix, $suffix); $vCard->addName($lastName, $firstName, $additional, $prefix, $suffix);
$company = $this->getProp($messageProps, "company_name"); $company = $this->getProp($messageProps, "company_name");
if (!empty($company)) { if (!empty($company)) {
$vcard->addCompany($company); $vCard->addCompany($company);
} }
$jobtitle = $this->getProp($messageProps, "title"); $jobTitle = $this->getProp($messageProps, "title");
if (!empty($jobtitle)) { if (!empty($jobTitle)) {
$vcard->addJobtitle($jobtitle); $vCard->addJobtitle($jobTitle);
} }
// MAIL // MAIL
$mail = $this->getProp($messageProps, "email_address_1"); $mail = $this->getProp($messageProps, "email_address_1");
if (!empty($mail)) { if (!empty($mail)) {
$vcard->addEmail($mail); $vCard->addEmail($mail);
} }
$mail = $this->getProp($messageProps, "email_address_2"); $mail = $this->getProp($messageProps, "email_address_2");
if (!empty($mail)) { if (!empty($mail)) {
$vcard->addEmail($mail); $vCard->addEmail($mail);
} }
$mail = $this->getProp($messageProps, "email_address_3"); $mail = $this->getProp($messageProps, "email_address_3");
if (!empty($mail)) { if (!empty($mail)) {
$vcard->addEmail($mail); $vCard->addEmail($mail);
} }
// PHONE // PHONE
$wphone = $this->getProp($messageProps, "business_telephone_number"); $wPhone = $this->getProp($messageProps, "business_telephone_number");
if (!empty($wphone)) { if (!empty($wPhone)) {
$vcard->addPhoneNumber($wphone, 'WORK'); $vCard->addPhoneNumber($wPhone, 'WORK');
} }
$wphone = $this->getProp($messageProps, "home_telephone_number"); $wPhone = $this->getProp($messageProps, "home_telephone_number");
if (!empty($wphone)) { if (!empty($wPhone)) {
$vcard->addPhoneNumber($wphone, 'HOME'); $vCard->addPhoneNumber($wPhone, 'HOME');
} }
$wphone = $this->getProp($messageProps, "cellular_telephone_number"); $wPhone = $this->getProp($messageProps, "cellular_telephone_number");
if (!empty($wphone)) { if (!empty($wPhone)) {
$vcard->addPhoneNumber($wphone, 'CELL'); $vCard->addPhoneNumber($wPhone, 'CELL');
} }
$wphone = $this->getProp($messageProps, "business_fax_number"); $wPhone = $this->getProp($messageProps, "business_fax_number");
if (!empty($wphone)) { if (!empty($wPhone)) {
$vcard->addPhoneNumber($wphone, 'FAX'); $vCard->addPhoneNumber($wPhone, 'FAX');
} }
$wphone = $this->getProp($messageProps, "pager_telephone_number"); $wPhone = $this->getProp($messageProps, "pager_telephone_number");
if (!empty($wphone)) { if (!empty($wPhone)) {
$vcard->addPhoneNumber($wphone, 'PAGER'); $vCard->addPhoneNumber($wPhone, 'PAGER');
} }
$wphone = $this->getProp($messageProps, "car_telephone_number"); $wPhone = $this->getProp($messageProps, "car_telephone_number");
if (!empty($wphone)) { if (!empty($wPhone)) {
$vcard->addPhoneNumber($wphone, 'CAR'); $vCard->addPhoneNumber($wPhone, 'CAR');
} }
// ADDRESS // ADDRESS
$addr = $this->getProp($messageProps, "business_address"); $address = $this->getProp($messageProps, "business_address");
if (!empty($addr)) { if (!empty($address)) {
$vcard->addAddress(null, null, $this->getProp($messageProps, "business_address_street"), $this->getProp($messageProps, "business_address_city"), $this->getProp($messageProps, "business_address_state"), $this->getProp($messageProps, "business_address_postal_code"), $this->getProp($messageProps, "business_address_country"), "WORK"); $vCard->addAddress(null, null, $this->getProp($messageProps, "business_address_street"), $this->getProp($messageProps, "business_address_city"), $this->getProp($messageProps, "business_address_state"), $this->getProp($messageProps, "business_address_postal_code"), $this->getProp($messageProps, "business_address_country"), "WORK");
} }
$addr = $this->getProp($messageProps, "home_address"); $address = $this->getProp($messageProps, "home_address");
if (!empty($addr)) { if (!empty($address)) {
$vcard->addAddress(null, null, $this->getProp($messageProps, "home_address_street"), $this->getProp($messageProps, "home_address_city"), $this->getProp($messageProps, "home_address_state"), $this->getProp($messageProps, "home_address_postal_code"), $this->getProp($messageProps, "home_address_country"), "HOME"); $vCard->addAddress(null, null, $this->getProp($messageProps, "home_address_street"), $this->getProp($messageProps, "home_address_city"), $this->getProp($messageProps, "home_address_state"), $this->getProp($messageProps, "home_address_postal_code"), $this->getProp($messageProps, "home_address_country"), "HOME");
} }
$addr = $this->getProp($messageProps, "other_address"); $address = $this->getProp($messageProps, "other_address");
if (!empty($addr)) { if (!empty($address)) {
$vcard->addAddress(null, null, $this->getProp($messageProps, "other_address_street"), $this->getProp($messageProps, "other_address_city"), $this->getProp($messageProps, "other_address_state"), $this->getProp($messageProps, "other_address_postal_code"), $this->getProp($messageProps, "other_address_country"), "OTHER"); $vCard->addAddress(null, null, $this->getProp($messageProps, "other_address_street"), $this->getProp($messageProps, "other_address_city"), $this->getProp($messageProps, "other_address_state"), $this->getProp($messageProps, "other_address_postal_code"), $this->getProp($messageProps, "other_address_country"), "OTHER");
} }
// MISC // MISC
$url = $this->getProp($messageProps, "webpage"); $url = $this->getProp($messageProps, "webpage");
if (!empty($url)) { if (!empty($url)) {
$vcard->addURL($url); $vCard->addURL($url);
} }
$bday = $this->getProp($messageProps, "birthday"); $birthday = $this->getProp($messageProps, "birthday");
if (!empty($bday)) { if (!empty($birthday)) {
$vcard->addBirthday(date("Y-m-d", $bday)); $vCard->addBirthday(date("Y-m-d", $birthday));
} }
$notes = $this->getProp($messageProps, "body"); $notes = $this->getProp($messageProps, "body");
if (!empty($notes)) { if (!empty($notes)) {
$vcard->addNote($notes); $vCard->addNote($notes);
} }
$haspicture = $this->getProp($messageProps, "has_picture"); $hasPicture = $this->getProp($messageProps, "has_picture");
if (!empty($haspicture) && $haspicture === true) { if (!empty($hasPicture) && $hasPicture === true) {
$attachnum = -1; $attachNum = -1;
if (isset($messageProps["attachments"]) && isset($messageProps["attachments"]["item"])) { if (isset($messageProps["attachments"]) && isset($messageProps["attachments"]["item"])) {
foreach ($messageProps["attachments"]["item"] as $attachment) { foreach ($messageProps["attachments"]["item"] as $attachment) {
if ($attachment["props"]["attachment_contactphoto"] == true) { if ($attachment["props"]["attachment_contactphoto"] == true) {
$attachnum = $attachment["props"]["attach_num"]; $attachNum = $attachment["props"]["attach_num"];
break; break;
} }
} }
} }
if ($attachnum >= 0) { if ($attachNum >= 0) {
$attachment = $this->getAttachmentByAttachNum($message, $attachnum); // get first attachment only $attachment = $this->getAttachmentByAttachNum($message, $attachNum); // get first attachment only
$phototoken = Helper::randomstring(16); $photoToken = Helper::randomstring(16);
$tmpphoto = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD . "photo_" . $phototoken . ".jpg"; $tmpPhoto = PLUGIN_CONTACTIMPORTER_TMP_UPLOAD . "photo_" . $photoToken . ".jpg";
$this->storeSavedAttachment($tmpphoto, $attachment); $this->storeSavedAttachment($tmpPhoto, $attachment);
$vcard->addPhoto($tmpphoto, true); $vCard->addPhoto($tmpPhoto, true);
unlink($tmpphoto); unlink($tmpPhoto);
} }
} }
// write combined vcf // write combined vcf
file_put_contents($file, file_get_contents($file) . $vcard->getOutput()); file_put_contents($file, file_get_contents($file) . $vCard->getOutput());
} }
} else { } else {
return false; return false;
@ -434,11 +437,14 @@ class ContactModule extends Module
$this->addActionData($actionType, $response); $this->addActionData($actionType, $response);
$GLOBALS["bus"]->addData($this->getResponseData()); $GLOBALS["bus"]->addData($this->getResponseData());
return true;
} }
/** /**
* Returns attachment based on specified attachNum, additionally it will also get embedded message * Returns attachment based on specified attachNum, additionally it will also get embedded message
* if we want to get the inline image attachment. * if we want to get the inline image attachment.
*
* @param $message * @param $message
* @param array $attachNum * @param array $attachNum
* @return MAPIAttach embedded message attachment or attachment that is requested * @return MAPIAttach embedded message attachment or attachment that is requested
@ -454,10 +460,11 @@ class ContactModule extends Module
/** /**
* Function will open passed attachment and generate response for that attachment to send it to client. * Function will open passed attachment and generate response for that attachment to send it to client.
* This should only be used to download attachment that is already saved in MAPIMessage. * This should only be used to download attachment that is already saved in MAPIMessage.
*
* @param MAPIAttach $attachment attachment which will be dumped to client side * @param MAPIAttach $attachment attachment which will be dumped to client side
* @return Response response to sent to client including attachment data * @return Response response to sent to client including attachment data
*/ */
private function storeSavedAttachment($temppath, $attachment) private function storeSavedAttachment($tempPath, $attachment)
{ {
// Check if the attachment is opened // Check if the attachment is opened
if ($attachment) { if ($attachment) {
@ -471,12 +478,13 @@ class ContactModule extends Module
$body .= mapi_stream_read($stream, BLOCK_SIZE); $body .= mapi_stream_read($stream, BLOCK_SIZE);
} }
file_put_contents($temppath, $body); file_put_contents($tempPath, $body);
} }
} }
/** /**
* Replace String Property Tags * Replace String Property Tags
*
* @param $store * @param $store
* @param $properties * @param $properties
* @return array * @return array
@ -544,7 +552,7 @@ class ContactModule extends Module
/** /**
* A simple Property map initialization * A simple Property map initialization
* *
* @return [array] the propertyarray * @return array the propertyarray
*/ */
private function getProperties() private function getProperties()
{ {
@ -689,7 +697,7 @@ class ContactModule extends Module
private function loadContacts($actionType, $actionData) private function loadContacts($actionType, $actionData)
{ {
$error = false; $error = false;
$error_msg = ""; $errorMsg = "";
if (is_readable($actionData["vcf_filepath"])) { if (is_readable($actionData["vcf_filepath"])) {
$parser = null; $parser = null;
@ -698,11 +706,11 @@ class ContactModule extends Module
$parser = VCardParser::parseFromFile($actionData["vcf_filepath"]); $parser = VCardParser::parseFromFile($actionData["vcf_filepath"]);
} catch (Exception $e) { } catch (Exception $e) {
$error = true; $error = true;
$error_msg = $e->getMessage(); $errorMsg = $e->getMessage();
} }
if ($error) { if ($error) {
$response['status'] = false; $response['status'] = false;
$response['message'] = $error_msg; $response['message'] = $errorMsg;
} else { } else {
if (iterator_count($parser) == 0) { if (iterator_count($parser) == 0) {
$response['status'] = false; $response['status'] = false;
@ -731,8 +739,8 @@ class ContactModule extends Module
/** /**
* Create a array with contacts * Create a array with contacts
* *
* @param contacts vcard or csv contacts * @param VCard $contacts or csv contacts
* @param csv optional, true if contacts are csv contacts * @param bool|optional $csv true if contacts are csv contacts
* @return array parsed contacts * @return array parsed contacts
* @private * @private
*/ */
@ -799,13 +807,13 @@ class ContactModule extends Module
} }
} }
if (isset($vCard->email) && count($vCard->email) > 0) { if (isset($vCard->email) && count($vCard->email) > 0) {
$emailcount = 0; $emailCount = 0;
$properties["address_book_long"] = 0; $properties["address_book_long"] = 0;
foreach ($vCard->email as $type => $email) { foreach ($vCard->email as $type => $email) {
foreach ($email as $mail) { foreach ($email as $mail) {
$fileas = $mail; $fileAs = $mail;
if (isset($properties["fileas"]) && !empty($properties["fileas"])) { if (isset($properties["fileas"]) && !empty($properties["fileas"])) {
$fileas = $properties["fileas"]; // set to real name $fileAs = $properties["fileas"]; // set to real name
} }
// we only have storage for 3 mail addresses! // we only have storage for 3 mail addresses!
@ -822,24 +830,24 @@ class ContactModule extends Module
* address_book_long stores sum of the flags * address_book_long stores sum of the flags
* these both properties should be in sync always * these both properties should be in sync always
*/ */
switch ($emailcount) { switch ($emailCount) {
case 0: case 0:
$properties["email_address_1"] = $mail; $properties["email_address_1"] = $mail;
$properties["email_address_display_name_1"] = $fileas . " (" . $mail . ")"; $properties["email_address_display_name_1"] = $fileAs . " (" . $mail . ")";
$properties["email_address_display_name_email_1"] = $mail; $properties["email_address_display_name_email_1"] = $mail;
$properties["address_book_mv"][] = 0; // this is needed for adding the contact to the email address book, 0 = email 1 $properties["address_book_mv"][] = 0; // this is needed for adding the contact to the email address book, 0 = email 1
$properties["address_book_long"] += 1; // this specifies the number of elements in address_book_mv $properties["address_book_long"] += 1; // this specifies the number of elements in address_book_mv
break; break;
case 1: case 1:
$properties["email_address_2"] = $mail; $properties["email_address_2"] = $mail;
$properties["email_address_display_name_2"] = $fileas . " (" . $mail . ")"; $properties["email_address_display_name_2"] = $fileAs . " (" . $mail . ")";
$properties["email_address_display_name_email_2"] = $mail; $properties["email_address_display_name_email_2"] = $mail;
$properties["address_book_mv"][] = 1; // this is needed for adding the contact to the email address book, 1 = email 2 $properties["address_book_mv"][] = 1; // this is needed for adding the contact to the email address book, 1 = email 2
$properties["address_book_long"] += 2; // this specifies the number of elements in address_book_mv $properties["address_book_long"] += 2; // this specifies the number of elements in address_book_mv
break; break;
case 2: case 2:
$properties["email_address_3"] = $mail; $properties["email_address_3"] = $mail;
$properties["email_address_display_name_3"] = $fileas . " (" . $mail . ")"; $properties["email_address_display_name_3"] = $fileAs . " (" . $mail . ")";
$properties["email_address_display_name_email_3"] = $mail; $properties["email_address_display_name_email_3"] = $mail;
$properties["address_book_mv"][] = 2; // this is needed for adding the contact to the email address book, 2 = email 3 $properties["address_book_mv"][] = 2; // this is needed for adding the contact to the email address book, 2 = email 3
$properties["address_book_long"] += 4; // this specifies the number of elements in address_book_mv $properties["address_book_long"] += 4; // this specifies the number of elements in address_book_mv
@ -847,7 +855,7 @@ class ContactModule extends Module
default: default:
break; break;
} }
$emailcount++; $emailCount++;
} }
} }
} }
@ -956,7 +964,7 @@ class ContactModule extends Module
* @param city * @param city
* @param state * @param state
* @param country * @param country
* @return string the concatinated address string * @return string the concatenated address string
* @private * @private
*/ */
private function buildAddressString($street, $zip, $city, $state, $country) private function buildAddressString($street, $zip, $city, $state, $country)
@ -990,6 +998,7 @@ class ContactModule extends Module
/** /**
* Store the file to a temporary directory * Store the file to a temporary directory
*
* @param $actionType * @param $actionType
* @param $actionData * @param $actionData
* @private * @private
@ -997,15 +1006,15 @@ class ContactModule extends Module
private function getAttachmentPath($actionType, $actionData) private function getAttachmentPath($actionType, $actionData)
{ {
// Get store id // Get store id
$storeid = false; $storeId = false;
if (isset($actionData["store"])) { if (isset($actionData["store"])) {
$storeid = $actionData["store"]; $storeId = $actionData["store"];
} }
// Get message entryid // Get message entryid
$entryid = false; $entryId = false;
if (isset($actionData["entryid"])) { if (isset($actionData["entryid"])) {
$entryid = $actionData["entryid"]; $entryId = $actionData["entryid"];
} }
// Check which type isset // Check which type isset
@ -1018,13 +1027,13 @@ class ContactModule extends Module
} }
// Check if storeid and entryid isset // Check if storeid and entryid isset
if ($storeid && $entryid) { if ($storeId && $entryId) {
// Open the store // Open the store
$store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeid)); $store = $GLOBALS["mapisession"]->openMessageStore(hex2bin($storeId));
if ($store) { if ($store) {
// Open the message // Open the message
$message = mapi_msgstore_openentry($store, hex2bin($entryid)); $message = mapi_msgstore_openentry($store, hex2bin($entryId));
if ($message) { if ($message) {
$attachment = false; $attachment = false;
@ -1034,10 +1043,10 @@ class ContactModule extends Module
// Loop through the attachNums, message in message in message ... // Loop through the attachNums, message in message in message ...
for ($i = 0; $i < (count($attachNum) - 1); $i++) { for ($i = 0; $i < (count($attachNum) - 1); $i++) {
// Open the attachment // Open the attachment
$tempattach = mapi_message_openattach($message, (int)$attachNum[$i]); $tempAttach = mapi_message_openattach($message, (int)$attachNum[$i]);
if ($tempattach) { if ($tempAttach) {
// Open the object in the attachment // Open the object in the attachment
$message = mapi_attach_openobj($tempattach); $message = mapi_attach_openobj($tempAttach);
} }
} }
@ -1081,7 +1090,7 @@ class ContactModule extends Module
$ext_found = false; $ext_found = false;
while (!feof($fh) && !$ext_found) { while (!feof($fh) && !$ext_found) {
$line = fgets($fh); $line = fgets($fh);
preg_match("/(\.[a-z0-9]+)[ \t]+([^ \t\n\r]*)/i", $line, $result); preg_match('/(\.[a-z0-9]+)[ \t]+([^ \t\n\r]*)/i', $line, $result);
if ($extension == $result[1]) { if ($extension == $result[1]) {
$ext_found = true; $ext_found = true;
$contentType = $result[2]; $contentType = $result[2];
@ -1093,25 +1102,26 @@ class ContactModule extends Module
} }
$tmpname = tempnam(TMP_PATH, stripslashes($filename)); $tmpName = tempnam(TMP_PATH, stripslashes($filename));
// Open a stream to get the attachment data // Open a stream to get the attachment data
$stream = mapi_openpropertytostream($attachment, PR_ATTACH_DATA_BIN); $stream = mapi_openpropertytostream($attachment, PR_ATTACH_DATA_BIN);
$stat = mapi_stream_stat($stream); $stat = mapi_stream_stat($stream);
// File length = $stat["cb"] // File length = $stat["cb"]
$fhandle = fopen($tmpname, 'w'); $fHandle = fopen($tmpName, 'w');
$buffer = null; $buffer = null;
for ($i = 0; $i < $stat["cb"]; $i += BLOCK_SIZE) { for ($i = 0; $i < $stat["cb"]; $i += BLOCK_SIZE) {
// Write stream // Write stream
$buffer = mapi_stream_read($stream, BLOCK_SIZE); $buffer = mapi_stream_read($stream, BLOCK_SIZE);
fwrite($fhandle, $buffer, strlen($buffer)); fwrite($fHandle, $buffer, strlen($buffer));
} }
fclose($fhandle); fclose($fHandle);
$response = array(); $response = array();
$response['tmpname'] = $tmpname; $response['tmpname'] = $tmpName;
$response['filename'] = $filename; $response['filename'] = $filename;
$response['contenttype'] = $contentType;
$response['status'] = true; $response['status'] = true;
$this->addActionData($actionType, $response); $this->addActionData($actionType, $response);
$GLOBALS["bus"]->addData($this->getResponseData()); $GLOBALS["bus"]->addData($this->getResponseData());
@ -1133,6 +1143,7 @@ class ContactModule extends Module
/** /**
* Check if string starts with other string. * Check if string starts with other string.
*
* @param $haystack * @param $haystack
* @param $needle * @param $needle
* @return bool * @return bool

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* plugin.contactimporter.php, Kopano Webapp contact to vcf im/exporter * plugin.contactimporter.php, Kopano Webapp contact to vcf im/exporter
* *
@ -20,7 +21,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
*/ */
require_once __DIR__ . "/download.php"; require_once(__DIR__ . "/download.php");
/** /**
* contactimporter Plugin * contactimporter Plugin