Andreas Schwarz
Andreas Schwarz

Reputation: 1798

imap_append with accents in folder

I have a mailbox (in French) with the following structure:

[email protected]
|
|_Inbox
|_Brouillons (="Drafts")
|_Éléments envoyés (="Sent items")
|_Éléments supprimés (="Deleted items")

My users usually check their emails with a webmail or a mail client. But sometimes I need to add messages manually in the "Sent" folder, which has the name Éléments envoyés, containing several accents and a whitespace.

Here is the relevant PHP code:

$imap_stream = imap_open("{imap.example.com:143/tls}", "[email protected]", "password");
imap_append($imap_stream, "{imap.example.com:143/tls}Éléments envoyés",
...

The above code does not work. If I try with a folder without accents, like Brouillons, the messages are correctly copied.

Could it be an encoding problem? If I check the properties with Thunderbird, the location is shown as

imap://me%[email protected]/%26AMk-l%26AOk-ments%20envoy%26AOk-s

Thanks in advance!

Upvotes: 0

Views: 705

Answers (1)

Andreas Schwarz
Andreas Schwarz

Reputation: 1798

Thanks to Max's comment, I knew what to look for, and I found beetstra's answer.

The solution is then:

$utf7_folder_name = mb_convert_encoding("Éléments envoyés", "UTF7-IMAP", "UTF-8");
$imap_stream = imap_open("{imap.example.com:143/tls}", "[email protected]", "password");
imap_append($imap_stream, "{imap.example.com:143/tls}".$utf7_folder_name,
...

Upvotes: 2

Related Questions