Skip to content
Draft
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
29 changes: 20 additions & 9 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
</delete>
</target>

<condition property="buildvariant" value="${buildvariant}" else="trunk">
<isset property="buildvariant"/>
</condition>

<condition property="is.windows">
<os family="windows"/>
</condition>
Expand All @@ -40,16 +44,17 @@
<available classname="javafx.embed.swing.JFXPanel" property="is.javafx" classpathref="classpath"/>
</condition>

<condition property="is.winrun4j">
<available classname="org.boris.winrun4j.AbstractService" classpathref="classpath"/>
</condition>

<condition property="is.java8">
<matches string="${ant.java.version}" pattern="8"/>
</condition>

<!-- recent debian jdk with OpenJFX -->
<condition property="is.debian">
<and>
<available file="/usr/share/java/javafx-base.jar"/>
<matches string="${ant.java.version}" pattern="1[1-9]|[2-9][0-9]"/>
</and>
<matches string="${ant.java.version}" pattern="1[1-9]|[2-9][0-9]"/>
</condition>

<condition property="is.java11">
Expand Down Expand Up @@ -108,16 +113,16 @@

<target name="compile-debian" if="is.debian">
<mkdir dir="target/classes"/>
<echo level="info" message="Compile on debian with openjfx"/>
<echo level="info" message="Compile on debian"/>
<javac srcdir="src/java" destdir="target/classes" encoding="UTF-8"
includeantruntime="false">
<exclude name="davmail/service/DavService.java" unless="is.winrun4j"/>
<exclude name="davmail/exchange/auth/O365InteractiveAuthenticatorFrame.java" unless="is.javafx"/>
<exclude name="davmail/exchange/auth/O365InteractiveJSLogger.java" unless="is.javafx"/>
<compilerarg value="--add-exports"/>
<compilerarg value="java.naming/com.sun.jndi.ldap=ALL-UNNAMED"/>
<compilerarg value="--add-exports"/>
<compilerarg value="java.base/sun.net.www.protocol.https=ALL-UNNAMED"/>
<compilerarg value="--module-path"/>
<compilerarg value="/usr/share/java/javafx-base.jar:/usr/share/java/javafx-controls.jar:/usr/share/java/javafx-fxml.jar:/usr/share/java/javafx-graphics.jar:/usr/share/java/javafx-media.jar:/usr/share/java/javafx-swing.jar:/usr/share/java/javafx-web.jar"/>
<compilerarg value="--add-modules=javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web"/>
<classpath>
<path refid="classpath"/>
</classpath>
Expand All @@ -130,6 +135,9 @@
<javac srcdir="src/java" destdir="target/classes" encoding="UTF-8" source="11" target="11"
includeantruntime="false">
<exclude name="davmail/exchange/auth/*Interactive*" unless="is.javafx"/>
<exclude name="davmail/service/DavService.java" unless="is.winrun4j"/>
<exclude name="davmail/exchange/auth/O365InteractiveAuthenticatorFrame.java" unless="is.javafx"/>
<exclude name="davmail/exchange/auth/O365InteractiveJSLogger.java" unless="is.javafx"/>
<compilerarg value="--add-exports"/>
<compilerarg value="java.naming/com.sun.jndi.ldap=ALL-UNNAMED"/>
<compilerarg value="--add-exports"/>
Expand All @@ -146,6 +154,9 @@
<javac srcdir="src/java" destdir="target/classes" source="1.8" target="1.8" debug="on" encoding="UTF-8"
includeantruntime="false">
<exclude name="davmail/exchange/auth/*Interactive*" unless="is.javafx"/>
<exclude name="davmail/service/DavService.java" unless="is.winrun4j"/>
<exclude name="davmail/exchange/auth/O365InteractiveAuthenticatorFrame.java" unless="is.javafx"/>
<exclude name="davmail/exchange/auth/O365InteractiveJSLogger.java" unless="is.javafx"/>
<classpath>
<path refid="classpath"/>
</classpath>
Expand Down Expand Up @@ -338,7 +349,7 @@
<target name="jar" depends="compile">
<delete dir="dist"/>
<mkdir dir="dist"/>
<property name="release-name" value="${version}-trunk"/>
<property name="release-name" value="${version}-${buildvariant}"/>
<pathconvert property="manifest-classpath" pathsep=" ">
<mapper>
<chainedmapper>
Expand Down
16 changes: 8 additions & 8 deletions src/java/davmail/exchange/auth/O365InteractiveAuthenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class O365InteractiveAuthenticator implements ExchangeAuthenticator {

URI ewsUrl = URI.create(Settings.getO365Url());

private O365InteractiveAuthenticatorFrame o365InteractiveAuthenticatorFrame;
private O365InteractiveAuthenticatorSWT o365InteractiveAuthenticatorSWT;
private O365InteractiveAuthenticatorBackend o365InteractiveAuthenticatorFrame;
private O365InteractiveAuthenticatorBackend o365InteractiveAuthenticatorSWT;
private O365ManualAuthenticatorDialog o365ManualAuthenticatorDialog;

private String username;
Expand Down Expand Up @@ -144,14 +144,14 @@ public PasswordAuthentication getPasswordAuthentication() {
if (isSWTAvailable && !isDocker) {
LOGGER.debug("Open SWT browser");
try {
o365InteractiveAuthenticatorSWT = new O365InteractiveAuthenticatorSWT();
o365InteractiveAuthenticatorSWT = (O365InteractiveAuthenticatorBackend)Class.forName("O365InteractiveAuthenticatorSWT").newInstance();
o365InteractiveAuthenticatorSWT.setO365InteractiveAuthenticator(O365InteractiveAuthenticator.this);
o365InteractiveAuthenticatorSWT.authenticate(initUrl, redirectUri);
} catch (Error e) {
} catch (Error | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
LOGGER.warn("Unable to load SWT browser: "+e.getMessage());
if (o365InteractiveAuthenticatorSWT != null) {
try {
o365InteractiveAuthenticatorSWT.dispose();
o365InteractiveAuthenticatorSWT.close();
} catch (Throwable t) {
LOGGER.warn("Error disposing SWT frame: "+t.getMessage());
}
Expand All @@ -166,10 +166,10 @@ public PasswordAuthentication getPasswordAuthentication() {
LOGGER.info("Open JavaFX (OpenJFX) browser");
SwingUtilities.invokeLater(() -> {
try {
o365InteractiveAuthenticatorFrame = new O365InteractiveAuthenticatorFrame();
o365InteractiveAuthenticatorFrame = (O365InteractiveAuthenticatorBackend)Class.forName("O365InteractiveAuthenticatorFrame").newInstance();
o365InteractiveAuthenticatorFrame.setO365InteractiveAuthenticator(O365InteractiveAuthenticator.this);
o365InteractiveAuthenticatorFrame.authenticate(initUrl, redirectUri);
} catch (NoClassDefFoundError e) {
} catch (NoClassDefFoundError | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
LOGGER.warn("Unable to load JavaFX (OpenJFX)");
} catch (IllegalAccessError e) {
LOGGER.warn("Unable to load JavaFX (OpenJFX), append --add-exports java.base/sun.net.www.protocol.https=ALL-UNNAMED to java options");
Expand Down Expand Up @@ -212,7 +212,7 @@ public PasswordAuthentication getPasswordAuthentication() {
}

if (o365InteractiveAuthenticatorSWT != null) {
o365InteractiveAuthenticatorSWT.dispose();
o365InteractiveAuthenticatorSWT.close();
}

if (isAuthenticated) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2026 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package davmail.exchange.auth;

public interface O365InteractiveAuthenticatorBackend {

public void setO365InteractiveAuthenticator(O365InteractiveAuthenticator authenticator);
public void authenticate(final String initUrl, final String redirectUri);
public boolean isVisible();
public void close();

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* Interactive authenticator UI based on OpenJFX.
* Need access to internal urlhandler on recent JDK versions with: --add-exports java.base/sun.net.www.protocol.https=ALL-UNNAMED
*/
public class O365InteractiveAuthenticatorFrame extends JFrame {
public class O365InteractiveAuthenticatorFrame extends JFrame implements O365InteractiveAuthenticatorBackend {
private static final Logger LOGGER = Logger.getLogger(O365InteractiveAuthenticatorFrame.class);

private O365InteractiveAuthenticator authenticator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
* Alternative embedded browser implementation based on SWT instead of OpenJFX
*/
public class O365InteractiveAuthenticatorSWT {
public class O365InteractiveAuthenticatorSWT implements O365InteractiveAuthenticatorBackend {

private static final Logger LOGGER = Logger.getLogger(O365InteractiveAuthenticatorSWT.class);

Expand Down Expand Up @@ -80,7 +80,7 @@ public void authenticate(final String initUrl, final String redirectUri) {
if (!authenticator.isAuthenticated && authenticator.errorCode == null) {
authenticator.errorCode = "user closed authentication window";
}
dispose();
close();
});

browser = new Browser(shell, SWT.NONE);
Expand All @@ -99,7 +99,7 @@ public void changing(LocationEvent locationEvent) {
authenticator.handleCode(location);

shell.close();
dispose();
close();
}

}
Expand Down Expand Up @@ -148,7 +148,11 @@ public void changed(LocationEvent locationEvent) {
}
}

protected void dispose() {
public boolean isVisible() {
return true;
}

public void close() {
Display.getDefault().asyncExec(() -> {
if (browser != null) {
browser.dispose();
Expand Down