]> git.argeo.org Git - gpl/argeo-slc.git/blob - ext/javax.mail.mbox/src/com/sun/mail/mbox/SolarisMailbox.java
Make logging synchronous during native image build
[gpl/argeo-slc.git] / ext / javax.mail.mbox / src / com / sun / mail / mbox / SolarisMailbox.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.File;
20
21 public class SolarisMailbox extends Mailbox {
22 private final String home;
23 private final String user;
24
25 private static final boolean homeRelative =
26 Boolean.getBoolean("mail.mbox.homerelative");
27
28 public SolarisMailbox() {
29 String h = System.getenv("HOME");
30 if (h == null)
31 h = System.getProperty("user.home");
32 home = h;
33 user = System.getProperty("user.name");
34 }
35
36 public MailFile getMailFile(String user, String folder) {
37 if (folder.equalsIgnoreCase("INBOX"))
38 return new UNIXInbox(user, filename(user, folder));
39 else
40 return new UNIXFolder(filename(user, folder));
41 }
42
43 /**
44 * Given a name of a mailbox folder, expand it to a full path name.
45 */
46 public String filename(String user, String folder) {
47 try {
48 switch (folder.charAt(0)) {
49 case '/':
50 return folder;
51 case '~':
52 int i = folder.indexOf(File.separatorChar);
53 String tail = "";
54 if (i > 0) {
55 tail = folder.substring(i);
56 folder = folder.substring(0, i);
57 }
58 if (folder.length() == 1)
59 return home + tail;
60 else
61 return "/home/" + folder.substring(1) + tail; // XXX
62 default:
63 if (folder.equalsIgnoreCase("INBOX")) {
64 if (user == null) // XXX - should never happen
65 user = this.user;
66 String inbox = System.getenv("MAIL");
67 if (inbox == null)
68 inbox = "/var/mail/" + user;
69 return inbox;
70 } else {
71 if (homeRelative)
72 return home + File.separator + folder;
73 else
74 return folder;
75 }
76 }
77 } catch (StringIndexOutOfBoundsException e) {
78 return folder;
79 }
80 }
81 }