IDEMPIERE-4765 IMAPS limited to GMAIL (#656)
* IDEMPIERE-4765 IMAPS limited to GMAIL * IDEMPIERE-4765 Added IMAPHost Protocol
This commit is contained in:
parent
a9b224c25d
commit
ad3debdd0e
|
@ -54,6 +54,7 @@ import org.compiere.util.Trx;
|
|||
* @version $Id: RequestEMailProcessor.java,v 1.2 2006/10/23 06:01:20 cruiz Exp $
|
||||
* hieplq:separate email process to other class for easy re-use and do IDEMPIERE-2244
|
||||
*
|
||||
* IMAPHost format: {imap|imaps}://[IMAPHostURL]:[Port] example: imaps://imap.gmail.com:993
|
||||
*/
|
||||
public class RequestEMailProcessor extends SvrProcess implements ProcessEmailHandle
|
||||
{
|
||||
|
@ -65,6 +66,7 @@ public class RequestEMailProcessor extends SvrProcess implements ProcessEmailHan
|
|||
protected String p_InboxFolder = null;
|
||||
protected Boolean p_NestInbox = true;
|
||||
protected String p_ErrorFolder = null;
|
||||
protected Boolean isSSL = null;
|
||||
protected int C_BPartner_ID = 0;
|
||||
protected int AD_User_ID = 0;
|
||||
protected int AD_Role_ID = 0;
|
||||
|
@ -146,7 +148,7 @@ public class RequestEMailProcessor extends SvrProcess implements ProcessEmailHan
|
|||
{
|
||||
parseParameter();
|
||||
|
||||
EmailSrv emailSrv = new EmailSrv(p_IMAPHost, p_IMAPUser, p_IMAPPwd, p_IMAPPort);
|
||||
EmailSrv emailSrv = new EmailSrv(p_IMAPHost, p_IMAPUser, p_IMAPPwd, p_IMAPPort, isSSL);
|
||||
|
||||
checkInputParameter (emailSrv);
|
||||
|
||||
|
@ -159,6 +161,22 @@ public class RequestEMailProcessor extends SvrProcess implements ProcessEmailHan
|
|||
} // doIt
|
||||
|
||||
protected void parseParameter() {
|
||||
// === check for ssl input parameter ===
|
||||
int imapProtocolIndex = p_IMAPHost.lastIndexOf("://");
|
||||
|
||||
if(imapProtocolIndex > 0) {
|
||||
String str_Protocol = p_IMAPHost.substring(0, imapProtocolIndex);
|
||||
if(str_Protocol.toLowerCase().equals("imaps"))
|
||||
isSSL = true;
|
||||
else if(str_Protocol.toLowerCase().equals("imap"))
|
||||
isSSL = false;
|
||||
else
|
||||
log.warning("Unrecognized protocol - " + str_Protocol);
|
||||
|
||||
if(isSSL != null) // Remove Imap Protocol
|
||||
p_IMAPHost = p_IMAPHost.substring(imapProtocolIndex + 3, p_IMAPHost.length());
|
||||
}
|
||||
|
||||
// === check input parameter ===
|
||||
int portStartIndex = p_IMAPHost.lastIndexOf(":");
|
||||
if (portStartIndex > 0){
|
||||
|
@ -171,6 +189,8 @@ public class RequestEMailProcessor extends SvrProcess implements ProcessEmailHan
|
|||
}
|
||||
}else if (p_IMAPHost.startsWith("imap.gmail.com")){
|
||||
p_IMAPPort = 993;
|
||||
} else if(portStartIndex <= 0 && isSSL != null && isSSL) {
|
||||
p_IMAPPort = 993; // Default Port for IMAPS protocol
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,25 +73,38 @@ public class EmailSrv {
|
|||
protected String imapUser;
|
||||
protected String imapPass;
|
||||
protected int imapPort = 143;
|
||||
protected boolean isGmail = false;
|
||||
protected boolean isSSL = false;
|
||||
|
||||
protected Session mailSession;
|
||||
protected Store mailStore;
|
||||
|
||||
public EmailSrv (String imapHost, String imapUser, String imapPass, int imapPort){
|
||||
public EmailSrv (String imapHost, String imapUser, String imapPass, int imapPort, Boolean isSSL){
|
||||
this.imapHost = imapHost;
|
||||
this.imapUser = imapUser;
|
||||
this.imapPass = imapPass;
|
||||
isGmail = this.imapHost.toLowerCase().startsWith ("imap.gmail.com");
|
||||
if (isGmail && imapPort != 993){
|
||||
log.warning("because imap is gmail server, force port to 993");
|
||||
imapPort = 993;
|
||||
if(isSSL != null) {
|
||||
this.isSSL = isSSL;
|
||||
} else {
|
||||
this.isSSL = this.imapHost.toLowerCase().startsWith ("imap.gmail.com");
|
||||
if(!this.isSSL && imapPort == 993)
|
||||
this.isSSL = true; // Port is 993 set to SSL IMAPS
|
||||
if (this.isSSL && imapPort != 993){
|
||||
log.warning("because imap is gmail server, force port to 993");
|
||||
imapPort = 993;
|
||||
}
|
||||
}
|
||||
|
||||
this.imapPort = imapPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated working only with gmail host.
|
||||
* @param imapHost
|
||||
* @param imapUser
|
||||
* @param imapPass
|
||||
*/
|
||||
public EmailSrv (String imapHost, String imapUser, String imapPass){
|
||||
this (imapHost, imapUser, imapPass, (imapHost != null && imapHost.toLowerCase().startsWith ("imap.gmail.com"))? 993 : 143);
|
||||
this (imapHost, imapUser, imapPass, (imapHost != null && imapHost.toLowerCase().startsWith ("imap.gmail.com"))? 993 : 143, (imapHost != null && imapHost.toLowerCase().startsWith ("imap.gmail.com"))? true : false);
|
||||
}
|
||||
|
||||
public static void logMailPartInfo (Part msg, CLogger log) throws MessagingException{
|
||||
|
@ -160,7 +173,7 @@ public class EmailSrv {
|
|||
// Session
|
||||
Properties props = System.getProperties();
|
||||
String protocol = "imap";
|
||||
if (isGmail){
|
||||
if (isSSL){
|
||||
protocol = "imaps";
|
||||
}
|
||||
props.put("mail.store.protocol", protocol);
|
||||
|
|
Loading…
Reference in New Issue