summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 576804d..9e58303 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,179 +1,179 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include <qpe/global.h> 3#include <qpe/global.h>
4#include <opie2/oapplication.h> 4#include <opie2/oapplication.h>
5#include <opie2/odebug.h> 5#include <opie2/odebug.h>
6 6
7#include "imapwrapper.h" 7#include "imapwrapper.h"
8#include "mailtypes.h" 8#include "mailtypes.h"
9#include "logindialog.h" 9#include "logindialog.h"
10 10
11using namespace Opie::Core; 11using namespace Opie::Core;
12IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 12IMAPwrapper::IMAPwrapper( IMAPaccount *a )
13 : AbstractMail(),MailStatics() 13 : AbstractMail(),MailStatics()
14{ 14{
15 account = a; 15 account = a;
16 m_imap = 0; 16 m_imap = 0;
17 m_Lastmbox = ""; 17 m_Lastmbox = "";
18} 18}
19 19
20IMAPwrapper::~IMAPwrapper() 20IMAPwrapper::~IMAPwrapper()
21{ 21{
22 logout(); 22 logout();
23} 23}
24 24
25/* to avoid to often select statements in loops etc. 25/* to avoid to often select statements in loops etc.
26 we trust that we are logged in and connection is established!*/ 26 we trust that we are logged in and connection is established!*/
27int IMAPwrapper::selectMbox(const QString&mbox) 27int IMAPwrapper::selectMbox(const QString&mbox)
28{ 28{
29 if (mbox == m_Lastmbox) { 29 if (mbox == m_Lastmbox) {
30 return MAILIMAP_NO_ERROR; 30 return MAILIMAP_NO_ERROR;
31 } 31 }
32 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 32 int err = mailimap_select( m_imap, (char*)mbox.latin1());
33 if ( err != MAILIMAP_NO_ERROR ) { 33 if ( err != MAILIMAP_NO_ERROR ) {
34 odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl; 34 odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl;
35 m_Lastmbox = ""; 35 m_Lastmbox = "";
36 return err; 36 return err;
37 } 37 }
38 m_Lastmbox = mbox; 38 m_Lastmbox = mbox;
39 return err; 39 return err;
40} 40}
41 41
42void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 42void IMAPwrapper::imap_progress( size_t current, size_t maximum )
43{ 43{
44 qApp->processEvents(); 44 qApp->processEvents();
45 odebug << "IMAP: " << current << " of " << maximum << "" << oendl; 45 odebug << "IMAP: " << current << " of " << maximum << "" << oendl;
46} 46}
47 47
48bool IMAPwrapper::start_tls(bool force_tls) 48bool IMAPwrapper::start_tls(bool force_tls)
49{ 49{
50 int err; 50 int err;
51 bool try_tls; 51 bool try_tls=false;
52 mailimap_capability_data * cap_data = 0; 52 mailimap_capability_data * cap_data = 0;
53 53
54 err = mailimap_capability(m_imap,&cap_data); 54 err = mailimap_capability(m_imap,&cap_data);
55 if (err != MAILIMAP_NO_ERROR) { 55 if (err != MAILIMAP_NO_ERROR) {
56 Global::statusMessage("error getting capabilities!"); 56 Global::statusMessage("error getting capabilities!");
57 odebug << "error getting capabilities!" << oendl; 57 odebug << "error getting capabilities!" << oendl;
58 return false; 58 return false;
59 } 59 }
60 clistiter * cur; 60 clistiter * cur;
61 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 61 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
62 struct mailimap_capability * cap; 62 struct mailimap_capability * cap;
63 cap = (struct mailimap_capability *)clist_content(cur); 63 cap = (struct mailimap_capability *)clist_content(cur);
64 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 64 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
65 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 65 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
66 try_tls = true; 66 try_tls = true;
67 break; 67 break;
68 } 68 }
69 } 69 }
70 } 70 }
71 if (cap_data) { 71 if (cap_data) {
72 mailimap_capability_data_free(cap_data); 72 mailimap_capability_data_free(cap_data);
73 } 73 }
74 if (try_tls) { 74 if (try_tls) {
75 err = mailimap_starttls(m_imap); 75 err = mailimap_starttls(m_imap);
76 if (err != MAILIMAP_NO_ERROR) { 76 if (err != MAILIMAP_NO_ERROR) {
77 if (force_tls) { 77 if (force_tls) {
78 Global::statusMessage(tr("Server has no TLS support!")); 78 Global::statusMessage(tr("Server has no TLS support!"));
79 odebug << "Server has no TLS support!" << oendl; 79 odebug << "Server has no TLS support!" << oendl;
80 } 80 }
81 try_tls = false; 81 try_tls = false;
82 } else { 82 } else {
83 mailstream_low * low; 83 mailstream_low * low;
84 mailstream_low * new_low; 84 mailstream_low * new_low;
85 low = mailstream_get_low(m_imap->imap_stream); 85 low = mailstream_get_low(m_imap->imap_stream);
86 if (!low) { 86 if (!low) {
87 try_tls = false; 87 try_tls = false;
88 } else { 88 } else {
89 int fd = mailstream_low_get_fd(low); 89 int fd = mailstream_low_get_fd(low);
90 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 90 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
91 mailstream_low_free(low); 91 mailstream_low_free(low);
92 mailstream_set_low(m_imap->imap_stream, new_low); 92 mailstream_set_low(m_imap->imap_stream, new_low);
93 } else { 93 } else {
94 try_tls = false; 94 try_tls = false;
95 } 95 }
96 } 96 }
97 } 97 }
98 } 98 }
99 return try_tls; 99 return try_tls;
100} 100}
101 101
102void IMAPwrapper::login() 102void IMAPwrapper::login()
103{ 103{
104 const char *server, *user, *pass; 104 const char *server, *user, *pass;
105 uint16_t port; 105 uint16_t port;
106 int err = MAILIMAP_NO_ERROR; 106 int err = MAILIMAP_NO_ERROR;
107 107
108 if (account->getOffline()) return; 108 if (account->getOffline()) return;
109 /* we are connected this moment */ 109 /* we are connected this moment */
110 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 110 /* TODO: setup a timer holding the line or if connection closed - delete the value */
111 if (m_imap) { 111 if (m_imap) {
112 err = mailimap_noop(m_imap); 112 err = mailimap_noop(m_imap);
113 if (err!=MAILIMAP_NO_ERROR) { 113 if (err!=MAILIMAP_NO_ERROR) {
114 logout(); 114 logout();
115 } else { 115 } else {
116 mailstream_flush(m_imap->imap_stream); 116 mailstream_flush(m_imap->imap_stream);
117 return; 117 return;
118 } 118 }
119 } 119 }
120 server = account->getServer().latin1(); 120 server = account->getServer().latin1();
121 port = account->getPort().toUInt(); 121 port = account->getPort().toUInt();
122 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 122 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
123 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 123 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
124 login.show(); 124 login.show();
125 if ( QDialog::Accepted == login.exec() ) { 125 if ( QDialog::Accepted == login.exec() ) {
126 // ok 126 // ok
127 user = login.getUser().latin1(); 127 user = login.getUser().latin1();
128 pass = login.getPassword().latin1(); 128 pass = login.getPassword().latin1();
129 } else { 129 } else {
130 // cancel 130 // cancel
131 odebug << "IMAP: Login canceled" << oendl; 131 odebug << "IMAP: Login canceled" << oendl;
132 return; 132 return;
133 } 133 }
134 } else { 134 } else {
135 user = account->getUser().latin1(); 135 user = account->getUser().latin1();
136 pass = account->getPassword().latin1(); 136 pass = account->getPassword().latin1();
137 } 137 }
138 138
139 m_imap = mailimap_new( 20, &imap_progress ); 139 m_imap = mailimap_new( 20, &imap_progress );
140 140
141 /* connect */ 141 /* connect */
142 bool ssl = false; 142 bool ssl = false;
143 bool try_tls = false; 143 bool try_tls = false;
144 bool force_tls = false; 144 bool force_tls = false;
145 145
146 if ( account->ConnectionType() == 2 ) { 146 if ( account->ConnectionType() == 2 ) {
147 ssl = true; 147 ssl = true;
148 } 148 }
149 if (account->ConnectionType()==1) { 149 if (account->ConnectionType()==1) {
150 force_tls = true; 150 force_tls = true;
151 } 151 }
152 152
153 if ( ssl ) { 153 if ( ssl ) {
154 odebug << "using ssl" << oendl; 154 odebug << "using ssl" << oendl;
155 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 155 err = mailimap_ssl_connect( m_imap, (char*)server, port );
156 } else { 156 } else {
157 err = mailimap_socket_connect( m_imap, (char*)server, port ); 157 err = mailimap_socket_connect( m_imap, (char*)server, port );
158 } 158 }
159 159
160 if ( err != MAILIMAP_NO_ERROR && 160 if ( err != MAILIMAP_NO_ERROR &&
161 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 161 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
162 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 162 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
163 QString failure = ""; 163 QString failure = "";
164 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 164 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
165 failure="Connection refused"; 165 failure="Connection refused";
166 } else { 166 } else {
167 failure="Unknown failure"; 167 failure="Unknown failure";
168 } 168 }
169 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 169 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
170 mailimap_free( m_imap ); 170 mailimap_free( m_imap );
171 m_imap = 0; 171 m_imap = 0;
172 return; 172 return;
173 } 173 }
174 174
175 if (!ssl) { 175 if (!ssl) {
176 try_tls = start_tls(force_tls); 176 try_tls = start_tls(force_tls);
177 } 177 }
178 178
179 bool ok = true; 179 bool ok = true;