3 * @brief This class contain functions for probing URL
7 use \Friendica\Core\Config;
8 use \Friendica\Core\PConfig;
10 require_once("include/feed.php");
11 require_once('include/email.php');
12 require_once('include/network.php');
16 private function rearrange_data($data) {
17 $fields = array("name", "nick", "guid", "url", "addr", "alias",
18 "photo", "community", "keywords", "location", "about",
19 "batch", "notify", "poll", "request", "confirm", "poco",
20 "priority", "network", "pubkey", "baseurl");
23 foreach ($fields AS $field)
24 if (isset($data[$field]))
25 $newdata[$field] = $data[$field];
27 $newdata[$field] = "";
29 // We don't use the "priority" field anymore and replace it with a dummy.
30 $newdata["priority"] = 0;
36 * @brief Probes for XRD data
39 * 'lrdd' => Link to LRDD endpoint
40 * 'lrdd-xml' => Link to LRDD endpoint in XML format
41 * 'lrdd-json' => Link to LRDD endpoint in JSON format
43 private function xrd($host) {
45 $ssl_url = "https://".$host."/.well-known/host-meta";
46 $url = "http://".$host."/.well-known/host-meta";
48 $xrd_timeout = Config::get('system','xrd_timeout', 20);
51 $xml = fetch_url($ssl_url, false, $redirects, $xrd_timeout, "application/xrd+xml");
52 $xrd = parse_xml_string($xml, false);
54 if (!is_object($xrd)) {
55 $xml = fetch_url($url, false, $redirects, $xrd_timeout, "application/xrd+xml");
56 $xrd = parse_xml_string($xml, false);
61 $links = xml::element_to_array($xrd);
62 if (!isset($links["xrd"]["link"]))
66 foreach ($links["xrd"]["link"] AS $value => $link) {
67 if (isset($link["@attributes"]))
68 $attributes = $link["@attributes"];
69 elseif ($value == "@attributes")
74 if (($attributes["rel"] == "lrdd") AND
75 ($attributes["type"] == "application/xrd+xml"))
76 $xrd_data["lrdd-xml"] = $attributes["template"];
77 elseif (($attributes["rel"] == "lrdd") AND
78 ($attributes["type"] == "application/json"))
79 $xrd_data["lrdd-json"] = $attributes["template"];
80 elseif ($attributes["rel"] == "lrdd")
81 $xrd_data["lrdd"] = $attributes["template"];
86 public static function uri($uri, $network = "", $cache = true) {
89 $result = Cache::get("probe_url:".$network.":".$uri);
90 if (!is_null($result)) {
91 $result = unserialize($result);
96 $data = self::detect($uri, $network);
98 if (!isset($data["url"]))
101 if ($data["photo"] != "")
102 $data["baseurl"] = matching_url(normalise_link($data["baseurl"]), normalise_link($data["photo"]));
104 $data["photo"] = App::get_baseurl().'/images/person-175.jpg';
106 if (!isset($data["name"]))
107 $data["name"] = $data["url"];
109 if (!isset($data["nick"]))
110 $data["nick"] = strtolower($data["name"]);
112 if (!isset($data["network"]))
113 $data["network"] = NETWORK_PHANTOM;
115 $data = self::rearrange_data($data);
117 // Only store into the cache if the value seems to be valid
118 if ($data['network'] != NETWORK_PHANTOM) {
119 Cache::set("probe_url:".$network.":".$uri,serialize($data), CACHE_DAY);
121 /// @todo temporary fix - we need a real contact update function that updates only changing fields
122 /// The biggest problem is the avatar picture that could have a reduced image size.
123 /// It should only be updated if the existing picture isn't existing anymore.
124 if (($data['network'] != NETWORK_FEED) AND ($mode == PROBE_NORMAL) AND
125 $data["name"] AND $data["nick"] AND $data["url"] AND $data["addr"] AND $data["poll"])
126 q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `addr` = '%s',
127 `notify` = '%s', `poll` = '%s', `alias` = '%s', `success_update` = '%s'
128 WHERE `nurl` = '%s' AND NOT `self` AND `uid` = 0",
129 dbesc($data["name"]),
130 dbesc($data["nick"]),
132 dbesc($data["addr"]),
133 dbesc($data["notify"]),
134 dbesc($data["poll"]),
135 dbesc($data["alias"]),
136 dbesc(datetime_convert()),
137 dbesc(normalise_link($data['url']))
143 private function detect($uri, $network) {
144 if (strstr($uri, '@')) {
145 // If the URI starts with "mailto:" then jum directly to the mail detection
146 if (strpos($url,'mailto:') !== false) {
147 $uri = str_replace('mailto:', '', $url);
148 return self::mail($uri);
151 if ($network == NETWORK_MAIL)
152 return self::mail($uri);
154 // Remove "acct:" from the URI
155 $uri = str_replace('acct:', '', $uri);
157 $host = substr($uri,strpos($uri, '@') + 1);
158 $nick = substr($uri,0, strpos($uri, '@'));
160 $lrdd = self::xrd($host);
162 return self::mail($uri);
166 $parts = parse_url($uri);
167 if (!isset($parts["scheme"]) OR
168 !isset($parts["host"]) OR
169 !isset($parts["path"]))
173 $host = $parts["host"];
174 $lrdd = self::xrd($host);
176 $path_parts = explode("/", trim($parts["path"], "/"));
178 while (!$lrdd AND (sizeof($path_parts) > 1)) {
179 $host .= "/".array_shift($path_parts);
180 $lrdd = self::xrd($host);
183 return self::feed($uri);
185 $nick = array_pop($path_parts);
186 $addr = $nick."@".$host;
191 /// @todo Do we need the prefix "acct:" or "acct://"?
193 foreach ($lrdd AS $key => $link) {
197 if (!in_array($key, array("lrdd", "lrdd-xml", "lrdd-json")))
200 $path = str_replace('{uri}', urlencode($addr), $link);
202 $webfinger = self::webfinger($path);
205 return self::feed($uri);
209 logger("Probing ".$uri, LOGGER_DEBUG);
211 if (in_array($network, array("", NETWORK_DFRN)))
212 $result = self::dfrn($webfinger);
213 if ((!$result AND ($network == "")) OR ($network == NETWORK_DIASPORA))
214 $result = self::diaspora($webfinger);
215 if ((!$result AND ($network == "")) OR ($network == NETWORK_OSTATUS))
216 $result = self::ostatus($webfinger);
217 if ((!$result AND ($network == "")) OR ($network == NETWORK_PUMPIO))
218 $result = self::pumpio($webfinger);
219 if ((!$result AND ($network == "")) OR ($network == NETWORK_FEED))
220 $result = self::feed($uri);
222 // We overwrite the detected nick with our try if the previois routines hadn't detected it.
223 // Additionally it is overwritten when the nickname doesn't make sense (contains spaces).
224 if (!isset($result["nick"]) OR ($result["nick"] == "") OR (strstr($result["nick"], " ")))
225 $result["nick"] = $nick;
227 if (!isset($result["addr"]) OR ($result["addr"] == ""))
228 $result["addr"] = $addr;
231 logger($uri." is ".$result["network"], LOGGER_DEBUG);
233 if (!isset($result["baseurl"]) OR ($result["baseurl"] == "")) {
234 $pos = strpos($result["url"], $host);
236 $result["baseurl"] = substr($result["url"], 0, $pos).$host;
242 private function webfinger($url) {
244 $xrd_timeout = Config::get('system','xrd_timeout', 20);
247 $data = fetch_url($url, false, $redirects, $xrd_timeout, "application/xrd+xml");
248 $xrd = parse_xml_string($data, false);
250 if (!is_object($xrd)) {
251 // If it is not XML, maybe it is JSON
252 $webfinger = json_decode($data, true);
254 if (!isset($webfinger["links"]))
260 $xrd_arr = xml::element_to_array($xrd);
261 if (!isset($xrd_arr["xrd"]["link"]))
264 $webfinger = array();
266 if (isset($xrd_arr["xrd"]["subject"]))
267 $webfinger["subject"] = $xrd_arr["xrd"]["subject"];
269 if (isset($xrd_arr["xrd"]["alias"]))
270 $webfinger["aliases"] = $xrd_arr["xrd"]["alias"];
272 $webfinger["links"] = array();
274 foreach ($xrd_arr["xrd"]["link"] AS $value => $data) {
275 if (isset($data["@attributes"]))
276 $attributes = $data["@attributes"];
277 elseif ($value == "@attributes")
282 $webfinger["links"][] = $attributes;
287 private function poll_noscrape($noscrape, $data) {
288 $content = fetch_url($noscrape);
292 $json = json_decode($content, true);
293 if (!is_array($json))
296 if (isset($json["fn"]))
297 $data["name"] = $json["fn"];
299 if (isset($json["addr"]))
300 $data["addr"] = $json["addr"];
302 if (isset($json["nick"]))
303 $data["nick"] = $json["nick"];
305 if (isset($json["comm"]))
306 $data["community"] = $json["comm"];
308 if (isset($json["tags"])) {
309 $keywords = implode(" ", $json["tags"]);
311 $data["keywords"] = $keywords;
314 $location = formatted_location($json);
316 $data["location"] = $location;
318 if (isset($json["about"]))
319 $data["about"] = $json["about"];
321 if (isset($json["key"]))
322 $data["pubkey"] = $json["key"];
324 if (isset($json["photo"]))
325 $data["photo"] = $json["photo"];
327 if (isset($json["dfrn-request"]))
328 $data["request"] = $json["dfrn-request"];
330 if (isset($json["dfrn-confirm"]))
331 $data["confirm"] = $json["dfrn-confirm"];
333 if (isset($json["dfrn-notify"]))
334 $data["notify"] = $json["dfrn-notify"];
336 if (isset($json["dfrn-poll"]))
337 $data["poll"] = $json["dfrn-poll"];
342 public static function valid_dfrn($data) {
344 if(!isset($data['key']))
346 if(!isset($data['dfrn-request']))
348 if(!isset($data['dfrn-confirm']))
350 if(!isset($data['dfrn-notify']))
352 if(!isset($data['dfrn-poll']))
357 public static function profile($profile) {
361 // Fetch data via noscrape - this is faster
362 $noscrape = str_replace(array("/hcard/", "/profile/"), "/noscrape/", $profile);
363 $data = self::poll_noscrape($noscrape, $data);
365 if (!isset($data["notify"]) OR !isset($data["confirm"]) OR
366 !isset($data["request"]) OR !isset($data["poll"]) OR
367 !isset($data["poco"]) OR !isset($data["name"]) OR
368 !isset($data["photo"]))
369 $data = self::poll_hcard($profile, $data, true);
371 $prof_data = array();
372 $prof_data["addr"] = $data["addr"];
373 $prof_data["nick"] = $data["nick"];
374 $prof_data["dfrn-request"] = $data["request"];
375 $prof_data["dfrn-confirm"] = $data["confirm"];
376 $prof_data["dfrn-notify"] = $data["notify"];
377 $prof_data["dfrn-poll"] = $data["poll"];
378 $prof_data["dfrn-poco"] = $data["poco"];
379 $prof_data["photo"] = $data["photo"];
380 $prof_data["fn"] = $data["name"];
381 $prof_data["key"] = $data["pubkey"];
386 private function dfrn($webfinger) {
390 foreach ($webfinger["links"] AS $link) {
391 if (($link["rel"] == NAMESPACE_DFRN) AND ($link["href"] != ""))
392 $data["network"] = NETWORK_DFRN;
393 elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != ""))
394 $data["poll"] = $link["href"];
395 elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
396 ($link["type"] == "text/html") AND ($link["href"] != ""))
397 $data["url"] = $link["href"];
398 elseif (($link["rel"] == "http://microformats.org/profile/hcard") AND ($link["href"] != ""))
399 $hcard = $link["href"];
400 elseif (($link["rel"] == NAMESPACE_POCO) AND ($link["href"] != ""))
401 $data["poco"] = $link["href"];
402 elseif (($link["rel"] == "http://webfinger.net/rel/avatar") AND ($link["href"] != ""))
403 $data["photo"] = $link["href"];
405 elseif (($link["rel"] == "http://joindiaspora.com/seed_location") AND ($link["href"] != ""))
406 $data["baseurl"] = trim($link["href"], '/');
407 elseif (($link["rel"] == "http://joindiaspora.com/guid") AND ($link["href"] != ""))
408 $data["guid"] = $link["href"];
409 elseif (($link["rel"] == "diaspora-public-key") AND ($link["href"] != "")) {
410 $data["pubkey"] = base64_decode($link["href"]);
412 //if (strstr($data["pubkey"], 'RSA ') OR ($link["type"] == "RSA"))
413 if (strstr($data["pubkey"], 'RSA '))
414 $data["pubkey"] = rsatopem($data["pubkey"]);
418 if (!isset($data["network"]) OR ($hcard == ""))
421 // Fetch data via noscrape - this is faster
422 $noscrape = str_replace("/hcard/", "/noscrape/", $hcard);
423 $data = self::poll_noscrape($noscrape, $data);
425 if (isset($data["notify"]) AND isset($data["confirm"]) AND isset($data["request"]) AND
426 isset($data["poll"]) AND isset($data["name"]) AND isset($data["photo"]))
429 $data = self::poll_hcard($hcard, $data, true);
434 private function poll_hcard($hcard, $data, $dfrn = false) {
436 $doc = new DOMDocument();
437 if (!@$doc->loadHTMLFile($hcard))
440 $xpath = new DomXPath($doc);
442 $vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]");
443 if (!is_object($vcards))
446 if ($vcards->length == 0)
449 $vcard = $vcards->item(0);
451 // We have to discard the guid from the hcard in favour of the guid from lrdd
452 // Reason: Hubzilla doesn't use the value "uid" in the hcard like Diaspora does.
453 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' uid ')]", $vcard); // */
454 if (($search->length > 0) AND ($data["guid"] == ""))
455 $data["guid"] = $search->item(0)->nodeValue;
457 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' nickname ')]", $vcard); // */
458 if ($search->length > 0)
459 $data["nick"] = $search->item(0)->nodeValue;
461 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' fn ')]", $vcard); // */
462 if ($search->length > 0)
463 $data["name"] = $search->item(0)->nodeValue;
465 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' searchable ')]", $vcard); // */
466 if ($search->length > 0)
467 $data["searchable"] = $search->item(0)->nodeValue;
469 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' key ')]", $vcard); // */
470 if ($search->length > 0) {
471 $data["pubkey"] = $search->item(0)->nodeValue;
472 if (strstr($data["pubkey"], 'RSA '))
473 $data["pubkey"] = rsatopem($data["pubkey"]);
476 $search = $xpath->query("//*[@id='pod_location']", $vcard); // */
477 if ($search->length > 0)
478 $data["baseurl"] = trim($search->item(0)->nodeValue, "/");
481 $photos = $xpath->query("//*[contains(concat(' ', @class, ' '), ' photo ') or contains(concat(' ', @class, ' '), ' avatar ')]", $vcard); // */
482 foreach ($photos AS $photo) {
484 foreach ($photo->attributes as $attribute)
485 $attr[$attribute->name] = trim($attribute->value);
487 if (isset($attr["src"]) AND isset($attr["width"]))
488 $avatar[$attr["width"]] = $attr["src"];
491 if (sizeof($avatar)) {
493 $data["photo"] = array_pop($avatar);
497 // Poll DFRN specific data
498 $search = $xpath->query("//link[contains(concat(' ', @rel), ' dfrn-')]");
499 if ($search->length > 0) {
500 foreach ($search AS $link) {
501 //$data["request"] = $search->item(0)->nodeValue;
503 foreach ($link->attributes as $attribute)
504 $attr[$attribute->name] = trim($attribute->value);
506 $data[substr($attr["rel"], 5)] = $attr["href"];
510 // Older Friendica versions had used the "uid" field differently than newer versions
511 if ($data["nick"] == $data["guid"])
512 unset($data["guid"]);
519 private function diaspora($webfinger) {
523 foreach ($webfinger["links"] AS $link) {
524 if (($link["rel"] == "http://microformats.org/profile/hcard") AND ($link["href"] != ""))
525 $hcard = $link["href"];
526 elseif (($link["rel"] == "http://joindiaspora.com/seed_location") AND ($link["href"] != ""))
527 $data["baseurl"] = trim($link["href"], '/');
528 elseif (($link["rel"] == "http://joindiaspora.com/guid") AND ($link["href"] != ""))
529 $data["guid"] = $link["href"];
530 elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
531 ($link["type"] == "text/html") AND ($link["href"] != ""))
532 $data["url"] = $link["href"];
533 elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != ""))
534 $data["poll"] = $link["href"];
535 elseif (($link["rel"] == NAMESPACE_POCO) AND ($link["href"] != ""))
536 $data["poco"] = $link["href"];
537 elseif (($link["rel"] == "salmon") AND ($link["href"] != ""))
538 $data["notify"] = $link["href"];
539 elseif (($link["rel"] == "diaspora-public-key") AND ($link["href"] != "")) {
540 $data["pubkey"] = base64_decode($link["href"]);
542 //if (strstr($data["pubkey"], 'RSA ') OR ($link["type"] == "RSA"))
543 if (strstr($data["pubkey"], 'RSA '))
544 $data["pubkey"] = rsatopem($data["pubkey"]);
548 if (!isset($data["url"]) OR ($hcard == ""))
551 if (is_array($webfinger["aliases"]))
552 foreach ($webfinger["aliases"] AS $alias)
553 if (normalise_link($alias) != normalise_link($data["url"]) AND !strstr($alias, "@"))
554 $data["alias"] = $alias;
556 // Fetch further information from the hcard
557 $data = self::poll_hcard($hcard, $data);
562 if (isset($data["url"]) AND isset($data["guid"]) AND isset($data["baseurl"]) AND
563 isset($data["pubkey"]) AND ($hcard != "")) {
564 $data["network"] = NETWORK_DIASPORA;
566 // We have to overwrite the detected value for "notify" since Hubzilla doesn't send it
567 $data["notify"] = $data["baseurl"]."/receive/users/".$data["guid"];
568 $data["batch"] = $data["baseurl"]."/receive/public";
575 private function ostatus($webfinger) {
579 foreach ($webfinger["links"] AS $link) {
580 if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
581 ($link["type"] == "text/html") AND ($link["href"] != ""))
582 $data["url"] = $link["href"];
583 elseif (($link["rel"] == "salmon") AND ($link["href"] != ""))
584 $data["notify"] = $link["href"];
585 elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != ""))
586 $data["poll"] = $link["href"];
587 elseif (($link["rel"] == "magic-public-key") AND ($link["href"] != "")) {
588 $pubkey = $link["href"];
590 if (substr($pubkey, 0, 5) === 'data:') {
591 if (strstr($pubkey, ','))
592 $pubkey = substr($pubkey, strpos($pubkey, ',') + 1);
594 $pubkey = substr($pubkey, 5);
596 $pubkey = fetch_url($pubkey);
598 $key = explode(".", $pubkey);
600 if (sizeof($key) >= 3) {
601 $m = base64url_decode($key[1]);
602 $e = base64url_decode($key[2]);
603 $data["pubkey"] = metopem($m,$e);
609 if (isset($data["notify"]) AND isset($data["pubkey"]) AND
610 isset($data["poll"]) AND isset($data["url"])) {
611 $data["network"] = NETWORK_OSTATUS;
615 // Fetch all additional data from the feed
616 $feed = fetch_url($data["poll"]);
617 $feed_data = feed_import($feed,$dummy1,$dummy2, $dummy3, true);
621 if ($feed_data["header"]["author-name"] != "")
622 $data["name"] = $feed_data["header"]["author-name"];
624 if ($feed_data["header"]["author-nick"] != "")
625 $data["nick"] = $feed_data["header"]["author-nick"];
627 if ($feed_data["header"]["author-avatar"] != "")
628 $data["photo"] = $feed_data["header"]["author-avatar"];
630 if ($feed_data["header"]["author-id"] != "")
631 $data["alias"] = $feed_data["header"]["author-id"];
633 // OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl)
634 // So we take the value that we just fetched, although the other one worked as well
635 if ($feed_data["header"]["author-link"] != "")
636 $data["url"] = $feed_data["header"]["author-link"];
638 /// @todo Fetch location and "about" from the feed as well
642 private function pumpio_profile_data($profile) {
644 $doc = new DOMDocument();
645 if (!@$doc->loadHTMLFile($profile))
648 $xpath = new DomXPath($doc);
652 // This is ugly - but pump.io doesn't seem to know a better way for it
653 $data["name"] = trim($xpath->query("//h1[@class='media-header']")->item(0)->nodeValue);
654 $pos = strpos($data["name"], chr(10));
656 $data["name"] = trim(substr($data["name"], 0, $pos));
658 $avatar = $xpath->query("//img[@class='img-rounded media-object']")->item(0);
660 foreach ($avatar->attributes as $attribute)
661 if ($attribute->name == "src")
662 $data["photo"] = trim($attribute->value);
664 $data["location"] = $xpath->query("//p[@class='location']")->item(0)->nodeValue;
665 $data["about"] = $xpath->query("//p[@class='summary']")->item(0)->nodeValue;
670 private function pumpio($webfinger) {
672 foreach ($webfinger["links"] AS $link) {
673 if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
674 ($link["type"] == "text/html") AND ($link["href"] != ""))
675 $data["url"] = $link["href"];
676 elseif (($link["rel"] == "activity-inbox") AND ($link["href"] != ""))
677 $data["activity-inbox"] = $link["href"];
678 elseif (($link["rel"] == "activity-outbox") AND ($link["href"] != ""))
679 $data["activity-outbox"] = $link["href"];
680 elseif (($link["rel"] == "dialback") AND ($link["href"] != ""))
681 $data["dialback"] = $link["href"];
683 if (isset($data["activity-inbox"]) AND isset($data["activity-outbox"]) AND
684 isset($data["dialback"]) AND isset($data["url"])) {
686 // by now we use these fields only for the network type detection
687 // So we unset all data that isn't used at the moment
688 unset($data["activity-inbox"]);
689 unset($data["activity-outbox"]);
690 unset($data["dialback"]);
692 $data["network"] = NETWORK_PUMPIO;
696 $profile_data = self::pumpio_profile_data($data["url"]);
701 $data = array_merge($data, $profile_data);
706 private function feed($url) {
707 $feed = fetch_url($url);
708 $feed_data = feed_import($feed, $dummy1, $dummy2, $dummy3, true);
713 if ($feed_data["header"]["author-name"] != "")
714 $data["name"] = $feed_data["header"]["author-name"];
716 if ($feed_data["header"]["author-nick"] != "")
717 $data["nick"] = $feed_data["header"]["author-nick"];
719 if ($feed_data["header"]["author-avatar"] != "")
720 $data["photo"] = $feed_data["header"]["author-avatar"];
722 if ($feed_data["header"]["author-id"] != "")
723 $data["alias"] = $feed_data["header"]["author-id"];
726 $data["poll"] = $url;
728 if ($feed_data["header"]["author-link"] != "")
729 $data["baseurl"] = $feed_data["header"]["author-link"];
731 $data["baseurl"] = $data["url"];
733 $data["network"] = NETWORK_FEED;
738 private function mail($uri) {
740 if (!validate_email($uri))
746 $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
748 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
750 if(count($x) && count($r)) {
751 $mailbox = construct_mailbox_name($r[0]);
753 openssl_private_decrypt(hex2bin($r[0]['pass']), $password,$x[0]['prvkey']);
754 $mbox = email_connect($mailbox,$r[0]['user'], $password);
759 $msgs = email_poll($mbox, $uri);
760 logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
767 $data["addr"] = $uri;
768 $data["network"] = NETWORK_MAIL;
769 $data["name"] = substr($uri, 0, strpos($uri,'@'));
770 $data["nick"] = $data["name"];
771 $data["photo"] = avatar_img($uri);
773 $phost = substr($uri, strpos($uri,'@') + 1);
774 $data["url"] = 'http://'.$phost."/".$data["nick"];
775 $data["notify"] = 'smtp '.random_string();
776 $data["poll"] = 'email '.random_string();
778 $x = email_msg_meta($mbox, $msgs[0]);
779 if(stristr($x[0]->from, $uri))
780 $adr = imap_rfc822_parse_adrlist($x[0]->from, '');
781 elseif(stristr($x[0]->to, $uri))
782 $adr = imap_rfc822_parse_adrlist($x[0]->to, '');
784 foreach($adr as $feadr) {
785 if((strcasecmp($feadr->mailbox, $data["name"]) == 0)
786 &&(strcasecmp($feadr->host, $phost) == 0)
787 && (strlen($feadr->personal))) {
789 $personal = imap_mime_header_decode($feadr->personal);
791 foreach($personal as $perspart)
792 if ($perspart->charset != "default")
793 $data["name"] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text);
795 $data["name"] .= $perspart->text;
797 $data["name"] = notags($data["name"]);