summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/imapwrapper.cpp
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index 5441a9b..91332c3 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -126,97 +126,97 @@ void IMAPwrapper::login()
126 uint16_t port; 126 uint16_t port;
127 int err = MAILIMAP_NO_ERROR; 127 int err = MAILIMAP_NO_ERROR;
128 128
129 if (account->getOffline()) return; 129 if (account->getOffline()) return;
130 /* we are connected this moment */ 130 /* we are connected this moment */
131 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 131 /* TODO: setup a timer holding the line or if connection closed - delete the value */
132 if (m_imap) { 132 if (m_imap) {
133 err = mailimap_noop(m_imap); 133 err = mailimap_noop(m_imap);
134 if (err!=MAILIMAP_NO_ERROR) { 134 if (err!=MAILIMAP_NO_ERROR) {
135 logout(); 135 logout();
136 } else { 136 } else {
137 mailstream_flush(m_imap->imap_stream); 137 mailstream_flush(m_imap->imap_stream);
138 return; 138 return;
139 } 139 }
140 } 140 }
141 server = account->getServer(); 141 server = account->getServer();
142 port = account->getPort().toUInt(); 142 port = account->getPort().toUInt();
143 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 143 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
144 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 144 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
145 login.show(); 145 login.show();
146 if ( QDialog::Accepted == login.exec() ) { 146 if ( QDialog::Accepted == login.exec() ) {
147 // ok 147 // ok
148 user = login.getUser(); 148 user = login.getUser();
149 pass = login.getPassword(); 149 pass = login.getPassword();
150 } else { 150 } else {
151 // cancel 151 // cancel
152 return; 152 return;
153 } 153 }
154 } else { 154 } else {
155 user = account->getUser(); 155 user = account->getUser();
156 pass = account->getPassword(); 156 pass = account->getPassword();
157 } 157 }
158 158
159 m_imap = mailimap_new( 20, &imap_progress ); 159 m_imap = mailimap_new( 20, &imap_progress );
160 160
161 /* connect */ 161 /* connect */
162 bool ssl = false; 162 bool ssl = false;
163 bool try_tls = false; 163 bool try_tls = false;
164 bool force_tls = false; 164 bool force_tls = false;
165 165
166 if ( account->ConnectionType() == 2 ) { 166 if ( account->ConnectionType() == 2 ) {
167 ssl = true; 167 ssl = true;
168 } 168 }
169 if (account->ConnectionType()==1) { 169 if (account->ConnectionType()==1) {
170 force_tls = true; 170 force_tls = true;
171 } 171 }
172 172
173 if ( ssl ) { 173 if ( ssl ) {
174 qDebug("using ssl "); 174 //qDebug("using ssl ");
175 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 175 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
176 } else { 176 } else {
177 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 177 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
178 } 178 }
179 179
180 if ( err != MAILIMAP_NO_ERROR && 180 if ( err != MAILIMAP_NO_ERROR &&
181 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 181 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
182 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 182 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
183 QString failure = ""; 183 QString failure = "";
184 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 184 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
185 failure="Connection refused"; 185 failure="Connection refused";
186 } else { 186 } else {
187 failure="Unknown failure"; 187 failure="Unknown failure";
188 } 188 }
189 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 189 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
190 mailimap_free( m_imap ); 190 mailimap_free( m_imap );
191 m_imap = 0; 191 m_imap = 0;
192 return; 192 return;
193 } 193 }
194 194
195 if (!ssl) { 195 if (!ssl) {
196 try_tls = start_tls(force_tls); 196 try_tls = start_tls(force_tls);
197 } 197 }
198 198
199 bool ok = true; 199 bool ok = true;
200 if (force_tls && !try_tls) { 200 if (force_tls && !try_tls) {
201 Global::statusMessage(tr("Server has no TLS support!")); 201 Global::statusMessage(tr("Server has no TLS support!"));
202 ok = false; 202 ok = false;
203 } 203 }
204 204
205 205
206 /* login */ 206 /* login */
207 207
208 if (ok) { 208 if (ok) {
209 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 209 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
210 if ( err != MAILIMAP_NO_ERROR ) { 210 if ( err != MAILIMAP_NO_ERROR ) {
211 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 211 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
212 ok = false; 212 ok = false;
213 } 213 }
214 } 214 }
215 if (!ok) { 215 if (!ok) {
216 err = mailimap_close( m_imap ); 216 err = mailimap_close( m_imap );
217 mailimap_free( m_imap ); 217 mailimap_free( m_imap );
218 m_imap = 0; 218 m_imap = 0;
219 } 219 }
220} 220}
221 221
222void IMAPwrapper::logout() 222void IMAPwrapper::logout()
@@ -1202,97 +1202,97 @@ void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1202 case MAILIMAP_STATUS_ATT_UNSEEN: 1202 case MAILIMAP_STATUS_ATT_UNSEEN:
1203 target_stat.message_unseen = status_info->st_value; 1203 target_stat.message_unseen = status_info->st_value;
1204 break; 1204 break;
1205 } 1205 }
1206 } 1206 }
1207 } else { 1207 } else {
1208 // odebug << "Error retrieving status" << oendl; 1208 // odebug << "Error retrieving status" << oendl;
1209 } 1209 }
1210 if (status) mailimap_mailbox_data_status_free(status); 1210 if (status) mailimap_mailbox_data_status_free(status);
1211 if (att_list) mailimap_status_att_list_free(att_list); 1211 if (att_list) mailimap_status_att_list_free(att_list);
1212} 1212}
1213 1213
1214void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1214void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1215{ 1215{
1216 login(); 1216 login();
1217 if (!m_imap) return; 1217 if (!m_imap) return;
1218 if (!msg) return; 1218 if (!msg) return;
1219 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1219 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1220 if (r != MAILIMAP_NO_ERROR) { 1220 if (r != MAILIMAP_NO_ERROR) {
1221 Global::statusMessage("Error storing mail!"); 1221 Global::statusMessage("Error storing mail!");
1222 } 1222 }
1223} 1223}
1224 1224
1225MAILLIB::ATYPE IMAPwrapper::getType()const 1225MAILLIB::ATYPE IMAPwrapper::getType()const
1226{ 1226{
1227 return account->getType(); 1227 return account->getType();
1228} 1228}
1229 1229
1230const QString&IMAPwrapper::getName()const 1230const QString&IMAPwrapper::getName()const
1231{ 1231{
1232 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1232 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1233 return account->getAccountName(); 1233 return account->getAccountName();
1234} 1234}
1235 1235
1236encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1236encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1237{ 1237{
1238 // dummy 1238 // dummy
1239 QValueList<int> path; 1239 QValueList<int> path;
1240 return fetchRawPart(mail,path,false); 1240 return fetchRawPart(mail,path,false);
1241} 1241}
1242 1242
1243void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1243void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1244 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1244 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1245{ 1245{
1246 if (targetWrapper != this || maxSizeInKb > 0 ) { 1246 if (targetWrapper != this || maxSizeInKb > 0 ) {
1247 mMax = 0; 1247 mMax = 0;
1248 progress( tr("Copy")); 1248 progress( tr("Copy"));
1249 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); 1249 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1250 qDebug("IMAPwrapper::mvcpAllMails::Using generic"); 1250 //qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1251 // odebug << "Using generic" << oendl; 1251 // odebug << "Using generic" << oendl;
1252 return; 1252 return;
1253 } 1253 }
1254 mailimap_set *set = 0; 1254 mailimap_set *set = 0;
1255 login(); 1255 login();
1256 if (!m_imap) { 1256 if (!m_imap) {
1257 return; 1257 return;
1258 } 1258 }
1259 int err = selectMbox(fromFolder->getName()); 1259 int err = selectMbox(fromFolder->getName());
1260 if ( err != MAILIMAP_NO_ERROR ) { 1260 if ( err != MAILIMAP_NO_ERROR ) {
1261 return; 1261 return;
1262 } 1262 }
1263 Global::statusMessage( tr("Copying mails on server...") ); 1263 Global::statusMessage( tr("Copying mails on server...") );
1264 int last = m_imap->imap_selection_info->sel_exists; 1264 int last = m_imap->imap_selection_info->sel_exists;
1265 set = mailimap_set_new_interval( 1, last ); 1265 set = mailimap_set_new_interval( 1, last );
1266 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1266 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1267 mailimap_set_free( set ); 1267 mailimap_set_free( set );
1268 if ( err != MAILIMAP_NO_ERROR ) { 1268 if ( err != MAILIMAP_NO_ERROR ) {
1269 QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); 1269 QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response);
1270 Global::statusMessage(error_msg); 1270 Global::statusMessage(error_msg);
1271 // odebug << error_msg << oendl; 1271 // odebug << error_msg << oendl;
1272 return; 1272 return;
1273 } 1273 }
1274 if (moveit) { 1274 if (moveit) {
1275 deleteAllMail(fromFolder); 1275 deleteAllMail(fromFolder);
1276 } 1276 }
1277} 1277}
1278 1278
1279void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1279void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1280{ 1280{
1281 if (targetWrapper != this) { 1281 if (targetWrapper != this) {
1282 // odebug << "Using generic" << oendl; 1282 // odebug << "Using generic" << oendl;
1283 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1283 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1284 return; 1284 return;
1285 } 1285 }
1286 mailimap_set *set = 0; 1286 mailimap_set *set = 0;
1287 login(); 1287 login();
1288 if (!m_imap) { 1288 if (!m_imap) {
1289 return; 1289 return;
1290 } 1290 }
1291 int err = selectMbox(mail->getMbox()); 1291 int err = selectMbox(mail->getMbox());
1292 if ( err != MAILIMAP_NO_ERROR ) { 1292 if ( err != MAILIMAP_NO_ERROR ) {
1293 return; 1293 return;
1294 } 1294 }
1295 set = mailimap_set_new_single(mail->getNumber()); 1295 set = mailimap_set_new_single(mail->getNumber());
1296 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1296 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1297 mailimap_set_free( set ); 1297 mailimap_set_free( set );
1298 if ( err != MAILIMAP_NO_ERROR ) { 1298 if ( err != MAILIMAP_NO_ERROR ) {