comparison program/lib/Roundcube/rcube_vcard.php @ 21:73124dd49283

More cleaning up php8 Warnings/deprecations, noticed that setting non-my-Dates mailboxes to sort on Date isn't sticky over ctrl-R
author Charlie Root
date Thu, 09 Oct 2025 11:31:41 -0400
parents 5039cc34571f
children 303b85d5b561
comparison
equal deleted inserted replaced
20:4aec5e272733 21:73124dd49283
127 // find well-known address fields 127 // find well-known address fields
128 $this->displayname = $this->raw['FN'][0][0]; 128 $this->displayname = $this->raw['FN'][0][0];
129 $this->surname = $this->raw['N'][0][0]; 129 $this->surname = $this->raw['N'][0][0];
130 $this->firstname = $this->raw['N'][0][1]; 130 $this->firstname = $this->raw['N'][0][1];
131 $this->middlename = $this->raw['N'][0][2]; 131 $this->middlename = $this->raw['N'][0][2];
132 $this->nickname = $this->raw['NICKNAME'][0][0]; 132 $this->nickname = empty($this->raw['NICKNAME']) ? null : $this->raw['NICKNAME'][0][0];
133 $this->organization = $this->raw['ORG'][0][0]; 133 $this->organization = empty($this->raw['ORG']) ? null : $this->raw['ORG'][0][0];
134 $this->business = ($this->raw['X-ABSHOWAS'][0][0] == 'COMPANY') || (join('', (array)$this->raw['N'][0]) == '' && !empty($this->organization)); 134 $this->business = ($this->raw['X-ABSHOWAS'][0][0] == 'COMPANY') || (join('', (array)$this->raw['N'][0]) == '' && !empty($this->organization));
135 135
136 foreach ((array)$this->raw['EMAIL'] as $i => $raw_email) { 136 foreach ((array)$this->raw['EMAIL'] as $i => $raw_email) {
137 $this->email[$i] = is_array($raw_email) ? $raw_email[0] : $raw_email; 137 $this->email[$i] = is_array($raw_email) ? $raw_email[0] : $raw_email;
138 } 138 }
161 $out = array('name' => $this->displayname); 161 $out = array('name' => $this->displayname);
162 $typemap = $this->typemap; 162 $typemap = $this->typemap;
163 163
164 // copy name fields to output array 164 // copy name fields to output array
165 foreach (array('firstname','surname','middlename','nickname','organization') as $col) { 165 foreach (array('firstname','surname','middlename','nickname','organization') as $col) {
166 if (strlen($this->$col)) { 166 if (!empty($this->$col) && strlen($this->$col)) {
167 $out[$col] = $this->$col; 167 $out[$col] = $this->$col;
168 } 168 }
169 } 169 }
170 170
171 if ($this->raw['N'][0][3]) 171 if ($this->raw['N'][0][3])
173 if ($this->raw['N'][0][4]) 173 if ($this->raw['N'][0][4])
174 $out['suffix'] = $this->raw['N'][0][4]; 174 $out['suffix'] = $this->raw['N'][0][4];
175 175
176 // convert from raw vcard data into associative data for Roundcube 176 // convert from raw vcard data into associative data for Roundcube
177 foreach (array_flip(self::$fieldmap) as $tag => $col) { 177 foreach (array_flip(self::$fieldmap) as $tag => $col) {
178 foreach ((array)$this->raw[$tag] as $i => $raw) { 178 if (!empty($this->raw[$tag])) {
179 if (is_array($raw)) { 179 foreach ((array)$this->raw[$tag] as $i => $raw) {
180 $k = -1; 180 if (is_array($raw)) {
181 $key = $col; 181 $k = -1;
182 $subtype = ''; 182 $key = $col;
183 183 $subtype = '';
184 if (!empty($raw['type'])) { 184
185 $combined = join(',', self::array_filter((array)$raw['type'], 'internet,pref', true)); 185 if (!empty($raw['type'])) {
186 $combined = strtoupper($combined); 186 $combined = join(',', self::array_filter((array)$raw['type'], 'internet,pref', true));
187 187 $combined = strtoupper($combined);
188 if ($typemap[$combined]) { 188
189 $subtype = $typemap[$combined]; 189 if ($typemap[$combined]) {
190 } 190 $subtype = $typemap[$combined];
191 else if ($typemap[$raw['type'][++$k]]) { 191 }
192 $subtype = $typemap[$raw['type'][$k]]; 192 else if ($typemap[$raw['type'][++$k]]) {
193 } 193 $subtype = $typemap[$raw['type'][$k]];
194 else { 194 }
195 $subtype = strtolower($raw['type'][$k]); 195 else {
196 } 196 $subtype = strtolower($raw['type'][$k]);
197 197 }
198 while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref')) { 198
199 $subtype = $typemap[$raw['type'][++$k]] ?: strtolower($raw['type'][$k]); 199 while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref')) {
200 } 200 $subtype = $typemap[$raw['type'][++$k]] ?: strtolower($raw['type'][$k]);
201 } 201 }
202 202 }
203 // read vcard 2.1 subtype 203
204 if (!$subtype) { 204 // read vcard 2.1 subtype
205 foreach ($raw as $k => $v) { 205 if (!$subtype) {
206 if (!is_numeric($k) && $v === true && ($k = strtolower($k)) 206 foreach ($raw as $k => $v) {
207 && !in_array($k, array('pref','internet','voice','base64')) 207 if (!is_numeric($k) && $v === true && ($k = strtolower($k))
208 ) { 208 && !in_array($k, array('pref','internet','voice','base64'))
209 $k_uc = strtoupper($k); 209 ) {
210 $subtype = $typemap[$k_uc] ?: $k; 210 $k_uc = strtoupper($k);
211 break; 211 $subtype = $typemap[$k_uc] ?: $k;
212 } 212 break;
213 } 213 }
214 } 214 }
215 215 }
216 // force subtype if none set 216
217 if (!$subtype && preg_match('/^(email|phone|address|website)/', $key)) { 217 // force subtype if none set
218 $subtype = 'other'; 218 if (!$subtype && preg_match('/^(email|phone|address|website)/', $key)) {
219 } 219 $subtype = 'other';
220 220 }
221 if ($subtype) { 221
222 $key .= ':' . $subtype; 222 if ($subtype) {
223 } 223 $key .= ':' . $subtype;
224 224 }
225 // split ADR values into assoc array 225
226 if ($tag == 'ADR') { 226 // split ADR values into assoc array
227 list(,, $value['street'], $value['locality'], $value['region'], $value['zipcode'], $value['country']) = $raw; 227 if ($tag == 'ADR') {
228 $out[$key][] = $value; 228 list(,, $value['street'], $value['locality'], $value['region'], $value['zipcode'], $value['country']) = $raw;
229 } 229 $out[$key][] = $value;
230 else { 230 }
231 $out[$key][] = $raw[0]; 231 else {
232 } 232 $out[$key][] = $raw[0];
233 } 233 }
234 else { 234 }
235 $out[$col][] = $raw; 235 else {
236 } 236 $out[$col][] = $raw;
237 } 237 }
238 }
239 }
238 } 240 }
239 241
240 // handle special IM fields as used by Apple 242 // handle special IM fields as used by Apple
241 foreach ($this->immap as $tag => $type) { 243 foreach ($this->immap as $tag => $type) {
242 foreach ((array)$this->raw[$tag] as $i => $raw) { 244 foreach ((array)$this->raw[$tag] as $i => $raw) {
609 if (preg_match('/^(BEGIN|END)$/i', $prefix)) { 611 if (preg_match('/^(BEGIN|END)$/i', $prefix)) {
610 continue; 612 continue;
611 } 613 }
612 614
613 // convert 2.1-style "EMAIL;internet;home:" to 3.0-style "EMAIL;TYPE=internet;TYPE=home:" 615 // convert 2.1-style "EMAIL;internet;home:" to 3.0-style "EMAIL;TYPE=internet;TYPE=home:"
614 if ($result['VERSION'][0] == "2.1" 616 if (!empty($result['VERSION']) && $result['VERSION'][0] == "2.1"
615 && preg_match('/^([^;]+);([^:]+)/', $prefix, $regs2) 617 && preg_match('/^([^;]+);([^:]+)/', $prefix, $regs2)
616 && !preg_match('/^TYPE=/i', $regs2[2]) 618 && !preg_match('/^TYPE=/i', $regs2[2])
617 ) { 619 ) {
618 $prefix = $regs2[1]; 620 $prefix = $regs2[1];
619 foreach (explode(';', $regs2[2]) as $prop) { 621 foreach (explode(';', $regs2[2]) as $prop) {
620 $prefix .= ';' . (strpos($prop, '=') ? $prop : 'TYPE='.$prop); 622 $prefix .= ';' . (strpos($prop, '=') ? $prop : 'TYPE='.$prop);
621 } 623 }
622 } 624 }
623 625
624 if (preg_match_all('/([^\\;]+);?/', $prefix, $regs2)) { 626 if (preg_match_all('/([^\\;]+);?/', $prefix, $regs2) &&
627 count($regs2) > 0) {
625 $entry = array(); 628 $entry = array();
626 $field = strtoupper($regs2[1][0]); 629 $field = strtoupper($regs2[1][0]);
627 $enc = null; 630 $enc = null;
628 631
629 foreach ($regs2[1] as $attrid => $attr) { 632 foreach ($regs2[1] as $attrid => $attr) {