From 80bfcc7694b4251cc00af7dc76f05d1cf2ff823d Mon Sep 17 00:00:00 2001
From: Michael Vogel <icarus@dabo.de>
Date: Tue, 23 Aug 2016 07:48:48 +0200
Subject: [PATCH] The handle (user@domain.tld) for Diaspora contacts must
 always be lowercase

---
 include/Probe.php    | 3 +++
 include/diaspora.php | 8 ++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/Probe.php b/include/Probe.php
index 7cda542d0b..44824103b4 100644
--- a/include/Probe.php
+++ b/include/Probe.php
@@ -788,6 +788,9 @@ class Probe {
 			isset($data["pubkey"]) AND ($hcard != "")) {
 			$data["network"] = NETWORK_DIASPORA;
 
+			// The Diaspora handle must always be lowercase
+			$data["addr"] = strtolower($data["addr"]);
+
 			// We have to overwrite the detected value for "notify" since Hubzilla doesn't send it
 			$data["notify"] = $data["baseurl"]."/receive/users/".$data["guid"];
 			$data["batch"] = $data["baseurl"]."/receive/public";
diff --git a/include/diaspora.php b/include/diaspora.php
index a1adb9b828..db6844f44d 100644
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -623,7 +623,7 @@ class diaspora {
 					dbesc($arr["photo"]),
 					dbesc($arr["request"]),
 					dbesc($arr["nick"]),
-					dbesc($arr["addr"]),
+					dbesc(strtolower($arr["addr"])),
 					dbesc($arr["guid"]),
 					dbesc($arr["batch"]),
 					dbesc($arr["notify"]),
@@ -677,7 +677,7 @@ class diaspora {
 			$r = q("SELECT `addr` FROM `gcontact` WHERE `id` = %d AND `addr` != ''",
 				intval($gcontact_id));
 			if ($r)
-				return $r[0]["addr"];
+				return strtolower($r[0]["addr"]);
 		}
 
 		$r = q("SELECT `network`, `addr`, `self`, `url`, `nick` FROM `contact` WHERE `id` = %d",
@@ -697,7 +697,7 @@ class diaspora {
 			}
 		}
 
-		return $handle;
+		return strtolower($handle);
 	}
 
 	/**
@@ -1652,7 +1652,7 @@ class diaspora {
 	 * @return bool Success
 	 */
 	private function receive_profile($importer, $data) {
-		$author = notags(unxmlify($data->author));
+		$author = strtolower(notags(unxmlify($data->author)));
 
 		$contact = self::contact_by_handle($importer["uid"], $author);
 		if (!$contact)