Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 29 additions & 8 deletions railo-java/railo-core/src/railo/runtime/net/mail/MailClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -107,24 +112,28 @@ 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
* @param port
* @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;
Expand All @@ -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;
}


Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion railo-java/railo-core/src/railo/runtime/tag/_Mail.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -43,6 +44,7 @@ public void release() {
startrow=1;
maxrows=-1;
generateUniqueFilenames=false;
secure=false;
super.release();

}
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions railo-java/railo-core/src/resource/tld/web-cfmtaglibrary_1_0
Original file line number Diff line number Diff line change
Expand Up @@ -9483,6 +9483,13 @@ Manipulates existing PDF documents. The following list describes some of the tas
<rtexprvalue>true</rtexprvalue>
<description>Password that corresponds to user name.</description>
</attribute>
<attribute>
<type>boolean</type>
<name>secure</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>enables SSL for pop requests</description>
</attribute>
<attribute>
<type>string</type>
<name>action</name>
Expand Down