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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations