Skip to content

Package: OlderTerm

OlderTerm

nameinstructionbranchcomplexitylinemethod
OlderTerm(int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 15 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getInterval()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hashCode()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
match(Message)
M: 26 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 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.imap;
18:
19: import java.util.Date;
20: import jakarta.mail.Message;
21: import jakarta.mail.search.SearchTerm;
22:
23: /**
24: * Find messages that are older than a given interval (in seconds).
25: * Relies on the server implementing the WITHIN search extension
26: * (<A HREF="http://www.ietf.org/rfc/rfc5032.txt">RFC 5032</A>).
27: *
28: * @since        JavaMail 1.5.1
29: * @author        Bill Shannon
30: */
31: public final class OlderTerm extends SearchTerm {
32:
33: private int interval;
34:
35: private static final long serialVersionUID = 3951078948727995682L;
36:
37: /**
38: * Constructor.
39: *
40: * @param interval        number of seconds older
41: */
42: public OlderTerm(int interval) {
43:         this.interval = interval;
44: }
45:
46: /**
47: * Return the interval.
48: *
49: * @return        the interval
50: */
51: public int getInterval() {
52:         return interval;
53: }
54:
55: /**
56: * The match method.
57: *
58: * @param msg        the date comparator is applied to this Message's
59: *                        received date
60: * @return                true if the comparison succeeds, otherwise false
61: */
62: @Override
63: public boolean match(Message msg) {
64:         Date d;
65:
66:         try {
67:          d = msg.getReceivedDate();
68:         } catch (Exception e) {
69:          return false;
70:         }
71:
72:•        if (d == null)
73:          return false;
74:
75:         return d.getTime() <=
76:•                 System.currentTimeMillis() - ((long)interval * 1000);
77: }
78:
79: /**
80: * Equality comparison.
81: */
82: @Override
83: public boolean equals(Object obj) {
84:•        if (!(obj instanceof OlderTerm))
85:          return false;
86:•        return interval == ((OlderTerm)obj).interval;
87: }
88:
89: /**
90: * Compute a hashCode for this object.
91: */
92: @Override
93: public int hashCode() {
94:         return interval;
95: }
96: }