summaryrefslogtreecommitdiff
authorjgf <jgf>2003-12-18 16:02:47 (UTC)
committer jgf <jgf>2003-12-18 16:02:47 (UTC)
commit5b88f5d05b2f3f5d106b58b07bc7018f757cfc03 (patch) (unidiff)
tree27f8a7ccb9dd659ea8484cb12c0e3dc3c3c99252
parent5cb08b0c69ffc7216405b552e17ff0541578bda0 (diff)
downloadopie-5b88f5d05b2f3f5d106b58b07bc7018f757cfc03.zip
opie-5b88f5d05b2f3f5d106b58b07bc7018f757cfc03.tar.gz
opie-5b88f5d05b2f3f5d106b58b07bc7018f757cfc03.tar.bz2
ask for user/password if field is empty
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp19
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp19
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp20
-rw-r--r--noncore/net/mail/pop3wrapper.cpp20
4 files changed, 70 insertions, 8 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 838300a..cce3d34 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,136 +1,151 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include "logindialog.h"
6#include <libetpan/mailimap.h> 7#include <libetpan/mailimap.h>
7 8
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 10 : AbstractMail()
10{ 11{
11 account = a; 12 account = a;
12 m_imap = 0; 13 m_imap = 0;
13} 14}
14 15
15IMAPwrapper::~IMAPwrapper() 16IMAPwrapper::~IMAPwrapper()
16{ 17{
17 logout(); 18 logout();
18} 19}
19 20
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 21void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 22{
22 qDebug( "IMAP: %i of %i", current, maximum ); 23 qDebug( "IMAP: %i of %i", current, maximum );
23} 24}
24 25
25void IMAPwrapper::login() 26void IMAPwrapper::login()
26{ 27{
27 const char *server, *user, *pass; 28 const char *server, *user, *pass;
28 uint16_t port; 29 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 30 int err = MAILIMAP_NO_ERROR;
30 31
31 /* we are connected this moment */ 32 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 33 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 34 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 35 mailstream_flush(m_imap->imap_stream);
35 return; 36 return;
36 } 37 }
37 server = account->getServer().latin1(); 38 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 39 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 40 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
40 pass = account->getPassword().latin1(); 41 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
42 login.show();
43 if ( QDialog::Accepted == login.exec() ) {
44 // ok
45 user = strdup( login.getUser().latin1() );
46 pass = strdup( login.getPassword().latin1() );
47 } else {
48 // cancel
49 qDebug( "IMAP: Login canceled" );
50 return;
51 }
52 } else {
53 user = account->getUser().latin1();
54 pass = account->getPassword().latin1();
55 }
41 56
42 m_imap = mailimap_new( 20, &imap_progress ); 57 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 58 /* connect */
44 if (account->getSSL()) { 59 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 60 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 61 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 62 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 63 }
49 64
50 if ( err != MAILIMAP_NO_ERROR && 65 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 66 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 67 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 68 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 69 mailimap_free( m_imap );
55 m_imap = 0; 70 m_imap = 0;
56 return; 71 return;
57 } 72 }
58 73
59 /* login */ 74 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 75 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 76 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 77 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 78 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 79 mailimap_free( m_imap );
65 m_imap = 0; 80 m_imap = 0;
66 } 81 }
67} 82}
68 83
69void IMAPwrapper::logout() 84void IMAPwrapper::logout()
70{ 85{
71 int err = MAILIMAP_NO_ERROR; 86 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 87 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 88 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 89 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 90 mailimap_free( m_imap );
76 m_imap = 0; 91 m_imap = 0;
77} 92}
78 93
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 94void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 95{
81 const char *mb; 96 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 97 int err = MAILIMAP_NO_ERROR;
83 clist *result; 98 clist *result;
84 clistcell *current; 99 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 100// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 101 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 102 mailimap_set *set;
88 103
89 mb = mailbox.latin1(); 104 mb = mailbox.latin1();
90 login(); 105 login();
91 if (!m_imap) { 106 if (!m_imap) {
92 return; 107 return;
93 } 108 }
94 /* select mailbox READONLY for operations */ 109 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 110 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 111 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 112 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 113 return;
99 } 114 }
100 115
101 int last = m_imap->imap_selection_info->sel_exists; 116 int last = m_imap->imap_selection_info->sel_exists;
102 117
103 if (last == 0) { 118 if (last == 0) {
104 qDebug("mailbox has no mails"); 119 qDebug("mailbox has no mails");
105 return; 120 return;
106 } 121 }
107 122
108 result = clist_new(); 123 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 124 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 125 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 126 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 127 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 131
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 132 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 133 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 134 mailimap_fetch_type_free( fetchType );
120 135
121 QString date,subject,from; 136 QString date,subject,from;
122 137
123 if ( err == MAILIMAP_NO_ERROR ) { 138 if ( err == MAILIMAP_NO_ERROR ) {
124 139
125 mailimap_msg_att * msg_att; 140 mailimap_msg_att * msg_att;
126 int i = 0; 141 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 142 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 143 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 144 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 145 RecMail*m = parse_list_result(msg_att);
131 if (m) { 146 if (m) {
132 m->setNumber(i); 147 m->setNumber(i);
133 m->setMbox(mailbox); 148 m->setMbox(mailbox);
134 m->setWrapper(this); 149 m->setWrapper(this);
135 target.append(m); 150 target.append(m);
136 } 151 }
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 838300a..cce3d34 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,136 +1,151 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include "logindialog.h"
6#include <libetpan/mailimap.h> 7#include <libetpan/mailimap.h>
7 8
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 10 : AbstractMail()
10{ 11{
11 account = a; 12 account = a;
12 m_imap = 0; 13 m_imap = 0;
13} 14}
14 15
15IMAPwrapper::~IMAPwrapper() 16IMAPwrapper::~IMAPwrapper()
16{ 17{
17 logout(); 18 logout();
18} 19}
19 20
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 21void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 22{
22 qDebug( "IMAP: %i of %i", current, maximum ); 23 qDebug( "IMAP: %i of %i", current, maximum );
23} 24}
24 25
25void IMAPwrapper::login() 26void IMAPwrapper::login()
26{ 27{
27 const char *server, *user, *pass; 28 const char *server, *user, *pass;
28 uint16_t port; 29 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 30 int err = MAILIMAP_NO_ERROR;
30 31
31 /* we are connected this moment */ 32 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 33 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 34 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 35 mailstream_flush(m_imap->imap_stream);
35 return; 36 return;
36 } 37 }
37 server = account->getServer().latin1(); 38 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 39 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 40 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
40 pass = account->getPassword().latin1(); 41 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
42 login.show();
43 if ( QDialog::Accepted == login.exec() ) {
44 // ok
45 user = strdup( login.getUser().latin1() );
46 pass = strdup( login.getPassword().latin1() );
47 } else {
48 // cancel
49 qDebug( "IMAP: Login canceled" );
50 return;
51 }
52 } else {
53 user = account->getUser().latin1();
54 pass = account->getPassword().latin1();
55 }
41 56
42 m_imap = mailimap_new( 20, &imap_progress ); 57 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 58 /* connect */
44 if (account->getSSL()) { 59 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 60 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 61 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 62 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 63 }
49 64
50 if ( err != MAILIMAP_NO_ERROR && 65 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 66 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 67 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 68 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 69 mailimap_free( m_imap );
55 m_imap = 0; 70 m_imap = 0;
56 return; 71 return;
57 } 72 }
58 73
59 /* login */ 74 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 75 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 76 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 77 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 78 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 79 mailimap_free( m_imap );
65 m_imap = 0; 80 m_imap = 0;
66 } 81 }
67} 82}
68 83
69void IMAPwrapper::logout() 84void IMAPwrapper::logout()
70{ 85{
71 int err = MAILIMAP_NO_ERROR; 86 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 87 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 88 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 89 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 90 mailimap_free( m_imap );
76 m_imap = 0; 91 m_imap = 0;
77} 92}
78 93
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 94void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 95{
81 const char *mb; 96 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 97 int err = MAILIMAP_NO_ERROR;
83 clist *result; 98 clist *result;
84 clistcell *current; 99 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 100// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 101 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 102 mailimap_set *set;
88 103
89 mb = mailbox.latin1(); 104 mb = mailbox.latin1();
90 login(); 105 login();
91 if (!m_imap) { 106 if (!m_imap) {
92 return; 107 return;
93 } 108 }
94 /* select mailbox READONLY for operations */ 109 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 110 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 111 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 112 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 113 return;
99 } 114 }
100 115
101 int last = m_imap->imap_selection_info->sel_exists; 116 int last = m_imap->imap_selection_info->sel_exists;
102 117
103 if (last == 0) { 118 if (last == 0) {
104 qDebug("mailbox has no mails"); 119 qDebug("mailbox has no mails");
105 return; 120 return;
106 } 121 }
107 122
108 result = clist_new(); 123 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 124 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 125 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 126 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 127 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 131
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 132 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 133 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 134 mailimap_fetch_type_free( fetchType );
120 135
121 QString date,subject,from; 136 QString date,subject,from;
122 137
123 if ( err == MAILIMAP_NO_ERROR ) { 138 if ( err == MAILIMAP_NO_ERROR ) {
124 139
125 mailimap_msg_att * msg_att; 140 mailimap_msg_att * msg_att;
126 int i = 0; 141 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 142 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 143 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 144 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 145 RecMail*m = parse_list_result(msg_att);
131 if (m) { 146 if (m) {
132 m->setNumber(i); 147 m->setNumber(i);
133 m->setMbox(mailbox); 148 m->setMbox(mailbox);
134 m->setWrapper(this); 149 m->setWrapper(this);
135 target.append(m); 150 target.append(m);
136 } 151 }
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 22a4c70..b0b985c 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,99 +1,100 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h"
4#include <libetpan/mailpop3.h> 5#include <libetpan/mailpop3.h>
5#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
6#include <libetpan/data_message_driver.h> 7#include <libetpan/data_message_driver.h>
7#include <qfile.h> 8#include <qfile.h>
8 9
9/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
10#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
11 12
12POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
13{ 14{
14 account = a; 15 account = a;
15 m_pop3 = NULL; 16 m_pop3 = NULL;
16 msgTempName = a->getFileName()+"_msg_cache"; 17 msgTempName = a->getFileName()+"_msg_cache";
17 last_msg_id = 0; 18 last_msg_id = 0;
18} 19}
19 20
20POP3wrapper::~POP3wrapper() 21POP3wrapper::~POP3wrapper()
21{ 22{
22 logout(); 23 logout();
23 QFile msg_cache(msgTempName); 24 QFile msg_cache(msgTempName);
24 if (msg_cache.exists()) { 25 if (msg_cache.exists()) {
25 msg_cache.remove(); 26 msg_cache.remove();
26 } 27 }
27} 28}
28 29
29void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 30void POP3wrapper::pop3_progress( size_t current, size_t maximum )
30{ 31{
31 //qDebug( "POP3: %i of %i", current, maximum ); 32 //qDebug( "POP3: %i of %i", current, maximum );
32} 33}
33 34
34RecBody POP3wrapper::fetchBody( const RecMail &mail ) 35RecBody POP3wrapper::fetchBody( const RecMail &mail )
35{ 36{
36 int err = MAILPOP3_NO_ERROR; 37 int err = MAILPOP3_NO_ERROR;
37 char *message; 38 char *message;
38 size_t length = 0; 39 size_t length = 0;
39 40
40 login(); 41 login();
41 if ( !m_pop3 ) { 42 if ( !m_pop3 ) {
42 return RecBody(); 43 return RecBody();
43 } 44 }
44 45
45 RecBody body; 46 RecBody body;
46 47
47 QFile msg_cache(msgTempName); 48 QFile msg_cache(msgTempName);
48 49
49 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
51 return body; 52 return body;
52 } 53 }
53 if (mail.getNumber()!=last_msg_id) { 54 if (mail.getNumber()!=last_msg_id) {
54 if (msg_cache.exists()) { 55 if (msg_cache.exists()) {
55 msg_cache.remove(); 56 msg_cache.remove();
56 } 57 }
57 msg_cache.open(IO_ReadWrite|IO_Truncate); 58 msg_cache.open(IO_ReadWrite|IO_Truncate);
58 last_msg_id = mail.getNumber(); 59 last_msg_id = mail.getNumber();
59 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 60 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
60 if ( err != MAILPOP3_NO_ERROR ) { 61 if ( err != MAILPOP3_NO_ERROR ) {
61 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 62 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
62 last_msg_id = 0; 63 last_msg_id = 0;
63 return RecBody(); 64 return RecBody();
64 } 65 }
65 msg_cache.writeBlock(message,length); 66 msg_cache.writeBlock(message,length);
66 } else { 67 } else {
67 QString msg=""; 68 QString msg="";
68 msg_cache.open(IO_ReadOnly); 69 msg_cache.open(IO_ReadOnly);
69 message = new char[4096]; 70 message = new char[4096];
70 memset(message,0,4096); 71 memset(message,0,4096);
71 while (msg_cache.readBlock(message,4095)>0) { 72 while (msg_cache.readBlock(message,4095)>0) {
72 msg+=message; 73 msg+=message;
73 memset(message,0,4096); 74 memset(message,0,4096);
74 } 75 }
75 delete message; 76 delete message;
76 message = (char*)malloc(msg.length()+1*sizeof(char)); 77 message = (char*)malloc(msg.length()+1*sizeof(char));
77 memset(message,0,msg.length()+1); 78 memset(message,0,msg.length()+1);
78 memcpy(message,msg.latin1(),msg.length()); 79 memcpy(message,msg.latin1(),msg.length());
79 } 80 }
80 body = parseMail(message); 81 body = parseMail(message);
81 free(message); 82 free(message);
82 return body; 83 return body;
83} 84}
84 85
85RecBody POP3wrapper::parseMail( char *message ) 86RecBody POP3wrapper::parseMail( char *message )
86{ 87{
87 int err = MAILIMF_NO_ERROR; 88 int err = MAILIMF_NO_ERROR;
88 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 89 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
89 size_t curTok = 0; 90 size_t curTok = 0;
90 mailimf_message *result = 0; 91 mailimf_message *result = 0;
91 mailmessage * msg=0; 92 mailmessage * msg=0;
92 struct mailmime * mime=0; 93 struct mailmime * mime=0;
93 struct mailmime_single_fields fields; 94 struct mailmime_single_fields fields;
94 95
95 RecBody body; 96 RecBody body;
96 97
97 98
98 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 99 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
99 if ( err != MAILIMF_NO_ERROR ) { 100 if ( err != MAILIMF_NO_ERROR ) {
@@ -264,179 +265,194 @@ QString POP3wrapper::parseDateTime( mailimf_date_time *date )
264 return QString( tmp ); 265 return QString( tmp );
265} 266}
266 267
267QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 268QString POP3wrapper::parseAddressList( mailimf_address_list *list )
268{ 269{
269 QString result( "" ); 270 QString result( "" );
270 271
271 bool first = true; 272 bool first = true;
272 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 273 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
273 mailimf_address *addr = (mailimf_address *) current->data; 274 mailimf_address *addr = (mailimf_address *) current->data;
274 275
275 if ( !first ) { 276 if ( !first ) {
276 result.append( "," ); 277 result.append( "," );
277 } else { 278 } else {
278 first = false; 279 first = false;
279 } 280 }
280 281
281 switch ( addr->ad_type ) { 282 switch ( addr->ad_type ) {
282 case MAILIMF_ADDRESS_MAILBOX: 283 case MAILIMF_ADDRESS_MAILBOX:
283 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 284 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
284 break; 285 break;
285 case MAILIMF_ADDRESS_GROUP: 286 case MAILIMF_ADDRESS_GROUP:
286 result.append( parseGroup( addr->ad_data.ad_group ) ); 287 result.append( parseGroup( addr->ad_data.ad_group ) );
287 break; 288 break;
288 default: 289 default:
289 qDebug( "POP3: unkown mailimf address type" ); 290 qDebug( "POP3: unkown mailimf address type" );
290 break; 291 break;
291 } 292 }
292 } 293 }
293 294
294 return result; 295 return result;
295} 296}
296 297
297QString POP3wrapper::parseGroup( mailimf_group *group ) 298QString POP3wrapper::parseGroup( mailimf_group *group )
298{ 299{
299 QString result( "" ); 300 QString result( "" );
300 301
301 result.append( group->grp_display_name ); 302 result.append( group->grp_display_name );
302 result.append( ": " ); 303 result.append( ": " );
303 304
304 if ( group->grp_mb_list != NULL ) { 305 if ( group->grp_mb_list != NULL ) {
305 result.append( parseMailboxList( group->grp_mb_list ) ); 306 result.append( parseMailboxList( group->grp_mb_list ) );
306 } 307 }
307 308
308 result.append( ";" ); 309 result.append( ";" );
309 310
310 return result; 311 return result;
311} 312}
312 313
313QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 314QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
314{ 315{
315 QString result( "" ); 316 QString result( "" );
316 317
317 if ( box->mb_display_name == NULL ) { 318 if ( box->mb_display_name == NULL ) {
318 result.append( box->mb_addr_spec ); 319 result.append( box->mb_addr_spec );
319 } else { 320 } else {
320 result.append( convert_String(box->mb_display_name).latin1() ); 321 result.append( convert_String(box->mb_display_name).latin1() );
321 result.append( " <" ); 322 result.append( " <" );
322 result.append( box->mb_addr_spec ); 323 result.append( box->mb_addr_spec );
323 result.append( ">" ); 324 result.append( ">" );
324 } 325 }
325 326
326 return result; 327 return result;
327} 328}
328 329
329QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 330QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
330{ 331{
331 QString result( "" ); 332 QString result( "" );
332 333
333 bool first = true; 334 bool first = true;
334 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 335 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
335 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 336 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
336 337
337 if ( !first ) { 338 if ( !first ) {
338 result.append( "," ); 339 result.append( "," );
339 } else { 340 } else {
340 first = false; 341 first = false;
341 } 342 }
342 343
343 result.append( parseMailbox( box ) ); 344 result.append( parseMailbox( box ) );
344 } 345 }
345 346
346 return result; 347 return result;
347} 348}
348 349
349void POP3wrapper::login() 350void POP3wrapper::login()
350{ 351{
351 /* we'll hold the line */ 352 /* we'll hold the line */
352 if ( m_pop3 != NULL ) return; 353 if ( m_pop3 != NULL ) return;
353 354
354 const char *server, *user, *pass; 355 const char *server, *user, *pass;
355 uint16_t port; 356 uint16_t port;
356 int err = MAILPOP3_NO_ERROR; 357 int err = MAILPOP3_NO_ERROR;
357 358
358 server = account->getServer().latin1(); 359 server = account->getServer().latin1();
359 port = account->getPort().toUInt(); 360 port = account->getPort().toUInt();
360 user = account->getUser().latin1(); 361
361 pass = account->getPassword().latin1(); 362 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
363 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
364 login.show();
365 if ( QDialog::Accepted == login.exec() ) {
366 // ok
367 user = strdup( login.getUser().latin1() );
368 pass = strdup( login.getPassword().latin1() );
369 } else {
370 // cancel
371 qDebug( "POP3: Login canceled" );
372 return;
373 }
374 } else {
375 user = account->getUser().latin1();
376 pass = account->getPassword().latin1();
377 }
362 378
363 m_pop3 = mailpop3_new( 200, &pop3_progress ); 379 m_pop3 = mailpop3_new( 200, &pop3_progress );
364 380
365 // connect 381 // connect
366 if (account->getSSL()) { 382 if (account->getSSL()) {
367 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 383 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
368 } else { 384 } else {
369 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 385 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
370 } 386 }
371 387
372 if ( err != MAILPOP3_NO_ERROR ) { 388 if ( err != MAILPOP3_NO_ERROR ) {
373 qDebug( "pop3: error connecting to %s\n reason: %s", server, 389 qDebug( "pop3: error connecting to %s\n reason: %s", server,
374 m_pop3->pop3_response ); 390 m_pop3->pop3_response );
375 mailpop3_free( m_pop3 ); 391 mailpop3_free( m_pop3 );
376 m_pop3 = NULL; 392 m_pop3 = NULL;
377 return; 393 return;
378 } 394 }
379 qDebug( "POP3: connected!" ); 395 qDebug( "POP3: connected!" );
380 396
381 // login 397 // login
382 // TODO: decide if apop or plain login should be used 398 // TODO: decide if apop or plain login should be used
383 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 399 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
384 if ( err != MAILPOP3_NO_ERROR ) { 400 if ( err != MAILPOP3_NO_ERROR ) {
385 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 401 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
386 logout(); 402 logout();
387 return; 403 return;
388 } 404 }
389 405
390 qDebug( "POP3: logged in!" ); 406 qDebug( "POP3: logged in!" );
391} 407}
392 408
393void POP3wrapper::logout() 409void POP3wrapper::logout()
394{ 410{
395 int err = MAILPOP3_NO_ERROR; 411 int err = MAILPOP3_NO_ERROR;
396 if ( m_pop3 == NULL ) return; 412 if ( m_pop3 == NULL ) return;
397 err = mailpop3_quit( m_pop3 ); 413 err = mailpop3_quit( m_pop3 );
398 mailpop3_free( m_pop3 ); 414 mailpop3_free( m_pop3 );
399 m_pop3 = NULL; 415 m_pop3 = NULL;
400} 416}
401 417
402 418
403QList<Folder>* POP3wrapper::listFolders() 419QList<Folder>* POP3wrapper::listFolders()
404{ 420{
405 /* TODO: integrate MH directories 421 /* TODO: integrate MH directories
406 but not before version 0.1 ;) 422 but not before version 0.1 ;)
407 */ 423 */
408 QList<Folder> * folders = new QList<Folder>(); 424 QList<Folder> * folders = new QList<Folder>();
409 folders->setAutoDelete( false ); 425 folders->setAutoDelete( false );
410 Folder*inb=new Folder("INBOX","/"); 426 Folder*inb=new Folder("INBOX","/");
411 folders->append(inb); 427 folders->append(inb);
412 return folders; 428 return folders;
413} 429}
414 430
415QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) 431QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
416{ 432{
417 return ""; 433 return "";
418} 434}
419 435
420void POP3wrapper::deleteMail(const RecMail&mail) 436void POP3wrapper::deleteMail(const RecMail&mail)
421{ 437{
422 login(); 438 login();
423 if (!m_pop3) return; 439 if (!m_pop3) return;
424 int err = mailpop3_dele(m_pop3,mail.getNumber()); 440 int err = mailpop3_dele(m_pop3,mail.getNumber());
425 if (err != MAILPOP3_NO_ERROR) { 441 if (err != MAILPOP3_NO_ERROR) {
426 qDebug("error deleting mail"); 442 qDebug("error deleting mail");
427 } 443 }
428} 444}
429 445
430void POP3wrapper::answeredMail(const RecMail&) 446void POP3wrapper::answeredMail(const RecMail&)
431{ 447{
432} 448}
433 449
434encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) 450encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
435{ 451{
436 return new encodedString(); 452 return new encodedString();
437} 453}
438 454
439encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) 455encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
440{ 456{
441 return new encodedString(); 457 return new encodedString();
442} 458}
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 22a4c70..b0b985c 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,99 +1,100 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h"
4#include <libetpan/mailpop3.h> 5#include <libetpan/mailpop3.h>
5#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
6#include <libetpan/data_message_driver.h> 7#include <libetpan/data_message_driver.h>
7#include <qfile.h> 8#include <qfile.h>
8 9
9/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
10#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
11 12
12POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
13{ 14{
14 account = a; 15 account = a;
15 m_pop3 = NULL; 16 m_pop3 = NULL;
16 msgTempName = a->getFileName()+"_msg_cache"; 17 msgTempName = a->getFileName()+"_msg_cache";
17 last_msg_id = 0; 18 last_msg_id = 0;
18} 19}
19 20
20POP3wrapper::~POP3wrapper() 21POP3wrapper::~POP3wrapper()
21{ 22{
22 logout(); 23 logout();
23 QFile msg_cache(msgTempName); 24 QFile msg_cache(msgTempName);
24 if (msg_cache.exists()) { 25 if (msg_cache.exists()) {
25 msg_cache.remove(); 26 msg_cache.remove();
26 } 27 }
27} 28}
28 29
29void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 30void POP3wrapper::pop3_progress( size_t current, size_t maximum )
30{ 31{
31 //qDebug( "POP3: %i of %i", current, maximum ); 32 //qDebug( "POP3: %i of %i", current, maximum );
32} 33}
33 34
34RecBody POP3wrapper::fetchBody( const RecMail &mail ) 35RecBody POP3wrapper::fetchBody( const RecMail &mail )
35{ 36{
36 int err = MAILPOP3_NO_ERROR; 37 int err = MAILPOP3_NO_ERROR;
37 char *message; 38 char *message;
38 size_t length = 0; 39 size_t length = 0;
39 40
40 login(); 41 login();
41 if ( !m_pop3 ) { 42 if ( !m_pop3 ) {
42 return RecBody(); 43 return RecBody();
43 } 44 }
44 45
45 RecBody body; 46 RecBody body;
46 47
47 QFile msg_cache(msgTempName); 48 QFile msg_cache(msgTempName);
48 49
49 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
51 return body; 52 return body;
52 } 53 }
53 if (mail.getNumber()!=last_msg_id) { 54 if (mail.getNumber()!=last_msg_id) {
54 if (msg_cache.exists()) { 55 if (msg_cache.exists()) {
55 msg_cache.remove(); 56 msg_cache.remove();
56 } 57 }
57 msg_cache.open(IO_ReadWrite|IO_Truncate); 58 msg_cache.open(IO_ReadWrite|IO_Truncate);
58 last_msg_id = mail.getNumber(); 59 last_msg_id = mail.getNumber();
59 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 60 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
60 if ( err != MAILPOP3_NO_ERROR ) { 61 if ( err != MAILPOP3_NO_ERROR ) {
61 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 62 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
62 last_msg_id = 0; 63 last_msg_id = 0;
63 return RecBody(); 64 return RecBody();
64 } 65 }
65 msg_cache.writeBlock(message,length); 66 msg_cache.writeBlock(message,length);
66 } else { 67 } else {
67 QString msg=""; 68 QString msg="";
68 msg_cache.open(IO_ReadOnly); 69 msg_cache.open(IO_ReadOnly);
69 message = new char[4096]; 70 message = new char[4096];
70 memset(message,0,4096); 71 memset(message,0,4096);
71 while (msg_cache.readBlock(message,4095)>0) { 72 while (msg_cache.readBlock(message,4095)>0) {
72 msg+=message; 73 msg+=message;
73 memset(message,0,4096); 74 memset(message,0,4096);
74 } 75 }
75 delete message; 76 delete message;
76 message = (char*)malloc(msg.length()+1*sizeof(char)); 77 message = (char*)malloc(msg.length()+1*sizeof(char));
77 memset(message,0,msg.length()+1); 78 memset(message,0,msg.length()+1);
78 memcpy(message,msg.latin1(),msg.length()); 79 memcpy(message,msg.latin1(),msg.length());
79 } 80 }
80 body = parseMail(message); 81 body = parseMail(message);
81 free(message); 82 free(message);
82 return body; 83 return body;
83} 84}
84 85
85RecBody POP3wrapper::parseMail( char *message ) 86RecBody POP3wrapper::parseMail( char *message )
86{ 87{
87 int err = MAILIMF_NO_ERROR; 88 int err = MAILIMF_NO_ERROR;
88 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 89 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
89 size_t curTok = 0; 90 size_t curTok = 0;
90 mailimf_message *result = 0; 91 mailimf_message *result = 0;
91 mailmessage * msg=0; 92 mailmessage * msg=0;
92 struct mailmime * mime=0; 93 struct mailmime * mime=0;
93 struct mailmime_single_fields fields; 94 struct mailmime_single_fields fields;
94 95
95 RecBody body; 96 RecBody body;
96 97
97 98
98 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 99 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
99 if ( err != MAILIMF_NO_ERROR ) { 100 if ( err != MAILIMF_NO_ERROR ) {
@@ -264,179 +265,194 @@ QString POP3wrapper::parseDateTime( mailimf_date_time *date )
264 return QString( tmp ); 265 return QString( tmp );
265} 266}
266 267
267QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 268QString POP3wrapper::parseAddressList( mailimf_address_list *list )
268{ 269{
269 QString result( "" ); 270 QString result( "" );
270 271
271 bool first = true; 272 bool first = true;
272 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 273 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
273 mailimf_address *addr = (mailimf_address *) current->data; 274 mailimf_address *addr = (mailimf_address *) current->data;
274 275
275 if ( !first ) { 276 if ( !first ) {
276 result.append( "," ); 277 result.append( "," );
277 } else { 278 } else {
278 first = false; 279 first = false;
279 } 280 }
280 281
281 switch ( addr->ad_type ) { 282 switch ( addr->ad_type ) {
282 case MAILIMF_ADDRESS_MAILBOX: 283 case MAILIMF_ADDRESS_MAILBOX:
283 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 284 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
284 break; 285 break;
285 case MAILIMF_ADDRESS_GROUP: 286 case MAILIMF_ADDRESS_GROUP:
286 result.append( parseGroup( addr->ad_data.ad_group ) ); 287 result.append( parseGroup( addr->ad_data.ad_group ) );
287 break; 288 break;
288 default: 289 default:
289 qDebug( "POP3: unkown mailimf address type" ); 290 qDebug( "POP3: unkown mailimf address type" );
290 break; 291 break;
291 } 292 }
292 } 293 }
293 294
294 return result; 295 return result;
295} 296}
296 297
297QString POP3wrapper::parseGroup( mailimf_group *group ) 298QString POP3wrapper::parseGroup( mailimf_group *group )
298{ 299{
299 QString result( "" ); 300 QString result( "" );
300 301
301 result.append( group->grp_display_name ); 302 result.append( group->grp_display_name );
302 result.append( ": " ); 303 result.append( ": " );
303 304
304 if ( group->grp_mb_list != NULL ) { 305 if ( group->grp_mb_list != NULL ) {
305 result.append( parseMailboxList( group->grp_mb_list ) ); 306 result.append( parseMailboxList( group->grp_mb_list ) );
306 } 307 }
307 308
308 result.append( ";" ); 309 result.append( ";" );
309 310
310 return result; 311 return result;
311} 312}
312 313
313QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 314QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
314{ 315{
315 QString result( "" ); 316 QString result( "" );
316 317
317 if ( box->mb_display_name == NULL ) { 318 if ( box->mb_display_name == NULL ) {
318 result.append( box->mb_addr_spec ); 319 result.append( box->mb_addr_spec );
319 } else { 320 } else {
320 result.append( convert_String(box->mb_display_name).latin1() ); 321 result.append( convert_String(box->mb_display_name).latin1() );
321 result.append( " <" ); 322 result.append( " <" );
322 result.append( box->mb_addr_spec ); 323 result.append( box->mb_addr_spec );
323 result.append( ">" ); 324 result.append( ">" );
324 } 325 }
325 326
326 return result; 327 return result;
327} 328}
328 329
329QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 330QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
330{ 331{
331 QString result( "" ); 332 QString result( "" );
332 333
333 bool first = true; 334 bool first = true;
334 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 335 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
335 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 336 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
336 337
337 if ( !first ) { 338 if ( !first ) {
338 result.append( "," ); 339 result.append( "," );
339 } else { 340 } else {
340 first = false; 341 first = false;
341 } 342 }
342 343
343 result.append( parseMailbox( box ) ); 344 result.append( parseMailbox( box ) );
344 } 345 }
345 346
346 return result; 347 return result;
347} 348}
348 349
349void POP3wrapper::login() 350void POP3wrapper::login()
350{ 351{
351 /* we'll hold the line */ 352 /* we'll hold the line */
352 if ( m_pop3 != NULL ) return; 353 if ( m_pop3 != NULL ) return;
353 354
354 const char *server, *user, *pass; 355 const char *server, *user, *pass;
355 uint16_t port; 356 uint16_t port;
356 int err = MAILPOP3_NO_ERROR; 357 int err = MAILPOP3_NO_ERROR;
357 358
358 server = account->getServer().latin1(); 359 server = account->getServer().latin1();
359 port = account->getPort().toUInt(); 360 port = account->getPort().toUInt();
360 user = account->getUser().latin1(); 361
361 pass = account->getPassword().latin1(); 362 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
363 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
364 login.show();
365 if ( QDialog::Accepted == login.exec() ) {
366 // ok
367 user = strdup( login.getUser().latin1() );
368 pass = strdup( login.getPassword().latin1() );
369 } else {
370 // cancel
371 qDebug( "POP3: Login canceled" );
372 return;
373 }
374 } else {
375 user = account->getUser().latin1();
376 pass = account->getPassword().latin1();
377 }
362 378
363 m_pop3 = mailpop3_new( 200, &pop3_progress ); 379 m_pop3 = mailpop3_new( 200, &pop3_progress );
364 380
365 // connect 381 // connect
366 if (account->getSSL()) { 382 if (account->getSSL()) {
367 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 383 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
368 } else { 384 } else {
369 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 385 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
370 } 386 }
371 387
372 if ( err != MAILPOP3_NO_ERROR ) { 388 if ( err != MAILPOP3_NO_ERROR ) {
373 qDebug( "pop3: error connecting to %s\n reason: %s", server, 389 qDebug( "pop3: error connecting to %s\n reason: %s", server,
374 m_pop3->pop3_response ); 390 m_pop3->pop3_response );
375 mailpop3_free( m_pop3 ); 391 mailpop3_free( m_pop3 );
376 m_pop3 = NULL; 392 m_pop3 = NULL;
377 return; 393 return;
378 } 394 }
379 qDebug( "POP3: connected!" ); 395 qDebug( "POP3: connected!" );
380 396
381 // login 397 // login
382 // TODO: decide if apop or plain login should be used 398 // TODO: decide if apop or plain login should be used
383 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 399 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
384 if ( err != MAILPOP3_NO_ERROR ) { 400 if ( err != MAILPOP3_NO_ERROR ) {
385 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 401 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
386 logout(); 402 logout();
387 return; 403 return;
388 } 404 }
389 405
390 qDebug( "POP3: logged in!" ); 406 qDebug( "POP3: logged in!" );
391} 407}
392 408
393void POP3wrapper::logout() 409void POP3wrapper::logout()
394{ 410{
395 int err = MAILPOP3_NO_ERROR; 411 int err = MAILPOP3_NO_ERROR;
396 if ( m_pop3 == NULL ) return; 412 if ( m_pop3 == NULL ) return;
397 err = mailpop3_quit( m_pop3 ); 413 err = mailpop3_quit( m_pop3 );
398 mailpop3_free( m_pop3 ); 414 mailpop3_free( m_pop3 );
399 m_pop3 = NULL; 415 m_pop3 = NULL;
400} 416}
401 417
402 418
403QList<Folder>* POP3wrapper::listFolders() 419QList<Folder>* POP3wrapper::listFolders()
404{ 420{
405 /* TODO: integrate MH directories 421 /* TODO: integrate MH directories
406 but not before version 0.1 ;) 422 but not before version 0.1 ;)
407 */ 423 */
408 QList<Folder> * folders = new QList<Folder>(); 424 QList<Folder> * folders = new QList<Folder>();
409 folders->setAutoDelete( false ); 425 folders->setAutoDelete( false );
410 Folder*inb=new Folder("INBOX","/"); 426 Folder*inb=new Folder("INBOX","/");
411 folders->append(inb); 427 folders->append(inb);
412 return folders; 428 return folders;
413} 429}
414 430
415QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) 431QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
416{ 432{
417 return ""; 433 return "";
418} 434}
419 435
420void POP3wrapper::deleteMail(const RecMail&mail) 436void POP3wrapper::deleteMail(const RecMail&mail)
421{ 437{
422 login(); 438 login();
423 if (!m_pop3) return; 439 if (!m_pop3) return;
424 int err = mailpop3_dele(m_pop3,mail.getNumber()); 440 int err = mailpop3_dele(m_pop3,mail.getNumber());
425 if (err != MAILPOP3_NO_ERROR) { 441 if (err != MAILPOP3_NO_ERROR) {
426 qDebug("error deleting mail"); 442 qDebug("error deleting mail");
427 } 443 }
428} 444}
429 445
430void POP3wrapper::answeredMail(const RecMail&) 446void POP3wrapper::answeredMail(const RecMail&)
431{ 447{
432} 448}
433 449
434encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) 450encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
435{ 451{
436 return new encodedString(); 452 return new encodedString();
437} 453}
438 454
439encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) 455encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
440{ 456{
441 return new encodedString(); 457 return new encodedString();
442} 458}