From 6b45c1f8e0293914c1328f15a665d2ea0fba7b43 Mon Sep 17 00:00:00 2001 From: jgf Date: Tue, 09 Dec 2003 21:36:56 +0000 Subject: POP3 support - first steps --- (limited to 'noncore/net/mail/libmailwrapper/pop3wrapper.cpp') diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp new file mode 100644 index 0000000..08e97f4 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -0,0 +1,74 @@ + +#include "pop3wrapper.h" +#include "mailtypes.h" +#include + +POP3wrapper::POP3wrapper( POP3account *a ) +{ + account = a; +} + +POP3wrapper::~POP3wrapper() +{ + logout(); +} + +void POP3wrapper::pop3_progress( size_t current, size_t maximum ) +{ + qDebug( "POP3: %i of %i", current, maximum ); +} + +void POP3wrapper::listMessages( QList &target ) +{ + login(); + //TODO: list messages + logout(); +} + +void POP3wrapper::login() +{ + logout(); + const char *server, *user, *pass; + uint16_t port; + int err = MAILPOP3_NO_ERROR; + + server = account->getServer().latin1(); + port = account->getPort().toUInt(); + user = account->getUser().latin1(); + pass = account->getPassword().latin1(); + + m_pop3 = mailpop3_new( 20, &pop3_progress ); + + // connect + err = mailpop3_socket_connect( m_pop3, (char *) server, port ); + if ( err != MAILPOP3_NO_ERROR ) { + qDebug( "pop3: error connecting to %s\n reason: %s", server, + m_pop3->response ); + mailpop3_free( m_pop3 ); + m_pop3 = NULL; + return; + } + qDebug( "POP3: connected!" ); + + // login + // TODO: decide if apop or plain login should be used + err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); + if ( err != MAILPOP3_NO_ERROR ) { + qDebug( "pop3: error logging in: %s", m_pop3->response ); + logout(); + return; + } + + qDebug( "POP3: logged in!" ); +} + +void POP3wrapper::logout() +{ + int err = MAILPOP3_NO_ERROR; + if ( !m_pop3 ) return; + err = mailpop3_quit( m_pop3 ); + mailpop3_free( m_pop3 ); + m_pop3 = NULL; +} + + -- cgit v0.9.0.2