mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
vCard parser fixes
This commit is contained in:
parent
147dce6e4a
commit
3613bf5270
8 changed files with 62 additions and 20 deletions
|
|
@ -353,7 +353,7 @@ class AddressBook extends \RainLoop\Providers\AbstractProvider
|
|||
$oVCard->UID = \Sabre\DAV\UUIDUtil::getUUID();
|
||||
}
|
||||
|
||||
$oContact->PopulateByVCard($oVCard->serialize());
|
||||
$oContact->PopulateByVCard($oVCard->UID, $oVCard->serialize());
|
||||
|
||||
if (0 < \count($oContact->Properties))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ class Contact
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function ToVCard($sPreVCard = '')
|
||||
public function ToVCard($sPreVCard = '', $oLogger = null)
|
||||
{
|
||||
$this->UpdateDependentValues();
|
||||
|
||||
|
|
@ -191,6 +191,11 @@ class Contact
|
|||
return '';
|
||||
}
|
||||
|
||||
if ("\xef\xbb\xbf" === \substr($sPreVCard, 0, 3))
|
||||
{
|
||||
$sPreVCard = \substr($sPreVCard, 3);
|
||||
}
|
||||
|
||||
$oVCard = null;
|
||||
if (0 < \strlen($sPreVCard))
|
||||
{
|
||||
|
|
@ -198,7 +203,14 @@ class Contact
|
|||
{
|
||||
$oVCard = \Sabre\VObject\Reader::read($sPreVCard);
|
||||
}
|
||||
catch (\Exception $oExc) {};
|
||||
catch (\Exception $oExc)
|
||||
{
|
||||
if ($oLogger)
|
||||
{
|
||||
$oLogger->WriteException($oExc);
|
||||
$oLogger->WriteDump($sPreVCard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$oVCard)
|
||||
|
|
@ -484,8 +496,13 @@ class Contact
|
|||
}
|
||||
}
|
||||
|
||||
public function PopulateByVCard($sVCard, $sEtag = '')
|
||||
public function PopulateByVCard($sUid, $sVCard, $sEtag = '', $oLogger = null)
|
||||
{
|
||||
if ("\xef\xbb\xbf" === \substr($sVCard, 0, 3))
|
||||
{
|
||||
$sVCard = \substr($sVCard, 3);
|
||||
}
|
||||
|
||||
$this->Properties = array();
|
||||
|
||||
if (!\class_exists('Sabre\DAV\Client'))
|
||||
|
|
@ -502,7 +519,16 @@ class Contact
|
|||
{
|
||||
$oVCard = \Sabre\VObject\Reader::read($sVCard);
|
||||
}
|
||||
catch (\Exception $oExc) {};
|
||||
catch (\Exception $oExc)
|
||||
{
|
||||
if ($oLogger)
|
||||
{
|
||||
$oLogger->WriteException($oExc);
|
||||
$oLogger->WriteDump($sVCard);
|
||||
}
|
||||
|
||||
$this->IdContactStr = $sUid;
|
||||
}
|
||||
|
||||
$aProperties = array();
|
||||
if ($oVCard)
|
||||
|
|
|
|||
|
|
@ -91,12 +91,17 @@ class PdoAddressBook
|
|||
if ($aItem && isset($aItem['id_contact'], $aItem['id_contact_str'], $aItem['changed'], $aItem['deleted'], $aItem['etag']) &&
|
||||
!empty($aItem['id_contact_str']))
|
||||
{
|
||||
$aResult[$aItem['id_contact_str']] = array(
|
||||
$sKeyID = $aItem['id_contact_str'];
|
||||
|
||||
$aResult[$sKeyID] = array(
|
||||
'deleted' => '1' === (string) $aItem['deleted'],
|
||||
'id_contact' => $aItem['id_contact'],
|
||||
'uid' => $sKeyID,
|
||||
'etag' => $aItem['etag'],
|
||||
'changed' => (int) $aItem['changed'],
|
||||
'deleted' => '1' === (string) $aItem['deleted']
|
||||
);
|
||||
|
||||
$aResult[$sKeyID]['changed_'] = \gmdate('c', $aResult[$sKeyID]['changed']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -141,12 +146,15 @@ class PdoAddressBook
|
|||
$sKeyID = \preg_replace('/\.vcf$/i', '', $sVcfFileName);
|
||||
|
||||
$mResult[$sKeyID] = array(
|
||||
'deleted' => false,
|
||||
'uid' => $sKeyID,
|
||||
'vcf' => $sVcfFileName,
|
||||
'etag' => \trim(\trim($aItem['{dav:}getetag']), '"\''),
|
||||
'lastmodified' => $aItem['{dav:}getlastmodified'],
|
||||
'changed' => \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($aItem['{dav:}getlastmodified']),
|
||||
'deleted' => false
|
||||
'changed' => \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($aItem['{dav:}getlastmodified'])
|
||||
);
|
||||
|
||||
$mResult[$sKeyID]['changed_'] = \gmdate('c', $mResult[$sKeyID]['changed']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -310,7 +318,7 @@ class PdoAddressBook
|
|||
}
|
||||
|
||||
$oResponse = $this->davClientRequest($oClient, 'PUT',
|
||||
$sPath.$oContact->CardDavNameUri(), $oContact->ToVCard($sExsistensBody));
|
||||
$sPath.$oContact->CardDavNameUri(), $oContact->ToVCard($sExsistensBody, $this->oLogger)."\r\n\r\n");
|
||||
|
||||
if ($oResponse && isset($oResponse['headers'], $oResponse['headers']['etag']))
|
||||
{
|
||||
|
|
@ -358,8 +366,9 @@ class PdoAddressBook
|
|||
$oContact = new \RainLoop\Providers\AddressBook\Classes\Contact();
|
||||
}
|
||||
|
||||
$oContact->PopulateByVCard($sBody,
|
||||
!empty($oResponse['headers']['etag']) ? \trim(\trim($oResponse['headers']['etag']), '"\'') : '');
|
||||
$oContact->PopulateByVCard($aData['uid'], $sBody,
|
||||
!empty($oResponse['headers']['etag']) ? \trim(\trim($oResponse['headers']['etag']), '"\'') : '',
|
||||
$this->oLogger);
|
||||
|
||||
$this->ContactSave($sEmail, $oContact);
|
||||
unset($oContact);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue