mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 00:47:04 +03:00
Get account local sqlite AddressBook working (but still inactive)
This commit is contained in:
parent
8d6eb96c8f
commit
e364b6286f
3 changed files with 44 additions and 26 deletions
|
|
@ -133,12 +133,16 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
||||||
$oParams->iLimit = 999; // Is the max
|
$oParams->iLimit = 999; // Is the max
|
||||||
$oMessageList = $this->MailClient()->MessageList($oParams);
|
$oMessageList = $this->MailClient()->MessageList($oParams);
|
||||||
foreach ($oMessageList as $oMessage) {
|
foreach ($oMessageList as $oMessage) {
|
||||||
if ($rCsv) {
|
try {
|
||||||
$oContact = $this->MessageAsContact($oMessage);
|
if ($rCsv) {
|
||||||
\RainLoop\Providers\AddressBook\Utils::VCardToCsv($rCsv, $oContact, $bCsvHeader);
|
$oContact = $this->MessageAsContact($oMessage);
|
||||||
$bCsvHeader = false;
|
\RainLoop\Providers\AddressBook\Utils::VCardToCsv($rCsv, $oContact->vCard, $bCsvHeader);
|
||||||
} else if ($xCard = $this->fetchXCardFromMessage($oMessage)) {
|
$bCsvHeader = false;
|
||||||
echo $xCard->serialize();
|
} else if ($xCard = $this->fetchXCardFromMessage($oMessage)) {
|
||||||
|
echo $xCard->serialize();
|
||||||
|
}
|
||||||
|
} catch (\Throwable $oExc) {
|
||||||
|
$this->oLogger && $this->oLogger->WriteException($oExc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,11 +52,17 @@ class PdoAddressBook
|
||||||
$sDsn = 'sqlite:' . APP_PRIVATE_DATA . 'AddressBook.sqlite';
|
$sDsn = 'sqlite:' . APP_PRIVATE_DATA . 'AddressBook.sqlite';
|
||||||
/*
|
/*
|
||||||
// TODO: use local db?
|
// TODO: use local db?
|
||||||
$homedir = \RainLoop\Api::Actions()->StorageProvider()->GenerateFilePath(
|
$oAccount = \RainLoop\Api::Actions()->getMainAccountFromToken(false);
|
||||||
$oAccount,
|
if ($oAccount) {
|
||||||
\RainLoop\Providers\Storage\Enumerations\StorageType::ROOT
|
$homedir = \RainLoop\Api::Actions()->StorageProvider()->GenerateFilePath(
|
||||||
);
|
$oAccount,
|
||||||
$sDsn = 'sqlite:' . $homedir . '/AddressBook.sqlite';
|
\RainLoop\Providers\Storage\Enumerations\StorageType::ROOT
|
||||||
|
);
|
||||||
|
if (!\is_file($homedir . 'AddressBook.sqlite') && \is_file(APP_PRIVATE_DATA . '/AddressBook.sqlite')) {
|
||||||
|
\copy(APP_PRIVATE_DATA . '/AddressBook.sqlite', $homedir . 'AddressBook.sqlite');
|
||||||
|
}
|
||||||
|
$sDsn = 'sqlite:' . $homedir . 'AddressBook.sqlite';
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
$sDsn = \trim($oConfig->Get('contacts', 'pdo_dsn', ''));
|
$sDsn = \trim($oConfig->Get('contacts', 'pdo_dsn', ''));
|
||||||
|
|
@ -308,6 +314,7 @@ class PdoAddressBook
|
||||||
public function Export(string $sType = 'vcf') : bool
|
public function Export(string $sType = 'vcf') : bool
|
||||||
{
|
{
|
||||||
if (1 > $this->iUserID) {
|
if (1 > $this->iUserID) {
|
||||||
|
\SnappyMail\Log::warning('PdoAddressBook', 'Export() invalid $iUserID');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,16 +324,21 @@ class PdoAddressBook
|
||||||
$aDatabaseSyncData = $this->prepareDatabaseSyncData();
|
$aDatabaseSyncData = $this->prepareDatabaseSyncData();
|
||||||
if (\count($aDatabaseSyncData)) {
|
if (\count($aDatabaseSyncData)) {
|
||||||
foreach ($aDatabaseSyncData as $mData) {
|
foreach ($aDatabaseSyncData as $mData) {
|
||||||
if ($mData && isset($mData['id_contact'], $mData['deleted']) && !$mData['deleted']) {
|
try {
|
||||||
$oContact = $this->GetContactByID($mData['id_contact']);
|
// if ($mData && isset($mData['id_contact'], $mData['deleted']) && !$mData['deleted']) {
|
||||||
if ($oContact) {
|
if ($mData && !empty($mData['id_contact'])) {
|
||||||
if ($rCsv) {
|
$oContact = $this->GetContactByID($mData['id_contact']);
|
||||||
Utils::VCardToCsv($rCsv, $oContact, $bCsvHeader);
|
if ($oContact) {
|
||||||
$bCsvHeader = false;
|
if ($rCsv) {
|
||||||
} else {
|
Utils::VCardToCsv($rCsv, $oContact->vCard, $bCsvHeader);
|
||||||
echo $oContact->vCard->serialize();
|
$bCsvHeader = false;
|
||||||
|
} else {
|
||||||
|
echo $oContact->vCard->serialize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (\Throwable $oExc) {
|
||||||
|
$this->oLogger && $this->oLogger->WriteException($oExc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -337,6 +349,7 @@ class PdoAddressBook
|
||||||
public function ContactSave(Contact $oContact) : bool
|
public function ContactSave(Contact $oContact) : bool
|
||||||
{
|
{
|
||||||
if (1 > $this->iUserID) {
|
if (1 > $this->iUserID) {
|
||||||
|
\SnappyMail\Log::warning('PdoAddressBook', 'ContactSave() invalid $iUserID');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -436,6 +449,7 @@ class PdoAddressBook
|
||||||
public function DeleteContacts(array $aContactIds) : bool
|
public function DeleteContacts(array $aContactIds) : bool
|
||||||
{
|
{
|
||||||
if (1 > $this->iUserID) {
|
if (1 > $this->iUserID) {
|
||||||
|
\SnappyMail\Log::warning('PdoAddressBook', 'DeleteContacts() invalid $iUserID');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -744,7 +758,7 @@ class PdoAddressBook
|
||||||
p.prop_value as jcard
|
p.prop_value as jcard
|
||||||
FROM rainloop_ab_contacts AS c
|
FROM rainloop_ab_contacts AS c
|
||||||
LEFT JOIN rainloop_ab_properties AS p ON (p.id_contact = c.id_contact AND p.prop_type = :prop_type)
|
LEFT JOIN rainloop_ab_properties AS p ON (p.id_contact = c.id_contact AND p.prop_type = :prop_type)
|
||||||
WHERE c.deleted = 0 AND c.id_user = :id_user';
|
WHERE c.id_user = :id_user AND c.deleted = 0';
|
||||||
|
|
||||||
$aParams = array(
|
$aParams = array(
|
||||||
':id_user' => array($this->iUserID, \PDO::PARAM_INT),
|
':id_user' => array($this->iUserID, \PDO::PARAM_INT),
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace RainLoop\Providers\AddressBook;
|
namespace RainLoop\Providers\AddressBook;
|
||||||
|
|
||||||
|
use Sabre\VObject\Component\VCard;
|
||||||
|
|
||||||
class Utils
|
class Utils
|
||||||
{
|
{
|
||||||
private static $aMap = array(
|
private static $aMap = array(
|
||||||
|
|
@ -98,7 +100,7 @@ class Utils
|
||||||
foreach ($aHeaders as $iIndex => $sItemName) {
|
foreach ($aHeaders as $iIndex => $sItemName) {
|
||||||
$sItemName = \MailSo\Base\Utils::Utf8Clear($sItemName);
|
$sItemName = \MailSo\Base\Utils::Utf8Clear($sItemName);
|
||||||
$sItemName = \strtoupper(\trim(\preg_replace('/[\s\-]+/', '', $sItemName)));
|
$sItemName = \strtoupper(\trim(\preg_replace('/[\s\-]+/', '', $sItemName)));
|
||||||
if (!\array_key_exists($sItemName, \Sabre\VObject\Component\VCard::$propertyMap)) {
|
if (!\array_key_exists($sItemName, VCard::$propertyMap)) {
|
||||||
$sItemName = \strtolower($sItemName);
|
$sItemName = \strtolower($sItemName);
|
||||||
$sItemName = isset(static::$aMap[$sItemName]) ? static::$aMap[$sItemName] : null;
|
$sItemName = isset(static::$aMap[$sItemName]) ? static::$aMap[$sItemName] : null;
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +110,7 @@ class Utils
|
||||||
while (false !== ($mRow = \fgetcsv($rFile, 5000, $sDelimiter, '"'))) {
|
while (false !== ($mRow = \fgetcsv($rFile, 5000, $sDelimiter, '"'))) {
|
||||||
\MailSo\Base\Utils::ResetTimeLimit();
|
\MailSo\Base\Utils::ResetTimeLimit();
|
||||||
$iCount = 0;
|
$iCount = 0;
|
||||||
$oVCard = new \Sabre\VObject\Component\VCard;
|
$oVCard = new VCard;
|
||||||
$aName = ['','','','',''];
|
$aName = ['','','','',''];
|
||||||
foreach ($mRow as $iIndex => $sItemValue) {
|
foreach ($mRow as $iIndex => $sItemValue) {
|
||||||
$sItemName = $aHeaders[$iIndex];
|
$sItemName = $aHeaders[$iIndex];
|
||||||
|
|
@ -138,7 +140,7 @@ class Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function VCardToCsv($stream, Classes\Contact $oContact, bool $bWithHeader = false)/* : int|false*/
|
public static function VCardToCsv($stream, VCard $oVCard, bool $bWithHeader = false)/* : int|false*/
|
||||||
{
|
{
|
||||||
$aData = array();
|
$aData = array();
|
||||||
if ($bWithHeader) {
|
if ($bWithHeader) {
|
||||||
|
|
@ -153,8 +155,6 @@ class Utils
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$oVCard = $oContact->vCard;
|
|
||||||
|
|
||||||
$aName = isset($oVCard->N) ? $oVCard->N->getParts() : ['','','','',''];
|
$aName = isset($oVCard->N) ? $oVCard->N->getParts() : ['','','','',''];
|
||||||
|
|
||||||
$adrHome = $oVCard->getByType('ADR', 'HOME');
|
$adrHome = $oVCard->getByType('ADR', 'HOME');
|
||||||
|
|
@ -203,7 +203,7 @@ class Utils
|
||||||
$oVCardSplitter = new \Sabre\VObject\Splitter\VCard($rFile);
|
$oVCardSplitter = new \Sabre\VObject\Splitter\VCard($rFile);
|
||||||
if ($oVCardSplitter) {
|
if ($oVCardSplitter) {
|
||||||
while ($oVCard = $oVCardSplitter->getNext()) {
|
while ($oVCard = $oVCardSplitter->getNext()) {
|
||||||
if ($oVCard instanceof \Sabre\VObject\Component\VCard) {
|
if ($oVCard instanceof VCard) {
|
||||||
\MailSo\Base\Utils::ResetTimeLimit();
|
\MailSo\Base\Utils::ResetTimeLimit();
|
||||||
$oContact = new Classes\Contact();
|
$oContact = new Classes\Contact();
|
||||||
$oContact->setVCard($oVCard);
|
$oContact->setVCard($oVCard);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue