Diffstat (limited to 'noncore/net/mailit/popclient.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mailit/popclient.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp index dc0116d..5da3bcb 100644 --- a/noncore/net/mailit/popclient.cpp +++ b/noncore/net/mailit/popclient.cpp | |||
@@ -54,25 +54,25 @@ void PopClient::newConnection(const QString &target, int port) | |||
54 | { | 54 | { |
55 | if (receiving) { | 55 | if (receiving) { |
56 | qWarning("socket in use, connection refused"); | 56 | qWarning("socket in use, connection refused"); |
57 | return; | 57 | return; |
58 | } | 58 | } |
59 | 59 | ||
60 | status = Init; | 60 | status = Init; |
61 | 61 | ||
62 | socket->connectToHost(target, port); | 62 | socket->connectToHost(target, port); |
63 | receiving = TRUE; | 63 | receiving = TRUE; |
64 | //selected = FALSE; | 64 | //selected = FALSE; |
65 | 65 | ||
66 | emit updateStatus("DNS lookup"); | 66 | emit updateStatus(tr("DNS lookup")); |
67 | } | 67 | } |
68 | 68 | ||
69 | void PopClient::setAccount(const QString &popUser, const QString &popPasswd) | 69 | void PopClient::setAccount(const QString &popUser, const QString &popPasswd) |
70 | { | 70 | { |
71 | popUserName = popUser; | 71 | popUserName = popUser; |
72 | popPassword = popPasswd; | 72 | popPassword = popPasswd; |
73 | } | 73 | } |
74 | 74 | ||
75 | void PopClient::setSynchronize(int lastCount) | 75 | void PopClient::setSynchronize(int lastCount) |
76 | { | 76 | { |
77 | synchronize = TRUE; | 77 | synchronize = TRUE; |
78 | lastSync = lastCount; | 78 | lastSync = lastCount; |
@@ -94,26 +94,30 @@ void PopClient::setSelectedMails(MailList *list) | |||
94 | { | 94 | { |
95 | selected = TRUE; | 95 | selected = TRUE; |
96 | mailList = list; | 96 | mailList = list; |
97 | } | 97 | } |
98 | 98 | ||
99 | void PopClient::connectionEstablished() | 99 | void PopClient::connectionEstablished() |
100 | { | 100 | { |
101 | emit updateStatus(tr("Connection established")); | 101 | emit updateStatus(tr("Connection established")); |
102 | } | 102 | } |
103 | 103 | ||
104 | void PopClient::errorHandling(int status) | 104 | void PopClient::errorHandling(int status) |
105 | { | 105 | { |
106 | errorHandlingWithMsg( status, QString::null ); | ||
107 | } | ||
108 | void PopClient::errorHandlingWithMsg(int status, const QString & Msg ) | ||
109 | { | ||
106 | emit updateStatus(tr("Error Occured")); | 110 | emit updateStatus(tr("Error Occured")); |
107 | emit errorOccurred(status); | 111 | emit errorOccurred(status, Msg); |
108 | socket->close(); | 112 | socket->close(); |
109 | receiving = FALSE; | 113 | receiving = FALSE; |
110 | } | 114 | } |
111 | 115 | ||
112 | void PopClient::incomingData() | 116 | void PopClient::incomingData() |
113 | { | 117 | { |
114 | QString response, temp, temp2, timeStamp; | 118 | QString response, temp, temp2, timeStamp; |
115 | QString md5Source; | 119 | QString md5Source; |
116 | int start, end; | 120 | int start, end; |
117 | // char *md5Digest; | 121 | // char *md5Digest; |
118 | char md5Digest[16]; | 122 | char md5Digest[16]; |
119 | // if ( !socket->canReadLine() ) | 123 | // if ( !socket->canReadLine() ) |
@@ -158,25 +162,25 @@ void PopClient::incomingData() | |||
158 | 162 | ||
159 | case Pass: { | 163 | case Pass: { |
160 | *stream << "PASS " << popPassword << "\r\n"; | 164 | *stream << "PASS " << popPassword << "\r\n"; |
161 | status = Stat; | 165 | status = Stat; |
162 | 166 | ||
163 | break; | 167 | break; |
164 | } | 168 | } |
165 | //ask for number of messages | 169 | //ask for number of messages |
166 | case Stat: { | 170 | case Stat: { |
167 | if (response[0] == '+') { | 171 | if (response[0] == '+') { |
168 | *stream << "STAT" << "\r\n"; | 172 | *stream << "STAT" << "\r\n"; |
169 | status = Mcnt; | 173 | status = Mcnt; |
170 | } else errorHandling(ErrLoginFailed); | 174 | } else errorHandlingWithMsg(ErrLoginFailed, response); |
171 | break; | 175 | break; |
172 | } | 176 | } |
173 | //get count of messages, eg "+OK 4 900.." -> int 4 | 177 | //get count of messages, eg "+OK 4 900.." -> int 4 |
174 | case Mcnt: { | 178 | case Mcnt: { |
175 | if (response[0] == '+') { | 179 | if (response[0] == '+') { |
176 | temp = response.replace(0, 4, ""); | 180 | temp = response.replace(0, 4, ""); |
177 | int x = temp.find(" ", 0); | 181 | int x = temp.find(" ", 0); |
178 | temp.truncate((uint) x); | 182 | temp.truncate((uint) x); |
179 | newMessages = temp.toInt(); | 183 | newMessages = temp.toInt(); |
180 | messageCount = 1; | 184 | messageCount = 1; |
181 | status = List; | 185 | status = List; |
182 | 186 | ||
@@ -186,25 +190,25 @@ void PopClient::incomingData() | |||
186 | lastSync = 0; | 190 | lastSync = 0; |
187 | messageCount = 1; | 191 | messageCount = 1; |
188 | } | 192 | } |
189 | 193 | ||
190 | if (selected) { | 194 | if (selected) { |
191 | int *ptr = mailList->first(); | 195 | int *ptr = mailList->first(); |
192 | if (ptr != 0) { | 196 | if (ptr != 0) { |
193 | newMessages++; //to ensure no early jumpout | 197 | newMessages++; //to ensure no early jumpout |
194 | messageCount = *ptr; | 198 | messageCount = *ptr; |
195 | } else newMessages = 0; | 199 | } else newMessages = 0; |
196 | } | 200 | } |
197 | 201 | ||
198 | } else errorHandling(ErrUnknownResponse); | 202 | } else errorHandlingWithMsg(ErrUnknownResponse, response); |
199 | } | 203 | } |
200 | //Read message number x, count upwards to messageCount | 204 | //Read message number x, count upwards to messageCount |
201 | case List: { | 205 | case List: { |
202 | if (messageCount <= newMessages) { | 206 | if (messageCount <= newMessages) { |
203 | *stream << "LIST " << messageCount << "\r\n"; | 207 | *stream << "LIST " << messageCount << "\r\n"; |
204 | status = Size; | 208 | status = Size; |
205 | temp2.setNum(newMessages - lastSync); | 209 | temp2.setNum(newMessages - lastSync); |
206 | temp.setNum(messageCount - lastSync); | 210 | temp.setNum(messageCount - lastSync); |
207 | if (!selected) { | 211 | if (!selected) { |
208 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 212 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
209 | } else { | 213 | } else { |
210 | //completing a previously closed transfer | 214 | //completing a previously closed transfer |
@@ -225,50 +229,50 @@ void PopClient::incomingData() | |||
225 | case Size: { | 229 | case Size: { |
226 | if (status != Quit) { //because of idiotic switch | 230 | if (status != Quit) { //because of idiotic switch |
227 | if (response[0] == '+') { | 231 | if (response[0] == '+') { |
228 | temp = response.replace(0, 4, ""); | 232 | temp = response.replace(0, 4, ""); |
229 | int x = temp.find(" ", 0); | 233 | int x = temp.find(" ", 0); |
230 | temp = temp.right(temp.length() - ((uint) x + 1) ); | 234 | temp = temp.right(temp.length() - ((uint) x + 1) ); |
231 | mailSize = temp.toInt(); | 235 | mailSize = temp.toInt(); |
232 | emit currentMailSize(mailSize); | 236 | emit currentMailSize(mailSize); |
233 | 237 | ||
234 | status = Retr; | 238 | status = Retr; |
235 | } else { | 239 | } else { |
236 | //qWarning(response); | 240 | //qWarning(response); |
237 | errorHandling(ErrUnknownResponse); | 241 | errorHandlingWithMsg(ErrUnknownResponse, response); |
238 | } | 242 | } |
239 | } | 243 | } |
240 | } | 244 | } |
241 | //Read message number x, count upwards to messageCount | 245 | //Read message number x, count upwards to messageCount |
242 | case Retr: { | 246 | case Retr: { |
243 | if (status != Quit) { | 247 | if (status != Quit) { |
244 | if ((selected)||(mailSize <= headerLimit)) | 248 | if ((selected)||(mailSize <= headerLimit)) |
245 | { | 249 | { |
246 | *stream << "RETR " << messageCount << "\r\n"; | 250 | *stream << "RETR " << messageCount << "\r\n"; |
247 | } else { //only header | 251 | } else { //only header |
248 | *stream << "TOP " << messageCount << " 0\r\n"; | 252 | *stream << "TOP " << messageCount << " 0\r\n"; |
249 | } | 253 | } |
250 | messageCount++; | 254 | messageCount++; |
251 | status = Ignore; | 255 | status = Ignore; |
252 | break; | 256 | break; |
253 | } } | 257 | } } |
254 | case Ignore: { | 258 | case Ignore: { |
255 | if (status != Quit) { //because of idiotic switch | 259 | if (status != Quit) { //because of idiotic switch |
256 | if (response[0] == '+') { | 260 | if (response[0] == '+') { |
257 | message = ""; | 261 | message = ""; |
258 | status = Read; | 262 | status = Read; |
259 | if (!socket->canReadLine()) //sync. problems | 263 | if (!socket->canReadLine()) //sync. problems |
260 | break; | 264 | break; |
261 | response = socket->readLine(); | 265 | response = socket->readLine(); |
262 | } else errorHandling(ErrUnknownResponse); | 266 | } else errorHandlingWithMsg(ErrUnknownResponse, response); |
263 | } | 267 | } |
264 | } | 268 | } |
265 | //add all incoming lines to body. When size is reached, send | 269 | //add all incoming lines to body. When size is reached, send |
266 | //message, and go back to read new message | 270 | //message, and go back to read new message |
267 | case Read: { | 271 | case Read: { |
268 | if (status != Quit) { //because of idiotic switch | 272 | if (status != Quit) { //because of idiotic switch |
269 | message += response; | 273 | message += response; |
270 | while ( socket->canReadLine() ) { | 274 | while ( socket->canReadLine() ) { |
271 | response = socket->readLine(); | 275 | response = socket->readLine(); |
272 | message += response; | 276 | message += response; |
273 | } | 277 | } |
274 | emit downloadedSize(message.length()); | 278 | emit downloadedSize(message.length()); |