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