2 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
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.
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.
14 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17 package com
.sun
.mail
.mbox
;
21 public class UNIXInbox
extends UNIXFolder
implements InboxFile
{
22 private final String user
;
24 private static final long serialVersionUID
= 651261842162777620L;
27 * Superclass UNIXFile loads the library containing all the
28 * native code and sets the "loaded" flag if successful.
31 public UNIXInbox(String user
, String name
) {
35 throw new NullPointerException("user name is null in UNIXInbox");
38 public boolean lock(String mode
) {
39 if (lockType
== NATIVE
) {
42 if (!maillock(user
, 5))
45 if (!super.lock(mode
)) {
53 public void unlock() {
59 public void touchlock() {
64 private transient RandomAccessFile lockfile
; // the user's ~/.Maillock file
65 private transient String lockfileName
; // its name
67 public boolean openLock(String mode
) {
70 if (lockfileName
== null) {
71 String home
= System
.getProperty("user.home");
72 lockfileName
= home
+ File
.separator
+ ".Maillock";
75 lockfile
= new RandomAccessFile(lockfileName
, mode
);
83 ret
= UNIXFile
.lock(lockfile
.getFD(), mode
);
86 ret
= lockfile
.getChannel().
87 tryLock(0L, Long
.MAX_VALUE
, !mode
.equals("rw")) != null;
93 } catch (IOException ex
) {
98 public void closeLock() {
103 } catch (IOException ex
) {
109 public boolean equals(Object o
) {
110 if (!(o
instanceof UNIXInbox
))
112 UNIXInbox other
= (UNIXInbox
)o
;
113 return user
.equals(other
.user
) && super.equals(other
);
116 public int hashCode() {
117 return super.hashCode() + user
.hashCode();
120 private native boolean maillock(String user
, int retryCount
);
121 private native void mailunlock();
122 private native void touchlock0();