Search in sources :

Example 36 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class SpamHandler method isSpam.

/**
     * Returns <tt>false</tt> if the value of the header named <tt>zimbraSpamWhitelistHeader</tt>
     * matches the pattern specified by <tt>zimbraSpamWhitelistHeaderValue</tt>.
     *
     * If <tt>zimbraSpamWhitelistHeader</tt> does not match, returns <tt>true</tt> if the value of the
     * header named <tt>zimbraSpamHeader</tt> matches the pattern specified by <tt>zimbraSpamHeaderValue</tt>.
     */
public static boolean isSpam(MimeMessage msg) {
    try {
        Config config = Provisioning.getInstance().getConfig();
        String whitelistHeader = config.getSpamWhitelistHeader();
        if (whitelistHeader != null) {
            String whitelistHeaderValue = config.getSpamWhitelistHeaderValue();
            if (whitelistHeaderValue != null) {
                if (!whitelistHeaderValue.equals(SpamHandler.whitelistHeaderValue)) {
                    // Value has changed.  Recompile pattern.
                    SpamHandler.whitelistHeaderValue = whitelistHeaderValue;
                    whitelistPattern = Pattern.compile(whitelistHeaderValue);
                }
                String[] values = Mime.getHeaders(msg, whitelistHeader);
                boolean matched = false;
                for (String val : values) {
                    Matcher m = whitelistPattern.matcher(val);
                    if (m.matches()) {
                        matched = true;
                    } else {
                        matched = false;
                        break;
                    }
                }
                if (matched) {
                    return false;
                }
            }
        }
        String spamHeader = config.getSpamHeader();
        if (spamHeader != null) {
            String spamHeaderValue = config.getSpamHeaderValue();
            if (spamHeaderValue != null) {
                if (!spamHeaderValue.equals(SpamHandler.spamHeaderValue)) {
                    // Value has changed.  Recompile pattern.
                    SpamHandler.spamHeaderValue = spamHeaderValue;
                    spamPattern = Pattern.compile(spamHeaderValue);
                }
                String[] values = Mime.getHeaders(msg, spamHeader);
                for (String val : values) {
                    Matcher m = spamPattern.matcher(val);
                    if (m.matches()) {
                        return true;
                    }
                }
            }
        }
    } catch (Exception e) {
        ZimbraLog.mailbox.warn("Unable to determine whether the message is spam.", e);
    }
    return false;
}
Also used : Matcher(java.util.regex.Matcher) Config(com.zimbra.cs.account.Config) MessagingException(javax.mail.MessagingException) ServiceException(com.zimbra.common.service.ServiceException)

Example 37 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class BUG_11562 method upgradeZimbraGalLdapFilterDef.

@SuppressWarnings("unchecked")
private void upgradeZimbraGalLdapFilterDef() throws ServiceException {
    Config config = prov.getConfig();
    Pair[] values = { new Pair<String, String>("ad:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(givenName=*%s*)(mail=*%s*))(!(msExchHideFromAddressLists=TRUE))(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))", "ad:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(givenName=*%s*)(mail=*%s*))(!(msExchHideFromAddressLists=TRUE))(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))"), new Pair<String, String>("adAutoComplete:(&(|(displayName=%s*)(cn=%s*)(sn=%s*)(givenName=%s*)(mail=%s*))(!(msExchHideFromAddressLists=TRUE))(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))", "adAutoComplete:(&(|(displayName=%s*)(cn=%s*)(sn=%s*)(givenName=%s*)(mail=%s*))(!(msExchHideFromAddressLists=TRUE))(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))") };
    Set<String> curValues = config.getMultiAttrSet(Provisioning.A_zimbraGalLdapFilterDef);
    Map<String, Object> attrs = new HashMap<String, Object>();
    for (Pair<String, String> change : values) {
        String oldValue = change.getFirst();
        String newValue = change.getSecond();
        if (curValues.contains(oldValue)) {
            StringUtil.addToMultiMap(attrs, "-" + Provisioning.A_zimbraGalLdapFilterDef, oldValue);
            StringUtil.addToMultiMap(attrs, "+" + Provisioning.A_zimbraGalLdapFilterDef, newValue);
        }
    }
    modifyAttrs(config, attrs);
}
Also used : HashMap(java.util.HashMap) Config(com.zimbra.cs.account.Config) Pair(com.zimbra.common.util.Pair)

