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