Skip to content

Package: SolarisMailbox

SolarisMailbox

nameinstructionbranchcomplexitylinemethod
SolarisMailbox()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
filename(String, String)
M: 70 C: 0
0%
M: 15 C: 0
0%
M: 9 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
getMailFile(String, String)
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

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 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: /**
29: * Creates a default {@code SolarisMailbox}.
30: *
31: * @throws SecurityException if unable to read the user home or user name.
32: */
33: public SolarisMailbox() {
34:         String h = System.getenv("HOME");
35:•        if (h == null)
36:          h = System.getProperty("user.home");
37:         home = h;
38:         user = System.getProperty("user.name");
39: }
40:
41: public MailFile getMailFile(String user, String folder) {
42:•        if (folder.equalsIgnoreCase("INBOX"))
43:          return new UNIXInbox(user, filename(user, folder));
44:         else
45:          return new UNIXFolder(filename(user, folder));
46: }
47:
48: /**
49: * Given a name of a mailbox folder, expand it to a full path name.
50: */
51: public String filename(String user, String folder) {
52:         try {
53:•         switch (folder.charAt(0)) {
54:          case '/':
55:                 return folder;
56:          case '~':
57:                 int i = folder.indexOf(File.separatorChar);
58:                 String tail = "";
59:•                if (i > 0) {
60:                  tail = folder.substring(i);
61:                  folder = folder.substring(0, i);
62:                 }
63:•                if (folder.length() == 1)
64:                  return home + tail;
65:                 else
66:                  return "/home/" + folder.substring(1) + tail;        // XXX
67:          default:
68:•                if (folder.equalsIgnoreCase("INBOX")) {
69:•                 if (user == null)        // XXX - should never happen
70:                         user = this.user;
71:                  String inbox = System.getenv("MAIL");
72:•                 if (inbox == null)
73:                         inbox = "/var/mail/" + user;
74:                  return inbox;
75:                 } else {
76:•                 if (homeRelative)
77:                         return home + File.separator + folder;
78:                  else
79:                         return folder;
80:                 }
81:          }
82:         } catch (StringIndexOutOfBoundsException e) {
83:          return folder;
84:         }
85: }
86: }