mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-30 17:04:20 +08: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
|
||||
$oMessageList = $this->MailClient()->MessageList($oParams);
|
||||
foreach ($oMessageList as $oMessage) {
|
||||
if ($rCsv) {
|
||||
$oContact = $this->MessageAsContact($oMessage);
|
||||
\RainLoop\Providers\AddressBook\Utils::VCardToCsv($rCsv, $oContact, $bCsvHeader);
|
||||
$bCsvHeader = false;
|
||||
} else if ($xCard = $this->fetchXCardFromMessage($oMessage)) {
|
||||
echo $xCard->serialize();
|
||||
try {
|
||||
if ($rCsv) {
|
||||
$oContact = $this->MessageAsContact($oMessage);
|
||||
\RainLoop\Providers\AddressBook\Utils::VCardToCsv($rCsv, $oContact->vCard, $bCsvHeader);
|
||||
$bCsvHeader = false;
|
||||
} 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';
|
||||
/*
|
||||
// TODO: use local db?
|
||||
$homedir = \RainLoop\Api::Actions()->StorageProvider()->GenerateFilePath(
|
||||
$oAccount,
|
||||
\RainLoop\Providers\Storage\Enumerations\StorageType::ROOT
|
||||
);
|
||||
$sDsn = 'sqlite:' . $homedir . '/AddressBook.sqlite';
|
||||
$oAccount = \RainLoop\Api::Actions()->getMainAccountFromToken(false);
|
||||
if ($oAccount) {
|
||||
$homedir = \RainLoop\Api::Actions()->StorageProvider()->GenerateFilePath(
|
||||
$oAccount,
|
||||
\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 {
|
||||
$sDsn = \trim($oConfig->Get('contacts', 'pdo_dsn', ''));
|
||||
|
@ -308,6 +314,7 @@ class PdoAddressBook
|
|||
public function Export(string $sType = 'vcf') : bool
|
||||
{
|
||||
if (1 > $this->iUserID) {
|
||||
\SnappyMail\Log::warning('PdoAddressBook', 'Export() invalid $iUserID');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -317,16 +324,21 @@ class PdoAddressBook
|
|||
$aDatabaseSyncData = $this->prepareDatabaseSyncData();
|
||||
if (\count($aDatabaseSyncData)) {
|
||||
foreach ($aDatabaseSyncData as $mData) {
|
||||
if ($mData && isset($mData['id_contact'], $mData['deleted']) && !$mData['deleted']) {
|
||||
$oContact = $this->GetContactByID($mData['id_contact']);
|
||||
if ($oContact) {
|
||||
if ($rCsv) {
|
||||
Utils::VCardToCsv($rCsv, $oContact, $bCsvHeader);
|
||||
$bCsvHeader = false;
|
||||
} else {
|
||||
echo $oContact->vCard->serialize();
|
||||
try {
|
||||
// if ($mData && isset($mData['id_contact'], $mData['deleted']) && !$mData['deleted']) {
|
||||
if ($mData && !empty($mData['id_contact'])) {
|
||||
$oContact = $this->GetContactByID($mData['id_contact']);
|
||||
if ($oContact) {
|
||||
if ($rCsv) {
|
||||
Utils::VCardToCsv($rCsv, $oContact->vCard, $bCsvHeader);
|
||||
$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
|
||||
{
|
||||
if (1 > $this->iUserID) {
|
||||
\SnappyMail\Log::warning('PdoAddressBook', 'ContactSave() invalid $iUserID');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -436,6 +449,7 @@ class PdoAddressBook
|
|||
public function DeleteContacts(array $aContactIds) : bool
|
||||
{
|
||||
if (1 > $this->iUserID) {
|
||||
\SnappyMail\Log::warning('PdoAddressBook', 'DeleteContacts() invalid $iUserID');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -744,7 +758,7 @@ class PdoAddressBook
|
|||
p.prop_value as jcard
|
||||
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)
|
||||
WHERE c.deleted = 0 AND c.id_user = :id_user';
|
||||
WHERE c.id_user = :id_user AND c.deleted = 0';
|
||||
|
||||
$aParams = array(
|
||||
':id_user' => array($this->iUserID, \PDO::PARAM_INT),
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace RainLoop\Providers\AddressBook;
|
||||
|
||||
use Sabre\VObject\Component\VCard;
|
||||
|
||||
class Utils
|
||||
{
|
||||
private static $aMap = array(
|
||||
|
@ -98,7 +100,7 @@ class Utils
|
|||
foreach ($aHeaders as $iIndex => $sItemName) {
|
||||
$sItemName = \MailSo\Base\Utils::Utf8Clear($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 = isset(static::$aMap[$sItemName]) ? static::$aMap[$sItemName] : null;
|
||||
}
|
||||
|
@ -108,7 +110,7 @@ class Utils
|
|||
while (false !== ($mRow = \fgetcsv($rFile, 5000, $sDelimiter, '"'))) {
|
||||
\MailSo\Base\Utils::ResetTimeLimit();
|
||||
$iCount = 0;
|
||||
$oVCard = new \Sabre\VObject\Component\VCard;
|
||||
$oVCard = new VCard;
|
||||
$aName = ['','','','',''];
|
||||
foreach ($mRow as $iIndex => $sItemValue) {
|
||||
$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();
|
||||
if ($bWithHeader) {
|
||||
|
@ -153,8 +155,6 @@ class Utils
|
|||
));
|
||||
}
|
||||
|
||||
$oVCard = $oContact->vCard;
|
||||
|
||||
$aName = isset($oVCard->N) ? $oVCard->N->getParts() : ['','','','',''];
|
||||
|
||||
$adrHome = $oVCard->getByType('ADR', 'HOME');
|
||||
|
@ -203,7 +203,7 @@ class Utils
|
|||
$oVCardSplitter = new \Sabre\VObject\Splitter\VCard($rFile);
|
||||
if ($oVCardSplitter) {
|
||||
while ($oVCard = $oVCardSplitter->getNext()) {
|
||||
if ($oVCard instanceof \Sabre\VObject\Component\VCard) {
|
||||
if ($oVCard instanceof VCard) {
|
||||
\MailSo\Base\Utils::ResetTimeLimit();
|
||||
$oContact = new Classes\Contact();
|
||||
$oContact->setVCard($oVCard);
|
||||
|
|
Loading…
Add table
Reference in a new issue