Package javax.mail

Examples of javax.mail.Flags$Flag


    // Retrieve the "Inbox"
    Folder inbox = store.getFolder("inbox");
    // Reading the Email Index in Read / Write Mode
    inbox.open(Folder.READ_WRITE);

    FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
    Message messages[] = inbox.search(ft);
    // Message messages[] = inbox.getMessages();
    int count = 0;
    // Loop over all of the messages
    for (Message message : messages) {
View Full Code Here


            if (count > 0) {
                Message[] messages;

                // should we process all messages or only unseen messages
                if (getEndpoint().getConfiguration().isUnseen()) {
                    messages = folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
                } else {
                    messages = folder.getMessages();
                }

                polledMessages = processBatch(CastUtils.cast(createExchanges(messages)));
View Full Code Here

        startElement("message-number", attributes);
        characters(String.valueOf(message.getMessageNumber()));
        endElement("message-number");

        // FLAGS:
        Flags flags = message.getFlags();
        Flags.Flag[] sf = flags.getSystemFlags();
        // get the system flags

        attributes.clear();
        for (int i = 0; i < sf.length; i++) {
            Flags.Flag flag = sf[i];
            if (flag == Flags.Flag.ANSWERED) {
                addAttribute("answered", "yes");
            } else if (flag == Flags.Flag.DELETED) {
                addAttribute("deleted", "yes");
            } else if (flag == Flags.Flag.DRAFT) {
                addAttribute("draft", "yes");
            } else if (flag == Flags.Flag.FLAGGED) {
                addAttribute("flagged", "yes");
            } else if (flag == Flags.Flag.RECENT) {
                addAttribute("recent", "yes");
            } else if (flag == Flags.Flag.SEEN) {
                addAttribute("seen", "yes");
            }
        }
        startElement("flags", attributes);
        endElement("flags");

        String[] uf = flags.getUserFlags();
        // get the user flag strings
        for (int i = 0; i < uf.length; i++) {
            attributes.clear();
            startElement("user-flags", attributes);
            characters(uf[i]);
View Full Code Here

            if (count > 0) {
                Message[] messages;

                // should we process all messages or only unseen messages
                if (endpoint.getConfiguration().isProcessOnlyUnseenMessages()) {
                    messages = folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
                } else {
                    messages = folder.getMessages();
                }

                processMessages(messages);
View Full Code Here

            final List<GmailMessage> unread = new ArrayList<GmailMessage>();
            final Store store = openGmailStore();
            final Folder folder = getFolder(this.srcFolder,store);
            folder.open(Folder.READ_ONLY);
            for (final Message msg : folder.search(new FlagTerm(
                    new Flags(Flags.Flag.SEEN), false))) {
                unread.add(new JavaMailGmailMessage(msg));
            }
            return unread;
        } catch (final Exception e) {
            throw new GmailException("Failed getting unread messages", e);
View Full Code Here

        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"
                    + " all GmailMessage as read" , e);
View Full Code Here

            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;
        } catch (final Exception e) {
View Full Code Here

     * org.apache.james.imap.decode.ImapRequestLineReader, java.lang.String,
     * org.apache.james.imap.api.process.ImapSession)
     */
    protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, ImapSession session) throws DecodingException {
        String mailboxName = request.mailbox();
        Flags flags = optionalAppendFlags(request);
        if (flags == null) {
            flags = new Flags();
        }
        Date datetime = optionalDateTime(request);
        if (datetime == null) {
            datetime = new Date();
        }
View Full Code Here

        ImapCommand imapCommand = command;
       
        try {
            final MessageManager mailbox = getSelectedMailbox(session);
            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
            final Flags flags = request.getFlags();
           
            if (unchangedSince != -1) {
              MetaData metaData = mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT);
                if (metaData.isModSeqPermanent() == false) {
                    // Check if the mailbox did not support modsequences. If so return a tagged bad response.
                    // See RFC4551 3.1.2. NOMODSEQ Response Code
                    taggedBad(command, tag, responder, HumanReadableText.NO_MOD_SEQ);
                    return;
                } else if (unchangedSince == 0){
                    Flags.Flag[] systemFlags = flags.getSystemFlags();
                    if (systemFlags != null && systemFlags.length != 0) {
                        // we need to return all sequences as failed when using a UNCHANGEDSINCE 0 and the request specify a SYSTEM flags
                        //
                        // See RFC4551 3.2. STORE and UID STORE Command;
                        //
                        //       Use of UNCHANGEDSINCE with a modification sequence of 0 always
                        //       fails if the metadata item exists.  A system flag MUST always be
                        //       considered existent, whether it was set or not.
                        final StatusResponse response = getStatusResponseFactory().taggedOk(tag, command, HumanReadableText.FAILED, ResponseCode.condStore(idSet));
                        responder.respond(response);
                        return;
                    }
                }
             
            }
            final List<Long> failed = new ArrayList<Long>();
            final List<String> userFlags = Arrays.asList(flags.getUserFlags());
            for (int i = 0; i < idSet.length; i++) {
                final SelectedMailbox selected = session.getSelected();
                MessageRange messageSet = messageRange(selected, idSet[i], useUids);
                if (messageSet != null) {
                   
View Full Code Here

     * @param responder
     * @throws MailboxException
     */
    private void setFlags(StoreRequest request, MailboxSession mailboxSession, MessageManager mailbox, MessageRange messageSet, ImapSession session, String tag, ImapCommand command, Responder responder) throws MailboxException {
       
        final Flags flags = request.getFlags();
        final boolean useUids = request.isUseUids();
        final boolean silent = request.isSilent();
        final boolean isSignedPlus = request.isSignedPlus();
        final boolean isSignedMinus = request.isSignedMinus();
        final long unchangedSince = request.getUnchangedSince();
        final boolean replace;
        final boolean value;
        if (isSignedMinus) {
            value = false;
            replace = false;
        } else if (isSignedPlus) {
            value = true;
            replace = false;
        } else {
            replace = true;
            value = true;
        }
       
        SelectedMailbox selected = session.getSelected();
        final Map<Long, Flags> flagsByUid = mailbox.setFlags(flags, value, replace, messageSet, mailboxSession);
        // As the STORE command is allowed to create a new "flag/keyword", we need to send a FLAGS and PERMANENTFLAGS response before the FETCH response
        // if some new flag/keyword was used
        // See IMAP-303
        if (selected.hasNewApplicableFlags()) {
            flags(responder, selected);
            permanentFlags(responder, mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT), selected);
            selected.resetNewApplicableFlags();
        }
       
        Set<String> enabled = EnableProcessor.getEnabledCapabilities(session);
        boolean qresyncEnabled = enabled.contains(ImapConstants.SUPPORTS_QRESYNC);
        boolean condstoreEnabled = enabled.contains(ImapConstants.SUPPORTS_CONDSTORE);
       
        if (!silent || unchangedSince != -1 || qresyncEnabled || condstoreEnabled) {
            final Map<Long, Long> modSeqs = new HashMap<Long, Long>();
          
            // Check if we need to also send the the mod-sequences back to the client
            //
            // This is the case if one of these is true:
            //      - UNCHANGEDSINCE was used
            //      - CONDSTORE was enabled via ENABLE CONDSTORE
            //      - QRESYNC was enabled via ENABLE QRESYNC
            //
            if (unchangedSince != -1 || qresyncEnabled || condstoreEnabled) {
                MessageResultIterator results = mailbox.getMessages(messageSet, FetchGroupImpl.MINIMAL, mailboxSession);
                while(results.hasNext()) {
                    MessageResult r = results.next();
                    // Store the modseq for the uid for later usage in the response
                    modSeqs.put(r.getUid(),r.getModSeq());
                }
            }
           
            for (Map.Entry<Long, Flags> entry : flagsByUid.entrySet()) {
                final long uid = entry.getKey();
                final int msn = selected.msn(uid);

                if (msn == SelectedMailbox.NO_SUCH_MESSAGE) {
                    if(session.getLog().isDebugEnabled()) {
                        session.getLog().debug("No message found with uid " + uid + " in the uid<->msn mapping for mailbox " + selected.getPath().getFullName(mailboxSession.getPathDelimiter()) +" , this may be because it was deleted by a concurrent session. So skip it..");
                       
                    }
                    // skip this as it was not found in the mapping
                    //
                    // See IMAP-346
                    continue;
                }

                final Flags resultFlags = entry.getValue();
                final Long resultUid;
               
                // Check if we need to include the uid. T
                //
                // This is the case if one of these is true:
                //      - FETCH (UID...)  was used
                //      - QRESYNC was enabled via ENABLE QRESYNC
                if (useUids || qresyncEnabled) {
                    resultUid = uid;
                } else {
                    resultUid = null;
                }

                if (selected.isRecent(uid)) {
                    resultFlags.add(Flags.Flag.RECENT);
                }
              
                final FetchResponse response;
                // For more informations related to the FETCH response see
                //
View Full Code Here

TOP

Related Classes of javax.mail.Flags$Flag

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.