Search in sources :

Example 1 with ServerImpl

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

the class SMTPClient method _send.

public void _send(lucee.runtime.config.ConfigWeb config, Server[] servers) throws MailException {
    long start = System.nanoTime();
    long _timeout = getTimeout(config);
    try {
        Proxy.start(proxyData);
        Log log = ((ConfigImpl) config).getLog("mail");
        // Server[] servers = config.getMailServers();
        if (host != null) {
            int prt;
            String usr, pwd;
            ServerImpl[] nServers = new ServerImpl[host.length];
            for (int i = 0; i < host.length; i++) {
                usr = null;
                pwd = null;
                prt = Server.DEFAULT_PORT;
                if (port > 0)
                    prt = port;
                if (!StringUtil.isEmpty(username)) {
                    usr = username;
                    pwd = password;
                }
                nServers[i] = toServerImpl(host[i], prt, usr, pwd, lifeTimespan, idleTimespan);
                if (ssl == SSL_YES)
                    nServers[i].setSSL(true);
                if (tls == TLS_YES)
                    nServers[i].setTLS(true);
            }
            servers = nServers;
        }
        if (servers.length == 0) {
            // return;
            throw new MailException("no SMTP Server defined");
        }
        boolean _ssl, _tls;
        for (int i = 0; i < servers.length; i++) {
            Server server = servers[i];
            String _username = null, _password = "";
            if (server.hasAuthentication()) {
                _username = server.getUsername();
                _password = server.getPassword();
            }
            // tls
            if (tls != TLS_NONE)
                _tls = tls == TLS_YES;
            else
                _tls = ((ServerImpl) server).isTLS();
            // ssl
            if (ssl != SSL_NONE)
                _ssl = ssl == SSL_YES;
            else
                _ssl = ((ServerImpl) server).isSSL();
            MimeMessageAndSession msgSess;
            boolean recyleConnection = ((ServerImpl) server).reuseConnections();
            {
                // synchronized(LOCK) {
                try {
                    msgSess = createMimeMessage(config, server.getHostName(), server.getPort(), _username, _password, ((ServerImpl) server).getLifeTimeSpan(), ((ServerImpl) server).getIdleTimeSpan(), _tls, _ssl, ((ConfigImpl) config).isMailSendPartial(), !recyleConnection, ((ConfigImpl) config).isUserset());
                } catch (MessagingException e) {
                    // listener
                    listener(config, server, log, e, System.nanoTime() - start);
                    MailException me = new MailException(e.getMessage());
                    me.setStackTrace(e.getStackTrace());
                    throw me;
                }
                try {
                    SerializableObject lock = new SerializableObject();
                    SMTPSender sender = new SMTPSender(lock, msgSess, server.getHostName(), server.getPort(), _username, _password, recyleConnection);
                    sender.start();
                    SystemUtil.wait(lock, _timeout);
                    if (!sender.isSent()) {
                        Throwable t = sender.getThrowable();
                        if (t != null)
                            throw Caster.toPageException(t);
                        // stop when still running
                        try {
                            if (sender.isAlive())
                                sender.stop();
                        } catch (Throwable t2) {
                            ExceptionUtil.rethrowIfNecessary(t2);
                        }
                        // after thread is stopped check sent flag again
                        if (!sender.isSent()) {
                            throw new MessagingException("timeout occurred after " + (_timeout / 1000) + " seconds while sending mail message");
                        }
                    }
                    // could have an exception but was send anyway
                    if (sender.getThrowable() != null) {
                        Throwable t = sender.getThrowable();
                        if (log != null)
                            LogUtil.log(log, Log.LEVEL_ERROR, "send mail", t);
                    }
                    clean(config, attachmentz);
                    listener(config, server, log, null, System.nanoTime() - start);
                    break;
                } catch (Exception e) {
                    SystemOut.printDate(e);
                    if (i + 1 == servers.length) {
                        listener(config, server, log, e, System.nanoTime() - start);
                        MailException me = new MailException(server.getHostName() + " " + ExceptionUtil.getStacktrace(e, true) + ":" + i);
                        me.setStackTrace(e.getStackTrace());
                        throw me;
                    }
                }
            }
        }
    } finally {
        Proxy.end();
    }
}
Also used : Server(lucee.runtime.net.mail.Server) Log(lucee.commons.io.log.Log) MessagingException(javax.mail.MessagingException) MessagingException(javax.mail.MessagingException) PageException(lucee.runtime.exp.PageException) FileNotFoundException(java.io.FileNotFoundException) MailException(lucee.runtime.net.mail.MailException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) SerializableObject(lucee.commons.lang.SerializableObject) ServerImpl(lucee.runtime.net.mail.ServerImpl) MailException(lucee.runtime.net.mail.MailException) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 2 with ServerImpl

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

the class GetApplicationSettings method call.

public static Struct call(PageContext pc, boolean suppressFunctions) {
    ApplicationContext ac = pc.getApplicationContext();
    Component cfc = null;
    if (ac instanceof ModernApplicationContext)
        cfc = ((ModernApplicationContext) ac).getComponent();
    Struct sct = new StructImpl();
    sct.setEL("applicationTimeout", ac.getApplicationTimeout());
    sct.setEL("clientManagement", Caster.toBoolean(ac.isSetClientManagement()));
    sct.setEL("clientStorage", ac.getClientstorage());
    sct.setEL("sessionStorage", ac.getSessionstorage());
    sct.setEL("customTagPaths", toArray(ac.getCustomTagMappings()));
    sct.setEL("loginStorage", AppListenerUtil.translateLoginStorage(ac.getLoginStorage()));
    sct.setEL(KeyConstants._mappings, toStruct(ac.getMappings()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("scriptProtect", AppListenerUtil.translateScriptProtect(ac.getScriptProtect()));
    sct.setEL("secureJson", Caster.toBoolean(ac.getSecureJson()));
    sct.setEL("typeChecking", Caster.toBoolean(ac.getTypeChecking()));
    sct.setEL("secureJsonPrefix", ac.getSecureJsonPrefix());
    sct.setEL("sessionManagement", Caster.toBoolean(ac.isSetSessionManagement()));
    sct.setEL("sessionTimeout", ac.getSessionTimeout());
    sct.setEL("clientTimeout", ac.getClientTimeout());
    sct.setEL("setClientCookies", Caster.toBoolean(ac.isSetClientCookies()));
    sct.setEL("setDomainCookies", Caster.toBoolean(ac.isSetDomainCookies()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("localMode", ac.getLocalMode() == Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS ? Boolean.TRUE : Boolean.FALSE);
    sct.setEL(KeyConstants._locale, LocaleFactory.toString(pc.getLocale()));
    sct.setEL(KeyConstants._timezone, TimeZoneUtil.toString(pc.getTimeZone()));
    // scope cascading
    sct.setEL("scopeCascading", ConfigWebUtil.toScopeCascading(ac.getScopeCascading(), null));
    if (ac.getScopeCascading() != Config.SCOPE_SMALL) {
        sct.setEL("searchImplicitScopes", ac.getScopeCascading() == Config.SCOPE_STANDARD);
    }
    Struct cs = new StructImpl();
    cs.setEL("web", pc.getWebCharset().name());
    cs.setEL("resource", ((PageContextImpl) pc).getResourceCharset().name());
    sct.setEL("charset", cs);
    sct.setEL("sessionType", AppListenerUtil.toSessionType(((PageContextImpl) pc).getSessionType(), "application"));
    // TODO impl
    sct.setEL("serverSideFormValidation", Boolean.FALSE);
    sct.setEL("clientCluster", Caster.toBoolean(ac.getClientCluster()));
    sct.setEL("sessionCluster", Caster.toBoolean(ac.getSessionCluster()));
    sct.setEL("invokeImplicitAccessor", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("triggerDataMember", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("sameformfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_FORM)));
    sct.setEL("sameurlfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_URL)));
    Object ds = ac.getDefDataSource();
    if (ds instanceof DataSource)
        ds = _call((DataSource) ds);
    else
        ds = Caster.toString(ds, null);
    sct.setEL(KeyConstants._datasource, ds);
    sct.setEL("defaultDatasource", ds);
    Resource src = ac.getSource();
    if (src != null)
        sct.setEL(KeyConstants._source, src.getAbsolutePath());
    // orm
    if (ac.isORMEnabled()) {
        ORMConfiguration conf = ac.getORMConfiguration();
        if (conf != null)
            sct.setEL(KeyConstants._orm, conf.toStruct());
    }
    // s3
    Properties props = ac.getS3();
    if (props != null) {
        sct.setEL(KeyConstants._s3, props.toStruct());
    }
    // ws settings
    {
        Struct wssettings = new StructImpl();
        wssettings.put(KeyConstants._type, AppListenerUtil.toWSType(ac.getWSType(), "Axis1"));
        sct.setEL("wssettings", wssettings);
    }
    // datasources
    Struct _sources = new StructImpl();
    sct.setEL(KeyConstants._datasources, _sources);
    DataSource[] sources = ac.getDataSources();
    if (!ArrayUtil.isEmpty(sources)) {
        for (int i = 0; i < sources.length; i++) {
            _sources.setEL(KeyImpl.init(sources[i].getName()), _call(sources[i]));
        }
    }
    // logs
    Struct _logs = new StructImpl();
    sct.setEL("logs", _logs);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Iterator<Key> it = acs.getLogNames().iterator();
        Key name;
        while (it.hasNext()) {
            name = it.next();
            _logs.setEL(name, acs.getLogMetaData(name.getString()));
        }
    }
    // mails
    Array _mails = new ArrayImpl();
    sct.setEL("mails", _mails);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Server[] servers = acs.getMailServers();
        Struct s;
        Server srv;
        if (servers != null) {
            for (int i = 0; i < servers.length; i++) {
                srv = servers[i];
                s = new StructImpl();
                _mails.appendEL(s);
                s.setEL(KeyConstants._host, srv.getHostName());
                s.setEL(KeyConstants._port, srv.getPort());
                if (!StringUtil.isEmpty(srv.getUsername()))
                    s.setEL(KeyConstants._username, srv.getUsername());
                if (!StringUtil.isEmpty(srv.getPassword()))
                    s.setEL(KeyConstants._password, srv.getPassword());
                s.setEL(KeyConstants._readonly, srv.isReadOnly());
                s.setEL("ssl", srv.isSSL());
                s.setEL("tls", srv.isTLS());
                if (srv instanceof ServerImpl) {
                    ServerImpl srvi = (ServerImpl) srv;
                    s.setEL("lifeTimespan", TimeSpanImpl.fromMillis(srvi.getLifeTimeSpan()));
                    s.setEL("idleTimespan", TimeSpanImpl.fromMillis(srvi.getIdleTimeSpan()));
                }
            }
        }
    }
    // tag
    Map<Key, Map<Collection.Key, Object>> tags = ac.getTagAttributeDefaultValues(pc);
    if (tags != null) {
        Struct tag = new StructImpl();
        Iterator<Entry<Key, Map<Collection.Key, Object>>> it = tags.entrySet().iterator();
        Entry<Collection.Key, Map<Collection.Key, Object>> e;
        Iterator<Entry<Collection.Key, Object>> iit;
        Entry<Collection.Key, Object> ee;
        Struct tmp;
        // TagLib lib = ((ConfigImpl)pc.getConfig()).getCoreTagLib();
        while (it.hasNext()) {
            e = it.next();
            iit = e.getValue().entrySet().iterator();
            tmp = new StructImpl();
            while (iit.hasNext()) {
                ee = iit.next();
                // lib.getTagByClassName(ee.getKey());
                tmp.setEL(ee.getKey(), ee.getValue());
            }
            tag.setEL(e.getKey(), tmp);
        }
        sct.setEL(KeyConstants._tag, tag);
    }
    // cache
    String fun = ac.getDefaultCacheName(Config.CACHE_TYPE_FUNCTION);
    String obj = ac.getDefaultCacheName(Config.CACHE_TYPE_OBJECT);
    String qry = ac.getDefaultCacheName(Config.CACHE_TYPE_QUERY);
    String res = ac.getDefaultCacheName(Config.CACHE_TYPE_RESOURCE);
    String tmp = ac.getDefaultCacheName(Config.CACHE_TYPE_TEMPLATE);
    String inc = ac.getDefaultCacheName(Config.CACHE_TYPE_INCLUDE);
    String htt = ac.getDefaultCacheName(Config.CACHE_TYPE_HTTP);
    String fil = ac.getDefaultCacheName(Config.CACHE_TYPE_FILE);
    String wse = ac.getDefaultCacheName(Config.CACHE_TYPE_WEBSERVICE);
    // cache connections
    Struct conns = new StructImpl();
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Key[] names = acs.getCacheConnectionNames();
        for (Key name : names) {
            CacheConnection data = acs.getCacheConnection(name.getString(), null);
            Struct _sct = new StructImpl();
            conns.setEL(name, _sct);
            _sct.setEL(KeyConstants._custom, data.getCustom());
            _sct.setEL(KeyConstants._storage, data.isStorage());
            ClassDefinition cd = data.getClassDefinition();
            if (cd != null) {
                _sct.setEL(KeyConstants._class, cd.getClassName());
                if (!StringUtil.isEmpty(cd.getName()))
                    _sct.setEL(KeyConstants._bundleName, cd.getClassName());
                if (cd.getVersion() != null)
                    _sct.setEL(KeyConstants._bundleVersion, cd.getVersionAsString());
            }
        }
    }
    if (!conns.isEmpty() || fun != null || obj != null || qry != null || res != null || tmp != null || inc != null || htt != null || fil != null || wse != null) {
        Struct cache = new StructImpl();
        sct.setEL(KeyConstants._cache, cache);
        if (fun != null)
            cache.setEL(KeyConstants._function, fun);
        if (obj != null)
            cache.setEL(KeyConstants._object, obj);
        if (qry != null)
            cache.setEL(KeyConstants._query, qry);
        if (res != null)
            cache.setEL(KeyConstants._resource, res);
        if (tmp != null)
            cache.setEL(KeyConstants._template, tmp);
        if (inc != null)
            cache.setEL(KeyConstants._include, inc);
        if (htt != null)
            cache.setEL(KeyConstants._http, htt);
        if (fil != null)
            cache.setEL(KeyConstants._file, fil);
        if (wse != null)
            cache.setEL(KeyConstants._webservice, wse);
        if (conns != null)
            cache.setEL(KeyConstants._connections, conns);
    }
    // java settings
    JavaSettings js = ac.getJavaSettings();
    StructImpl jsSct = new StructImpl();
    jsSct.put("loadCFMLClassPath", js.loadCFMLClassPath());
    jsSct.put("reloadOnChange", js.reloadOnChange());
    jsSct.put("watchInterval", new Double(js.watchInterval()));
    jsSct.put("watchExtensions", ListUtil.arrayToList(js.watchedExtensions(), ","));
    Resource[] reses = js.getResources();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < reses.length; i++) {
        if (i > 0)
            sb.append(',');
        sb.append(reses[i].getAbsolutePath());
    }
    jsSct.put("loadCFMLClassPath", sb.toString());
    sct.put("javaSettings", jsSct);
    if (cfc != null) {
        sct.setEL(KeyConstants._component, cfc.getPageSource().getDisplayPath());
        try {
            ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, cfc);
            Iterator<Key> it = cw.keyIterator();
            Collection.Key key;
            Object value;
            while (it.hasNext()) {
                key = it.next();
                value = cw.get(key);
                if (suppressFunctions && value instanceof UDF)
                    continue;
                if (!sct.containsKey(key))
                    sct.setEL(key, value);
            }
        } catch (PageException e) {
            SystemOut.printDate(e);
        }
    }
    return sct;
}
Also used : Server(lucee.runtime.net.mail.Server) ArrayImpl(lucee.runtime.type.ArrayImpl) Properties(lucee.runtime.net.s3.Properties) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) ApplicationContext(lucee.runtime.listener.ApplicationContext) Entry(java.util.Map.Entry) ServerImpl(lucee.runtime.net.mail.ServerImpl) UDF(lucee.runtime.type.UDF) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Component(lucee.runtime.Component) ORMConfiguration(lucee.runtime.orm.ORMConfiguration) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) PageException(lucee.runtime.exp.PageException) JavaSettings(lucee.runtime.listener.JavaSettings) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) DataSource(lucee.runtime.db.DataSource) Array(lucee.runtime.type.Array) Key(lucee.runtime.type.Collection.Key) StructImpl(lucee.runtime.type.StructImpl) Collection(lucee.runtime.type.Collection) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) Map(java.util.Map) CacheConnection(lucee.runtime.cache.CacheConnection) Key(lucee.runtime.type.Collection.Key)

Example 3 with ServerImpl

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

the class AppListenerUtil method toMailServer.

public static Server toMailServer(Config config, Struct data, Server defaultValue) {
    String hostName = Caster.toString(data.get(KeyConstants._host, null), null);
    if (StringUtil.isEmpty(hostName, true))
        hostName = Caster.toString(data.get(KeyConstants._server, null), null);
    if (StringUtil.isEmpty(hostName, true))
        return defaultValue;
    int port = Caster.toIntValue(data.get(KeyConstants._port, null), 25);
    String username = Caster.toString(data.get(KeyConstants._username, null), null);
    if (StringUtil.isEmpty(username, true))
        username = Caster.toString(data.get(KeyConstants._user, null), null);
    String password = ConfigWebUtil.decrypt(Caster.toString(data.get(KeyConstants._password, null), null));
    TimeSpan lifeTimespan = Caster.toTimespan(data.get("lifeTimespan", null), null);
    if (lifeTimespan == null)
        lifeTimespan = Caster.toTimespan(data.get("life", null), FIVE_MINUTES);
    TimeSpan idleTimespan = Caster.toTimespan(data.get("idleTimespan", null), null);
    if (idleTimespan == null)
        idleTimespan = Caster.toTimespan(data.get("idle", null), ONE_MINUTE);
    boolean tls = Caster.toBooleanValue(data.get("tls", null), false);
    boolean ssl = Caster.toBooleanValue(data.get("ssl", null), false);
    // MUST improve store connection somehow
    return new ServerImpl(-1, hostName, port, username, password, lifeTimespan.getMillis(), idleTimespan.getMillis(), tls, ssl, false, ServerImpl.TYPE_LOCAL);
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) ServerImpl(lucee.runtime.net.mail.ServerImpl)

Example 4 with ServerImpl

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

the class Admin method doGetMailServers.

private void doGetMailServers() throws PageException {
    Server[] servers = config.getMailServers();
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "id", "hostname", "password", "passwordEncrypted", "username", "port", "authentication", "readonly", "tls", "ssl", "life", "idle", "type" }, servers.length, "query");
    for (int i = 0; i < servers.length; i++) {
        Server s = servers[i];
        int row = i + 1;
        qry.setAt("id", row, s instanceof ServerImpl ? ((ServerImpl) s).getId() : -1);
        qry.setAt("hostname", row, s.getHostName());
        qry.setAt("password", row, s.isReadOnly() ? "" : s.getPassword());
        qry.setAt("passwordEncrypted", row, s.isReadOnly() ? "" : ConfigWebUtil.encrypt(s.getPassword()));
        qry.setAt("username", row, s.isReadOnly() ? "" : s.getUsername());
        qry.setAt("port", row, Caster.toInteger(s.getPort()));
        qry.setAt("readonly", row, Caster.toBoolean(s.isReadOnly()));
        qry.setAt("authentication", row, Caster.toBoolean(s.hasAuthentication()));
        qry.setAt("ssl", row, Caster.toBoolean(s.isSSL()));
        qry.setAt("tls", row, Caster.toBoolean(s.isTLS()));
        if (s instanceof ServerImpl) {
            ServerImpl si = (ServerImpl) s;
            qry.setAt("type", row, si.getType() == ServerImpl.TYPE_GLOBAL ? "global" : "local");
            qry.setAt("life", row, (si.getLifeTimeSpan() / 1000));
            qry.setAt("idle", row, (si.getIdleTimeSpan() / 1000));
        }
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) ConfigServer(lucee.runtime.config.ConfigServer) Server(lucee.runtime.net.mail.Server) ServerImpl(lucee.runtime.net.mail.ServerImpl) ConfigServerImpl(lucee.runtime.config.ConfigServerImpl) Query(lucee.runtime.type.Query)

Example 5 with ServerImpl

use of lucee.runtime.net.mail.ServerImpl 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

ServerImpl (lucee.runtime.net.mail.ServerImpl)6 Server (lucee.runtime.net.mail.Server)4 ExpressionException (lucee.runtime.exp.ExpressionException)2 PageException (lucee.runtime.exp.PageException)2 MailException (lucee.runtime.net.mail.MailException)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)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 Component (lucee.runtime.Component)1 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)1 PageContextImpl (lucee.runtime.PageContextImpl)1 CacheConnection (lucee.runtime.cache.CacheConnection)1 ConfigImpl (lucee.runtime.config.ConfigImpl)1