Package javax.mail

Examples of javax.mail.Folder


        if (gmailMessages == null || gmailMessages.length <= 0) {
            LOG.warn("ImapGmailClient requires GmailMessage(s) to move"
                    + " to move messages to trash folder");
            return;
        }
        Folder folder = null;
       
        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder,store);
            if(!folder.isOpen())
            {
                folder.open(Folder.READ_WRITE);               
            }
           
            List<Message> markedMsgList = new ArrayList<Message>();
            for (GmailMessage gmailMessage : gmailMessages) {
                // get only messages that match to the specified message number
                Message message = folder.getMessage(gmailMessage.getMessageNumber());
                message.setFlag(Flags.Flag.SEEN, true);
                // mark message as delete
                message.setFlag(Flags.Flag.DELETED, true);
                markedMsgList.add(message);
            }

            Folder trash = getFolder(ImapGmailLabel.TRASH.getName(),store);
            if(folder.getURLName().equals(trash.getURLName())){
                LOG.warn("ImapGmailClient trying to move GmailMessage(s) within"
                        + " same folder(ImapGmailLabel.TRASH.getName())");
            }
            // move the marked messages to trash folder
            if (!markedMsgList.isEmpty()) {
View Full Code Here


    public void markAsRead(int messageNumber) {
        if (messageNumber <= 0) {
            throw new GmailException("ImapGmailClient invalid "
                    + "GmailMessage number");
        }
        Folder folder = null;
       
        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder, store);
            folder.open(Folder.READ_WRITE);
            Message message = folder.getMessage(messageNumber);
            if (!message.isSet(Flags.Flag.SEEN)) {
                message.setFlag(Flags.Flag.SEEN, true);
            }
        } catch (Exception e) {
            throw new GmailException("ImapGmailClient failed marking"
View Full Code Here

     * Mark all {@link GmailMessage}(s) as read in a folder.
     *
     * @throws GmailException if unable to mark all {@link GmailMessage} as read
     */
    public void markAllAsRead() {
        Folder folder = null;

        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder, store);
            folder.open(Folder.READ_WRITE);
            for (final Message message : folder.search(new FlagTerm(
                    new Flags(Flags.Flag.SEEN), false))) {
                message.setFlag(Flags.Flag.SEEN, true);
            }
        } catch (Exception e) {
            throw new GmailException("ImapGmailClient failed marking"
View Full Code Here

    public void markAsUnread(int messageNumber) {
        if (messageNumber <= 0) {
            throw new GmailException("ImapGmailClient invalid "
                    + "GmailMessage number");
        }
        Folder folder = null;

        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder, store);
            folder.open(Folder.READ_WRITE);
            Message message = folder.getMessage(messageNumber);
            if (message.isSet(Flags.Flag.SEEN)) {
                message.setFlag(Flags.Flag.SEEN, false);
            }
        } catch (Exception e) {
            throw new GmailException("ImapGmailClient failed marking"
View Full Code Here

    public void addStar(int messageNumber){
        if (messageNumber <= 0) {
            throw new GmailException("ImapGmailClient invalid "
                    + "GmailMessage number");
        }
        Folder folder = null;

        try {
            final Store store = openGmailStore();
            folder = getFolder(this.srcFolder, store);
            folder.open(Folder.READ_WRITE);
            Message message = folder.getMessage(messageNumber);
            if (!message.isSet(Flags.Flag.FLAGGED)) {
                message.setFlag(Flags.Flag.FLAGGED, true);
            }
        } catch (Exception e) {
            throw new GmailException("ImapGmailClient failed flagging"
View Full Code Here

    public void removeStar(int messageNumber){
        if (messageNumber <= 0) {
            throw new GmailException("ImapGmailClient invalid "
                    + "GmailMessage number");
        }
        Folder folder = null;

        try {
            final Store store = openGmailStore();
            folder = getFolder(ImapGmailLabel.STARRED.getName(), store);
            folder.open(Folder.READ_WRITE);
            Message message = folder.getMessage(messageNumber);
            if (message.isSet(Flags.Flag.FLAGGED)) {
                message.setFlag(Flags.Flag.FLAGGED, false);
            }
        } catch (Exception e) {
            throw new GmailException("ImapGmailClient failed removing"
View Full Code Here

    public void moveTo(ImapGmailLabel destFolder,int messageNumber){
        if (messageNumber <= 0) {
            throw new GmailException("ImapGmailClient invalid GmailMessage number");
        }

        Folder fromFolder = null;
        Folder toFolder = null;

        try {
            final Store store = openGmailStore();
            fromFolder = getFolder(this.srcFolder, store);
            fromFolder.open(Folder.READ_WRITE);
            Message message = fromFolder.getMessage(messageNumber);

            if (message != null) {
                toFolder = getFolder(destFolder.getName(), store);

                if (fromFolder.getURLName().equals(toFolder.getURLName())) {
                    throw new GmailException("ImapGmailClient cannot move "
                            + "GmailMessage within same folder "
                            + "(from " + fromFolder.getFullName() + " to "
                            + toFolder.getFullName() + ")");
                }
                // copy from source folder to destination folder
                fromFolder.copyMessages(new Message[]{message}, toFolder);
                // move the copied message to trash folder
                moveToTrash(new GmailMessage[]{new JavaMailGmailMessage(message)});
View Full Code Here

     */
    public List<GmailMessage> getPriorityMessages(boolean unreadOnly){
        try {
            final List<GmailMessage> priorityMessages = new ArrayList<GmailMessage>();
            final Store store = openGmailStore();
            Folder folder = getFolder(ImapGmailLabel.IMPORTANT.getName(),store);
            folder.open(Folder.READ_ONLY);
            for (final Message msg : folder.search(new FlagTerm(
                    new Flags(Flags.Flag.SEEN), !unreadOnly))) {
                priorityMessages.add(new JavaMailGmailMessage(msg));
            }
           
            return priorityMessages;
View Full Code Here

        Store store =
                session.getStore(new URLName("pop3://" + user.getUsername()
                        + ":" + user.getPassword() + "@" + remoteHost + ":"
                        + +remotePort + "/INBOX"));
        store.connect();
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_WRITE);
        Message[] messages = folder.getMessages();
        int cSuccessfulMails = 0;
        // user name currently equals with the maildrop name, but this is
        // not necessarily true in general.
        String maildropName = user.getUsername().toString();
        for (Message message : messages) {
            try {
                importMail(maildropName, message);
                message.setFlag(Flags.Flag.DELETED, true);
                cSuccessfulMails++;
            } catch (Exception e) {
                logger.error("Importing a mail for " + user.getUsername()
                        + " failed", e);
            }
        }
        folder.close(true);
        store.close();
        totalMailCount += cSuccessfulMails;
        if (cSuccessfulMails > 0)
            totalUsersWithAtLeastOneMail++;
        logger.debug(cSuccessfulMails + " mails were imported for "
View Full Code Here

        Session session = Session.getInstance(properties);
        Store store =
                session.getStore(new URLName("pop3://john:secret@localhost:"
                        + PORT_POP + "/INBOX"));
        store.connect();
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_WRITE);
        Message[] messages = folder.getMessages();
        assertEquals(1, messages.length);
        Message message = messages[0];
        assertEquals("Hello World!\r\n", message.getContent());
        message.setFlag(Flags.Flag.DELETED, true);
        folder.close(true);
        store.close();
    }
View Full Code Here

TOP

Related Classes of javax.mail.Folder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.