karastojko / mailio

mailio is a cross platform C++ library for MIME format and SMTP, POP3 and IMAP protocols. It is based on standard C++ 17 and Boost library.
Other
371 stars 98 forks source link

select folder failed #169

Open shgli opened 1 month ago

shgli commented 1 month ago

我登录了126邮箱,发现select folder报错: Select or examine mailbox failure. 代码如下: int main() { try { imaps conn("imap.126.com", 993); // modify username/password to use real credentials std::cout << 1 << std::endl; conn.authenticate("user@126.com", "xxxx", imaps::auth_method_t::LOGIN); std::cout << 2 << std::endl; imaps::mailbox_folder fld = conn.list_folders(list()); print_folders(0, fld); conn.select("TEST"); std::cout << 3 << std::endl; list messages; list conds; conds.push_back(imaps::search_condition_t(imaps::search_condition_t::ALL)); conn.search(conds, messages, true); std::cout << 4 << std::endl; for_each(messages.begin(), messages.end(), [](unsigned int msg_uid){ cout << msg_uid << endl; }); } catch (imap_error& exc) { cout << exc.what() << endl; } catch (dialog_error& exc) { cout << exc.what() << endl; }

return EXIT_SUCCESS;

}

我在网上搜了一下,发现python模块imapclient在登陆126邮箱之前需要调用client.id_(parameters={"name": "dwn_mail", "version": "1.0"}), 不知道mailio怎么做到

karastojko commented 1 month ago

Hello, what is the name of the folder? Is it in the Latin alphabet?

shgli commented 1 month ago

the folder name is ZT_AFZ, it in Latin alphabet,

karastojko commented 1 month ago

Let me try it with my own test.

karastojko commented 1 month ago

There is nothing wrong with such name. What is the full directory path? I see you are selecting the TEST directory. This message can be thrown in case the directory path is wrong. The 126 provider has only the Chinese version or it can be switched to English?

shgli commented 1 month ago

I changed the folder name from 'ZTAFZ' to 'TEST' when paste.This issue is caused by 126 server, when I using imapclient (a python module) do the same thing, and got a similar error, after search google, the stack overflow told me that I need client.id(parameters={"name": "dwn_mail", "version": "1.0"}) before client.login. so I want do the same thing in mailio

karastojko commented 1 month ago

So, you get the same error with Python?

shgli commented 1 month ago

if no client.id_(parameters={"name": "dwn_mail", "version": "1.0"}), python error: imaplib.error: select failed: SELECT Unsafe Login. Please contact kefu@188.com for help

karastojko commented 1 month ago

Can you please copy here the minimal reproducible example in Python, so I could try it?

shgli commented 1 month ago

import os import sys import email import mimetypes from imapclient import IMAPClient import datetime

if 3 != len(sys.argv): print(f'usage:{os.path.basename(sys.argv[0])} save_pth from_date') sys.exit(0)

save_dir, since_date=sys.argv[1:] user='xx@126.com' password='xx' host='imap.126.com'

since_date = int(since_date) since_year = since_date//10000 since_mon = since_date%10000//100 since_day = since_date%100 since_date = datetime.date(since_year, since_mon, since_day) server = IMAPClient(host, use_uid=True)

server.id_(parameters={"name": "dwn_mail", "version": "1.0"})

server.login(user, password) selected_info = server.select_folder('ZT_AFZ') messages = server.search([b'SINCE', since_date])