Completed
Pull Request — master (#7490)
by Tobia
30:30 queued 16:48
created
lib/private/Collaboration/Collaborators/MailPlugin.php 1 patch
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -33,135 +33,135 @@
 block discarded – undo
33 33
 use OCP\Share;
34 34
 
35 35
 class MailPlugin implements ISearchPlugin {
36
-	protected $shareeEnumeration;
37
-
38
-	/** @var IManager */
39
-	private $contactsManager;
40
-	/** @var ICloudIdManager */
41
-	private $cloudIdManager;
42
-	/** @var IConfig */
43
-	private $config;
44
-
45
-	public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) {
46
-		$this->contactsManager = $contactsManager;
47
-		$this->cloudIdManager = $cloudIdManager;
48
-		$this->config = $config;
49
-
50
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
51
-	}
52
-
53
-	/**
54
-	 * @param $search
55
-	 * @param $limit
56
-	 * @param $offset
57
-	 * @param ISearchResult $searchResult
58
-	 * @return bool
59
-	 * @since 13.0.0
60
-	 */
61
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
62
-		$result = ['wide' => [], 'exact' => []];
63
-		$userType = new SearchResultType('users');
64
-		$emailType = new SearchResultType('emails');
65
-
66
-		// Search in contacts
67
-		//@todo Pagination missing
68
-		$addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']);
69
-		$lowerSearch = strtolower($search);
70
-		foreach ($addressBookContacts as $contact) {
71
-			if (isset($contact['isLocalSystemBook'])) {
72
-				continue;
73
-			}
74
-			if (isset($contact['EMAIL'])) {
75
-				$emailAddresses = $contact['EMAIL'];
76
-				if (!is_array($emailAddresses)) {
77
-					$emailAddresses = [$emailAddresses];
78
-				}
79
-				foreach ($emailAddresses as $emailAddress) {
80
-					$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
81
-
82
-					if (isset($contact['isLocalSystemBook'])) {
83
-						if ($exactEmailMatch) {
84
-							try {
85
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
86
-							} catch (\InvalidArgumentException $e) {
87
-								continue;
88
-							}
89
-
90
-							if (!$searchResult->hasResult($userType, $cloud->getUser())) {
91
-								$singleResult = [[
92
-									'label' => $contact['FN'] . " ($emailAddress)",
93
-									'value' => [
94
-										'shareType' => Share::SHARE_TYPE_USER,
95
-										'shareWith' => $cloud->getUser(),
96
-									],
97
-								]];
98
-								$searchResult->addResultSet($userType, [], $singleResult);
99
-								$searchResult->markExactIdMatch($emailType);
100
-							}
101
-							return false;
102
-						}
103
-
104
-						if ($this->shareeEnumeration) {
105
-							try {
106
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
107
-							} catch (\InvalidArgumentException $e) {
108
-								continue;
109
-							}
110
-
111
-							if (!$searchResult->hasResult($userType, $cloud->getUser())) {
112
-								$singleResult = [[
113
-									'label' => $contact['FN'] . " ($emailAddress)",
114
-									'value' => [
115
-										'shareType' => Share::SHARE_TYPE_USER,
116
-										'shareWith' => $cloud->getUser(),
117
-									]],
118
-								];
119
-								$searchResult->addResultSet($userType, $singleResult, []);
120
-							}
121
-						}
122
-						continue;
123
-					}
124
-
125
-					if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
126
-						if ($exactEmailMatch) {
127
-							$searchResult->markExactIdMatch($emailType);
128
-						}
129
-						$result['exact'][] = [
130
-							'label' => $contact['FN'] . " ($emailAddress)",
131
-							'value' => [
132
-								'shareType' => Share::SHARE_TYPE_EMAIL,
133
-								'shareWith' => $emailAddress,
134
-							],
135
-						];
136
-					} else {
137
-						$result['wide'][] = [
138
-							'label' => $contact['FN'] . " ($emailAddress)",
139
-							'value' => [
140
-								'shareType' => Share::SHARE_TYPE_EMAIL,
141
-								'shareWith' => $emailAddress,
142
-							],
143
-						];
144
-					}
145
-				}
146
-			}
147
-		}
148
-
149
-		if (!$this->shareeEnumeration) {
150
-			$result['wide'] = [];
151
-		}
152
-
153
-		if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
154
-			$result['exact'][] = [
155
-				'label' => $search,
156
-				'value' => [
157
-					'shareType' => Share::SHARE_TYPE_EMAIL,
158
-					'shareWith' => $search,
159
-				],
160
-			];
161
-		}
162
-
163
-		$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
164
-
165
-		return true;
166
-	}
36
+    protected $shareeEnumeration;
37
+
38
+    /** @var IManager */
39
+    private $contactsManager;
40
+    /** @var ICloudIdManager */
41
+    private $cloudIdManager;
42
+    /** @var IConfig */
43
+    private $config;
44
+
45
+    public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) {
46
+        $this->contactsManager = $contactsManager;
47
+        $this->cloudIdManager = $cloudIdManager;
48
+        $this->config = $config;
49
+
50
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
51
+    }
52
+
53
+    /**
54
+     * @param $search
55
+     * @param $limit
56
+     * @param $offset
57
+     * @param ISearchResult $searchResult
58
+     * @return bool
59
+     * @since 13.0.0
60
+     */
61
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
62
+        $result = ['wide' => [], 'exact' => []];
63
+        $userType = new SearchResultType('users');
64
+        $emailType = new SearchResultType('emails');
65
+
66
+        // Search in contacts
67
+        //@todo Pagination missing
68
+        $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']);
69
+        $lowerSearch = strtolower($search);
70
+        foreach ($addressBookContacts as $contact) {
71
+            if (isset($contact['isLocalSystemBook'])) {
72
+                continue;
73
+            }
74
+            if (isset($contact['EMAIL'])) {
75
+                $emailAddresses = $contact['EMAIL'];
76
+                if (!is_array($emailAddresses)) {
77
+                    $emailAddresses = [$emailAddresses];
78
+                }
79
+                foreach ($emailAddresses as $emailAddress) {
80
+                    $exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
81
+
82
+                    if (isset($contact['isLocalSystemBook'])) {
83
+                        if ($exactEmailMatch) {
84
+                            try {
85
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
86
+                            } catch (\InvalidArgumentException $e) {
87
+                                continue;
88
+                            }
89
+
90
+                            if (!$searchResult->hasResult($userType, $cloud->getUser())) {
91
+                                $singleResult = [[
92
+                                    'label' => $contact['FN'] . " ($emailAddress)",
93
+                                    'value' => [
94
+                                        'shareType' => Share::SHARE_TYPE_USER,
95
+                                        'shareWith' => $cloud->getUser(),
96
+                                    ],
97
+                                ]];
98
+                                $searchResult->addResultSet($userType, [], $singleResult);
99
+                                $searchResult->markExactIdMatch($emailType);
100
+                            }
101
+                            return false;
102
+                        }
103
+
104
+                        if ($this->shareeEnumeration) {
105
+                            try {
106
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
107
+                            } catch (\InvalidArgumentException $e) {
108
+                                continue;
109
+                            }
110
+
111
+                            if (!$searchResult->hasResult($userType, $cloud->getUser())) {
112
+                                $singleResult = [[
113
+                                    'label' => $contact['FN'] . " ($emailAddress)",
114
+                                    'value' => [
115
+                                        'shareType' => Share::SHARE_TYPE_USER,
116
+                                        'shareWith' => $cloud->getUser(),
117
+                                    ]],
118
+                                ];
119
+                                $searchResult->addResultSet($userType, $singleResult, []);
120
+                            }
121
+                        }
122
+                        continue;
123
+                    }
124
+
125
+                    if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
126
+                        if ($exactEmailMatch) {
127
+                            $searchResult->markExactIdMatch($emailType);
128
+                        }
129
+                        $result['exact'][] = [
130
+                            'label' => $contact['FN'] . " ($emailAddress)",
131
+                            'value' => [
132
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
133
+                                'shareWith' => $emailAddress,
134
+                            ],
135
+                        ];
136
+                    } else {
137
+                        $result['wide'][] = [
138
+                            'label' => $contact['FN'] . " ($emailAddress)",
139
+                            'value' => [
140
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
141
+                                'shareWith' => $emailAddress,
142
+                            ],
143
+                        ];
144
+                    }
145
+                }
146
+            }
147
+        }
148
+
149
+        if (!$this->shareeEnumeration) {
150
+            $result['wide'] = [];
151
+        }
152
+
153
+        if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
154
+            $result['exact'][] = [
155
+                'label' => $search,
156
+                'value' => [
157
+                    'shareType' => Share::SHARE_TYPE_EMAIL,
158
+                    'shareWith' => $search,
159
+                ],
160
+            ];
161
+        }
162
+
163
+        $searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
164
+
165
+        return true;
166
+    }
167 167
 }
Please login to merge, or discard this patch.