use of com.zimbra.cs.filter.DummyMailAdapter in project zm-mailbox by Zimbra.
the class AddressBookTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
assert (headers != null);
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
Mailbox mbox = ((ZimbraMailAdapter) mail).getMailbox();
List<InternetAddress> addrs = new ArrayList<InternetAddress>();
for (String header : headers) {
for (String value : mail.getHeader(header)) {
addrs.add(new InternetAddress(value));
}
}
try {
return mbox.index.existsInContacts(addrs);
} catch (IOException e) {
ZimbraLog.filter.error("Failed to lookup contacts", e);
}
return false;
}
use of com.zimbra.cs.filter.DummyMailAdapter in project zm-mailbox by Zimbra.
the class ContactRankingTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException {
assert (headers != null);
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
Mailbox mbox = ((ZimbraMailAdapter) mail).getMailbox();
List<InternetAddress> addrs = new ArrayList<InternetAddress>();
for (String header : headers) {
for (String value : mail.getHeader(header)) {
addrs.add(new InternetAddress(value));
}
}
try {
ContactRankings ranking = new ContactRankings(mbox.getAccountId());
for (InternetAddress addr : addrs) {
if (ranking.query(addr.getAddress()) > 0) {
return true;
}
}
} catch (ServiceException e) {
ZimbraLog.filter.error("Failed to lookup ranking", e);
}
return false;
}
use of com.zimbra.cs.filter.DummyMailAdapter in project zm-mailbox by Zimbra.
the class ConversationTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException {
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
ZimbraMailAdapter adapter = (ZimbraMailAdapter) mail;
Mailbox mbox = adapter.getMailbox();
List<Conversation> convs;
try {
convs = mbox.lookupConversation(adapter.getParsedMessage());
} catch (ServiceException e) {
throw new ZimbraSieveException(e);
}
if (convs.isEmpty()) {
return false;
}
switch(where) {
case STARTED:
for (Conversation conv : convs) {
if ((conv.getFlagBitmask() & Flag.BITMASK_FROM_ME) > 0) {
try {
List<Message> msgs = mbox.getMessagesByConversation(null, conv.getId(), SortBy.DATE_ASC, 1);
if (!msgs.isEmpty()) {
Message msg = msgs.get(0);
// oldest.
if ((msg.getFlagBitmask() & Flag.BITMASK_FROM_ME) > 0 && !ParsedMessage.isReply(msgs.get(0).getSubject())) {
return true;
}
}
} catch (ServiceException e) {
throw new ZimbraSieveException(e);
}
}
}
break;
case PARTICIPATED:
for (Conversation conv : convs) {
if ((conv.getFlagBitmask() & Flag.BITMASK_FROM_ME) > 0) {
return true;
}
}
break;
default:
assert false : where;
}
return false;
}
use of com.zimbra.cs.filter.DummyMailAdapter in project zm-mailbox by Zimbra.
the class CurrentDayOfWeekTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();
// First argument MUST be a ":is" tag
String comparator = null;
if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof TagArgument)
comparator = ((TagArgument) argument).getTag();
}
if (!":is".equals(comparator))
throw new SyntaxException("Expecting \":is\"");
// Second argument MUST be a list of day of week indices; 0=Sunday, 6=Saturday
Set<Integer> daysToCheckAgainst = new HashSet<Integer>();
if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof StringListArgument) {
List<String> valList = ((StringListArgument) argument).getList();
for (String val : valList) {
int day;
try {
day = Integer.valueOf(val);
} catch (NumberFormatException e) {
throw new SyntaxException(e);
}
if (day < 0 || day > 6)
throw new SyntaxException("Expected values between 0 - 6");
// In Java 1=Sunday, 7=Saturday
daysToCheckAgainst.add(day + 1);
}
}
}
if (daysToCheckAgainst.isEmpty())
throw new SyntaxException("Expecting at least one value");
// There MUST NOT be any further arguments
if (argumentsIter.hasNext())
throw new SyntaxException("Found unexpected argument(s)");
TimeZone accountTimeZone;
try {
accountTimeZone = Util.getAccountTimeZone(((ZimbraMailAdapter) mail).getMailbox().getAccount());
} catch (ServiceException e) {
throw new ZimbraSieveException(e);
}
Calendar rightNow = Calendar.getInstance(accountTimeZone);
return daysToCheckAgainst.contains(rightNow.get(Calendar.DAY_OF_WEEK));
}
use of com.zimbra.cs.filter.DummyMailAdapter in project zm-mailbox by Zimbra.
the class CurrentTimeTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();
// First argument MUST be a tag of ":before" or ":after"
String comparator = null;
if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof TagArgument) {
String tag = ((TagArgument) argument).getTag();
if (tag.equals(BEFORE) || tag.equals(AFTER))
comparator = tag;
else
throw new SyntaxException("Found unexpected: \"" + tag + "\"");
}
}
if (comparator == null)
throw new SyntaxException("Expecting \"" + BEFORE + "\" or \"" + AFTER + "\"");
// Second argument MUST be a time in "HHmm" format
DateFormat timeFormat = new SimpleDateFormat("HHmm");
TimeZone accountTimeZone;
try {
accountTimeZone = Util.getAccountTimeZone(((ZimbraMailAdapter) mail).getMailbox().getAccount());
} catch (ServiceException e) {
throw new ZimbraSieveException(e);
}
timeFormat.setTimeZone(accountTimeZone);
Date timeArg = null;
if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof StringListArgument) {
List<String> valList = ((StringListArgument) argument).getList();
if (valList.size() != 1)
throw new SyntaxException("Expecting exactly one time value");
String timeStr = valList.get(0);
try {
timeArg = timeFormat.parse(timeStr);
} catch (ParseException e) {
throw new SyntaxException(e);
}
}
}
if (timeArg == null)
throw new SyntaxException("Expecting a time value");
// There MUST NOT be any further arguments
if (argumentsIter.hasNext())
throw new SyntaxException("Found unexpected argument(s)");
Calendar rightNow = Calendar.getInstance(accountTimeZone);
Calendar timeToCompareWith = Calendar.getInstance(accountTimeZone);
// set the time part
timeToCompareWith.setTime(timeArg);
// now set the right date
timeToCompareWith.set(rightNow.get(Calendar.YEAR), rightNow.get(Calendar.MONTH), rightNow.get(Calendar.DAY_OF_MONTH));
return BEFORE.equals(comparator) ? rightNow.getTime().before(timeToCompareWith.getTime()) : rightNow.getTime().after(timeToCompareWith.getTime());
}
Aggregations