Package: MboxStore
MboxStore
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MboxStore(Session, URLName) |
|
|
|
|
|
||||||||||||||||||||
checkConnected() |
|
|
|
|
|
||||||||||||||||||||
getDefaultFolder() |
|
|
|
|
|
||||||||||||||||||||
getFolder(String) |
|
|
|
|
|
||||||||||||||||||||
getFolder(URLName) |
|
|
|
|
|
||||||||||||||||||||
getMailFile(String) |
|
|
|
|
|
||||||||||||||||||||
getSession() |
|
|
|
|
|
||||||||||||||||||||
protocolConnect(String, int, String, String) |
|
|
|
|
|
||||||||||||||||||||
setURLName(URLName) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
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.
7: *
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.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.eclipse.angus.mail.mbox;
18:
19: import jakarta.mail.*;
20:
21: public class MboxStore extends Store {
22:
23: String user;
24: String home;
25: Mailbox mb;
26: static Flags permFlags;
27:
28: static {
29:         // we support all flags
30:         permFlags = new Flags();
31:         permFlags.add(Flags.Flag.SEEN);
32:         permFlags.add(Flags.Flag.RECENT);
33:         permFlags.add(Flags.Flag.DELETED);
34:         permFlags.add(Flags.Flag.FLAGGED);
35:         permFlags.add(Flags.Flag.ANSWERED);
36:         permFlags.add(Flags.Flag.DRAFT);
37:         permFlags.add(Flags.Flag.USER);
38: }
39:
40: public MboxStore(Session session, URLName url) {
41:         super(session, url);
42:
43:         // XXX - handle security exception
44:         user = System.getProperty("user.name");
45:         home = System.getProperty("user.home");
46:         String os = System.getProperty("os.name");
47:         try {
48:          String cl = "org.eclipse.angus.mail.mbox." + os + "Mailbox";
49:          mb = (Mailbox)Class.forName(cl).
50:                                         getDeclaredConstructor().newInstance();
51:         } catch (Exception e) {
52:          mb = new DefaultMailbox();
53:         }
54: }
55:
56: /**
57: * Since we do not have any authentication
58: * to do and we do not want a dialog put up asking the user for a
59: * password we always succeed in connecting.
60: * But if we're given a password, that means the user is
61: * doing something wrong so fail the request.
62: */
63: protected boolean protocolConnect(String host, int port, String user,
64:                                 String passwd) throws MessagingException {
65:
66:•        if (passwd != null)
67:          throw new AuthenticationFailedException(
68:                                 "mbox does not allow passwords");
69:         // XXX - should we use the user?
70:         return true;
71: }
72:
73: protected void setURLName(URLName url) {
74:         // host, user, password, and file don't matter so we strip them out
75:•        if (url != null && (url.getUsername() != null ||
76:•                         url.getHost() != null ||
77:•                         url.getFile() != null))
78:          url = new URLName(url.getProtocol(), null, -1, null, null, null);
79:         super.setURLName(url);
80: }
81:
82:
83: public Folder getDefaultFolder() throws MessagingException {
84:         checkConnected();
85:
86:         return new MboxFolder(this, null);
87: }
88:
89: public Folder getFolder(String name) throws MessagingException {
90:         checkConnected();
91:
92:         return new MboxFolder(this, name);
93: }
94:
95: public Folder getFolder(URLName url) throws MessagingException {
96:         checkConnected();
97:         return getFolder(url.getFile());
98: }
99:
100: private void checkConnected() throws MessagingException {
101:•        if (!isConnected())
102:          throw new MessagingException("Not connected");
103: }
104:
105: MailFile getMailFile(String folder) {
106:         return mb.getMailFile(user, folder);
107: }
108:
109: Session getSession() {
110:         return session;
111: }
112: }