summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 8e5212b..576804d 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -28,99 +28,101 @@ int 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;
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 && force_tls) { 76 if (err != MAILIMAP_NO_ERROR) {
77 Global::statusMessage(tr("Server has no TLS support!")); 77 if (force_tls) {
78 odebug << "Server has no TLS support!" << oendl; 78 Global::statusMessage(tr("Server has no TLS support!"));
79 odebug << "Server has no TLS support!" << oendl;
80 }
79 try_tls = false; 81 try_tls = false;
80 } else { 82 } else {
81 mailstream_low * low; 83 mailstream_low * low;
82 mailstream_low * new_low; 84 mailstream_low * new_low;
83 low = mailstream_get_low(m_imap->imap_stream); 85 low = mailstream_get_low(m_imap->imap_stream);
84 if (!low) { 86 if (!low) {
85 try_tls = false; 87 try_tls = false;
86 } else { 88 } else {
87 int fd = mailstream_low_get_fd(low); 89 int fd = mailstream_low_get_fd(low);
88 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 90 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
89 mailstream_low_free(low); 91 mailstream_low_free(low);
90 mailstream_set_low(m_imap->imap_stream, new_low); 92 mailstream_set_low(m_imap->imap_stream, new_low);
91 } else { 93 } else {
92 try_tls = false; 94 try_tls = false;
93 } 95 }
94 } 96 }
95 } 97 }
96 } 98 }
97 return try_tls; 99 return try_tls;
98} 100}
99 101
100void IMAPwrapper::login() 102void IMAPwrapper::login()
101{ 103{
102 const char *server, *user, *pass; 104 const char *server, *user, *pass;
103 uint16_t port; 105 uint16_t port;
104 int err = MAILIMAP_NO_ERROR; 106 int err = MAILIMAP_NO_ERROR;
105 107
106 if (account->getOffline()) return; 108 if (account->getOffline()) return;
107 /* we are connected this moment */ 109 /* we are connected this moment */
108 /* 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 */
109 if (m_imap) { 111 if (m_imap) {
110 err = mailimap_noop(m_imap); 112 err = mailimap_noop(m_imap);
111 if (err!=MAILIMAP_NO_ERROR) { 113 if (err!=MAILIMAP_NO_ERROR) {
112 logout(); 114 logout();
113 } else { 115 } else {
114 mailstream_flush(m_imap->imap_stream); 116 mailstream_flush(m_imap->imap_stream);
115 return; 117 return;
116 } 118 }
117 } 119 }
118 server = account->getServer().latin1(); 120 server = account->getServer().latin1();
119 port = account->getPort().toUInt(); 121 port = account->getPort().toUInt();
120 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 122 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
121 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 123 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
122 login.show(); 124 login.show();
123 if ( QDialog::Accepted == login.exec() ) { 125 if ( QDialog::Accepted == login.exec() ) {
124 // ok 126 // ok
125 user = login.getUser().latin1(); 127 user = login.getUser().latin1();
126 pass = login.getPassword().latin1(); 128 pass = login.getPassword().latin1();
@@ -140,97 +142,97 @@ void IMAPwrapper::login()
140 bool ssl = false; 142 bool ssl = false;
141 bool try_tls = false; 143 bool try_tls = false;
142 bool force_tls = false; 144 bool force_tls = false;
143 145
144 if ( account->ConnectionType() == 2 ) { 146 if ( account->ConnectionType() == 2 ) {
145 ssl = true; 147 ssl = true;
146 } 148 }
147 if (account->ConnectionType()==1) { 149 if (account->ConnectionType()==1) {
148 force_tls = true; 150 force_tls = true;
149 } 151 }
150 152
151 if ( ssl ) { 153 if ( ssl ) {
152 odebug << "using ssl" << oendl; 154 odebug << "using ssl" << oendl;
153 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 155 err = mailimap_ssl_connect( m_imap, (char*)server, port );
154 } else { 156 } else {
155 err = mailimap_socket_connect( m_imap, (char*)server, port ); 157 err = mailimap_socket_connect( m_imap, (char*)server, port );
156 } 158 }
157 159
158 if ( err != MAILIMAP_NO_ERROR && 160 if ( err != MAILIMAP_NO_ERROR &&
159 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 161 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
160 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 162 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
161 QString failure = ""; 163 QString failure = "";
162 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 164 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
163 failure="Connection refused"; 165 failure="Connection refused";
164 } else { 166 } else {
165 failure="Unknown failure"; 167 failure="Unknown failure";
166 } 168 }
167 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 169 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
168 mailimap_free( m_imap ); 170 mailimap_free( m_imap );
169 m_imap = 0; 171 m_imap = 0;
170 return; 172 return;
171 } 173 }
172 174
173 if (!ssl) { 175 if (!ssl) {
174 try_tls = start_tls(force_tls); 176 try_tls = start_tls(force_tls);
175 } 177 }
176 178
177 bool ok = true; 179 bool ok = true;
178 if (force_tls && !try_tls) { 180 if (force_tls && !try_tls) {
179 Global::statusMessage(tr("Server has no TLS support!")); 181 Global::statusMessage(tr("Server has no TLS support!"));
180 odebug << "Server has no TLS support!" << oendl; 182 odebug << "Server has no TLS support!" << oendl;
181 ok = false; 183 ok = false;
182 } 184 }
183 185
184 186
185 /* login */ 187 /* login */
186 188
187 if (ok) { 189 if (ok) {
188 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 190 err = mailimap_login( m_imap, (char*)user, (char*)pass );
189 if ( err != MAILIMAP_NO_ERROR ) { 191 if ( err != MAILIMAP_NO_ERROR ) {
190 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 192 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
191 ok = false; 193 ok = false;
192 } 194 }
193 } 195 }
194 if (!ok) { 196 if (!ok) {
195 err = mailimap_close( m_imap ); 197 err = mailimap_close( m_imap );
196 mailimap_free( m_imap ); 198 mailimap_free( m_imap );
197 m_imap = 0; 199 m_imap = 0;
198 } 200 }
199} 201}
200 202
201void IMAPwrapper::logout() 203void IMAPwrapper::logout()
202{ 204{
203 int err = MAILIMAP_NO_ERROR; 205 int err = MAILIMAP_NO_ERROR;
204 if (!m_imap) return; 206 if (!m_imap) return;
205 err = mailimap_logout( m_imap ); 207 err = mailimap_logout( m_imap );
206 err = mailimap_close( m_imap ); 208 err = mailimap_close( m_imap );
207 mailimap_free( m_imap ); 209 mailimap_free( m_imap );
208 m_imap = 0; 210 m_imap = 0;
209 m_Lastmbox = ""; 211 m_Lastmbox = "";
210} 212}
211 213
212void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) 214void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target )
213{ 215{
214 int err = MAILIMAP_NO_ERROR; 216 int err = MAILIMAP_NO_ERROR;
215 clist *result = 0; 217 clist *result = 0;
216 clistcell *current; 218 clistcell *current;
217 mailimap_fetch_type *fetchType = 0; 219 mailimap_fetch_type *fetchType = 0;
218 mailimap_set *set = 0; 220 mailimap_set *set = 0;
219 221
220 login(); 222 login();
221 if (!m_imap) { 223 if (!m_imap) {
222 return; 224 return;
223 } 225 }
224 /* select mailbox READONLY for operations */ 226 /* select mailbox READONLY for operations */
225 err = selectMbox(mailbox); 227 err = selectMbox(mailbox);
226 if ( err != MAILIMAP_NO_ERROR ) { 228 if ( err != MAILIMAP_NO_ERROR ) {
227 return; 229 return;
228 } 230 }
229 231
230 int last = m_imap->imap_selection_info->sel_exists; 232 int last = m_imap->imap_selection_info->sel_exists;
231 233
232 if (last == 0) { 234 if (last == 0) {
233 Global::statusMessage(tr("Mailbox has no mails")); 235 Global::statusMessage(tr("Mailbox has no mails"));
234 return; 236 return;
235 } else { 237 } else {
236 } 238 }