(boolean expunge)
| 228 | } |
| 229 | |
| 230 | @Override |
| 231 | public synchronized void close(boolean expunge) throws MessagingException { |
| 232 | checkOpen(); |
| 233 | |
| 234 | try { |
| 235 | /* |
| 236 | * Some POP3 servers will mark messages for deletion when |
| 237 | * they're read. To prevent such messages from being |
| 238 | * deleted before the client deletes them, you can set |
| 239 | * the mail.pop3.rsetbeforequit property to true. This |
| 240 | * causes us to issue a POP3 RSET command to clear all |
| 241 | * the "marked for deletion" flags. We can then explicitly |
| 242 | * delete messages as desired. |
| 243 | */ |
| 244 | if (store.rsetBeforeQuit && !forceClose) |
| 245 | port.rset(); |
| 246 | POP3Message m; |
| 247 | if (expunge && mode == READ_WRITE && !forceClose) { |
| 248 | // find all messages marked deleted and issue DELE commands |
| 249 | for (int i = 0; i < message_cache.length; i++) { |
| 250 | if ((m = message_cache[i]) != null) { |
| 251 | if (m.isSet(Flags.Flag.DELETED)) |
| 252 | try { |
| 253 | port.dele(i + 1); |
| 254 | } catch (IOException ioex) { |
| 255 | throw new MessagingException( |
| 256 | "Exception deleting messages during close", |
| 257 | ioex); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * Flush and free all cached data for the messages. |
| 265 | */ |
| 266 | for (int i = 0; i < message_cache.length; i++) { |
| 267 | if ((m = message_cache[i]) != null) |
| 268 | m.invalidate(true); |
| 269 | } |
| 270 | |
| 271 | if (forceClose) |
| 272 | port.close(); |
| 273 | else |
| 274 | port.quit(); |
| 275 | } catch (IOException ex) { |
| 276 | // do nothing |
| 277 | } finally { |
| 278 | port = null; |
| 279 | store.closePort(this); |
| 280 | message_cache = null; |
| 281 | opened = false; |
| 282 | notifyConnectionListeners(ConnectionEvent.CLOSED); |
| 283 | if (fileCache != null) { |
| 284 | fileCache.close(); |
| 285 | fileCache = null; |
| 286 | } |
| 287 | } |
no test coverage detected