]>
git.argeo.org Git - gpl/argeo-slc.git/blob - ext/javax.mail.mbox/src/com/sun/mail/remote/RemoteStore.java
2 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0, which is available at
6 * http://www.eclipse.org/legal/epl-2.0.
8 * This Source Code may also be made available under the following Secondary
9 * Licenses when the conditions for such availability set forth in the
10 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11 * version 2 with the GNU Classpath Exception, which is available at
12 * https://www.gnu.org/software/classpath/license.html.
14 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17 package com
.sun
.mail
.remote
;
21 import com
.sun
.mail
.mbox
.*;
24 * A wrapper around a local <code>MboxStore</code> that fetches data
25 * from the Inbox in a remote store and adds it to our local Inbox.
27 public abstract class RemoteStore
extends MboxStore
{
29 protected Store remoteStore
;
30 protected Folder remoteInbox
;
31 protected Folder inbox
;
32 protected String host
, user
, password
;
34 protected long lastUpdate
= 0;
36 public RemoteStore(Session session
, URLName url
) {
38 remoteStore
= getRemoteStore(session
, url
);
42 * Subclasses override this method to return the appropriate
43 * <code>Store</code> object. This method will be called by
44 * the <code>RemoteStore</code> constructor.
46 protected abstract Store
getRemoteStore(Session session
, URLName url
);
49 * Connect to the store.
51 public void connect(String host
, int port
, String user
, String password
)
52 throws MessagingException
{
56 this.password
= password
;
61 * Fetch any new mail in the remote INBOX and add it to the local INBOX.
63 protected void updateInbox() throws MessagingException
{
64 // is it time to do an update yet?
65 // XXX - polling frequency, rules, etc. should be in properties
66 if (System
.currentTimeMillis() < lastUpdate
+ (5 * 1000))
70 * Connect to the remote store, using the saved
71 * authentication information.
73 remoteStore
.connect(host
, port
, user
, password
);
76 * If this store isn't connected yet, do it now, because
77 * it needs to be connected to get the INBOX folder.
80 super.connect(host
, port
, user
, password
);
81 if (remoteInbox
== null)
82 remoteInbox
= remoteStore
.getFolder("INBOX");
84 inbox
= getFolder("INBOX");
85 remoteInbox
.open(Folder
.READ_WRITE
);
86 Message
[] msgs
= remoteInbox
.getMessages();
87 inbox
.appendMessages(msgs
);
88 remoteInbox
.setFlags(msgs
, new Flags(Flags
.Flag
.DELETED
), true);
89 remoteInbox
.close(true);
91 } catch (MessagingException ex
) {
93 if (remoteInbox
!= null && remoteInbox
.isOpen())
94 remoteInbox
.close(false);
96 if (remoteStore
!= null && remoteStore
.isConnected())
103 public Folder
getDefaultFolder() throws MessagingException
{
106 return new RemoteDefaultFolder(this, null);
109 public Folder
getFolder(String name
) throws MessagingException
{
112 if (name
.equalsIgnoreCase("INBOX"))
113 return new RemoteInbox(this, name
);
115 return super.getFolder(name
);
118 public Folder
getFolder(URLName url
) throws MessagingException
{
120 return getFolder(url
.getFile());
123 private void checkConnected() throws MessagingException
{
125 throw new MessagingException("Not connected");