use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.
the class TestSpam method setUp.
@Before
public void setUp() throws Exception {
String prefix = String.format("%s-%s-", NAME_PREFIX, testInfo.getMethodName()).toLowerCase();
USER_NAME = String.format("%s-%s-", prefix, "user1");
SPAM_NAME = String.format("%s-%s-", prefix, "spam");
HAM_NAME = String.format("%s-%s-", prefix, "ham");
REMOTE_USER_NAME = String.format("%s-%s-", prefix, "remote");
Config config = prov.getConfig();
mOriginalSpamHeaderValue = config.getSpamHeaderValue();
mOriginalSpamAccount = config.getSpamIsSpamAccount();
mOriginalHamAccount = config.getSpamIsNotSpamAccount();
cleanUp();
Account account = TestUtil.createAccount(USER_NAME);
mOriginalSieveScript = account.getMailSieveScript();
}
use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.
the class TestSpam method testSpamHandler.
@Test
public void testSpamHandler() throws Exception {
TestUtil.createAccount(REMOTE_USER_NAME);
TestUtil.createAccount(SPAM_NAME);
TestUtil.createAccount(HAM_NAME);
//check if AS is installed
List<String> zimbraServiceInstalled = Arrays.asList(prov.getLocalServer().getServiceInstalled());
if (zimbraServiceInstalled == null || zimbraServiceInstalled.isEmpty() || !zimbraServiceInstalled.contains("antispam")) {
return;
}
Config config = prov.getConfig();
config.setSpamIsSpamAccount(TestUtil.getAddress(SPAM_NAME));
config.setSpamIsNotSpamAccount(TestUtil.getAddress(HAM_NAME));
// Set filter rule.
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFilterCondition cond = new ZHeaderCondition("Subject", ZFilterCondition.HeaderOp.CONTAINS, NAME_PREFIX);
ZFolder spamFolder = mbox.getFolderById(Integer.toString(Mailbox.ID_FOLDER_SPAM));
ZFolder inboxFolder = mbox.getFolderById(Integer.toString(Mailbox.ID_FOLDER_INBOX));
ZFilterAction action = new ZFileIntoAction(spamFolder.getPath());
ZFilterRule rule = new ZFilterRule(NAME_PREFIX + " testSpamHandler", true, true, Arrays.asList(cond), Arrays.asList(action));
ZFilterRules rules = new ZFilterRules(Arrays.asList(rule));
mbox.saveIncomingFilterRules(rules);
// Confirm that the message was delivered to the Spam folder and that the report was sent.
String subject = NAME_PREFIX + " testSpamHandler";
TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
ZMessage msg = TestUtil.getMessage(mbox, "in:" + spamFolder.getPath() + " subject:\"" + subject + "\"");
ZMailbox spamMbox = TestUtil.getZMailbox(SPAM_NAME);
ZMessage reportMsg = TestUtil.waitForMessage(spamMbox, "zimbra-spam-report spam");
validateSpamReport(TestUtil.getContent(spamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "spam", "filter", null, spamFolder.getPath(), null);
spamMbox.deleteMessage(reportMsg.getId());
// Move out of spam folder.
mbox.moveMessage(msg.getId(), Integer.toString(Mailbox.ID_FOLDER_INBOX));
ZMailbox hamMbox = TestUtil.getZMailbox(HAM_NAME);
reportMsg = TestUtil.waitForMessage(hamMbox, "zimbra-spam-report ham");
validateSpamReport(TestUtil.getContent(hamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "ham", "move", spamFolder.getPath(), inboxFolder.getPath(), null);
hamMbox.deleteMessage(reportMsg.getId());
// Move back to spam folder.
mbox.moveMessage(msg.getId(), Integer.toString(Mailbox.ID_FOLDER_SPAM));
reportMsg = TestUtil.waitForMessage(spamMbox, "zimbra-spam-report spam");
validateSpamReport(TestUtil.getContent(spamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "spam", "move", inboxFolder.getPath(), spamFolder.getPath(), null);
spamMbox.deleteMessage(reportMsg.getId());
// Move to remote folder.
ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
String mountpointPath = NAME_PREFIX + " remote";
TestUtil.createMountpoint(remoteMbox, "/Inbox", mbox, mountpointPath);
ZFolder mountpoint = mbox.getFolderByPath(mountpointPath);
mbox.moveMessage(msg.getId(), mountpoint.getId());
reportMsg = TestUtil.waitForMessage(hamMbox, "zimbra-spam-report ham");
validateSpamReport(TestUtil.getContent(hamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "ham", "remote move", spamFolder.getPath(), inboxFolder.getPath(), TestUtil.getAddress(REMOTE_USER_NAME));
hamMbox.deleteMessage(reportMsg.getId());
}
use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.
the class TestSpam method tearDown.
@After
public void tearDown() throws Exception {
Config config = prov.getConfig();
config.setSpamHeaderValue(mOriginalSpamHeaderValue);
config.setSpamIsSpamAccount(mOriginalSpamAccount);
config.setSpamIsNotSpamAccount(mOriginalHamAccount);
Account account = TestUtil.getAccount(USER_NAME);
account.setMailSieveScript(mOriginalSieveScript);
cleanUp();
}
use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.
the class TestUtil method setConfigAttr.
public static void setConfigAttr(String attrName, String attrValue) throws ServiceException {
Provisioning prov = Provisioning.getInstance();
Config config = prov.getConfig();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(attrName, attrValue);
prov.modifyAttrs(config, attrs);
}
use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.
the class GetInfo method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
if (!canAccessAccount(zsc, account)) {
throw ServiceException.PERM_DENIED("can not access account");
}
// figure out the subset of data the caller wants (default to all data)
String secstr = request.getAttribute(AccountConstants.A_SECTIONS, null);
Set<Section> sections;
if (secstr != null) {
sections = EnumSet.noneOf(Section.class);
for (String sec : Splitter.on(',').omitEmptyStrings().trimResults().split(secstr)) {
sections.add(Section.lookup(sec));
}
} else {
sections = EnumSet.allOf(Section.class);
}
String rightsStr = request.getAttribute(AccountConstants.A_RIGHTS, null);
Set<Right> rights = null;
if (rightsStr != null) {
RightManager rightMgr = RightManager.getInstance();
rights = Sets.newHashSet();
for (String right : Splitter.on(',').omitEmptyStrings().trimResults().split(rightsStr)) {
rights.add(rightMgr.getUserRight(right));
}
}
Element response = zsc.createElement(AccountConstants.GET_INFO_RESPONSE);
response.addAttribute(AccountConstants.E_VERSION, BuildInfo.FULL_VERSION, Element.Disposition.CONTENT);
response.addAttribute(AccountConstants.E_ID, account.getId(), Element.Disposition.CONTENT);
response.addAttribute(AccountConstants.E_NAME, account.getUnicodeName(), Element.Disposition.CONTENT);
try {
response.addAttribute(AccountConstants.E_CRUMB, zsc.getAuthToken().getCrumb(), Element.Disposition.CONTENT);
} catch (AuthTokenException e) {
// shouldn't happen
ZimbraLog.account.warn("can't generate crumb", e);
}
long lifetime = zsc.getAuthToken().getExpires() - System.currentTimeMillis();
response.addAttribute(AccountConstants.E_LIFETIME, lifetime, Element.Disposition.CONTENT);
Provisioning prov = Provisioning.getInstance();
// bug 53770, return if the request is using a delegated authtoken issued to an admin account
AuthToken authToken = zsc.getAuthToken();
if (authToken.isDelegatedAuth()) {
Account admin = prov.get(AccountBy.id, authToken.getAdminAccountId());
if (admin != null) {
boolean isAdmin = AdminAccessControl.isAdequateAdminAccount(admin);
if (isAdmin) {
response.addAttribute(AccountConstants.E_ADMIN_DELEGATED, true, Element.Disposition.CONTENT);
}
}
}
try {
Server server = prov.getLocalServer();
if (server != null) {
response.addAttribute(AccountConstants.A_DOCUMENT_SIZE_LIMIT, server.getFileUploadMaxSize());
}
Config config = prov.getConfig();
if (config != null) {
long maxAttachSize = config.getMtaMaxMessageSize();
if (maxAttachSize == 0) {
maxAttachSize = -1;
/* means unlimited */
}
response.addAttribute(AccountConstants.A_ATTACHMENT_SIZE_LIMIT, maxAttachSize);
}
} catch (ServiceException e) {
}
if (sections.contains(Section.MBOX) && Provisioning.onLocalServer(account)) {
response.addAttribute(AccountConstants.E_REST, UserServlet.getRestUrl(account), Element.Disposition.CONTENT);
try {
Mailbox mbox = getRequestedMailbox(zsc);
response.addAttribute(AccountConstants.E_QUOTA_USED, mbox.getSize(), Element.Disposition.CONTENT);
Session s = (Session) context.get(SoapEngine.ZIMBRA_SESSION);
if (s instanceof SoapSession) {
// we have a valid session; get the stats on this session
response.addAttribute(AccountConstants.E_PREVIOUS_SESSION, ((SoapSession) s).getPreviousSessionTime(), Element.Disposition.CONTENT);
response.addAttribute(AccountConstants.E_LAST_ACCESS, ((SoapSession) s).getLastWriteAccessTime(), Element.Disposition.CONTENT);
response.addAttribute(AccountConstants.E_RECENT_MSGS, ((SoapSession) s).getRecentMessageCount(), Element.Disposition.CONTENT);
} else {
// we have no session; calculate the stats from the mailbox and the other SOAP sessions
long lastAccess = mbox.getLastSoapAccessTime();
response.addAttribute(AccountConstants.E_PREVIOUS_SESSION, lastAccess, Element.Disposition.CONTENT);
response.addAttribute(AccountConstants.E_LAST_ACCESS, lastAccess, Element.Disposition.CONTENT);
response.addAttribute(AccountConstants.E_RECENT_MSGS, mbox.getRecentMessageCount(), Element.Disposition.CONTENT);
}
} catch (ServiceException e) {
}
}
doCos(account, response);
Map<String, Object> attrMap = account.getUnicodeAttrs();
Locale locale = Provisioning.getInstance().getLocale(account);
if (sections.contains(Section.PREFS)) {
Element prefs = response.addUniqueElement(AccountConstants.E_PREFS);
GetPrefs.doPrefs(account, prefs, attrMap, null);
}
if (sections.contains(Section.ATTRS)) {
Element attrs = response.addUniqueElement(AccountConstants.E_ATTRS);
doAttrs(account, locale.toString(), attrs, attrMap);
}
if (sections.contains(Section.ZIMLETS)) {
Element zimlets = response.addUniqueElement(AccountConstants.E_ZIMLETS);
doZimlets(zimlets, account);
}
if (sections.contains(Section.PROPS)) {
Element props = response.addUniqueElement(AccountConstants.E_PROPERTIES);
doProperties(props, account);
}
if (sections.contains(Section.IDENTS)) {
Element ids = response.addUniqueElement(AccountConstants.E_IDENTITIES);
doIdentities(ids, account);
}
if (sections.contains(Section.SIGS)) {
Element sigs = response.addUniqueElement(AccountConstants.E_SIGNATURES);
doSignatures(sigs, account);
}
if (sections.contains(Section.DSRCS)) {
Element ds = response.addUniqueElement(AccountConstants.E_DATA_SOURCES);
doDataSources(ds, account);
}
if (sections.contains(Section.CHILDREN)) {
Element ca = response.addUniqueElement(AccountConstants.E_CHILD_ACCOUNTS);
doChildAccounts(ca, account, zsc.getAuthToken());
}
if (rights != null && !rights.isEmpty()) {
Element eRights = response.addUniqueElement(AccountConstants.E_RIGHTS);
doDiscoverRights(eRights, account, rights);
}
GetAccountInfo.addUrls(response, account);
for (GetInfoExt extension : extensions) {
extension.handle(zsc, response);
}
return response;
}
Aggregations