从 POP3 帐户创建 mimetic::mimeEntity from std::string 电子邮件
Create mimetic::MimeEntity from std::string email from POP3 Account
我目前正在尝试从POP3 Gmail帐户读取一些邮件,我使用libCurl库来完成此任务。我创建了一个 std::list m_mailsInbox,它存储了此帐户中每封电子邮件的索引。
如您所见,我正在使用提到的索引在此列表中获取,并且我阅读了存储在 std::string dataEmail 中的每封邮件。在这个变量中,我有邮件的标头和正文,我需要的是使用模拟库创建一个 MimeEntity 对象。
这是我当前的代码:
void MailServer::ReadMails(char *username,char *password)
{
//fetchs into the list one by one
for(std::list<MailInbox>::iterator it = m_mailsInbox.begin(); it != m_mailsInbox.end(); ++it)
{
struct MemoryStruct chunkMail;
chunkMail.memory = (char*) malloc(1); //it will grow as necessary
chunkMail.size = 0; //there's no data at this point
curl_easy_setopt(handle,CURLOPT_USERNAME,username);
curl_easy_setopt(handle,CURLOPT_PASSWORD,password);
m_popsAccount = "pop3s://pop.gmail.com:995/" + it->index; //creates the URL for the email it->index (i.e: 1)
curl_easy_setopt(handle, CURLOPT_URL, m_popsAccount.c_str());
curl_easy_setopt(handle, CURLOPT_USE_SSL, CURLUSESSL_ALL);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(handle, CURLOPT_HEADER, 1);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)&chunkMail);
//some servers needs this validation
curl_easy_setopt(handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
res = curl_easy_perform(handle);
if(res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %sn",
curl_easy_strerror(res));
}
else //everything was fine
{
printf("%sn",chunkMail.memory); //here is the information of the email
if(ReadMailHeader(chunkMail.memory))
{
std::string dataEmail = chunkMail.memory;
//if returns true, the mail must be saved
MimeEntity mime;
//how i create this object using dataEmail string??
}
}
//frees the data inside
if(chunkMail.memory)
free(chunkMail.memory);
}
}
有什么建议吗?
std::istringstream ss(std::string(chunkMail.memory,m_mailsInbox.at(i).size));
ios_base::sync_with_stdio(false);
//si la funcion retorno true, entonces hay que guardar los datos
MimeEntity me(ss);
这已经足够了!:)
相关文章:
- 如何解决"invalid conversion from 'char' to 'const char*'"
- std::async from std::async in windows xp
- std::is_reference from std::any
- std::time_point from and to std::string
- "No suitable conversion function from 'std::string' to 'const char *' exists"
- std::chrono::time_point from std::string
- Visual accept std::string from std::byte iterator
- C++中链表的错误"Abort signal from abort(3) (sigabrt) "
- dopen():不以 root 身份运行时"failed to map segment from shared object"
- C++ 中的"template <typename From, typename Tag> struct Alias;"是什么?
- from std::vector to adept::avector
- qt get child (Callout) from QChart
- Webassembly from Javascript
- Generate boost::uuids::uuid from boost::compute::detail::sha
- 什么是"Reading unbounded stream from standard input (Memory Management)"的例子
- Calling C++ dll from python
- 为什么我会收到"invalid conversion from 'Queue*/Stack*' to 'int'"错误消息?
- std::chrono 在从 main 或 from 类方法使用时给出不同的值
- Calling Python Script from Visual Studio C++ Solution
- 从 POP3 帐户创建 mimetic::mimeEntity from std::string 电子邮件