001/*
002 * JGrapes Event driven Framework
003 * Copyright (C) 2022 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jgrapes.mail.events;
020
021import jakarta.mail.Folder;
022import java.util.Arrays;
023import java.util.List;
024import org.jgrapes.core.Event;
025import org.jgrapes.mail.MailChannel;
026import org.jgrapes.mail.MailStoreMonitor;
027
028/**
029 * Triggers the retrieval of mails (update) by a {@link MailStoreMonitor}.
030 * Must be fired on a {@link MailChannel}.
031 */
032public class UpdateFolders extends Event<List<Folder>> {
033
034    private final String[] folderNames;
035
036    /**
037     * Causes new messages to be retrieved from the given folders.
038     * 
039     * The folders specified may be a subset of the folder names used
040     * in the initial {@link OpenMailConnection} event. If left empty,
041     * all folders specified in the open event are retrieved again.
042     *
043     * @param folderNames the folder names
044     */
045    @SuppressWarnings("PMD.ArrayIsStoredDirectly")
046    public UpdateFolders(String... folderNames) {
047        this.folderNames = Arrays.copyOf(folderNames, folderNames.length);
048    }
049
050    /**
051     * Returns the folder names.
052     *
053     * @return the string[]
054     */
055    @SuppressWarnings("PMD.MethodReturnsInternalArray")
056    public String[] folderNames() {
057        return folderNames;
058    }
059
060}