mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-10-06 11:45:48 +08:00
Bugfixes for KolabAddressBook
This commit is contained in:
parent
010f38ea25
commit
14fdd4aa32
4 changed files with 61 additions and 38 deletions
|
@ -58,15 +58,19 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
|||
protected function fetchXCardFromMessage(\MailSo\Mail\Message $oMessage) : ?\Sabre\VObject\Component\VCard
|
||||
{
|
||||
$xCard = null;
|
||||
foreach ($oMessage->Attachments() ?: [] as $oAttachment) {
|
||||
if ('application/vcard+xml' === $oAttachment->MimeType()) {
|
||||
$result = $this->MailClient()->MessageMimeStream(function ($rResource) use (&$xCard) {
|
||||
if (\is_resource($rResource)) {
|
||||
$xCard = \Sabre\VObject\Reader::readXML($rResource);
|
||||
}
|
||||
}, $this->sFolderName, $oMessage->Uid(), $oAttachment->MimeIndex());
|
||||
break;
|
||||
try {
|
||||
foreach ($oMessage->Attachments() ?: [] as $oAttachment) {
|
||||
if ('application/vcard+xml' === $oAttachment->MimeType()) {
|
||||
$result = $this->MailClient()->MessageMimeStream(function ($rResource) use (&$xCard) {
|
||||
if (\is_resource($rResource)) {
|
||||
$xCard = \Sabre\VObject\Reader::readXML($rResource);
|
||||
}
|
||||
}, $this->sFolderName, $oMessage->Uid(), $oAttachment->MimeIndex());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
\error_log("KolabAddressBook message {$oMessage->Uid()} error: {$e->getMessage()}");
|
||||
}
|
||||
return $xCard;
|
||||
}
|
||||
|
@ -183,11 +187,28 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
|||
$oVCard = null;
|
||||
$iUID = 0;
|
||||
}
|
||||
$oVCard = $oVCard ?: new \Sabre\VObject\Component\VCard();
|
||||
$oContact->UpdateDependentValues();
|
||||
$oContact->fillVCard($oVCard);
|
||||
$sUid = (string) $oVCard->UID;
|
||||
$sUid = \str_replace('urn:uuid:', '', $sUid ?: $oContact->GetUID());
|
||||
if (!\SnappyMail\UUID::isValid($sUid)) {
|
||||
$sUid = \SnappyMail\UUID::generate();
|
||||
}
|
||||
$oContact->IdContactStr = $sUid;
|
||||
$oContact->SetUID($sUid);
|
||||
$oVCard->UID = new \Sabre\VObject\Property\Uri($oVCard, 'uid', 'urn:uuid:' . $sUid);
|
||||
|
||||
if (!\count($oVCard->select('x-kolab-version'))) {
|
||||
$oVCard->add(new \Sabre\VObject\Property\Text($oVCard, 'x-kolab-version', '3.1.0'));
|
||||
}
|
||||
|
||||
$oMessage = new \MailSo\Mime\Message();
|
||||
$oMessage->DoesNotAddDefaultXMailer();
|
||||
$oMessage->messageIdRequired = false;
|
||||
|
||||
$sEmail = '';
|
||||
if (isset($oVCard->EMAIL)) {
|
||||
if ($oVCard && isset($oVCard->EMAIL)) {
|
||||
foreach ($oVCard->EMAIL as $oProp) {
|
||||
$oTypes = $oProp ? $oProp['TYPE'] : null;
|
||||
$sValue = $oProp ? \trim($oProp->getValue()) : '';
|
||||
|
@ -200,27 +221,27 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
|||
}
|
||||
}
|
||||
|
||||
$oMessage->SetSubject($oContact->GetUID());
|
||||
$oMessage->SetSubject($sUid);
|
||||
// $oMessage->SetDate(\time());
|
||||
$oMessage->Headers->AddByName('X-Kolab-Type', 'application/x-vnd.kolab.contact');
|
||||
$oMessage->Headers->AddByName('X-Kolab-Mime-Version', '3.0');
|
||||
// $oMessage->Headers->AddByName('User-Agent', 'SnappyMail');
|
||||
$oMessage->SetCustomHeader('X-Kolab-Type', 'application/x-vnd.kolab.contact');
|
||||
$oMessage->SetCustomHeader('X-Kolab-Mime-Version', '3.0');
|
||||
$oMessage->SetCustomHeader('User-Agent', 'SnappyMail');
|
||||
|
||||
$oPart = new \MailSo\Mime\Part;
|
||||
$oPart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, 'text/plain');
|
||||
$oPart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, 'text/plain; charset="us-ascii"');
|
||||
$oPart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING, '7Bit');
|
||||
$oPart->Body = "This is a Kolab Groupware object.\r\n"
|
||||
. "To view this object you will need an email client that can understand the Kolab Groupware format.\r\n"
|
||||
. "For a list of such email clients please visit\r\n"
|
||||
. "http://www.kolab.org/get-kolab";
|
||||
. "http://www.kolab.org/get-kolab\r\n";
|
||||
$oMessage->SubParts->append($oPart);
|
||||
|
||||
// Now the vCard
|
||||
$oPart = new \MailSo\Mime\Part;
|
||||
$oPart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE, 'application/vcard+xml; name="kolab.xml"');
|
||||
// $oPart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING, 'quoted-printable');
|
||||
$oPart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING, 'quoted-printable');
|
||||
$oPart->Headers->AddByName(\MailSo\Mime\Enumerations\Header::CONTENT_DISPOSITION, 'attachment; filename="kolab.xml"');
|
||||
$oPart->Body = $oContact->ToXCard($oVCard/*, $oLogger*/);
|
||||
$oPart->Body = \quoted_printable_encode(\preg_replace('/\r?\n/s', "\r\n", \Sabre\VObject\Writer::writeXml($oVCard)));
|
||||
$oMessage->SubParts->append($oPart);
|
||||
|
||||
// Store Message
|
||||
|
|
|
@ -4,11 +4,11 @@ class KolabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
{
|
||||
const
|
||||
NAME = 'Kolab',
|
||||
VERSION = '1.0',
|
||||
RELEASE = '2022-05-19',
|
||||
VERSION = '1.1',
|
||||
RELEASE = '2022-05-20',
|
||||
CATEGORY = 'Contacts',
|
||||
DESCRIPTION = 'Use an Address Book of Kolab.',
|
||||
REQUIRED = '2.16.0';
|
||||
REQUIRED = '2.16.2';
|
||||
|
||||
public function Init() : void
|
||||
{
|
||||
|
|
|
@ -57,6 +57,8 @@ class Message extends Part
|
|||
*/
|
||||
private $bAddDefaultXMailer = true;
|
||||
|
||||
public $messageIdRequired = true;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
@ -439,11 +441,11 @@ class Message extends Part
|
|||
$oRootPart->Headers->SetByName(Enumerations\Header::DATE, \gmdate('r'), true);
|
||||
}
|
||||
|
||||
if (!isset($this->aHeadersValue[Enumerations\Header::MESSAGE_ID])) {
|
||||
if ($this->messageIdRequired && !isset($this->aHeadersValue[Enumerations\Header::MESSAGE_ID])) {
|
||||
$oRootPart->Headers->SetByName(Enumerations\Header::MESSAGE_ID, $this->generateNewMessageId(), true);
|
||||
}
|
||||
|
||||
if (!isset($this->aHeadersValue[Enumerations\Header::X_MAILER]) && $this->bAddDefaultXMailer) {
|
||||
if ($this->bAddDefaultXMailer && !isset($this->aHeadersValue[Enumerations\Header::X_MAILER])) {
|
||||
$oRootPart->Headers->SetByName(Enumerations\Header::X_MAILER, 'SnappyMail/'.APP_VERSION, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -180,6 +180,17 @@ class Contact implements \JsonSerializable
|
|||
return $this->IdContactStr.'.vcf';
|
||||
}
|
||||
|
||||
public function SetUID(string $value) : void
|
||||
{
|
||||
foreach ($this->Properties as $oProperty) {
|
||||
if ($oProperty && PropertyType::UID == $oProperty->Type) {
|
||||
$oProperty->Value = $value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->Properties[] = new Property(PropertyType::UID, $value);
|
||||
}
|
||||
|
||||
public function GetUID() : string
|
||||
{
|
||||
foreach ($this->Properties as $oProperty) {
|
||||
|
@ -187,13 +198,13 @@ class Contact implements \JsonSerializable
|
|||
return $oProperty->Value;
|
||||
}
|
||||
}
|
||||
return $this->IdContactStr;
|
||||
return '';
|
||||
}
|
||||
|
||||
private function fillVCard(\Sabre\VObject\Component\VCard $oVCard) : void
|
||||
public function fillVCard(\Sabre\VObject\Component\VCard $oVCard) : void
|
||||
{
|
||||
$oVCard->VERSION = '3.0';
|
||||
$oVCard->PRODID = '-//SnappyMail//'.APP_VERSION.'//EN';
|
||||
$oVCard->PRODID = 'SnappyMail-'.APP_VERSION;
|
||||
|
||||
unset($oVCard->FN, $oVCard->EMAIL, $oVCard->TEL, $oVCard->URL, $oVCard->NICKNAME);
|
||||
|
||||
|
@ -255,7 +266,7 @@ class Contact implements \JsonSerializable
|
|||
}
|
||||
}
|
||||
|
||||
$oVCard->UID = empty($sUid) ? $this->IdContactStr : $sUid;
|
||||
$oVCard->UID = $sUid ?: \SnappyMail\UUID::generate();
|
||||
$oVCard->N = array($sLastName, $sFirstName, $sMiddleName, $sPrefix, $sSuffix);
|
||||
$oVCard->REV = \gmdate('Ymd', $this->Changed).'T'.\gmdate('His', $this->Changed).'Z';
|
||||
}
|
||||
|
@ -295,17 +306,6 @@ class Contact implements \JsonSerializable
|
|||
return (string) $oVCard->serialize();
|
||||
}
|
||||
|
||||
public function ToXCard(?\Sabre\VObject\Component\VCard $oVCard = null, $oLogger = null) : string
|
||||
{
|
||||
$this->UpdateDependentValues();
|
||||
|
||||
$oVCard = $oVCard ?: new \Sabre\VObject\Component\VCard();
|
||||
|
||||
$this->fillVCard($oVCard);
|
||||
|
||||
return (string) \Sabre\VObject\Writer::writeXml($oVCard);
|
||||
}
|
||||
|
||||
public function ToCsv(bool $bWithHeader = false) : string
|
||||
{
|
||||
$aData = array();
|
||||
|
@ -599,9 +599,9 @@ class Contact implements \JsonSerializable
|
|||
}
|
||||
|
||||
$this->IdContactStr = $oVCard->UID ? (string) $oVCard->UID : \SnappyMail\UUID::generate();
|
||||
$aProperties[] = new Property(PropertyType::UID, $this->IdContactStr);
|
||||
|
||||
$this->Properties = $aProperties;
|
||||
$this->SetUID($this->IdContactStr);
|
||||
|
||||
$this->UpdateDependentValues();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue