Search in sources :

Example 6 with Server

use of lucee.runtime.net.mail.Server in project Lucee by lucee.

the class XMLConfigWebFactory method loadMail.

/**
 * @param configServer
 * @param config
 * @param doc
 * @throws IOException
 */
private static void loadMail(ConfigServerImpl configServer, ConfigImpl config, Document doc) throws IOException {
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_MAIL);
    boolean hasCS = configServer != null;
    Element mail = getChildByName(doc.getDocumentElement(), "mail");
    // Send partial
    String strSendPartial = mail.getAttribute("send-partial");
    if (!StringUtil.isEmpty(strSendPartial) && hasAccess) {
        config.setMailSendPartial(toBoolean(strSendPartial, false));
    } else if (hasCS)
        config.setMailSendPartial(configServer.isMailSendPartial());
    // Spool Interval
    String strSpoolInterval = getAttr(mail, "spool-interval");
    if (!StringUtil.isEmpty(strSpoolInterval) && hasAccess) {
        config.setMailSpoolInterval(Caster.toIntValue(strSpoolInterval, 30));
    } else if (hasCS)
        config.setMailSpoolInterval(configServer.getMailSpoolInterval());
    String strEncoding = getAttr(mail, "default-encoding");
    if (!StringUtil.isEmpty(strEncoding) && hasAccess)
        config.setMailDefaultEncoding(strEncoding);
    else if (hasCS)
        config.setMailDefaultEncoding(configServer.getMailDefaultCharset());
    // Spool Enable
    String strSpoolEnable = getAttr(mail, "spool-enable");
    if (!StringUtil.isEmpty(strSpoolEnable) && hasAccess) {
        config.setMailSpoolEnable(toBoolean(strSpoolEnable, false));
    } else if (hasCS)
        config.setMailSpoolEnable(configServer.isMailSpoolEnable());
    // Timeout
    String strTimeout = getAttr(mail, "timeout");
    if (!StringUtil.isEmpty(strTimeout) && hasAccess) {
        config.setMailTimeout(Caster.toIntValue(strTimeout, 60));
    } else if (hasCS)
        config.setMailTimeout(configServer.getMailTimeout());
    // Servers
    int index = 0;
    // Server[] servers = null;
    Element[] elServers = getChildren(mail, "server");
    List<Server> servers = new ArrayList<Server>();
    if (hasCS) {
        Server[] readOnlyServers = configServer.getMailServers();
        for (int i = 0; i < readOnlyServers.length; i++) {
            servers.add(readOnlyServers[index++].cloneReadOnly());
        }
    }
    /*else {
			servers = new Server[elServers.length];
		}*/
    if (hasAccess) {
        for (int i = 0; i < elServers.length; i++) {
            Element el = elServers[i];
            if (el.getNodeName().equals("server"))
                servers.add(i, new ServerImpl(Caster.toIntValue(getAttr(el, "id"), i + 1), getAttr(el, "smtp"), Caster.toIntValue(getAttr(el, "port"), 25), getAttr(el, "username"), ConfigWebUtil.decrypt(getAttr(el, "password")), toLong(el.getAttribute("life"), 1000 * 60 * 5), toLong(el.getAttribute("idle"), 1000 * 60 * 1), toBoolean(getAttr(el, "tls"), false), toBoolean(getAttr(el, "ssl"), false), toBoolean(getAttr(el, "reuse-connection"), true), hasCS ? ServerImpl.TYPE_LOCAL : ServerImpl.TYPE_GLOBAL));
        }
    }
    config.setMailServers(servers.toArray(new Server[servers.size()]));
}
Also used : Server(lucee.runtime.net.mail.Server) ServerImpl(lucee.runtime.net.mail.ServerImpl) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) lucee.aprint(lucee.aprint)

Aggregations

Server (lucee.runtime.net.mail.Server)6 ServerImpl (lucee.runtime.net.mail.ServerImpl)4 ArrayList (java.util.ArrayList)2 Component (lucee.runtime.Component)2 PageContextImpl (lucee.runtime.PageContextImpl)2 PageException (lucee.runtime.exp.PageException)2 MailException (lucee.runtime.net.mail.MailException)2 Struct (lucee.runtime.type.Struct)2 UDF (lucee.runtime.type.UDF)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 MessagingException (javax.mail.MessagingException)1 lucee.aprint (lucee.aprint)1 Log (lucee.commons.io.log.Log)1 Resource (lucee.commons.io.res.Resource)1 SerializableObject (lucee.commons.lang.SerializableObject)1 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)1 CacheConnection (lucee.runtime.cache.CacheConnection)1