Search in sources :

Example 21 with Config

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

the class SpamExtract method getAccount.

private static Account getAccount(CommandLine cl) throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    Config conf;
    try {
        conf = prov.getConfig();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("Unable to connect to LDAP directory", e);
    }
    String name = null;
    if (cl.hasOption('s')) {
        if (cl.hasOption('n') || cl.hasOption('m')) {
            LOG.error("only one of s, n or m options can be specified");
            return null;
        }
        name = conf.getAttr(Provisioning.A_zimbraSpamIsSpamAccount);
        if (name == null || name.length() == 0) {
            LOG.error("no account configured for spam");
            return null;
        }
    } else if (cl.hasOption('n')) {
        if (cl.hasOption('m')) {
            LOG.error("only one of s, n, or m options can be specified");
            return null;
        }
        name = conf.getAttr(Provisioning.A_zimbraSpamIsNotSpamAccount);
        if (name == null || name.length() == 0) {
            LOG.error("no account configured for ham");
            return null;
        }
    } else if (cl.hasOption('m')) {
        name = cl.getOptionValue('m');
        if (name.length() == 0) {
            LOG.error("illegal argument to m option");
            return null;
        }
    } else {
        LOG.error("one of s, n or m options must be specified");
        return null;
    }
    Account account = prov.get(AccountBy.name, name);
    if (account == null) {
        LOG.error("can not find account " + name);
        return null;
    }
    return account;
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) Config(com.zimbra.cs.account.Config) Provisioning(com.zimbra.cs.account.Provisioning)

Example 22 with Config

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

the class RetentionPolicyManager method getCachedSystemPolicy.

private SystemPolicy getCachedSystemPolicy(Entry entry) throws ServiceException {
    SystemPolicy sp;
    synchronized (entry) {
        sp = (SystemPolicy) entry.getCachedData(SYSTEM_POLICY_KEY);
        if (sp == null) {
            String xml;
            if (entry instanceof Config)
                xml = ((Config) entry).getMailPurgeSystemPolicy();
            else if (entry instanceof Cos)
                xml = ((Cos) entry).getMailPurgeSystemPolicy();
            else
                throw ServiceException.UNSUPPORTED();
            sp = new SystemPolicy();
            if (!Strings.isNullOrEmpty(xml)) {
                ZimbraLog.purge.debug("Parsing system retention policy:\n%s", xml);
                try {
                    Element el = Element.parseXML(xml);
                    RetentionPolicy rp = JaxbUtil.elementToJaxb(el, RetentionPolicy.class);
                    for (Policy p : rp.getKeepPolicy()) {
                        assert (p.getId() != null);
                        sp.keep.put(p.getId(), p);
                    }
                    for (Policy p : rp.getPurgePolicy()) {
                        assert (p.getId() != null);
                        sp.purge.put(p.getId(), p);
                    }
                } catch (XmlParseException e) {
                    throw ServiceException.FAILURE("Unable to parse system retention policy.", e);
                }
            }
            entry.setCachedData(SYSTEM_POLICY_KEY, sp);
        }
    }
    return sp;
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Config(com.zimbra.cs.account.Config) Cos(com.zimbra.cs.account.Cos) XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) XmlParseException(com.zimbra.common.soap.XmlParseException) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 23 with Config

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

the class ImapLoadBalancingMechanism method newInstance.

public static ImapLoadBalancingMechanism newInstance() throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    Config config = prov.getConfig();
    String lbMechStr = config.getAttr(Provisioning.A_zimbraImapLoadBalancingAlgorithm, ImapLBMech.ClientIpHash.name());
    return newInstance(lbMechStr);
}
Also used : Config(com.zimbra.cs.account.Config) Provisioning(com.zimbra.cs.account.Provisioning)

Example 24 with Config

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

the class SpamHandler method sendReport.

private void sendReport(SpamReport sr) throws ServiceException, MessagingException {
    Config config = Provisioning.getInstance().getConfig();
    String isSpamString = sr.isSpam ? config.getSpamReportTypeSpam() : config.getSpamReportTypeHam();
    SMTPMessage out = new SMTPMessage(JMSession.getSmtpSession());
    Mailbox mbox = MailboxManager.getInstance().getMailboxById(sr.mailboxId);
    Message msg = mbox.getMessageById(null, sr.messageId);
    MimeMultipart mmp = new ZMimeMultipart("mixed");
    MimeBodyPart infoPart = new ZMimeBodyPart();
    infoPart.setHeader("Content-Description", "Zimbra spam classification report");
    String body = String.format("Classified-By: %s\r\n" + "Classified-As: %s\r\n" + "Action: %s\r\n" + "Source-Folder: %s\r\n" + "Destination-Folder: %s\r\n" + "Destination-Mailbox: %s\r\n", Strings.nullToEmpty(sr.accountName), isSpamString, Strings.nullToEmpty(sr.action), Strings.nullToEmpty(sr.sourceFolder), Strings.nullToEmpty(sr.destFolder), Strings.nullToEmpty(sr.destAccountName));
    infoPart.setText(body);
    mmp.addBodyPart(infoPart);
    MailboxBlob blob = msg.getBlob();
    MimeBodyPart mbp = new ZMimeBodyPart();
    mbp.setDataHandler(new DataHandler(new MailboxBlobDataSource(blob)));
    mbp.setHeader("Content-Type", MimeConstants.CT_MESSAGE_RFC822);
    mbp.setHeader("Content-Disposition", Part.ATTACHMENT);
    mmp.addBodyPart(mbp);
    out.setContent(mmp);
    out.addHeader(config.getSpamReportSenderHeader(), sr.accountName);
    out.addHeader(config.getSpamReportTypeHeader(), isSpamString);
    if (config.isSmtpSendAddOriginatingIP() && sr.origIp != null)
        out.addHeader(MailSender.X_ORIGINATING_IP, MailSender.formatXOrigIpHeader(sr.origIp));
    out.setRecipient(javax.mail.Message.RecipientType.TO, sr.reportRecipient);
    out.setEnvelopeFrom(config.getSpamReportEnvelopeFrom());
    out.setSubject(config.getSpamTrainingSubjectPrefix() + " " + sr.accountName + ": " + isSpamString);
    Transport.send(out);
    ZimbraLog.misc.info("Sent " + sr);
}
Also used : SMTPMessage(com.sun.mail.smtp.SMTPMessage) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) SMTPMessage(com.sun.mail.smtp.SMTPMessage) MimeMessage(javax.mail.internet.MimeMessage) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ZMimeMultipart(com.zimbra.common.zmime.ZMimeMultipart) MimeMultipart(javax.mail.internet.MimeMultipart) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MailboxBlobDataSource(com.zimbra.cs.mime.MailboxBlobDataSource) Config(com.zimbra.cs.account.Config) ZMimeMultipart(com.zimbra.common.zmime.ZMimeMultipart) DataHandler(javax.activation.DataHandler) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Example 25 with Config

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

the class ModifyConfig method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Map<String, Object> attrs = AdminService.getAttrs(request);
    Config config = prov.getConfig();
    checkRight(zsc, context, config, attrs);
    // pass in true to checkImmutable
    prov.modifyAttrs(config, attrs, true);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "ModifyConfig" }, attrs));
    Element response = zsc.createElement(AdminConstants.MODIFY_CONFIG_RESPONSE);
    return response;
}
Also used : ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Config(com.zimbra.cs.account.Config) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

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