diff --git a/api/js/etemplate/Et2Avatar/Et2Avatar.ts b/api/js/etemplate/Et2Avatar/Et2Avatar.ts index a57d2801f9..b13085b0ef 100644 --- a/api/js/etemplate/Et2Avatar/Et2Avatar.ts +++ b/api/js/etemplate/Et2Avatar/Et2Avatar.ts @@ -158,15 +158,18 @@ export class Et2Avatar extends Et2Widget(SlotMixin(SlAvatar)) implements et2_IDe return this._contactId; } + static RFC822EMAIL = /<([^<>]+)>$/; + /** * Function to set contactId * contactId could be in one of these formats: - * 'number', will be consider as contact_id + * 'number', will be considered as contact_id * 'contact:number', similar to above - * 'account:number', will be consider as account id + * 'account:number', will be considered as account id + * 'email:', will be considered as email address * @example: contactId = "account:4" * - * @param {string} _contactId contact id could be as above mentioned formats + * @param {string} _contactId contact id could be as above-mentioned formats */ set contactId(_contactId : string) { @@ -177,10 +180,16 @@ export class Et2Avatar extends Et2Widget(SlotMixin(SlAvatar)) implements et2_IDe { _contactId = this.egw().user('account_id'); } - else if(_contactId.match(/account:/)) + else if(_contactId.substr(0, 8) === 'account:') { id = 'account_id'; - _contactId = _contactId.replace('account:',''); + _contactId = _contactId.substr(8); + } + else if(_contactId.substr(0, 6) === 'email:') + { + id = 'email'; + const matches = Et2Avatar.RFC822EMAIL.exec(_contactId); + _contactId = matches ? matches[1] : _contactId.substr(6); } else { diff --git a/api/src/Contacts.php b/api/src/Contacts.php index 12e5ee1d7c..4e10ff0630 100755 --- a/api/src/Contacts.php +++ b/api/src/Contacts.php @@ -2745,7 +2745,7 @@ class Contacts extends Contacts\Storage ob_start(); $contact_id = isset($_GET['contact_id']) ? $_GET['contact_id'] : - (isset($_GET['account_id']) ? 'account:'.$_GET['account_id'] : 0); + (isset($_GET['account_id']) ? 'account:'.$_GET['account_id'] : null); if (substr($contact_id,0,8) == 'account:') { @@ -2753,11 +2753,29 @@ class Contacts extends Contacts\Storage $contact_id = $GLOBALS['egw']->accounts->id2name(substr($contact_id, 8), 'person_id'); } - $contact = $this->read($contact_id); + if (!$contact_id && !empty($_GET['email'])) + { + $email = strtolower(current(Mail::stripRFC822Addresses([$_GET['email']]))); + + if (!($contact = current($this->search(['contact_email' => $email, 'contact_email_home' => $email], + ['contact_id', 'email', 'email_home', 'n_fn', 'n_given', 'n_family', 'contact_files', 'etag'], + 'contact_files & '.self::FILES_BIT_PHOTO.' DESC', '', '', false, 'OR', [0, 1]) ?: [])) || + !self::hasPhoto($contact)) + { + Session::cache_control(86400); // cache for 1 day + header('Content-type: image/jpeg'); + http_response_code(404); + exit; + } + } + else + { + $contact = $this->read($contact_id); + } if (!$contact || !self::hasPhoto($contact, $url, $size)) { - if(!$contact_id && $id < 0) + if(!$contact_id && isset($id) && $id < 0) { $group = $GLOBALS['egw']->accounts->read($id); $contact = array( @@ -2777,7 +2795,7 @@ class Contacts extends Contacts\Storage } // use an etag over the image mapp - $etag = '"'.$contact_id.':'.$contact['etag'].'"'; + $etag = '"'.$contact['id'].':'.$contact['etag'].'"'; if (!ob_get_contents()) { header('Content-type: image/jpeg'); @@ -2788,6 +2806,10 @@ class Contacts extends Contacts\Storage { Session::cache_control(30*86400); // cache for 30 days } + else + { + Session::cache_control(7*86400); // cache for 7 days + } // if servers send a If-None-Match header, response with 304 Not Modified, if etag matches if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag) { diff --git a/api/src/Mail/Avatar.php b/api/src/Mail/Avatar.php index f319084d7d..9977ff1ba0 100644 --- a/api/src/Mail/Avatar.php +++ b/api/src/Mail/Avatar.php @@ -41,7 +41,7 @@ class Avatar static function($email, $address) { if (($contacts = $GLOBALS['egw']->contacts->search(['contact_email' => $email, 'contact_email_home' => $email], - ['contact_id', 'email', 'email_home', 'n_fn', 'n_given', 'n_family'], '', '', '', false, 'OR', false))) + ['contact_id', 'email', 'email_home', 'n_fn', 'n_given', 'n_family'], '', '', '', false, 'OR', [0,1]))) { return [$contacts[0]['photo'], ['lname' => $contacts[0]['n_family'], 'fname' => $contacts[0]['n_given']]]; } diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index ef868dc8a1..96b53ff394 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -2133,17 +2133,9 @@ $filter['before']= date("d-M-Y", $cutoffdate2); if ($header['disposition-notification-to']) $data['dispositionnotificationto'] = $header['disposition-notification-to']; if (($header['mdnsent']||$header['mdnnotsent']|$header['seen'])&&isset($data['dispositionnotificationto'])) unset($data['dispositionnotificationto']); $data['attachmentsBlock'] = $imageHTMLBlock; - if ($_folderType) - { - $data['fromavatar'] = Api\Mail\Avatar::getAvatar($data['fromaddress']); - } $data['address'] = $_folderType ? $data["toaddress"] : $data["fromaddress"]; $data['lavatar'] = Api\Mail\Avatar::getLavatar($data['address']); - - if (($data['avatar'] = Api\Mail\Avatar::getAvatar($data['address'], $data['lavatar'])) && !$_folderType) - { - $data['fromavatar'] = $data['avatar']; - } + $data['fromlavatar'] = $_folderType ? Api\Mail\Avatar::getLavatar($data['fromaddress']) : $data['lavatar']; if (in_array("bodypreview", $cols) && $header['bodypreview']) { diff --git a/mail/templates/default/index.rows.horizental.xet b/mail/templates/default/index.rows.horizental.xet index 30d35f26ed..9be4b40254 100644 --- a/mail/templates/default/index.rows.horizental.xet +++ b/mail/templates/default/index.rows.horizental.xet @@ -31,7 +31,7 @@ - diff --git a/mail/templates/default/index.rows.vertical.xet b/mail/templates/default/index.rows.vertical.xet index bb634a65ee..369fb5b030 100644 --- a/mail/templates/default/index.rows.vertical.xet +++ b/mail/templates/default/index.rows.vertical.xet @@ -14,12 +14,11 @@ - - diff --git a/mail/templates/default/index.xet b/mail/templates/default/index.xet index 3a50640f54..29b5411d68 100644 --- a/mail/templates/default/index.xet +++ b/mail/templates/default/index.xet @@ -25,7 +25,7 @@ - +