use of com.zimbra.cs.imap.AppendMessage.Part in project zm-mailbox by Zimbra.
the class ImapCommandThrottleTest method makeAppendPart.
private Part makeAppendPart(AppendMessage append, int size, byte fillByte) throws IOException {
Literal literal = Literal.newInstance(size);
byte[] bytes = new byte[size];
Arrays.fill(bytes, fillByte);
literal.put(bytes, 0, bytes.length);
return append.new Part(literal);
}
use of com.zimbra.cs.imap.AppendMessage.Part in project zm-mailbox by Zimbra.
the class AppendCommand method hasSameParams.
@Override
protected boolean hasSameParams(ImapCommand command) {
if (this.equals(command)) {
return true;
}
AppendCommand other = (AppendCommand) command;
if (path != null && path.equals(other.path)) {
if (appends != null) {
if (other.appends == null || appends.size() != other.appends.size()) {
return false;
}
// both have appends, both same size
for (int i = 0; i < appends.size(); i++) {
AppendMessage myMsg = appends.get(i);
AppendMessage otherMsg = other.appends.get(i);
if ((myMsg.getDate() != null && !myMsg.getDate().equals(otherMsg.getDate())) || (myMsg.getDate() == null && otherMsg.getDate() != null)) {
return false;
// date mismatch
} else if ((myMsg.getPersistentFlagNames() != null && !myMsg.getPersistentFlagNames().equals(otherMsg.getPersistentFlagNames())) || (myMsg.getPersistentFlagNames() == null && otherMsg.getPersistentFlagNames() != null)) {
return false;
// flag name mismatch
}
List<Part> myParts = myMsg.getParts();
List<Part> otherParts = otherMsg.getParts();
if ((myParts == null && otherParts != null) || (myParts != null && otherParts == null) || (myParts.size() != otherParts.size())) {
return false;
}
for (int j = 0; j < myParts.size(); j++) {
Part myPart = myParts.get(j);
Part otherPart = otherParts.get(j);
if ((myPart.getLiteral() != null && otherPart.getLiteral() != null && myPart.getLiteral().size() != otherPart.getLiteral().size()) || (myPart.getLiteral() == null && otherPart.getLiteral() != null) || (myPart.getLiteral() != null && otherPart.getLiteral() == null)) {
return false;
// just checking literal size here; can't check blob
// content since it is streamed and not kept in heap
// this is good enough for now; if a client is
// flooding with bunches of same-length blobs we'll
// block them
}
if (myPart.getUrl() != null && !myPart.getUrl().equals(otherPart.getUrl()) || (myPart.getUrl() == null && otherPart.getUrl() != null)) {
return false;
}
}
}
// all appends have same size, date, flags; URL
return true;
// same or Literals with same size
} else {
return other.appends != null;
}
} else {
return false;
}
}
use of com.zimbra.cs.imap.AppendMessage.Part in project zm-mailbox by Zimbra.
the class ImapCommandThrottleTest method append.
@Test
public void append() throws IOException {
String path = "testPath";
AppendCommand append = new AppendCommand(new ImapPath(path, null), makeAppends());
Assert.assertTrue("same obj", append.isDuplicate(append));
AppendCommand append2 = new AppendCommand(new ImapPath(path, null), makeAppends());
Assert.assertTrue("diff obj same params", append.isDuplicate(append2));
AppendCommand append3 = new AppendCommand(new ImapPath(path + "foo", null), makeAppends());
Assert.assertFalse("different path", append.isDuplicate(append3));
List<AppendMessage> appends = makeAppends();
appends.remove(0);
AppendCommand append4 = new AppendCommand(new ImapPath(path, null), appends);
Assert.assertFalse("different length appends", append.isDuplicate(append4));
appends = makeAppends();
AppendMessage appendMsg = appends.remove(0);
List<Part> parts = new ArrayList<Part>();
AppendMessage appendMsg2 = new AppendMessage(appendMsg.getPersistentFlagNames(), appendMsg.getDate(), parts);
parts.add(makeAppendPart(appendMsg2, 215, (byte) 215));
appends.add(0, appendMsg2);
AppendCommand append5 = new AppendCommand(new ImapPath(path, null), appends);
Assert.assertFalse("different append parts", append.isDuplicate(append5));
parts = new ArrayList<Part>();
appendMsg2 = new AppendMessage(appendMsg.getPersistentFlagNames(), new Date(), parts);
parts.add(makeAppendPart(appendMsg2, 123, (byte) 99));
appends.remove(0);
appends.add(0, appendMsg2);
AppendCommand append6 = new AppendCommand(new ImapPath(path, null), appends);
Assert.assertFalse("different date", append.isDuplicate(append6));
parts = new ArrayList<Part>();
List<String> flagNames = new ArrayList<String>();
flagNames.add("F1");
flagNames.add("F3");
appendMsg2 = new AppendMessage(flagNames, appendMsg.getDate(), parts);
parts.add(makeAppendPart(appendMsg2, 123, (byte) 99));
appends.remove(0);
appends.add(0, appendMsg2);
AppendCommand append7 = new AppendCommand(new ImapPath(path, null), appends);
Assert.assertFalse("different flag names", append.isDuplicate(append7));
}
use of com.zimbra.cs.imap.AppendMessage.Part in project zm-mailbox by Zimbra.
the class ImapCommandThrottleTest method makeAppends.
private List<AppendMessage> makeAppends() throws IOException {
List<AppendMessage> list = new ArrayList<AppendMessage>();
List<String> flagNames = new ArrayList<String>();
flagNames.add("F1");
flagNames.add("F2");
Date date = new Date(1234567890);
List<Part> parts = new ArrayList<Part>();
AppendMessage append = new AppendMessage(flagNames, date, parts);
parts.add(makeAppendPart(append, 123, (byte) 99));
List<String> flagNames2 = new ArrayList<String>();
flagNames.add("F3");
flagNames.add("F4");
Date date2 = new Date(222222222);
List<Part> parts2 = new ArrayList<Part>();
AppendMessage append2 = new AppendMessage(flagNames2, date2, parts2);
parts2.add(makeAppendPart(append2, 555, (byte) 55));
parts2.add(makeAppendPart(append2, 444, (byte) 44));
list.add(append);
list.add(append2);
return list;
}
Aggregations