From 3e496a51aae9f2d41ba220d17e2aae8ba7ea7d59 Mon Sep 17 00:00:00 2001 From: alec Date: Fri, 13 Aug 2010 19:21:21 +0000 Subject: - Recognize Apple Address Book vcards (#1486916) git-svn-id: https://svn.roundcube.net/trunk@3897 208e9e7b-5314-0410-a742-e7e81cd9613c --- plugins/vcard_attachments/vcard_attachments.php | 43 ++++++++++++++++--------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/plugins/vcard_attachments/vcard_attachments.php b/plugins/vcard_attachments/vcard_attachments.php index 17dff4dc3..4bf9accbb 100644 --- a/plugins/vcard_attachments/vcard_attachments.php +++ b/plugins/vcard_attachments/vcard_attachments.php @@ -26,32 +26,21 @@ class vcard_attachments extends rcube_plugin } /** - * Check message attachments for vcards + * Check message bodies and attachments for vcards */ function message_load($p) { $this->message = $p['object']; - // handle attachments with specified content type: - // Content-Type: text/vcard; - // Content-Type: text/x-vcard; - // Content-Type: text/directory; profile=vCard; + // handle attachments vcard attachments foreach ((array)$this->message->attachments as $attachment) { - if ($attachment->mimetype == 'text/vcard' || - $attachment->mimetype == 'text/x-vcard' || - ($attachment->mimetype == 'text/directory' && $attachment->ctype_parameters['profile'] - && strtolower($attachment->ctype_parameters['profile']) == 'vcard') - ) { + if ($this->is_vcard($attachment)) { $this->vcard_parts[] = $attachment->mime_id; } } // the same with message bodies foreach ((array)$this->message->parts as $idx => $part) { - if ($part->mimetype == 'text/vcard' || - $part->mimetype == 'text/x-vcard' || - ($part->mimetype == 'text/directory' && $part->ctype_parameters['profile'] - && strtolower($part->ctype_parameters['profile']) == 'vcard') - ) { + if ($this->is_vcard($part)) { $this->vcard_parts[] = $part->mime_id; $this->vcard_bodies[] = $part->mime_id; } @@ -157,4 +146,28 @@ class vcard_attachments extends rcube_plugin $rcmail->output->send(); } + /** + * Checks if specified message part is a vcard data + * + * @param rcube_message_part Part object + * + * @return boolean True if part is of type vcard + */ + function is_vcard($part) + { + return ( + // Content-Type: text/vcard; + $part->mimetype == 'text/vcard' || + // Content-Type: text/x-vcard; + $part->mimetype == 'text/x-vcard' || + // Content-Type: text/directory; profile=vCard; + ($part->mimetype == 'text/directory' && ( + ($part->ctype_parameters['profile'] && + strtolower($part->ctype_parameters['profile']) == 'vcard') + // Content-Type: text/directory; (with filename=*.vcf) + || ($part->filename && preg_match('/\.vcf$/i', $part->filename)) + ) + ) + ); + } } -- cgit v1.2.3