GH-10083: Apply Nullability to spring-integration-mail
Related to: #10083 Signed-off-by: Jiandong Ma <jiandong.ma.cn@gmail.com>
This commit is contained in:
@@ -40,6 +40,7 @@ import jakarta.mail.Session;
|
||||
import jakarta.mail.Store;
|
||||
import jakarta.mail.URLName;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -79,7 +80,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
*/
|
||||
public static final String DEFAULT_SI_USER_FLAG = "spring-integration-mail-adapter";
|
||||
|
||||
private final URLName url;
|
||||
private final @Nullable URLName url;
|
||||
|
||||
private final ReentrantReadWriteLock folderLock = new ReentrantReadWriteLock();
|
||||
|
||||
@@ -87,11 +88,11 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
|
||||
private final Lock folderWriteLock = this.folderLock.writeLock();
|
||||
|
||||
private String protocol;
|
||||
private @Nullable String protocol;
|
||||
|
||||
private int maxFetchSize = -1;
|
||||
|
||||
private Session session;
|
||||
private @Nullable Session session;
|
||||
|
||||
private boolean shouldDeleteMessages;
|
||||
|
||||
@@ -99,13 +100,14 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
|
||||
private Properties javaMailProperties = new Properties();
|
||||
|
||||
private Authenticator javaMailAuthenticator;
|
||||
private @Nullable Authenticator javaMailAuthenticator;
|
||||
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private StandardEvaluationContext evaluationContext;
|
||||
|
||||
private Expression selectorExpression;
|
||||
private @Nullable Expression selectorExpression;
|
||||
|
||||
private HeaderMapper<MimeMessage> headerMapper;
|
||||
private @Nullable HeaderMapper<MimeMessage> headerMapper;
|
||||
|
||||
private String userFlag = DEFAULT_SI_USER_FLAG;
|
||||
|
||||
@@ -117,9 +119,9 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
|
||||
private boolean flaggedAsFallback = true;
|
||||
|
||||
private volatile Store store;
|
||||
private volatile @Nullable Store store;
|
||||
|
||||
private volatile Folder folder;
|
||||
private volatile @Nullable Folder folder;
|
||||
|
||||
public AbstractMailReceiver() {
|
||||
this.url = null;
|
||||
@@ -130,7 +132,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
this.url = urlName;
|
||||
}
|
||||
|
||||
public AbstractMailReceiver(String url) {
|
||||
public AbstractMailReceiver(@Nullable String url) {
|
||||
if (url != null) {
|
||||
this.url = new URLName(url);
|
||||
}
|
||||
@@ -139,7 +141,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelectorExpression(Expression selectorExpression) {
|
||||
public void setSelectorExpression(@Nullable Expression selectorExpression) {
|
||||
this.selectorExpression = selectorExpression;
|
||||
}
|
||||
|
||||
@@ -306,7 +308,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
this.flaggedAsFallback = flaggedAsFallback;
|
||||
}
|
||||
|
||||
protected Folder getFolder() {
|
||||
protected @Nullable Folder getFolder() {
|
||||
return this.folder;
|
||||
}
|
||||
|
||||
@@ -334,6 +336,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
|
||||
private void connectStoreIfNecessary() throws MessagingException {
|
||||
if (this.store == null) {
|
||||
Assert.state(this.session != null, "'session' should not be null");
|
||||
if (this.url != null) {
|
||||
this.store = this.session.getStore(this.url);
|
||||
}
|
||||
@@ -345,7 +348,8 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
}
|
||||
}
|
||||
if (!this.store.isConnected()) {
|
||||
this.logger.debug(() -> "connecting to store [" + this.store.getURLName() + "]");
|
||||
URLName urlName = this.store.getURLName();
|
||||
this.logger.debug(() -> "connecting to store [" + urlName + "]");
|
||||
this.store.connect();
|
||||
}
|
||||
}
|
||||
@@ -360,7 +364,8 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
connectStoreIfNecessary();
|
||||
}
|
||||
if (this.folder == null || !this.folder.exists()) {
|
||||
throw new IllegalStateException("no such folder [" + this.url.getFile() + "]");
|
||||
String file = this.url != null ? this.url.getFile() : "";
|
||||
throw new IllegalStateException("no such folder [" + file + "]");
|
||||
}
|
||||
if (this.folder.isOpen()) {
|
||||
return;
|
||||
@@ -371,6 +376,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
}
|
||||
|
||||
private Folder obtainFolderInstance() throws MessagingException {
|
||||
Assert.state(this.store != null, "'store' should not be null");
|
||||
if (this.url == null) {
|
||||
return this.store.getDefaultFolder();
|
||||
}
|
||||
@@ -422,7 +428,9 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
}
|
||||
|
||||
private MimeMessage[] searchAndFilterMessages() throws MessagingException {
|
||||
this.logger.debug(() -> "attempting to receive mail from folder [" + this.folder.getFullName() + "]");
|
||||
Assert.state(this.folder != null, "'folder' should not be null");
|
||||
String fullName = this.folder.getFullName();
|
||||
this.logger.debug(() -> "attempting to receive mail from folder [" + fullName + "]");
|
||||
Message[] messagesToProcess;
|
||||
Message[] messages = searchForNewMessages();
|
||||
if (this.maxFetchSize > 0 && messages.length > this.maxFetchSize) {
|
||||
@@ -549,7 +557,9 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
private void setMessageFlags(Message[] filteredMessages) throws MessagingException {
|
||||
boolean recentFlagSupported = false;
|
||||
|
||||
Flags flags = getFolder().getPermanentFlags();
|
||||
Folder folder = getFolder();
|
||||
Assert.state(folder != null, "'folder' should not be null");
|
||||
Flags flags = folder.getPermanentFlags();
|
||||
|
||||
if (flags != null) {
|
||||
recentFlagSupported = flags.contains(Flags.Flag.RECENT);
|
||||
@@ -612,6 +622,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
contentsProfile.add(FetchProfile.Item.ENVELOPE);
|
||||
contentsProfile.add(FetchProfile.Item.CONTENT_INFO);
|
||||
contentsProfile.add(FetchProfile.Item.FLAGS);
|
||||
Assert.state(this.folder != null, "'folder' should not be null");
|
||||
this.folder.fetch(messages, contentsProfile);
|
||||
}
|
||||
|
||||
@@ -658,10 +669,12 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.url.toString();
|
||||
String urlName = this.store != null && this.store.getURLName() != null
|
||||
? this.store.getURLName().toString() : "";
|
||||
return this.url != null ? this.url.toString() : urlName;
|
||||
}
|
||||
|
||||
Store getStore() {
|
||||
@Nullable Store getStore() {
|
||||
return this.store;
|
||||
}
|
||||
|
||||
@@ -678,7 +691,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
|
||||
private final MimeMessage source;
|
||||
|
||||
private final Object content;
|
||||
private final @Nullable Object content;
|
||||
|
||||
IntegrationMimeMessage(MimeMessage source) throws MessagingException {
|
||||
super(source);
|
||||
@@ -700,7 +713,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Folder getFolder() {
|
||||
public @Nullable Folder getFolder() {
|
||||
if (!AbstractMailReceiver.this.autoCloseFolder) {
|
||||
return AbstractMailReceiver.this.folder;
|
||||
}
|
||||
@@ -731,7 +744,7 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContent() throws IOException, MessagingException {
|
||||
public @Nullable Object getContent() throws IOException, MessagingException {
|
||||
if (AbstractMailReceiver.this.simpleContent) {
|
||||
return super.getContent();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import java.util.function.Consumer;
|
||||
import jakarta.mail.Folder;
|
||||
import jakarta.mail.Message;
|
||||
import org.aopalliance.aop.Advice;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
@@ -35,7 +36,6 @@ import org.springframework.integration.mail.event.MailIntegrationEvent;
|
||||
import org.springframework.integration.transaction.IntegrationResourceHolder;
|
||||
import org.springframework.integration.transaction.IntegrationResourceHolderSynchronization;
|
||||
import org.springframework.integration.transaction.TransactionSynchronizationFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
@@ -62,18 +62,22 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport implements Be
|
||||
|
||||
private final ImapMailReceiver mailReceiver;
|
||||
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private Executor taskExecutor;
|
||||
|
||||
private TransactionSynchronizationFactory transactionSynchronizationFactory;
|
||||
private @Nullable TransactionSynchronizationFactory transactionSynchronizationFactory;
|
||||
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private ClassLoader classLoader;
|
||||
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
private boolean shouldReconnectAutomatically = true;
|
||||
|
||||
private List<Advice> adviceChain;
|
||||
private @Nullable List<Advice> adviceChain;
|
||||
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private Consumer<Object> messageSender;
|
||||
|
||||
private long reconnectDelay = DEFAULT_RECONNECT_DELAY; // milliseconds
|
||||
@@ -252,8 +256,8 @@ public class ImapIdleChannelAdapter extends MessageProducerSupport implements Be
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static jakarta.mail.MessagingException getJakartaMailMessagingExceptionFromCause(Throwable cause) {
|
||||
private static jakarta.mail.@Nullable MessagingException getJakartaMailMessagingExceptionFromCause(
|
||||
@Nullable Throwable cause) {
|
||||
if (cause == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import jakarta.mail.search.FlagTerm;
|
||||
import jakarta.mail.search.NotTerm;
|
||||
import jakarta.mail.search.SearchTerm;
|
||||
import org.eclipse.angus.mail.imap.IMAPFolder;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
@@ -67,11 +68,12 @@ public class ImapMailReceiver extends AbstractMailReceiver {
|
||||
|
||||
private long cancelIdleInterval = DEFAULT_CANCEL_IDLE_INTERVAL;
|
||||
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private TaskScheduler scheduler;
|
||||
|
||||
private boolean isInternalScheduler;
|
||||
|
||||
private volatile ScheduledFuture<?> pingTask;
|
||||
private volatile @Nullable ScheduledFuture<?> pingTask;
|
||||
|
||||
@SuppressWarnings("this-escape")
|
||||
public ImapMailReceiver() {
|
||||
@@ -79,7 +81,7 @@ public class ImapMailReceiver extends AbstractMailReceiver {
|
||||
}
|
||||
|
||||
@SuppressWarnings("this-escape")
|
||||
public ImapMailReceiver(String url) {
|
||||
public ImapMailReceiver(@Nullable String url) {
|
||||
super(url);
|
||||
if (url != null) {
|
||||
Assert.isTrue(url.toLowerCase(Locale.ROOT).startsWith(PROTOCOL),
|
||||
@@ -212,6 +214,7 @@ public class ImapMailReceiver extends AbstractMailReceiver {
|
||||
@Override
|
||||
protected Message[] searchForNewMessages() throws MessagingException {
|
||||
Folder folderToUse = getFolder();
|
||||
Assert.state(folderToUse != null, "'folderToUse' should not be null");
|
||||
Flags supportedFlags = folderToUse.getPermanentFlags();
|
||||
SearchTerm searchTerm = compileSearchTerms(supportedFlags);
|
||||
if (folderToUse.isOpen()) {
|
||||
@@ -238,8 +241,10 @@ public class ImapMailReceiver extends AbstractMailReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
private SearchTerm compileSearchTerms(Flags supportedFlags) {
|
||||
return this.searchTermStrategy.generateSearchTerm(supportedFlags, this.getFolder());
|
||||
private @Nullable SearchTerm compileSearchTerms(Flags supportedFlags) {
|
||||
Folder folderToUse = this.getFolder();
|
||||
Assert.state(folderToUse != null, "'folderToUse' should not be null");
|
||||
return this.searchTermStrategy.generateSearchTerm(supportedFlags, folderToUse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -277,7 +282,7 @@ public class ImapMailReceiver extends AbstractMailReceiver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder) {
|
||||
public @Nullable SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder) {
|
||||
SearchTerm searchTerm = null;
|
||||
boolean recentFlagSupported = false;
|
||||
if (supportedFlags != null) {
|
||||
@@ -320,7 +325,7 @@ public class ImapMailReceiver extends AbstractMailReceiver {
|
||||
return searchTerm;
|
||||
}
|
||||
|
||||
private SearchTerm applyTermsWhenNoRecentFlag(Folder folder, SearchTerm searchTerm) {
|
||||
private SearchTerm applyTermsWhenNoRecentFlag(Folder folder, @Nullable SearchTerm searchTerm) {
|
||||
NotTerm notFlagged;
|
||||
if (folder.getPermanentFlags().contains(Flag.USER)) {
|
||||
logger.debug(() -> "This email server does not support RECENT flag, but it does support " +
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.mail;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Strategy interface for receiving mail {@link jakarta.mail.Message Messages}.
|
||||
*
|
||||
@@ -25,6 +27,6 @@ package org.springframework.integration.mail;
|
||||
*/
|
||||
public interface MailReceiver {
|
||||
|
||||
Object[] receive() throws jakarta.mail.MessagingException;
|
||||
Object @Nullable [] receive() throws jakarta.mail.MessagingException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,8 @@ import java.util.Arrays;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.core.log.LogMessage;
|
||||
import org.springframework.integration.endpoint.AbstractMessageSource;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
@@ -54,7 +56,7 @@ public class MailReceivingMessageSource extends AbstractMessageSource<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doReceive() {
|
||||
protected @Nullable Object doReceive() {
|
||||
try {
|
||||
Object mailMessage = this.mailQueue.poll();
|
||||
if (mailMessage == null) {
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
|
||||
package org.springframework.integration.mail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
@@ -190,12 +194,14 @@ public class MailSendingMessageHandler extends AbstractMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private String[] retrieveHeaderValueAsStringArray(MessageHeaders headers, String key) {
|
||||
private String @Nullable [] retrieveHeaderValueAsStringArray(MessageHeaders headers, String key) {
|
||||
Object value = headers.get(key);
|
||||
String[] returnedHeaders = null;
|
||||
if (value != null) {
|
||||
if (value instanceof String[]) {
|
||||
returnedHeaders = (String[]) value;
|
||||
if (value instanceof String[] strArr) {
|
||||
returnedHeaders = Arrays.stream(strArr)
|
||||
.filter(Objects::nonNull)
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
returnedHeaders = StringUtils.commaDelimitedListToStringArray((String) value);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2024 the original author or authors.
|
||||
* Copyright 2007-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import jakarta.mail.Service;
|
||||
import jakarta.mail.URLName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -44,7 +45,7 @@ public abstract class MailTransportUtils {
|
||||
* @see jakarta.mail.Transport
|
||||
* @see jakarta.mail.Store
|
||||
*/
|
||||
public static void closeService(Service service) {
|
||||
public static void closeService(@Nullable Service service) {
|
||||
if (service != null) {
|
||||
try {
|
||||
service.close();
|
||||
@@ -61,7 +62,7 @@ public abstract class MailTransportUtils {
|
||||
* @param folder the JavaMail Folder to close (may be <code>null</code>)
|
||||
* @param expunge whether all deleted messages should be expunged from the folder
|
||||
*/
|
||||
public static void closeFolder(Folder folder, boolean expunge) {
|
||||
public static void closeFolder(@Nullable Folder folder, boolean expunge) {
|
||||
if (folder != null && folder.isOpen()) {
|
||||
try {
|
||||
folder.close(expunge);
|
||||
|
||||
@@ -21,6 +21,7 @@ import jakarta.mail.Message;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.URLName;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class Pop3MailReceiver extends AbstractMailReceiver {
|
||||
}
|
||||
|
||||
@SuppressWarnings("this-escape")
|
||||
public Pop3MailReceiver(String url) {
|
||||
public Pop3MailReceiver(@Nullable String url) {
|
||||
super(url);
|
||||
if (url != null) {
|
||||
Assert.isTrue(url.startsWith(PROTOCOL), "url must start with 'pop3'");
|
||||
@@ -63,6 +64,7 @@ public class Pop3MailReceiver extends AbstractMailReceiver {
|
||||
@Override
|
||||
protected Message[] searchForNewMessages() throws MessagingException {
|
||||
Folder folderToUse = getFolder();
|
||||
Assert.state(folderToUse != null, "'folderToUse' should not be null");
|
||||
int messageCount = folderToUse.getMessageCount();
|
||||
if (messageCount == 0) {
|
||||
return new Message[0];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.mail;
|
||||
import jakarta.mail.Flags;
|
||||
import jakarta.mail.Folder;
|
||||
import jakarta.mail.search.SearchTerm;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Strategy to be used to generate a {@link SearchTerm}.
|
||||
@@ -38,6 +39,6 @@ public interface SearchTermStrategy {
|
||||
* @param folder The folder.
|
||||
* @return The search term.
|
||||
*/
|
||||
SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder);
|
||||
@Nullable SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import jakarta.mail.Authenticator;
|
||||
import jakarta.mail.Session;
|
||||
import jakarta.mail.URLName;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
@@ -34,7 +35,6 @@ import org.springframework.integration.mail.MailReceiver;
|
||||
import org.springframework.integration.mail.Pop3MailReceiver;
|
||||
import org.springframework.integration.mail.SearchTermStrategy;
|
||||
import org.springframework.integration.mapping.HeaderMapper;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -48,41 +48,42 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class MailReceiverFactoryBean extends AbstractFactoryBean<MailReceiver> {
|
||||
|
||||
private String storeUri;
|
||||
private @Nullable String storeUri;
|
||||
|
||||
private String protocol;
|
||||
private @Nullable String protocol;
|
||||
|
||||
private Session session;
|
||||
private @Nullable Session session;
|
||||
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private MailReceiver receiver;
|
||||
|
||||
private Properties javaMailProperties;
|
||||
private @Nullable Properties javaMailProperties;
|
||||
|
||||
private Authenticator authenticator;
|
||||
private @Nullable Authenticator authenticator;
|
||||
|
||||
/**
|
||||
* Indicates whether retrieved messages should be deleted from the server.
|
||||
* This value will be <code>null</code> <i>unless</i> explicitly configured.
|
||||
*/
|
||||
private Boolean shouldDeleteMessages = null;
|
||||
private @Nullable Boolean shouldDeleteMessages = null;
|
||||
|
||||
private Boolean shouldMarkMessagesAsRead = null;
|
||||
private @Nullable Boolean shouldMarkMessagesAsRead = null;
|
||||
|
||||
private int maxFetchSize = 1;
|
||||
|
||||
private Expression selectorExpression;
|
||||
private @Nullable Expression selectorExpression;
|
||||
|
||||
private SearchTermStrategy searchTermStrategy;
|
||||
private @Nullable SearchTermStrategy searchTermStrategy;
|
||||
|
||||
private String userFlag;
|
||||
private @Nullable String userFlag;
|
||||
|
||||
private HeaderMapper<MimeMessage> headerMapper;
|
||||
private @Nullable HeaderMapper<MimeMessage> headerMapper;
|
||||
|
||||
private Boolean embeddedPartsAsBytes;
|
||||
private @Nullable Boolean embeddedPartsAsBytes;
|
||||
|
||||
private Boolean simpleContent;
|
||||
private @Nullable Boolean simpleContent;
|
||||
|
||||
private Boolean autoCloseFolder;
|
||||
private @Nullable Boolean autoCloseFolder;
|
||||
|
||||
public void setStoreUri(@Nullable String storeUri) {
|
||||
this.storeUri = storeUri;
|
||||
@@ -163,6 +164,7 @@ public class MailReceiverFactoryBean extends AbstractFactoryBean<MailReceiver> {
|
||||
|
||||
private MailReceiver createReceiver() { // NOSONAR
|
||||
verifyProtocol();
|
||||
Assert.state(this.protocol != null, "'protocol' should not be null ");
|
||||
boolean isPop3 = this.protocol.toLowerCase(Locale.ROOT).startsWith("pop3");
|
||||
boolean isImap = this.protocol.toLowerCase(Locale.ROOT).startsWith("imap");
|
||||
Assert.isTrue(isPop3 || isImap, "the store URI must begin with 'pop3' or 'imap'");
|
||||
@@ -203,7 +205,7 @@ public class MailReceiverFactoryBean extends AbstractFactoryBean<MailReceiver> {
|
||||
}
|
||||
}
|
||||
else {
|
||||
((ImapMailReceiver) mailReceiver).setShouldMarkMessagesAsRead(this.shouldMarkMessagesAsRead);
|
||||
((ImapMailReceiver) mailReceiver).setShouldMarkMessagesAsRead(isShouldMarkMessagesAsRead());
|
||||
}
|
||||
BeanFactory beanFactory = getBeanFactory();
|
||||
if (beanFactory != null) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/**
|
||||
* Provides classes for configuration - parsers, namespace handlers.
|
||||
*/
|
||||
@org.jspecify.annotations.NullMarked
|
||||
package org.springframework.integration.mail.config;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2024 the original author or authors.
|
||||
* Copyright 2014-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.springframework.integration.mail.dsl;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.integration.mail.ImapMailReceiver;
|
||||
import org.springframework.integration.mail.MailSendingMessageHandler;
|
||||
import org.springframework.integration.mail.Pop3MailReceiver;
|
||||
import org.springframework.integration.mail.transformer.MailToStringTransformer;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.mail.MailSender;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,11 +20,11 @@ import java.util.Properties;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import jakarta.activation.FileTypeMap;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.integration.dsl.MessageHandlerSpec;
|
||||
import org.springframework.integration.mail.MailSendingMessageHandler;
|
||||
import org.springframework.integration.support.PropertiesBuilder;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/**
|
||||
* Provides Mail Components for the Java DSL.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
@org.springframework.lang.NonNullFields
|
||||
@org.jspecify.annotations.NullMarked
|
||||
package org.springframework.integration.mail.dsl;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/**
|
||||
* Events generated by the mail module
|
||||
*/
|
||||
@org.jspecify.annotations.NullMarked
|
||||
package org.springframework.integration.mail.event;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/**
|
||||
* Base package for Mail support.
|
||||
*/
|
||||
@org.jspecify.annotations.NullMarked
|
||||
package org.springframework.integration.mail;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/**
|
||||
* Provides classes to support email.
|
||||
*/
|
||||
@org.jspecify.annotations.NullMarked
|
||||
package org.springframework.integration.mail.support;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,8 @@ package org.springframework.integration.mail.transformer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.integration.mail.support.MailUtils;
|
||||
@@ -41,7 +43,7 @@ import org.springframework.messaging.Message;
|
||||
*/
|
||||
public abstract class AbstractMailMessageTransformer<T> implements Transformer, BeanFactoryAware {
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
private @Nullable BeanFactory beanFactory;
|
||||
|
||||
private MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
|
||||
|
||||
@@ -71,9 +73,6 @@ public abstract class AbstractMailMessageTransformer<T> implements Transformer,
|
||||
}
|
||||
AbstractIntegrationMessageBuilder<T> builder;
|
||||
builder = doTransform(mailMessage);
|
||||
if (builder == null) {
|
||||
throw new MessageTransformationException(message, "failed to transform mail message");
|
||||
}
|
||||
return builder.copyHeaders(extractHeaderMapFromMailMessage(mailMessage)).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/**
|
||||
* Provides classes related to transforming mail messages.
|
||||
*/
|
||||
@org.jspecify.annotations.NullMarked
|
||||
package org.springframework.integration.mail.transformer;
|
||||
|
||||
Reference in New Issue
Block a user