Opened 2 years ago
Closed 2 years ago
#1487868 closed Bugs (fixed)
vcard folding problem with utf-8 database
| Reported by: | koessler | Owned by: | thomasb |
|---|---|---|---|
| Priority: | 5 | Milestone: | 0.6-beta |
| Component: | Addressbook | Version: | git-master |
| Severity: | major | Keywords: | |
| Cc: |
Description (last modified by alec)
The method rfc2425_fold in class rcube_vcard splits multibyte characters in the middle. When the database table is defined with character set UTF-8 the contact cannot be stored.
Create a contact with last name:
12345679801234567980123456798012345679801234567980123456798012345679801ä
and save the contact. You will get error message: "invalid byte sequence for encoding "UTF8": 0xc30a"
A possible correction would be:
1) be sure that php environment 'mbstring.internal_encoding' is set correctly to the internal coding of the vcard (probably UTF-8)
2) then you may use the following method rfc2425_fold_callback() in rcube_vcard.php, line 466:
private static function rfc2425_fold_callback($matches)
{
return ":" . mb_ereg_replace('(.{72})', "\\1\n ", $matches[1]);
}
Attachments (1)
Change History (12)
comment:1 Changed 2 years ago by alec
- Description modified (diff)
comment:2 Changed 2 years ago by alec
comment:3 Changed 2 years ago by koessler
According to http://www.php.net/manual/de/function.mb-ereg-replace.php this method is not deprecated....
comment:4 Changed 2 years ago by alec
I've found in rcube_vcard class comments that it was intended to store vcard unfolded. Attached patch fixes the DB error issue by disabling folding. However, we need still to fix folding.
Changed 2 years ago by alec
comment:5 Changed 2 years ago by thomasb
- Owner set to thomasb
- Status changed from new to assigned
comment:6 Changed 2 years ago by thomasb
- Resolution set to fixed
- Status changed from assigned to closed
Fixed in [bf80b5a2]
comment:7 Changed 2 years ago by koessler
Your fix is not working as desired. Pls read the description carefully.
Function mb_ereg_replace() works only when environment value "mbstring.internal_encoding" is set. Currently this variable is not set and therefore the method still splits the € sign inbetween the 3 bytes representation.
Before using mb_ereg_replace() be sure to set the variable "mbstring.internal_encoding" to UTF-8 (respectively to the same character coding which the database expects and which rcube_vcard uses internally)
Please reopen the ticket.
comment:8 Changed 2 years ago by alec
- Resolution fixed deleted
- Status changed from closed to reopened
It is set in inlude/iniset.php file.
comment:9 Changed 2 years ago by koessler
Yes, you are right.
I checked trunk 4655, it's not working there. Strange, I will have closer look.........
comment:10 Changed 2 years ago by koessler
Found the problem:
See http://www.php.net/manual/en/function.mb-ereg-replace.php:
Note:
The internal encoding or the character encoding specified by mb_regex_encoding() will be used as the character encoding for this function.
Solution: you also have to call mb_regex_encoding(RCMAIL_CHARSET) in iniset.php then it works.
comment:11 Changed 2 years ago by alec
- Resolution set to fixed
- Status changed from reopened to closed
Fixed in [5c4c0666].

Isn't mb_ereg* deprecated? This can be done also with a loop and mb_substr(). Also we should add checking if these mb_* functions exists.