php-imap
php-imap copied to clipboard
Need to get readable folder list
Hello there,
I need to get proper readable folder list for Daum.net IMAP access.
Below is my code for get folder list : $folder = $client->getFolder('*'); Here if I print_r($folder) gives below reasult.
Array ( [0] => Array ( [fullpath] => {imap.daum.net:993/imap/ssl}Inbox [attributes] => 1 [delimiter] => / [shortpath] => Inbox ) [1] => Array ( [fullpath] => {imap.daum.net:993/imap/ssl}Sent Messages [attributes] => 1 [delimiter] => / [shortpath] => Sent Messages ) [2] => Array ( [fullpath] => {imap.daum.net:993/imap/ssl}Drafts [attributes] => 1 [delimiter] => / [shortpath] => Drafts ) [3] => Array ( [fullpath] => {imap.daum.net:993/imap/ssl}¤�8Ӹ���h [attributes] => 1 [delimiter] => / [shortpath] => ¤�8Ӹ���h ) [4] => Array ( [fullpath] => {imap.daum.net:993/imap/ssl}Deleted Messages [attributes] => 1 [delimiter] => / [shortpath] => Deleted Messages ) [5] => Array ( [fullpath] => {imap.daum.net:993/imap/ssl}������Ӹ���h [attributes] => 1 [delimiter] => / [shortpath] => ������Ӹ���h ) )
Here I need readable format folder list. same like INBOX
Is is possible using IMAP ?
You can iterate the folders in a foreach loop.
use Webklex\PHPIMAP\Folder;
$folders = $client->getFolders();
/** @var Folder $folder */
foreach ($folders as $folder) {
// ...
}
Or if you just want a list of names, you can do the following:
$names = array_map(function(Folder $folder) {
return $folder->name;
}, $folders);
Yes this solution works for Gmail, but in case of Daum.net this solution is not working. Geting unreadable text in folder list.
Below is code and output : foreach($folders as $folder) { echo $folder; }exit;
Result : Inbox Sent Messages Drafts ¤�8Ӹ���h
I need proper readable solution. Have any idea ?
What is ¤�8Ӹ���h supposed to mean?
Actully I did not get that may be spam but not readable
I need that readable Is there any way ?
You could enable debug mode and then see what actually comes back from the server.
$config["options"]["debug"] = true;
$cm = new ClientManager($config);
Nothing comes in error.
Daum.net looks to be a Korean provider. Could it be that the characters are not recognized correctly and are therefore misinterpreted?
In Gmail I have a mailbox, which is only used internally for Gmail. [Gmail]
When I see the logs, the mailbox has the following flags:
<< LIST (\HasChildren \Noselect) "/" "[Gmail]"
Does your mailbox also have a \Noselect flag?
I'm sorry I can't be of more help to you.
I found the method that converts the name of the folder. Maybe this one does not work properly?
https://github.com/Webklex/php-imap/blob/ed93fe43ac3e71ffcc4e9a61d3016f91173d617a/src/Folder.php#L186-L195
What happens if you change it to the following method?
protected function decodeName($name) {
return $name;
}
Yes this is not working properly.
Gives below output : Inbox Sent Messages Drafts ???8?????h
Still not readable
Hi @hiralmmavani , if you dump the entire folder object:
var_dump($folder);
//or
dump($folder);
is the correct name somewhere within?
Have you tried to enable the debug mode? If so is the correct name being transferred from the server?
Best regards,
I may be having a similar issue except I get an Exception from the decodeName method:
iconv(): Wrong encoding, conversion from "UTF7-IMAP" to "UTF-8//IGNORE" is not allowed
I'm connecting to imap.gmail.com. If I change the method to this it works...
class Folder
...
protected function decodeName($name)
{
return mb_convert_encoding($name, "UTF-8");
}
Could this be a setting/config either in the environment or in this package?
Seems to me it can't assume the response from the IMAP server is going to be UTF7-IMAP. I discovered the $name was ASCII. Perhaps it should mb_detect_encoding the $name value first and adjust accordingly?
PHP 8.1.3 iconv (Ubuntu GLIBC 2.31-0ubuntu9.7) 2.31
Hi @hiralmmavani , if you dump the entire folder object:
var_dump($folder); //or dump($folder);is the correct name somewhere within?
Have you tried to enable the debug mode? If so is the correct name being transferred from the server?
Best regards,
No this is still not working : Output : array(6) { [0]=> array(4) { ["fullpath"]=> string(33) "{imap.daum.net:993/imap/ssl}Inbox" ["attributes"]=> int(1) ["delimiter"]=> string(1) "/" ["shortpath"]=> string(5) "Inbox" } [1]=> array(4) { ["fullpath"]=> string(41) "{imap.daum.net:993/imap/ssl}Sent Messages" ["attributes"]=> int(1) ["delimiter"]=> string(1) "/" ["shortpath"]=> string(13) "Sent Messages" } [2]=> array(4) { ["fullpath"]=> string(34) "{imap.daum.net:993/imap/ssl}Drafts" ["attributes"]=> int(1) ["delimiter"]=> string(1) "/" ["shortpath"]=> string(6) "Drafts" } [3]=> array(4) { ["fullpath"]=> string(38) "{imap.daum.net:993/imap/ssl}¤�8Ӹ���h" ["attributes"]=> int(1) ["delimiter"]=> string(1) "/" ["shortpath"]=> string(10) "¤�8Ӹ���h" } [4]=> array(4) { ["fullpath"]=> string(44) "{imap.daum.net:993/imap/ssl}Deleted Messages" ["attributes"]=> int(1) ["delimiter"]=> string(1) "/" ["shortpath"]=> string(16) "Deleted Messages" } [5]=> array(4) { ["fullpath"]=> string(40) "{imap.daum.net:993/imap/ssl}������Ӹ���h" ["attributes"]=> int(1) ["delimiter"]=> string(1) "/" ["shortpath"]=> string(12) "������Ӹ���h" } }
Hi @hiralmavani,
please enable debug mode and provide us with the output. Maybe the server is not sending the mailbox name correctly.
Do you have the possibility to log into the account with an email client and check what �8Ӹ���h stands for?
Hi @gcornelisse, take a look at this issue. Maybe it will help with your error. https://github.com/Webklex/laravel-imap/issues/273
The idea with mb_detect_encoding is very interesting. But what should the function do then if mb_detect_encoding returns false?
Hi @gcornelisse, take a look at this issue. Maybe it will help with your error. Webklex/laravel-imap#273
The idea with
mb_detect_encodingis very interesting. But what should the function do then ifmb_detect_encodingreturnsfalse?
This is also not working : $name = ������Ӹ���h After function user $name = ??????Ӹ???h;
Still not readable folder list