use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class CalendarItem method processNewInviteReply.
boolean processNewInviteReply(Invite reply, String sender) throws ServiceException {
List<ZAttendee> attendees = reply.getAttendees();
String senderAddress = null;
if (sender != null && !sender.isEmpty()) {
try {
JavaMailInternetAddress address = new JavaMailInternetAddress(sender);
senderAddress = address.getAddress();
} catch (AddressException e) {
// ignore invalid sender address.
}
}
if (senderAddress != null && !attendees.isEmpty()) {
AccountAddressMatcher acctMatcher = null;
Account acct = Provisioning.getInstance().get(AccountBy.name, senderAddress);
if (acct != null) {
acctMatcher = new AccountAddressMatcher(acct);
}
Iterator<ZAttendee> iter = attendees.iterator();
while (iter.hasNext()) {
ZAttendee att = iter.next();
// Remove the attendee if not same as the sender.
if (!(att.addressMatches(senderAddress) || (acctMatcher != null && acctMatcher.matches(att.getAddress())))) {
iter.remove();
}
}
}
// trace logging
ZAttendee att1 = !attendees.isEmpty() ? attendees.get(0) : null;
if (att1 != null) {
String ptst = IcalXmlStrMap.sPartStatMap.toIcal(att1.getPartStat());
if (!reply.hasRecurId())
ZimbraLog.calendar.info("Processing CalendarItem reply: attendee=%s, partstat=%s, id=%d, folderId=%d, subject=\"%s\", UID=%s", att1.getAddress(), ptst, mId, getFolderId(), reply.isPublic() ? reply.getName() : "(private)", mUid);
else
ZimbraLog.calendar.info("Processing CalendarItem reply: attendee=%s, partstat=%s, id=%d, folderId=%d, subject=\"%s\", UID=%s, recurId=%s", att1.getAddress(), ptst, mId, getFolderId(), reply.isPublic() ? reply.getName() : "(private)", mUid, reply.getRecurId().getDtZ());
}
// Require private access permission only when we're replying to a private series/instance.
boolean requirePrivateCheck = requirePrivateCheck(reply);
OperationContext octxt = getMailbox().getOperationContext();
Account authAccount = octxt != null ? octxt.getAuthenticatedUser() : null;
boolean asAdmin = octxt != null ? octxt.isUsingAdminPrivileges() : false;
if (!canAccess(ACL.RIGHT_ACTION, authAccount, asAdmin, requirePrivateCheck))
throw ServiceException.PERM_DENIED("you do not have sufficient permissions to change this appointment/task's state");
boolean dirty = false;
// unique ID: UID+RECURRENCE_ID
// See RFC2446: 2.1.5 Message Sequencing
// UID already matches...next check if RecurId matches
// if so, then seqNo is next
// finally use DTStamp
Invite matchingInvite = matchingInvite(reply.getRecurId());
if (matchingInvite != null) {
// up to date with the organizer's event, provided there were no major changes.
if ((matchingInvite.isOrganizer() && (matchingInvite.getLastFullSeqNo() > reply.getSeqNo())) || (!matchingInvite.isOrganizer() && (matchingInvite.getSeqNo() > reply.getSeqNo()))) {
sLog.info("Invite-Reply %s is outdated (Calendar entry has higher SEQUENCE), ignoring!", reply);
return false;
}
// maybeStoreNewReply does some further checks which might invalidate this reply
// so, postpone updating attendee information until after that.
}
// they must be replying to a arbitrary instance)
for (ZAttendee at : attendees) {
if (mReplyList.maybeStoreNewReply(reply, at, this))
dirty = true;
}
if (!dirty) {
sLog.info("Invite-Reply %s is outdated ignoring!", reply);
return false;
}
if (matchingInvite != null) {
matchingInvite.updateMatchingAttendeesFromReply(reply);
updateLocalExceptionsWhichMatchSeriesReply(reply);
} else {
createPseudoExceptionForSingleInstanceReplyIfNecessary(reply);
}
saveMetadata();
return true;
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class ReplyTest method testReplyMimeVariables.
@Test
public void testReplyMimeVariables() {
try {
String sampleMsg = "from: test2@zimbra.com\n" + "Return-Path: test2@zimbra.com\n" + "Subject: Hello\n" + "to: test@zimbra.com\n";
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
RuleManager.clearCachedRules(acct1);
String filterScript = "require \"variables\";\n" + "set \"var\" \"World\";\n" + "if anyof (true) { reply \"${Subject} ${var}\"" + " stop;" + "}";
acct1.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox1), mbox1, new ParsedMessage(sampleMsg.getBytes(), false), 0, acct1.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Integer item = mbox2.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message notifyMsg = mbox2.getMessageById(null, item);
Assert.assertEquals("Hello World", notifyMsg.getFragment());
} catch (Exception e) {
fail("No exception should be thrown");
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class RuleManagerAdminFilterTest method stopInTheAdminRule.
@Test
public void stopInTheAdminRule() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.unsetAdminSieveScriptBefore();
account.unsetMailSieveScript();
account.unsetAdminSieveScriptAfter();
account.setAdminSieveScriptBefore(scriptAdminBeforeStop);
account.setMailSieveScript(scriptUser);
account.setAdminSieveScriptAfter(scriptAdminAfter);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(message.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("admin-defined-before", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class RuleManagerAdminFilterTest method stopAtAdminBefore.
/* @Test
public void variableAdminOnUserOn() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Map<String, Object> attrs = Maps.newHashMap();
attrs = Maps.newHashMap();
Provisioning.getInstance().getServer(account).modify(attrs);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
account.unsetMailAdminSieveScriptBefore();
account.unsetMailSieveScript();
account.unsetMailAdminSieveScriptAfter();
account.setMailAdminSieveScriptBefore(variableScripts[0]);
account.setMailSieveScript(variableScripts[1]);
account.setMailAdminSieveScriptAfter(variableScripts[2]);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox),
mbox, new ParsedMessage(message.getBytes(), false),
0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
String[] tags = msg.getTags();
Assert.assertEquals(3, tags.length);
Assert.assertEquals("before-foo", tags[0]); // ${var} is a valid variable
Assert.assertEquals("enduser-", tags[1]); // Variable feature is on but no definition of ${var}
Assert.assertEquals("after-", tags[2]); // Variable feature is on but no definition of ${var}
}
@Test
public void variableAdminOnUserOn2() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Map<String, Object> attrs = Maps.newHashMap();
attrs = Maps.newHashMap();
Provisioning.getInstance().getServer(account).modify(attrs);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
account.unsetMailAdminSieveScriptBefore();
account.unsetMailSieveScript();
account.unsetMailAdminSieveScriptAfter();
String enduserScript = "require [\"tag\", \"log\", \"variables\"];"
+ "set \"var\" \"bar\";"
+ "tag \"enduser-${var}\";";
account.setMailAdminSieveScriptBefore(variableScripts[0]);
account.setMailSieveScript(enduserScript);
account.setMailAdminSieveScriptAfter(variableScripts[2]);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox),
mbox, new ParsedMessage(message.getBytes(), false),
0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
String[] tags = msg.getTags();
Assert.assertEquals(3, tags.length);
Assert.assertEquals("before-foo", tags[0]); // "foo" is assigned in admin-defined filter
Assert.assertEquals("enduser-bar", tags[1]);// "bar" is assigned in user-defined filter
Assert.assertEquals("after-", tags[2]); // Variable feature is on but no definition of ${var}
}*/
@Test
public void stopAtAdminBefore() throws Exception {
String adminBefore = "tag \"before-admin\";" + "stop;";
String enduser = "tag \"enduser\";";
String adminAfter = "tag \"after\";";
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.unsetAdminSieveScriptBefore();
account.unsetMailSieveScript();
account.unsetAdminSieveScriptAfter();
account.setAdminSieveScriptBefore(adminBefore);
account.setMailSieveScript(enduser);
account.setAdminSieveScriptAfter(adminAfter);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(message.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
String[] tags = msg.getTags();
Assert.assertEquals(1, tags.length);
Assert.assertEquals("before-admin", tags[0]);
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class RuleManagerAdminFilterTest method requireText.
// Verification for the ZCS-272
/* @Test
public void deleteHeaderInAdminBefore() throws Exception {
String adminBefore = "require [\"editheader\",\"log\"];\n"
+ "deleteheader :matches \"X-Test-Header\" \"Ran*\";\n";
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.unsetAdminSieveScriptBefore();
account.unsetMailSieveScript();
account.unsetAdminSieveScriptAfter();
account.setAdminSieveScriptBefore(adminBefore);
String rawTest = "From: sender@zimbra.com\n"
+ "To: test1@zimbra.com\n"
+ "Subject: Test\n"
+ "X-Test-Header: Random\n"
+ "\n"
+ "Hello World";
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox),
mbox, new ParsedMessage(rawTest.getBytes(), false), 0, account.getName(),
new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox.getMessageById(null, itemId);
boolean headerDeleted = true;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements();) {
Header temp = enumeration.nextElement();
if ("X-Test-Header".equals(temp.getName())) {
headerDeleted = false;
break;
}
}
Assert.assertTrue(headerDeleted);
}
// Verification for the ZCS-272
@Test
public void deleteHeaderInUser() throws Exception {
String endUser = "require [\"editheader\",\"log\"];\n"
+ "deleteheader :matches \"X-Test-Header\" \"Ran*\";\n";
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.unsetAdminSieveScriptBefore();
account.unsetMailSieveScript();
account.unsetAdminSieveScriptAfter();
account.setMailSieveScript(endUser);
String rawTest = "From: sender@zimbra.com\n"
+ "To: test1@zimbra.com\n"
+ "Subject: Test\n"
+ "X-Test-Header: Random\n"
+ "\n"
+ "Hello World";
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox),
mbox, new ParsedMessage(rawTest.getBytes(), false), 0, account.getName(),
new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox.getMessageById(null, itemId);
boolean headerDeleted = true;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements();) {
Header temp = enumeration.nextElement();
if ("X-Test-Header".equals(temp.getName())) {
headerDeleted = false;
break;
}
}
Assert.assertTrue(headerDeleted);
}
// Verification for the ZCS-272
@Test
public void deleteHeaderInAdminAfter() throws Exception {
String adminAfter = "require [\"editheader\",\"log\"];\n"
+ "deleteheader :matches \"X-Test-Header\" \"Ran*\";\n";
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.unsetAdminSieveScriptBefore();
account.unsetMailSieveScript();
account.unsetAdminSieveScriptAfter();
account.setAdminSieveScriptAfter(adminAfter);
String rawTest = "From: sender@zimbra.com\n"
+ "To: test1@zimbra.com\n"
+ "Subject: Test\n"
+ "X-Test-Header: Random\n"
+ "\n"
+ "Hello World";
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox),
mbox, new ParsedMessage(rawTest.getBytes(), false), 0, account.getName(),
new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox.getMessageById(null, itemId);
boolean headerDeleted = true;
for (Enumeration<Header> enumeration = message.getMimeMessage().getAllHeaders(); enumeration.hasMoreElements();) {
Header temp = enumeration.nextElement();
if ("X-Test-Header".equals(temp.getName())) {
headerDeleted = false;
break;
}
}
Assert.assertTrue(headerDeleted);
}
*/
/* Verification for the ZCS-611
*/
@Test
public void requireText() throws Exception {
String adminAfter = "require [\"log\", \"fileinto\"];\n" + "require \"tag\";\n" + "if header :contains [\"Subject\"] \"require abc def\" {\n" + " tag \"--require--\";" + " tag \"123require789\";\n" + "}";
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.unsetAdminSieveScriptBefore();
account.unsetMailSieveScript();
account.unsetAdminSieveScriptAfter();
account.setAdminSieveScriptAfter(adminAfter);
RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("Subject: require abc def\n".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Integer itemId = mbox.getItemIds(null, Mailbox.ID_FOLDER_INBOX).getIds(MailItem.Type.MESSAGE).get(0);
Message message = mbox.getMessageById(null, itemId);
String[] tags = message.getTags();
Assert.assertTrue(tags != null);
Assert.assertEquals(2, tags.length);
Assert.assertEquals("--require--", tags[0]);
Assert.assertEquals("123require789", tags[1]);
}
Aggregations