Создать mimetic :: MimeEntity из std :: string email от учетной записи POP3

0

В настоящее время я пытаюсь прочитать некоторые сообщения из учетной записи 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 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: %s\n",
                curl_easy_strerror(res));
        }
        else //everything was fine
        {
            printf("%s\n",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);
    }
}

Какие-либо предложения?

  • 0
    Тьфу; ручное управление памятью. tinyurl.com/so-cxxbooks
Теги:
libcurl
pop3

1 ответ

0
                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); 

этого достаточно для этого! :)

Ещё вопросы

Сообщество Overcoder
Наверх
Меню