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 = "", $uid = 0, $cache = true) {
89 $result = Cache::get("probe_url:".$network.":".$uri);
90 if (!is_null($result)) {
91 $result = unserialize($result);
99 $data = self::detect($uri, $network, $uid);
101 if (!isset($data["url"]))
104 if ($data["photo"] != "")
105 $data["baseurl"] = matching_url(normalise_link($data["baseurl"]), normalise_link($data["photo"]));
107 $data["photo"] = App::get_baseurl().'/images/person-175.jpg';
109 if (!isset($data["name"]))
110 $data["name"] = $data["url"];
112 if (!isset($data["nick"]))
113 $data["nick"] = strtolower($data["name"]);
115 if (!isset($data["network"]))
116 $data["network"] = NETWORK_PHANTOM;
118 $data = self::rearrange_data($data);
120 // Only store into the cache if the value seems to be valid
121 if (!in_array($data['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
122 Cache::set("probe_url:".$network.":".$uri,serialize($data), CACHE_DAY);
124 /// @todo temporary fix - we need a real contact update function that updates only changing fields
125 /// The biggest problem is the avatar picture that could have a reduced image size.
126 /// It should only be updated if the existing picture isn't existing anymore.
127 if (($data['network'] != NETWORK_FEED) AND ($mode == PROBE_NORMAL) AND
128 $data["name"] AND $data["nick"] AND $data["url"] AND $data["addr"] AND $data["poll"])
129 q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `addr` = '%s',
130 `notify` = '%s', `poll` = '%s', `alias` = '%s', `success_update` = '%s'
131 WHERE `nurl` = '%s' AND NOT `self` AND `uid` = 0",
132 dbesc($data["name"]),
133 dbesc($data["nick"]),
135 dbesc($data["addr"]),
136 dbesc($data["notify"]),
137 dbesc($data["poll"]),
138 dbesc($data["alias"]),
139 dbesc(datetime_convert()),
140 dbesc(normalise_link($data['url']))
146 private function detect($uri, $network, $uid) {
147 if (strstr($uri, '@')) {
148 // If the URI starts with "mailto:" then jum directly to the mail detection
149 if (strpos($url,'mailto:') !== false) {
150 $uri = str_replace('mailto:', '', $url);
151 return self::mail($uri, $uid);
154 if ($network == NETWORK_MAIL)
155 return self::mail($uri, $uid);
157 // Remove "acct:" from the URI
158 $uri = str_replace('acct:', '', $uri);
160 $host = substr($uri,strpos($uri, '@') + 1);
161 $nick = substr($uri,0, strpos($uri, '@'));
163 $lrdd = self::xrd($host);
165 return self::mail($uri, $uid);
169 $parts = parse_url($uri);
170 if (!isset($parts["scheme"]) OR
171 !isset($parts["host"]) OR
172 !isset($parts["path"]))
176 $host = $parts["host"];
177 $lrdd = self::xrd($host);
179 $path_parts = explode("/", trim($parts["path"], "/"));
181 while (!$lrdd AND (sizeof($path_parts) > 1)) {
182 $host .= "/".array_shift($path_parts);
183 $lrdd = self::xrd($host);
186 return self::feed($uri);
188 $nick = array_pop($path_parts);
189 $addr = $nick."@".$host;
194 /// @todo Do we need the prefix "acct:" or "acct://"?
196 foreach ($lrdd AS $key => $link) {
200 if (!in_array($key, array("lrdd", "lrdd-xml", "lrdd-json")))
203 $path = str_replace('{uri}', urlencode($addr), $link);
205 $webfinger = self::webfinger($path);
208 return self::feed($uri);
212 logger("Probing ".$uri, LOGGER_DEBUG);
214 if (in_array($network, array("", NETWORK_DFRN)))
215 $result = self::dfrn($webfinger);
216 if ((!$result AND ($network == "")) OR ($network == NETWORK_DIASPORA))
217 $result = self::diaspora($webfinger);
218 if ((!$result AND ($network == "")) OR ($network == NETWORK_OSTATUS))
219 $result = self::ostatus($webfinger);
220 if ((!$result AND ($network == "")) OR ($network == NETWORK_PUMPIO))
221 $result = self::pumpio($webfinger);
222 if ((!$result AND ($network == "")) OR ($network == NETWORK_FEED))
223 $result = self::feed($uri);
225 // We overwrite the detected nick with our try if the previois routines hadn't detected it.
226 // Additionally it is overwritten when the nickname doesn't make sense (contains spaces).
227 if (!isset($result["nick"]) OR ($result["nick"] == "") OR (strstr($result["nick"], " ")))
228 $result["nick"] = $nick;
230 if (!isset($result["addr"]) OR ($result["addr"] == ""))
231 $result["addr"] = $addr;
234 logger($uri." is ".$result["network"], LOGGER_DEBUG);
236 if (!isset($result["baseurl"]) OR ($result["baseurl"] == "")) {
237 $pos = strpos($result["url"], $host);
239 $result["baseurl"] = substr($result["url"], 0, $pos).$host;
245 private function webfinger($url) {
247 $xrd_timeout = Config::get('system','xrd_timeout', 20);
250 $data = fetch_url($url, false, $redirects, $xrd_timeout, "application/xrd+xml");
251 $xrd = parse_xml_string($data, false);
253 if (!is_object($xrd)) {
254 // If it is not XML, maybe it is JSON
255 $webfinger = json_decode($data, true);
257 if (!isset($webfinger["links"]))
263 $xrd_arr = xml::element_to_array($xrd);
264 if (!isset($xrd_arr["xrd"]["link"]))
267 $webfinger = array();
269 if (isset($xrd_arr["xrd"]["subject"]))
270 $webfinger["subject"] = $xrd_arr["xrd"]["subject"];
272 if (isset($xrd_arr["xrd"]["alias"]))
273 $webfinger["aliases"] = $xrd_arr["xrd"]["alias"];
275 $webfinger["links"] = array();
277 foreach ($xrd_arr["xrd"]["link"] AS $value => $data) {
278 if (isset($data["@attributes"]))
279 $attributes = $data["@attributes"];
280 elseif ($value == "@attributes")
285 $webfinger["links"][] = $attributes;
290 private function poll_noscrape($noscrape, $data) {
291 $content = fetch_url($noscrape);
295 $json = json_decode($content, true);
296 if (!is_array($json))
299 if (isset($json["fn"]))
300 $data["name"] = $json["fn"];
302 if (isset($json["addr"]))
303 $data["addr"] = $json["addr"];
305 if (isset($json["nick"]))
306 $data["nick"] = $json["nick"];
308 if (isset($json["comm"]))
309 $data["community"] = $json["comm"];
311 if (isset($json["tags"])) {
312 $keywords = implode(" ", $json["tags"]);
314 $data["keywords"] = $keywords;
317 $location = formatted_location($json);
319 $data["location"] = $location;
321 if (isset($json["about"]))
322 $data["about"] = $json["about"];
324 if (isset($json["key"]))
325 $data["pubkey"] = $json["key"];
327 if (isset($json["photo"]))
328 $data["photo"] = $json["photo"];
330 if (isset($json["dfrn-request"]))
331 $data["request"] = $json["dfrn-request"];
333 if (isset($json["dfrn-confirm"]))
334 $data["confirm"] = $json["dfrn-confirm"];
336 if (isset($json["dfrn-notify"]))
337 $data["notify"] = $json["dfrn-notify"];
339 if (isset($json["dfrn-poll"]))
340 $data["poll"] = $json["dfrn-poll"];
345 public static function valid_dfrn($data) {
347 if(!isset($data['key']))
349 if(!isset($data['dfrn-request']))
351 if(!isset($data['dfrn-confirm']))
353 if(!isset($data['dfrn-notify']))
355 if(!isset($data['dfrn-poll']))
360 public static function profile($profile) {
364 // Fetch data via noscrape - this is faster
365 $noscrape = str_replace(array("/hcard/", "/profile/"), "/noscrape/", $profile);
366 $data = self::poll_noscrape($noscrape, $data);
368 if (!isset($data["notify"]) OR !isset($data["confirm"]) OR
369 !isset($data["request"]) OR !isset($data["poll"]) OR
370 !isset($data["poco"]) OR !isset($data["name"]) OR
371 !isset($data["photo"]))
372 $data = self::poll_hcard($profile, $data, true);
374 $prof_data = array();
375 $prof_data["addr"] = $data["addr"];
376 $prof_data["nick"] = $data["nick"];
377 $prof_data["dfrn-request"] = $data["request"];
378 $prof_data["dfrn-confirm"] = $data["confirm"];
379 $prof_data["dfrn-notify"] = $data["notify"];
380 $prof_data["dfrn-poll"] = $data["poll"];
381 $prof_data["dfrn-poco"] = $data["poco"];
382 $prof_data["photo"] = $data["photo"];
383 $prof_data["fn"] = $data["name"];
384 $prof_data["key"] = $data["pubkey"];
389 private function dfrn($webfinger) {
393 foreach ($webfinger["links"] AS $link) {
394 if (($link["rel"] == NAMESPACE_DFRN) AND ($link["href"] != ""))
395 $data["network"] = NETWORK_DFRN;
396 elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != ""))
397 $data["poll"] = $link["href"];
398 elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
399 ($link["type"] == "text/html") AND ($link["href"] != ""))
400 $data["url"] = $link["href"];
401 elseif (($link["rel"] == "http://microformats.org/profile/hcard") AND ($link["href"] != ""))
402 $hcard = $link["href"];
403 elseif (($link["rel"] == NAMESPACE_POCO) AND ($link["href"] != ""))
404 $data["poco"] = $link["href"];
405 elseif (($link["rel"] == "http://webfinger.net/rel/avatar") AND ($link["href"] != ""))
406 $data["photo"] = $link["href"];
408 elseif (($link["rel"] == "http://joindiaspora.com/seed_location") AND ($link["href"] != ""))
409 $data["baseurl"] = trim($link["href"], '/');
410 elseif (($link["rel"] == "http://joindiaspora.com/guid") AND ($link["href"] != ""))
411 $data["guid"] = $link["href"];
412 elseif (($link["rel"] == "diaspora-public-key") AND ($link["href"] != "")) {
413 $data["pubkey"] = base64_decode($link["href"]);
415 //if (strstr($data["pubkey"], 'RSA ') OR ($link["type"] == "RSA"))
416 if (strstr($data["pubkey"], 'RSA '))
417 $data["pubkey"] = rsatopem($data["pubkey"]);
421 if (!isset($data["network"]) OR ($hcard == ""))
424 // Fetch data via noscrape - this is faster
425 $noscrape = str_replace("/hcard/", "/noscrape/", $hcard);
426 $data = self::poll_noscrape($noscrape, $data);
428 if (isset($data["notify"]) AND isset($data["confirm"]) AND isset($data["request"]) AND
429 isset($data["poll"]) AND isset($data["name"]) AND isset($data["photo"]))
432 $data = self::poll_hcard($hcard, $data, true);
437 private function poll_hcard($hcard, $data, $dfrn = false) {
439 $doc = new DOMDocument();
440 if (!@$doc->loadHTMLFile($hcard))
443 $xpath = new DomXPath($doc);
445 $vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]");
446 if (!is_object($vcards))
449 if ($vcards->length == 0)
452 $vcard = $vcards->item(0);
454 // We have to discard the guid from the hcard in favour of the guid from lrdd
455 // Reason: Hubzilla doesn't use the value "uid" in the hcard like Diaspora does.
456 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' uid ')]", $vcard); // */
457 if (($search->length > 0) AND ($data["guid"] == ""))
458 $data["guid"] = $search->item(0)->nodeValue;
460 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' nickname ')]", $vcard); // */
461 if ($search->length > 0)
462 $data["nick"] = $search->item(0)->nodeValue;
464 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' fn ')]", $vcard); // */
465 if ($search->length > 0)
466 $data["name"] = $search->item(0)->nodeValue;
468 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' searchable ')]", $vcard); // */
469 if ($search->length > 0)
470 $data["searchable"] = $search->item(0)->nodeValue;
472 $search = $xpath->query("//*[contains(concat(' ', @class, ' '), ' key ')]", $vcard); // */
473 if ($search->length > 0) {
474 $data["pubkey"] = $search->item(0)->nodeValue;
475 if (strstr($data["pubkey"], 'RSA '))
476 $data["pubkey"] = rsatopem($data["pubkey"]);
479 $search = $xpath->query("//*[@id='pod_location']", $vcard); // */
480 if ($search->length > 0)
481 $data["baseurl"] = trim($search->item(0)->nodeValue, "/");
484 $photos = $xpath->query("//*[contains(concat(' ', @class, ' '), ' photo ') or contains(concat(' ', @class, ' '), ' avatar ')]", $vcard); // */
485 foreach ($photos AS $photo) {
487 foreach ($photo->attributes as $attribute)
488 $attr[$attribute->name] = trim($attribute->value);
490 if (isset($attr["src"]) AND isset($attr["width"]))
491 $avatar[$attr["width"]] = $attr["src"];
494 if (sizeof($avatar)) {
496 $data["photo"] = array_pop($avatar);
500 // Poll DFRN specific data
501 $search = $xpath->query("//link[contains(concat(' ', @rel), ' dfrn-')]");
502 if ($search->length > 0) {
503 foreach ($search AS $link) {
504 //$data["request"] = $search->item(0)->nodeValue;
506 foreach ($link->attributes as $attribute)
507 $attr[$attribute->name] = trim($attribute->value);
509 $data[substr($attr["rel"], 5)] = $attr["href"];
513 // Older Friendica versions had used the "uid" field differently than newer versions
514 if ($data["nick"] == $data["guid"])
515 unset($data["guid"]);
522 private function diaspora($webfinger) {
526 foreach ($webfinger["links"] AS $link) {
527 if (($link["rel"] == "http://microformats.org/profile/hcard") AND ($link["href"] != ""))
528 $hcard = $link["href"];
529 elseif (($link["rel"] == "http://joindiaspora.com/seed_location") AND ($link["href"] != ""))
530 $data["baseurl"] = trim($link["href"], '/');
531 elseif (($link["rel"] == "http://joindiaspora.com/guid") AND ($link["href"] != ""))
532 $data["guid"] = $link["href"];
533 elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
534 ($link["type"] == "text/html") AND ($link["href"] != ""))
535 $data["url"] = $link["href"];
536 elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != ""))
537 $data["poll"] = $link["href"];
538 elseif (($link["rel"] == NAMESPACE_POCO) AND ($link["href"] != ""))
539 $data["poco"] = $link["href"];
540 elseif (($link["rel"] == "salmon") AND ($link["href"] != ""))
541 $data["notify"] = $link["href"];
542 elseif (($link["rel"] == "diaspora-public-key") AND ($link["href"] != "")) {
543 $data["pubkey"] = base64_decode($link["href"]);
545 //if (strstr($data["pubkey"], 'RSA ') OR ($link["type"] == "RSA"))
546 if (strstr($data["pubkey"], 'RSA '))
547 $data["pubkey"] = rsatopem($data["pubkey"]);
551 if (!isset($data["url"]) OR ($hcard == ""))
554 if (is_array($webfinger["aliases"]))
555 foreach ($webfinger["aliases"] AS $alias)
556 if (normalise_link($alias) != normalise_link($data["url"]) AND !strstr($alias, "@"))
557 $data["alias"] = $alias;
559 // Fetch further information from the hcard
560 $data = self::poll_hcard($hcard, $data);
565 if (isset($data["url"]) AND isset($data["guid"]) AND isset($data["baseurl"]) AND
566 isset($data["pubkey"]) AND ($hcard != "")) {
567 $data["network"] = NETWORK_DIASPORA;
569 // We have to overwrite the detected value for "notify" since Hubzilla doesn't send it
570 $data["notify"] = $data["baseurl"]."/receive/users/".$data["guid"];
571 $data["batch"] = $data["baseurl"]."/receive/public";
578 private function ostatus($webfinger) {
582 foreach ($webfinger["links"] AS $link) {
583 if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
584 ($link["type"] == "text/html") AND ($link["href"] != ""))
585 $data["url"] = $link["href"];
586 elseif (($link["rel"] == "salmon") AND ($link["href"] != ""))
587 $data["notify"] = $link["href"];
588 elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != ""))
589 $data["poll"] = $link["href"];
590 elseif (($link["rel"] == "magic-public-key") AND ($link["href"] != "")) {
591 $pubkey = $link["href"];
593 if (substr($pubkey, 0, 5) === 'data:') {
594 if (strstr($pubkey, ','))
595 $pubkey = substr($pubkey, strpos($pubkey, ',') + 1);
597 $pubkey = substr($pubkey, 5);
599 $pubkey = fetch_url($pubkey);
601 $key = explode(".", $pubkey);
603 if (sizeof($key) >= 3) {
604 $m = base64url_decode($key[1]);
605 $e = base64url_decode($key[2]);
606 $data["pubkey"] = metopem($m,$e);
612 if (isset($data["notify"]) AND isset($data["pubkey"]) AND
613 isset($data["poll"]) AND isset($data["url"])) {
614 $data["network"] = NETWORK_OSTATUS;
618 // Fetch all additional data from the feed
619 $feed = fetch_url($data["poll"]);
620 $feed_data = feed_import($feed,$dummy1,$dummy2, $dummy3, true);
624 if ($feed_data["header"]["author-name"] != "")
625 $data["name"] = $feed_data["header"]["author-name"];
627 if ($feed_data["header"]["author-nick"] != "")
628 $data["nick"] = $feed_data["header"]["author-nick"];
630 if ($feed_data["header"]["author-avatar"] != "")
631 $data["photo"] = $feed_data["header"]["author-avatar"];
633 if ($feed_data["header"]["author-id"] != "")
634 $data["alias"] = $feed_data["header"]["author-id"];
636 // OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl)
637 // So we take the value that we just fetched, although the other one worked as well
638 if ($feed_data["header"]["author-link"] != "")
639 $data["url"] = $feed_data["header"]["author-link"];
641 /// @todo Fetch location and "about" from the feed as well
645 private function pumpio_profile_data($profile) {
647 $doc = new DOMDocument();
648 if (!@$doc->loadHTMLFile($profile))
651 $xpath = new DomXPath($doc);
655 // This is ugly - but pump.io doesn't seem to know a better way for it
656 $data["name"] = trim($xpath->query("//h1[@class='media-header']")->item(0)->nodeValue);
657 $pos = strpos($data["name"], chr(10));
659 $data["name"] = trim(substr($data["name"], 0, $pos));
661 $avatar = $xpath->query("//img[@class='img-rounded media-object']")->item(0);
663 foreach ($avatar->attributes as $attribute)
664 if ($attribute->name == "src")
665 $data["photo"] = trim($attribute->value);
667 $data["location"] = $xpath->query("//p[@class='location']")->item(0)->nodeValue;
668 $data["about"] = $xpath->query("//p[@class='summary']")->item(0)->nodeValue;
673 private function pumpio($webfinger) {
675 foreach ($webfinger["links"] AS $link) {
676 if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
677 ($link["type"] == "text/html") AND ($link["href"] != ""))
678 $data["url"] = $link["href"];
679 elseif (($link["rel"] == "activity-inbox") AND ($link["href"] != ""))
680 $data["activity-inbox"] = $link["href"];
681 elseif (($link["rel"] == "activity-outbox") AND ($link["href"] != ""))
682 $data["activity-outbox"] = $link["href"];
683 elseif (($link["rel"] == "dialback") AND ($link["href"] != ""))
684 $data["dialback"] = $link["href"];
686 if (isset($data["activity-inbox"]) AND isset($data["activity-outbox"]) AND
687 isset($data["dialback"]) AND isset($data["url"])) {
689 // by now we use these fields only for the network type detection
690 // So we unset all data that isn't used at the moment
691 unset($data["activity-inbox"]);
692 unset($data["activity-outbox"]);
693 unset($data["dialback"]);
695 $data["network"] = NETWORK_PUMPIO;
699 $profile_data = self::pumpio_profile_data($data["url"]);
704 $data = array_merge($data, $profile_data);
709 private function feed($url) {
710 $feed = fetch_url($url);
711 $feed_data = feed_import($feed, $dummy1, $dummy2, $dummy3, true);
716 if ($feed_data["header"]["author-name"] != "")
717 $data["name"] = $feed_data["header"]["author-name"];
719 if ($feed_data["header"]["author-nick"] != "")
720 $data["nick"] = $feed_data["header"]["author-nick"];
722 if ($feed_data["header"]["author-avatar"] != "")
723 $data["photo"] = $feed_data["header"]["author-avatar"];
725 if ($feed_data["header"]["author-id"] != "")
726 $data["alias"] = $feed_data["header"]["author-id"];
729 $data["poll"] = $url;
731 if ($feed_data["header"]["author-link"] != "")
732 $data["baseurl"] = $feed_data["header"]["author-link"];
734 $data["baseurl"] = $data["url"];
736 $data["network"] = NETWORK_FEED;
741 private function mail($uri, $uid) {
743 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"]);