summaryrefslogtreecommitdiff
authorjgf <jgf>2003-12-10 08:59:11 (UTC)
committer jgf <jgf>2003-12-10 08:59:11 (UTC)
commit434db5193380185cc1b6347ff5882ad558f401d4 (patch) (unidiff)
tree0ebffad568e343ebb650dec9ed19699b91eb5961
parent9754061378940cf1d7637262305239deedc732b7 (diff)
downloadopie-434db5193380185cc1b6347ff5882ad558f401d4.zip
opie-434db5193380185cc1b6347ff5882ad558f401d4.tar.gz
opie-434db5193380185cc1b6347ff5882ad558f401d4.tar.bz2
retrieve headers from mailbox
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp41
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h1
-rw-r--r--noncore/net/mail/pop3wrapper.cpp41
-rw-r--r--noncore/net/mail/pop3wrapper.h1
4 files changed, 76 insertions, 8 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 08e97f4..6decb6a 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,74 +1,107 @@
1 1
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include <libetpan/mailpop3.h> 4#include <libetpan/mailpop3.h>
5 5
6POP3wrapper::POP3wrapper( POP3account *a ) 6POP3wrapper::POP3wrapper( POP3account *a )
7{ 7{
8 account = a; 8 account = a;
9 m_pop3 = NULL;
9} 10}
10 11
11POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
12{ 13{
13 logout(); 14 logout();
14} 15}
15 16
16void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
17{ 18{
18 qDebug( "POP3: %i of %i", current, maximum ); 19 qDebug( "POP3: %i of %i", current, maximum );
19} 20}
20 21
21void POP3wrapper::listMessages( QList<RecMail> &target ) 22void POP3wrapper::listMessages( QList<RecMail> &target )
22{ 23{
24 int err = MAILPOP3_NO_ERROR;
25 char *header;
26 size_t length;
27 carray *messages;
28
23 login(); 29 login();
24 //TODO: list messages 30 mailpop3_list( m_pop3, &messages );
31
32 for ( int i = carray_count( messages ); i > 0; i-- ) {
33 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
34
35 err = mailpop3_header( m_pop3, info->index, &header, &length );
36 if ( err != MAILPOP3_NO_ERROR ) {
37 qDebug( "POP3: error retrieving header msgid: %i", info->index );
38 logout();
39 return;
40 }
41 RecMail *mail = parseHeader( header );
42 mail->setNumber( info->index );
43 target.append( mail );
44 }
45
25 logout(); 46 logout();
26} 47}
27 48
49RecMail *POP3wrapper::parseHeader( const char *h )
50{
51 RecMail *mail = new RecMail();
52 QString header( h );
53
54 //TODO: parse header - maybe something like this is already implemented in libetpan?
55 mail->setSubject( "Blah blubb" );
56
57 return mail;
58}
59
28void POP3wrapper::login() 60void POP3wrapper::login()
29{ 61{
30 logout(); 62 if ( m_pop3 != NULL ) logout();
63
31 const char *server, *user, *pass; 64 const char *server, *user, *pass;
32 uint16_t port; 65 uint16_t port;
33 int err = MAILPOP3_NO_ERROR; 66 int err = MAILPOP3_NO_ERROR;
34 67
35 server = account->getServer().latin1(); 68 server = account->getServer().latin1();
36 port = account->getPort().toUInt(); 69 port = account->getPort().toUInt();
37 user = account->getUser().latin1(); 70 user = account->getUser().latin1();
38 pass = account->getPassword().latin1(); 71 pass = account->getPassword().latin1();
39 72
40 m_pop3 = mailpop3_new( 20, &pop3_progress ); 73 m_pop3 = mailpop3_new( 200, &pop3_progress );
41 74
42 // connect 75 // connect
43 err = mailpop3_socket_connect( m_pop3, (char *) server, port ); 76 err = mailpop3_socket_connect( m_pop3, (char *) server, port );
44 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
45 qDebug( "pop3: error connecting to %s\n reason: %s", server, 78 qDebug( "pop3: error connecting to %s\n reason: %s", server,
46 m_pop3->response ); 79 m_pop3->response );
47 mailpop3_free( m_pop3 ); 80 mailpop3_free( m_pop3 );
48 m_pop3 = NULL; 81 m_pop3 = NULL;
49 return; 82 return;
50 } 83 }
51 qDebug( "POP3: connected!" ); 84 qDebug( "POP3: connected!" );
52 85
53 // login 86 // login
54 // TODO: decide if apop or plain login should be used 87 // TODO: decide if apop or plain login should be used
55 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 88 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
56 if ( err != MAILPOP3_NO_ERROR ) { 89 if ( err != MAILPOP3_NO_ERROR ) {
57 qDebug( "pop3: error logging in: %s", m_pop3->response ); 90 qDebug( "pop3: error logging in: %s", m_pop3->response );
58 logout(); 91 logout();
59 return; 92 return;
60 } 93 }
61 94
62 qDebug( "POP3: logged in!" ); 95 qDebug( "POP3: logged in!" );
63} 96}
64 97
65void POP3wrapper::logout() 98void POP3wrapper::logout()
66{ 99{
67 int err = MAILPOP3_NO_ERROR; 100 int err = MAILPOP3_NO_ERROR;
68 if ( !m_pop3 ) return; 101 if ( m_pop3 == NULL ) return;
69 err = mailpop3_quit( m_pop3 ); 102 err = mailpop3_quit( m_pop3 );
70 mailpop3_free( m_pop3 ); 103 mailpop3_free( m_pop3 );
71 m_pop3 = NULL; 104 m_pop3 = NULL;
72} 105}
73 106
74 107
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index b791409..f242746 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,28 +1,29 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5 5
6class RecMail; 6class RecMail;
7 7
8class POP3wrapper : public QObject 8class POP3wrapper : public QObject
9{ 9{
10 Q_OBJECT 10 Q_OBJECT
11 11
12public: 12public:
13 POP3wrapper( POP3account *a ); 13 POP3wrapper( POP3account *a );
14 virtual ~POP3wrapper(); 14 virtual ~POP3wrapper();
15 void listMessages( QList<RecMail> &target ); 15 void listMessages( QList<RecMail> &target );
16 static void pop3_progress( size_t current, size_t maximum ); 16 static void pop3_progress( size_t current, size_t maximum );
17 17
18protected: 18protected:
19 void login(); 19 void login();
20 void logout(); 20 void logout();
21 21
22private: 22private:
23 RecMail *parseHeader( const char *header );
23 POP3account *account; 24 POP3account *account;
24 mailpop3 *m_pop3; 25 mailpop3 *m_pop3;
25 26
26}; 27};
27 28
28#endif 29#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 08e97f4..6decb6a 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,74 +1,107 @@
1 1
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include <libetpan/mailpop3.h> 4#include <libetpan/mailpop3.h>
5 5
6POP3wrapper::POP3wrapper( POP3account *a ) 6POP3wrapper::POP3wrapper( POP3account *a )
7{ 7{
8 account = a; 8 account = a;
9 m_pop3 = NULL;
9} 10}
10 11
11POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
12{ 13{
13 logout(); 14 logout();
14} 15}
15 16
16void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
17{ 18{
18 qDebug( "POP3: %i of %i", current, maximum ); 19 qDebug( "POP3: %i of %i", current, maximum );
19} 20}
20 21
21void POP3wrapper::listMessages( QList<RecMail> &target ) 22void POP3wrapper::listMessages( QList<RecMail> &target )
22{ 23{
24 int err = MAILPOP3_NO_ERROR;
25 char *header;
26 size_t length;
27 carray *messages;
28
23 login(); 29 login();
24 //TODO: list messages 30 mailpop3_list( m_pop3, &messages );
31
32 for ( int i = carray_count( messages ); i > 0; i-- ) {
33 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
34
35 err = mailpop3_header( m_pop3, info->index, &header, &length );
36 if ( err != MAILPOP3_NO_ERROR ) {
37 qDebug( "POP3: error retrieving header msgid: %i", info->index );
38 logout();
39 return;
40 }
41 RecMail *mail = parseHeader( header );
42 mail->setNumber( info->index );
43 target.append( mail );
44 }
45
25 logout(); 46 logout();
26} 47}
27 48
49RecMail *POP3wrapper::parseHeader( const char *h )
50{
51 RecMail *mail = new RecMail();
52 QString header( h );
53
54 //TODO: parse header - maybe something like this is already implemented in libetpan?
55 mail->setSubject( "Blah blubb" );
56
57 return mail;
58}
59
28void POP3wrapper::login() 60void POP3wrapper::login()
29{ 61{
30 logout(); 62 if ( m_pop3 != NULL ) logout();
63
31 const char *server, *user, *pass; 64 const char *server, *user, *pass;
32 uint16_t port; 65 uint16_t port;
33 int err = MAILPOP3_NO_ERROR; 66 int err = MAILPOP3_NO_ERROR;
34 67
35 server = account->getServer().latin1(); 68 server = account->getServer().latin1();
36 port = account->getPort().toUInt(); 69 port = account->getPort().toUInt();
37 user = account->getUser().latin1(); 70 user = account->getUser().latin1();
38 pass = account->getPassword().latin1(); 71 pass = account->getPassword().latin1();
39 72
40 m_pop3 = mailpop3_new( 20, &pop3_progress ); 73 m_pop3 = mailpop3_new( 200, &pop3_progress );
41 74
42 // connect 75 // connect
43 err = mailpop3_socket_connect( m_pop3, (char *) server, port ); 76 err = mailpop3_socket_connect( m_pop3, (char *) server, port );
44 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
45 qDebug( "pop3: error connecting to %s\n reason: %s", server, 78 qDebug( "pop3: error connecting to %s\n reason: %s", server,
46 m_pop3->response ); 79 m_pop3->response );
47 mailpop3_free( m_pop3 ); 80 mailpop3_free( m_pop3 );
48 m_pop3 = NULL; 81 m_pop3 = NULL;
49 return; 82 return;
50 } 83 }
51 qDebug( "POP3: connected!" ); 84 qDebug( "POP3: connected!" );
52 85
53 // login 86 // login
54 // TODO: decide if apop or plain login should be used 87 // TODO: decide if apop or plain login should be used
55 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 88 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
56 if ( err != MAILPOP3_NO_ERROR ) { 89 if ( err != MAILPOP3_NO_ERROR ) {
57 qDebug( "pop3: error logging in: %s", m_pop3->response ); 90 qDebug( "pop3: error logging in: %s", m_pop3->response );
58 logout(); 91 logout();
59 return; 92 return;
60 } 93 }
61 94
62 qDebug( "POP3: logged in!" ); 95 qDebug( "POP3: logged in!" );
63} 96}
64 97
65void POP3wrapper::logout() 98void POP3wrapper::logout()
66{ 99{
67 int err = MAILPOP3_NO_ERROR; 100 int err = MAILPOP3_NO_ERROR;
68 if ( !m_pop3 ) return; 101 if ( m_pop3 == NULL ) return;
69 err = mailpop3_quit( m_pop3 ); 102 err = mailpop3_quit( m_pop3 );
70 mailpop3_free( m_pop3 ); 103 mailpop3_free( m_pop3 );
71 m_pop3 = NULL; 104 m_pop3 = NULL;
72} 105}
73 106
74 107
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index b791409..f242746 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -1,28 +1,29 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5 5
6class RecMail; 6class RecMail;
7 7
8class POP3wrapper : public QObject 8class POP3wrapper : public QObject
9{ 9{
10 Q_OBJECT 10 Q_OBJECT
11 11
12public: 12public:
13 POP3wrapper( POP3account *a ); 13 POP3wrapper( POP3account *a );
14 virtual ~POP3wrapper(); 14 virtual ~POP3wrapper();
15 void listMessages( QList<RecMail> &target ); 15 void listMessages( QList<RecMail> &target );
16 static void pop3_progress( size_t current, size_t maximum ); 16 static void pop3_progress( size_t current, size_t maximum );
17 17
18protected: 18protected:
19 void login(); 19 void login();
20 void logout(); 20 void logout();
21 21
22private: 22private:
23 RecMail *parseHeader( const char *header );
23 POP3account *account; 24 POP3account *account;
24 mailpop3 *m_pop3; 25 mailpop3 *m_pop3;
25 26
26}; 27};
27 28
28#endif 29#endif