Example 38 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class BUG_14531 method doUpgrade.

@Override
void doUpgrade() throws ServiceException {
    Config config = prov.getConfig();
    String value = "zimbraSync:(&(|(displayName=*)(cn=*)(sn=*)(gn=*)(mail=*)(zimbraMailDeliveryAddress=*)(zimbraMailAlias=*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(zimbraHideInGal=TRUE))(!(zimbraIsSystemResource=TRUE)))";
    Map<String, Object> attr = new HashMap<String, Object>();
    attr.put("+" + Provisioning.A_zimbraGalLdapFilterDef, value);
    printer.println("Adding zimbraSync filter to global config " + Provisioning.A_zimbraGalLdapFilterDef);
    prov.modifyAttrs(config, attr);
}
Also used : HashMap(java.util.HashMap) Config(com.zimbra.cs.account.Config)

Example 39 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class BUG_27075 method doGlobalConfig.

private void doGlobalConfig(ZLdapContext zlc) throws ServiceException {
    Config config = prov.getConfig();
    doEntry(zlc, config, "global config", AttributeClass.globalConfig);
    doBug79208(config);
    doBug83551(config);
}
Also used : Config(com.zimbra.cs.account.Config)

Example 40 with Config

use of com.zimbra.cs.account.Config in project zm-mailbox by Zimbra.

the class RenameDomain method updateGlobalConfigSettings.

// TODO: should modify FlushCache to take more than one entry types, so that we
// can also flsuh the global config cache in the same request when we flush accounts.
private void updateGlobalConfigSettings(String curDefaultDomainName) {
    try {
        Config config = mProv.getConfig();
        HashMap<String, Object> attrMap = new HashMap<String, Object>();
        updateSystemAccount(config, Provisioning.A_zimbraNotebookAccount, attrMap);
        updateSystemAccount(config, Provisioning.A_zimbraSpamIsSpamAccount, attrMap);
        updateSystemAccount(config, Provisioning.A_zimbraSpamIsNotSpamAccount, attrMap);
        updateSystemAccount(config, Provisioning.A_zimbraAmavisQuarantineAccount, attrMap);
        String newDomainName = getNewDomain(curDefaultDomainName);
        if (curDefaultDomainName != null && newDomainName != null)
            attrMap.put(Provisioning.A_zimbraDefaultDomainName, newDomainName);
        mProv.modifyAttrs(config, attrMap);
        flushCacheOnAllServers(CacheEntryType.config);
    } catch (ServiceException e) {
        // just log it an continue
        warn("failed to update system accounts on global config", e);
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) Config(com.zimbra.cs.account.Config)

Aggregations

Config (com.zimbra.cs.account.Config)73 HashMap (java.util.HashMap)24 Provisioning (com.zimbra.cs.account.Provisioning)10 Test (org.junit.Test)8 ServiceException (com.zimbra.common.service.ServiceException)7 Account (com.zimbra.cs.account.Account)7 RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)7 Element (com.zimbra.common.soap.Element)6 Policy (com.zimbra.soap.mail.type.Policy)6 Cos (com.zimbra.cs.account.Cos)5 Server (com.zimbra.cs.account.Server)5 Domain (com.zimbra.cs.account.Domain)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 Pair (com.zimbra.common.util.Pair)3 HashSet (java.util.HashSet)3 SMTPMessage (com.sun.mail.smtp.SMTPMessage)2 ZFilterAction (com.zimbra.client.ZFilterAction)2 ZFileIntoAction (com.zimbra.client.ZFilterAction.ZFileIntoAction)2 ZFilterCondition (com.zimbra.client.ZFilterCondition)2 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)2