summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-12-10 11:44:00 (UTC)
committer harlekin <harlekin>2003-12-10 11:44:00 (UTC)
commit9f974b45ef133d807f8441d84cfebe9b51865499 (patch) (unidiff)
tree85b5f286516f79d425e7769044e0a7b20848d529
parent434db5193380185cc1b6347ff5882ad558f401d4 (diff)
downloadopie-9f974b45ef133d807f8441d84cfebe9b51865499.zip
opie-9f974b45ef133d807f8441d84cfebe9b51865499.tar.gz
opie-9f974b45ef133d807f8441d84cfebe9b51865499.tar.bz2
added ssl connection support for pop3
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp11
-rw-r--r--noncore/net/mail/pop3wrapper.cpp11
2 files changed, 16 insertions, 6 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 6decb6a..1538d50 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,107 +1,112 @@
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 m_pop3 = NULL;
10} 10}
11 11
12POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
13{ 13{
14 logout(); 14 logout();
15} 15}
16 16
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
18{ 18{
19 qDebug( "POP3: %i of %i", current, maximum ); 19 qDebug( "POP3: %i of %i", current, maximum );
20} 20}
21 21
22void POP3wrapper::listMessages( QList<RecMail> &target ) 22void POP3wrapper::listMessages( QList<RecMail> &target )
23{ 23{
24 int err = MAILPOP3_NO_ERROR; 24 int err = MAILPOP3_NO_ERROR;
25 char *header; 25 char *header;
26 size_t length; 26 size_t length;
27 carray *messages; 27 carray *messages;
28 28
29 login(); 29 login();
30 mailpop3_list( m_pop3, &messages ); 30 mailpop3_list( m_pop3, &messages );
31 31
32 for ( int i = carray_count( messages ); i > 0; i-- ) { 32 for ( int i = carray_count( messages ); i > 0; i-- ) {
33 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 33 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
34 34
35 err = mailpop3_header( m_pop3, info->index, &header, &length ); 35 err = mailpop3_header( m_pop3, info->index, &header, &length );
36 if ( err != MAILPOP3_NO_ERROR ) { 36 if ( err != MAILPOP3_NO_ERROR ) {
37 qDebug( "POP3: error retrieving header msgid: %i", info->index ); 37 qDebug( "POP3: error retrieving header msgid: %i", info->index );
38 logout(); 38 logout();
39 return; 39 return;
40 } 40 }
41 RecMail *mail = parseHeader( header ); 41 RecMail *mail = parseHeader( header );
42 mail->setNumber( info->index ); 42 mail->setNumber( info->index );
43 target.append( mail ); 43 target.append( mail );
44 } 44 }
45 45
46 logout(); 46 logout();
47} 47}
48 48
49RecMail *POP3wrapper::parseHeader( const char *h ) 49RecMail *POP3wrapper::parseHeader( const char *h )
50{ 50{
51 RecMail *mail = new RecMail(); 51 RecMail *mail = new RecMail();
52 QString header( h ); 52 QString header( h );
53 53
54 //TODO: parse header - maybe something like this is already implemented in libetpan? 54 //TODO: parse header - maybe something like this is already implemented in libetpan?
55 mail->setSubject( "Blah blubb" ); 55 mail->setSubject( "Blah blubb" );
56 56
57 return mail; 57 return mail;
58} 58}
59 59
60void POP3wrapper::login() 60void POP3wrapper::login()
61{ 61{
62 if ( m_pop3 != NULL ) logout(); 62 if ( m_pop3 != NULL ) logout();
63 63
64 const char *server, *user, *pass; 64 const char *server, *user, *pass;
65 uint16_t port; 65 uint16_t port;
66 int err = MAILPOP3_NO_ERROR; 66 int err = MAILPOP3_NO_ERROR;
67 67
68 server = account->getServer().latin1(); 68 server = account->getServer().latin1();
69 port = account->getPort().toUInt(); 69 port = account->getPort().toUInt();
70 user = account->getUser().latin1(); 70 user = account->getUser().latin1();
71 pass = account->getPassword().latin1(); 71 pass = account->getPassword().latin1();
72 72
73 m_pop3 = mailpop3_new( 200, &pop3_progress ); 73 m_pop3 = mailpop3_new( 200, &pop3_progress );
74 74
75 // connect 75 // connect
76 err = mailpop3_socket_connect( m_pop3, (char *) server, port ); 76 if (account->getSSL()) {
77 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
78 } else {
79 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
80 }
81
77 if ( err != MAILPOP3_NO_ERROR ) { 82 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "pop3: error connecting to %s\n reason: %s", server, 83 qDebug( "pop3: error connecting to %s\n reason: %s", server,
79 m_pop3->response ); 84 m_pop3->response );
80 mailpop3_free( m_pop3 ); 85 mailpop3_free( m_pop3 );
81 m_pop3 = NULL; 86 m_pop3 = NULL;
82 return; 87 return;
83 } 88 }
84 qDebug( "POP3: connected!" ); 89 qDebug( "POP3: connected!" );
85 90
86 // login 91 // login
87 // TODO: decide if apop or plain login should be used 92 // TODO: decide if apop or plain login should be used
88 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 93 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
89 if ( err != MAILPOP3_NO_ERROR ) { 94 if ( err != MAILPOP3_NO_ERROR ) {
90 qDebug( "pop3: error logging in: %s", m_pop3->response ); 95 qDebug( "pop3: error logging in: %s", m_pop3->response );
91 logout(); 96 logout();
92 return; 97 return;
93 } 98 }
94 99
95 qDebug( "POP3: logged in!" ); 100 qDebug( "POP3: logged in!" );
96} 101}
97 102
98void POP3wrapper::logout() 103void POP3wrapper::logout()
99{ 104{
100 int err = MAILPOP3_NO_ERROR; 105 int err = MAILPOP3_NO_ERROR;
101 if ( m_pop3 == NULL ) return; 106 if ( m_pop3 == NULL ) return;
102 err = mailpop3_quit( m_pop3 ); 107 err = mailpop3_quit( m_pop3 );
103 mailpop3_free( m_pop3 ); 108 mailpop3_free( m_pop3 );
104 m_pop3 = NULL; 109 m_pop3 = NULL;
105} 110}
106 111
107 112
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 6decb6a..1538d50 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,107 +1,112 @@
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 m_pop3 = NULL;
10} 10}
11 11
12POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
13{ 13{
14 logout(); 14 logout();
15} 15}
16 16
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
18{ 18{
19 qDebug( "POP3: %i of %i", current, maximum ); 19 qDebug( "POP3: %i of %i", current, maximum );
20} 20}
21 21
22void POP3wrapper::listMessages( QList<RecMail> &target ) 22void POP3wrapper::listMessages( QList<RecMail> &target )
23{ 23{
24 int err = MAILPOP3_NO_ERROR; 24 int err = MAILPOP3_NO_ERROR;
25 char *header; 25 char *header;
26 size_t length; 26 size_t length;
27 carray *messages; 27 carray *messages;
28 28
29 login(); 29 login();
30 mailpop3_list( m_pop3, &messages ); 30 mailpop3_list( m_pop3, &messages );
31 31
32 for ( int i = carray_count( messages ); i > 0; i-- ) { 32 for ( int i = carray_count( messages ); i > 0; i-- ) {
33 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 33 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
34 34
35 err = mailpop3_header( m_pop3, info->index, &header, &length ); 35 err = mailpop3_header( m_pop3, info->index, &header, &length );
36 if ( err != MAILPOP3_NO_ERROR ) { 36 if ( err != MAILPOP3_NO_ERROR ) {
37 qDebug( "POP3: error retrieving header msgid: %i", info->index ); 37 qDebug( "POP3: error retrieving header msgid: %i", info->index );
38 logout(); 38 logout();
39 return; 39 return;
40 } 40 }
41 RecMail *mail = parseHeader( header ); 41 RecMail *mail = parseHeader( header );
42 mail->setNumber( info->index ); 42 mail->setNumber( info->index );
43 target.append( mail ); 43 target.append( mail );
44 } 44 }
45 45
46 logout(); 46 logout();
47} 47}
48 48
49RecMail *POP3wrapper::parseHeader( const char *h ) 49RecMail *POP3wrapper::parseHeader( const char *h )
50{ 50{
51 RecMail *mail = new RecMail(); 51 RecMail *mail = new RecMail();
52 QString header( h ); 52 QString header( h );
53 53
54 //TODO: parse header - maybe something like this is already implemented in libetpan? 54 //TODO: parse header - maybe something like this is already implemented in libetpan?
55 mail->setSubject( "Blah blubb" ); 55 mail->setSubject( "Blah blubb" );
56 56
57 return mail; 57 return mail;
58} 58}
59 59
60void POP3wrapper::login() 60void POP3wrapper::login()
61{ 61{
62 if ( m_pop3 != NULL ) logout(); 62 if ( m_pop3 != NULL ) logout();
63 63
64 const char *server, *user, *pass; 64 const char *server, *user, *pass;
65 uint16_t port; 65 uint16_t port;
66 int err = MAILPOP3_NO_ERROR; 66 int err = MAILPOP3_NO_ERROR;
67 67
68 server = account->getServer().latin1(); 68 server = account->getServer().latin1();
69 port = account->getPort().toUInt(); 69 port = account->getPort().toUInt();
70 user = account->getUser().latin1(); 70 user = account->getUser().latin1();
71 pass = account->getPassword().latin1(); 71 pass = account->getPassword().latin1();
72 72
73 m_pop3 = mailpop3_new( 200, &pop3_progress ); 73 m_pop3 = mailpop3_new( 200, &pop3_progress );
74 74
75 // connect 75 // connect
76 err = mailpop3_socket_connect( m_pop3, (char *) server, port ); 76 if (account->getSSL()) {
77 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
78 } else {
79 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
80 }
81
77 if ( err != MAILPOP3_NO_ERROR ) { 82 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "pop3: error connecting to %s\n reason: %s", server, 83 qDebug( "pop3: error connecting to %s\n reason: %s", server,
79 m_pop3->response ); 84 m_pop3->response );
80 mailpop3_free( m_pop3 ); 85 mailpop3_free( m_pop3 );
81 m_pop3 = NULL; 86 m_pop3 = NULL;
82 return; 87 return;
83 } 88 }
84 qDebug( "POP3: connected!" ); 89 qDebug( "POP3: connected!" );
85 90
86 // login 91 // login
87 // TODO: decide if apop or plain login should be used 92 // TODO: decide if apop or plain login should be used
88 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 93 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
89 if ( err != MAILPOP3_NO_ERROR ) { 94 if ( err != MAILPOP3_NO_ERROR ) {
90 qDebug( "pop3: error logging in: %s", m_pop3->response ); 95 qDebug( "pop3: error logging in: %s", m_pop3->response );
91 logout(); 96 logout();
92 return; 97 return;
93 } 98 }
94 99
95 qDebug( "POP3: logged in!" ); 100 qDebug( "POP3: logged in!" );
96} 101}
97 102
98void POP3wrapper::logout() 103void POP3wrapper::logout()
99{ 104{
100 int err = MAILPOP3_NO_ERROR; 105 int err = MAILPOP3_NO_ERROR;
101 if ( m_pop3 == NULL ) return; 106 if ( m_pop3 == NULL ) return;
102 err = mailpop3_quit( m_pop3 ); 107 err = mailpop3_quit( m_pop3 );
103 mailpop3_free( m_pop3 ); 108 mailpop3_free( m_pop3 );
104 m_pop3 = NULL; 109 m_pop3 = NULL;
105} 110}
106 111
107 112