Skip to content

Package: DefaultMailFile

DefaultMailFile

nameinstructionbranchcomplexitylinemethod
DefaultMailFile(String)
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%
getFD()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
lock(String)
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
touchlock()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
unlock()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 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: import java.io.FileDescriptor;
21: import java.io.FileNotFoundException;
22: import java.io.IOException;
23: import java.io.RandomAccessFile;
24:
25: public class DefaultMailbox extends Mailbox {
26: private final String home;
27:
28: private static final boolean homeRelative =
29: Boolean.getBoolean("mail.mbox.homerelative");
30:
31: public DefaultMailbox() {
32: home = System.getProperty("user.home");
33: }
34:
35: public MailFile getMailFile(String user, String folder) {
36: return new DefaultMailFile(filename(user, folder));
37: }
38:
39: public String filename(String user, String folder) {
40: try {
41: char c = folder.charAt(0);
42: if (c == File.separatorChar) {
43: return folder;
44: } else if (c == '~') {
45: int i = folder.indexOf(File.separatorChar);
46: String tail = "";
47: if (i > 0) {
48: tail = folder.substring(i);
49: folder = folder.substring(0, i);
50: }
51: return home + tail;
52: } else {
53: if (folder.equalsIgnoreCase("INBOX"))
54: folder = "INBOX";
55: if (homeRelative)
56: return home + File.separator + folder;
57: else
58: return folder;
59: }
60: } catch (StringIndexOutOfBoundsException e) {
61: return folder;
62: }
63: }
64: }
65:
66: class DefaultMailFile extends File implements MailFile {
67: protected transient RandomAccessFile file;
68:
69: private static final long serialVersionUID = 3713116697523761684L;
70:
71: DefaultMailFile(String name) {
72: super(name);
73: }
74:
75: public boolean lock(String mode) {
76: try {
77: file = new RandomAccessFile(this, mode);
78: return true;
79: } catch (FileNotFoundException fe) {
80: return false;
81: } catch (IOException ie) {
82: file = null;
83: return false;
84: }
85: }
86:
87: public void unlock() {
88:• if (file != null) {
89: try {
90: file.close();
91: } catch (IOException e) {
92: // ignore it
93: }
94: file = null;
95: }
96: }
97:
98: public void touchlock() {
99: }
100:
101: public FileDescriptor getFD() {
102:• if (file == null)
103: return null;
104: try {
105: return file.getFD();
106: } catch (IOException e) {
107: return null;
108: }
109: }
110: }