implement basic funktionality of recvnext and async population of rx_queue

master
Gernot Kranz 2 weeks ago
parent 4bf94e504b
commit effcdf4100

@ -10,6 +10,7 @@
#include <sstream>
#include <list> //what for?
#include <memory>
#include <unistd.h> // for sleep(). only works for unixes
pEp::Transport::Config::~Config() {}
@ -73,17 +74,10 @@ namespace pEp {
// and then populate rx_queue via conn_imap.select()
conn_imap = new mailio::imaps(login_imap.server, login_imap.port);
conn_imap->authenticate(login_imap.username, login_imap.passphrase, login_imap.auth_method);
////should be repeated in different thread:
//conn_imap->search( welp, mailio atm doesn't support to search for unread messages only…
//we could try something like:
mailio::imap::mailbox_stat_t inbox_stat = conn_imap->select("inbox");
print_stats(inbox_stat);
if (inbox_stat.messages_first_unseen)
rx_queue.push(inbox_stat.messages_first_unseen);
//but that only gives us one unread email.
//shoouuld we use pop3 instead?
//that differentiates between unread and not-yet-fetched mails.
//or should we abandon mailio and use vmime or mailcore2?
if (!protocol_thread.joinable()) {
protocol_thread_stop.store(false);
protocol_thread = std::thread(&pEpTransportMail::worker, this);
}
}
void pEpTransportMail::shutdown()
@ -235,8 +229,25 @@ namespace pEp {
}
// private
void pEpTransportMail::throwInvalidState()
void pEpTransportMail::throwInvalidState() {}
// private
void pEpTransportMail::worker()
{
mailio::imap::mailbox_stat_t inbox_stat;
while (!protocol_thread_stop.load()) {
//conn_imap->search( welp, mailio atm doesn't support to search for unread messages only…
//we could try something like:
inbox_stat = conn_imap->select("inbox");
print_stats(inbox_stat);
if (inbox_stat.messages_first_unseen)
rx_queue.push(inbox_stat.messages_first_unseen);
//but that only gives us one unread email.
//shoouuld we use pop3 instead?
//that differentiates between unread and not-yet-fetched mails.
//or should we abandon mailio and use vmime or mailcore2?
sleep(60);
}
}
// pEpTox Callbacks-------------------------------------------------------------------------

@ -26,8 +26,6 @@ namespace pEp {
* @brief Transport API
*/
class pEpTransportMail : public Transport {
// friend pEpToxCB;
public:
class ConfigMail : public Config {
public:
@ -83,6 +81,11 @@ namespace pEp {
void print_stats(mailio::imap::mailbox_stat_t);
void print_stats(std::string);
// async stuff
std::thread protocol_thread;
std::atomic<bool> protocol_thread_stop;
void worker();
// The registered callback functions
CBStatusChange cb_statuschange;
CBSendToResult cb_sendto_result;

@ -1,5 +1,6 @@
#include "../src/pEpTransportMail.hh"
#include <pEp/transport.hh>
#include <pEp/transport_status_code.h>
#include <pEp/Adapter.hh>
#include <pEp/utils.hh> //to_string for c-datatypes are here.
#include <pEp/pEpLog.hh>
@ -54,10 +55,18 @@ int main(void)
pEpTransportMail::ConfigMail cfg{ own_ident.get(), lsend, lrecv };
mail.configure(cfg);
mail.startup();
::message* msg = mail.recvnext();
std::cout << "Mail received:" << std::endl;
std::cout << "Subject: " << msg->shortmsg << std::endl;
std::cout << "Body: " << msg->longmsg << std::endl;
while (true) {
try {
::message* msg = mail.recvnext();
std::cout << "Mail received:" << std::endl;
std::cout << "Subject: " << msg->shortmsg << std::endl;
std::cout << "Body: " << msg->longmsg << std::endl;
} catch (pEp::Transport::TransportError e) {
std::cout << "Error executing recvnext: " << e.tsc //::transport_status_code_label(e.tsc)
<< std::endl;
}
sleep(30);
}
mail.shutdown();
}

Loading…
Cancel
Save