
org.springframework.xd.mail.MailSourceOptionsMetadata Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2013-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.xd.mail;
import static org.springframework.xd.mail.MailProtocol.imap;
import static org.springframework.xd.mail.MailProtocol.imaps;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import org.springframework.xd.module.options.spi.Mixin;
import org.springframework.xd.module.options.spi.ModuleOption;
import org.springframework.xd.module.options.spi.ProfileNamesProvider;
/**
* Captures options for the {@code mail} source module.
*
* @author Eric Bottard
*/
@Mixin({ MailServerMixin.class })
public class MailSourceOptionsMetadata implements ProfileNamesProvider {
private int fixedDelay = 60;
private MailProtocol protocol = imap;
private boolean usePolling = false;
private boolean delete = true;
private boolean markAsRead = false;
private String charset = "UTF-8";
private String folder = "INBOX";
private String expression = "true";
@NotNull
public String getExpression() {
return expression;
}
@ModuleOption("a SpEL expression which filters which mail messages will be processed (non polling imap only)")
public void setExpression(String expression) {
this.expression = expression;
}
@NotNull
public String getFolder() {
return folder;
}
@ModuleOption("the folder to take emails from")
public void setFolder(String folder) {
this.folder = folder;
}
@NotNull
public String getCharset() {
return charset;
}
@ModuleOption("the charset used to transform the body of the incoming emails to Strings")
public void setCharset(String charset) {
this.charset = charset;
}
public boolean isDelete() {
return delete;
}
public boolean isMarkAsRead() {
return markAsRead;
}
@ModuleOption("whether to delete the emails once they’ve been fetched")
public void setDelete(boolean delete) {
this.delete = delete;
}
@ModuleOption("whether to mark emails as read once they’ve been fetched")
public void setMarkAsRead(boolean markAsRead) {
this.markAsRead = markAsRead;
}
@Min(0)
public int getFixedDelay() {
return fixedDelay;
}
@NotNull
public MailProtocol getProtocol() {
return protocol;
}
public boolean isUsePolling() {
return usePolling;
}
@Override
public String[] profilesToActivate() {
return usePolling ? new String[] { "use-polling" } : new String[] { "use-idle" };
}
@ModuleOption("the polling interval used for looking up messages (s)")
public void setFixedDelay(int fixedDelay) {
this.fixedDelay = fixedDelay;
}
@ModuleOption("the protocol to use to retrieve messages")
public void setProtocol(MailProtocol protocol) {
this.protocol = protocol;
}
@ModuleOption("whether to use polling or not (no polling works with imap(s) only)")
public void setUsePolling(boolean usePolling) {
this.usePolling = usePolling;
}
@AssertTrue(message = "usePolling=false is only supported with imap(s)")
private boolean isUsePollingValid() {
if (!usePolling) {
return protocol == imap || protocol == imaps;
}
else {
return true;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy