MCPcopy Create free account
hub / github.com/M66B/FairEmail / toMessageSet

Method toMessageSet

app/src/main/java/com/sun/mail/imap/Utility.java:55–105  ·  view source on GitHub ↗

Run thru the given array of messages, apply the given Condition on each message and generate sets of contiguous sequence-numbers for the successful messages. If a message in the given array is found to be expunged, it is ignored. ASSERT: Since this method uses and returns message sequence numbers,

(Message[] msgs, Condition cond)

Source from the content-addressed store, hash-verified

53 * @return the MessageSet array
54 */
55 public static MessageSet[] toMessageSet(Message[] msgs, Condition cond) {
56 List<MessageSet> v = new ArrayList<>(1);
57 int current, next;
58
59 IMAPMessage msg;
60 for (int i = 0; i < msgs.length; i++) {
61 msg = (IMAPMessage)msgs[i];
62 if (msg.isExpunged()) // expunged message, skip it
63 continue;
64
65 current = msg.getSequenceNumber();
66 // Apply the condition. If it fails, skip it.
67 if ((cond != null) && !cond.test(msg))
68 continue;
69
70 MessageSet set = new MessageSet();
71 set.start = current;
72
73 // Look for contiguous sequence numbers
74 for (++i; i < msgs.length; i++) {
75 // get next message
76 msg = (IMAPMessage)msgs[i];
77
78 if (msg.isExpunged()) // expunged message, skip it
79 continue;
80 next = msg.getSequenceNumber();
81
82 // Does this message match our condition ?
83 if ((cond != null) && !cond.test(msg))
84 continue;
85
86 if (next == current+1)
87 current = next;
88 else { // break in sequence
89 // We need to reexamine this message at the top of
90 // the outer loop, so decrement 'i' to cancel the
91 // outer loop's autoincrement
92 i--;
93 break;
94 }
95 }
96 set.end = current;
97 v.add(set);
98 }
99
100 if (v.isEmpty()) // No valid messages
101 return null;
102 else {
103 return v.toArray(new MessageSet[v.size()]);
104 }
105 }
106 /**
107 * Sort (a copy of) the given array of messages and then
108 * run thru the sorted array of messages, apply the given

Callers 5

copyMessagesMethod · 0.95
doCommandMethod · 0.95
toMessageSetSortedMethod · 0.95
copymoveMessagesMethod · 0.95
copymoveUIDMessagesMethod · 0.95

Calls 7

isExpungedMethod · 0.95
getSequenceNumberMethod · 0.95
toArrayMethod · 0.80
testMethod · 0.65
sizeMethod · 0.65
addMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected