diff --git a/railo-java/railo-core/src/railo/runtime/net/imap/ImapClient.java b/railo-java/railo-core/src/railo/runtime/net/imap/ImapClient.java index 0c8ac163ab..a8da8cfbae 100644 --- a/railo-java/railo-core/src/railo/runtime/net/imap/ImapClient.java +++ b/railo-java/railo-core/src/railo/runtime/net/imap/ImapClient.java @@ -11,8 +11,8 @@ public final class ImapClient extends MailClient { - public ImapClient(String server, int port, String username, String password) { - super(server, port, username, password); + public ImapClient(String server, int port, String username, String password, boolean secure) { + super(server, port, username, password, secure); } protected String getId(Folder folder,Message message) throws MessagingException { diff --git a/railo-java/railo-core/src/railo/runtime/net/mail/MailClient.java b/railo-java/railo-core/src/railo/runtime/net/mail/MailClient.java index 0d4c0fba26..326763e594 100644 --- a/railo-java/railo-core/src/railo/runtime/net/mail/MailClient.java +++ b/railo-java/railo-core/src/railo/runtime/net/mail/MailClient.java @@ -2,6 +2,8 @@ import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.nio.charset.Charset; import java.text.Normalizer; import java.util.Enumeration; @@ -22,9 +24,12 @@ import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Store; +import javax.mail.URLName; import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeUtility; +import com.sun.mail.pop3.POP3SSLStore; + import railo.commons.io.CharsetUtil; import railo.commons.io.IOUtil; import railo.commons.io.SystemUtil; @@ -107,16 +112,20 @@ public _Authenticator(String s, String s1) { private int maxrows = 0; private boolean uniqueFilenames = false; private Resource attachmentDirectory = null; + private boolean secure = false; - - public static MailClient getInstance(int type,String server, int port, String username, String password){ + public static MailClient getInstance(int type,String server, int port, String username, String password, boolean secure){ if(TYPE_POP3==type) - return new PopClient(server,port,username,password); + return new PopClient(server,port,username,password, secure); if(TYPE_IMAP==type) - return new ImapClient(server,port,username,password); + return new ImapClient(server,port,username,password, secure); return null; } + public static MailClient getInstance(int type,String server, int port, String username, String password){ + return getInstance(type,server,port,username,password,false); + } + /** * constructor of the class * @param server @@ -124,7 +133,7 @@ public static MailClient getInstance(int type,String server, int port, String us * @param username * @param password */ - public MailClient(String server, int port, String username, String password) { + public MailClient(String server, int port, String username, String password, boolean secure) { timeout = 60000; startrow = 0; maxrows = -1; @@ -133,6 +142,7 @@ public MailClient(String server, int port, String username, String password) { this.port = port; this.username = username; this.password = password; + this.secure = secure; } @@ -186,10 +196,21 @@ public void connect() throws MessagingException { //properties.put("mail.mime.charset", "UTF-8"); - if(TYPE_IMAP==getType())properties.put("mail.imap.partialfetch", "false" ); - + if(TYPE_IMAP==getType()) properties.put("mail.imap.partialfetch", "false" ); + else { + if(secure) properties.put("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); // will failover + } + _fldtry = username != null ? Session.getInstance(properties, new _Authenticator(username, password)) : Session.getInstance(properties); - _fldelse = _fldtry.getStore(type); + + + + if(TYPE_POP3==getType() && secure) { + URLName url = new URLName("pop3", server, port, "",username, password); + _fldelse = new POP3SSLStore(_fldtry, url); + } else { + _fldelse = _fldtry.getStore(type); + } if(!StringUtil.isEmpty(username))_fldelse.connect(server,username,password); else _fldelse.connect(); } diff --git a/railo-java/railo-core/src/railo/runtime/net/pop/PopClient.java b/railo-java/railo-core/src/railo/runtime/net/pop/PopClient.java index a9f0249a88..314ee5283a 100644 --- a/railo-java/railo-core/src/railo/runtime/net/pop/PopClient.java +++ b/railo-java/railo-core/src/railo/runtime/net/pop/PopClient.java @@ -10,8 +10,8 @@ public final class PopClient extends MailClient { - public PopClient(String server, int port, String username, String password) { - super(server, port, username, password); + public PopClient(String server, int port, String username, String password, boolean secure) { + super(server, port, username, password, secure); } protected String getId(Folder folder,Message message) throws MessagingException { diff --git a/railo-java/railo-core/src/railo/runtime/tag/_Mail.java b/railo-java/railo-core/src/railo/runtime/tag/_Mail.java index 1d80568d18..5b5d10f4e8 100755 --- a/railo-java/railo-core/src/railo/runtime/tag/_Mail.java +++ b/railo-java/railo-core/src/railo/runtime/tag/_Mail.java @@ -28,6 +28,7 @@ public abstract class _Mail extends TagImpl { private int startrow=1; private int maxrows=-1; private boolean generateUniqueFilenames=false; + private boolean secure=false; @Override public void release() { @@ -43,6 +44,7 @@ public void release() { startrow=1; maxrows=-1; generateUniqueFilenames=false; + secure=false; super.release(); } @@ -142,6 +144,14 @@ public void setStartrow(double startrow) { this.startrow = (int)startrow; } + /** + * @param secure The secure to set. + */ + public void setSecure(boolean secure) { + this.secure = secure; + } + + /** * @param timeout The timeout to set. */ @@ -170,7 +180,7 @@ public int doStartTag() throws PageException { if(port==-1)port=getDefaultPort(); //PopClient client = new PopClient(server,port,username,password); - MailClient client = MailClient.getInstance(getType(),server,port,username,password); + MailClient client = MailClient.getInstance(getType(),server,port,username,password,secure); client.setTimeout(timeout*1000); client.setMaxrows(maxrows); if(startrow>1)client.setStartrow(startrow-1); diff --git a/railo-java/railo-core/src/resource/tld/web-cfmtaglibrary_1_0 b/railo-java/railo-core/src/resource/tld/web-cfmtaglibrary_1_0 index d31288a2ce..62fc562681 100755 --- a/railo-java/railo-core/src/resource/tld/web-cfmtaglibrary_1_0 +++ b/railo-java/railo-core/src/resource/tld/web-cfmtaglibrary_1_0 @@ -9483,6 +9483,13 @@ Manipulates existing PDF documents. The following list describes some of the tas true Password that corresponds to user name. + + boolean + secure + false + true + enables SSL for pop requests + string action