Java 类javax.mail.Flags 实例源码

项目:oscm    文件:MailReader.java   
/**
 * Connect to the mail server and delete all mails.
 */
public void deleteMails() throws MessagingException {
    Folder folder = getStore().getFolder(MAIL_INBOX);
    folder.open(Folder.READ_WRITE);

    // Get folder's list of messages.
    Message[] messages = folder.getMessages();

    // Retrieve message headers for each message in folder.
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.ENVELOPE);
    folder.fetch(messages, profile);

    for (Message message : messages) {
        message.setFlag(Flags.Flag.DELETED, true);
    }
    folder.close(true);

}
项目:openbd-core    文件:cfImapConnection.java   
public void changeStatus( String folderName, long mailIDs[], Flags.Flag newFlag, boolean value ){
  try{

    Folder folderToUse = mailStore.getFolder(folderName);
    folderToUse.open( Folder.READ_WRITE );

    Flags f = new Flags();
    f.add( newFlag );

    Message mlist[];
    if ( folderToUse instanceof UIDFolder )
        mlist = ((UIDFolder)folderToUse).getMessagesByUID( mailIDs );
    else
        mlist = folderToUse.getMessages( returnToInts(mailIDs) );

    for ( int x=0; x < mlist.length; x++ )
        mlist[x].setFlags( f, value );

    folderToUse.close( true );
    setData( "succeeded",   cfBooleanData.TRUE );

  } catch (Exception E ){
    setData( "errortext",   new cfStringData( E.getMessage() ) );
    setData( "succeeded",   cfBooleanData.FALSE );
  }
}
项目:alfresco-repository    文件:AlfrescoImapFolder.java   
/**
 *  Creates the EML message in the specified folder.
 *  
 *  @param folderFileInfo The folder to create message in.
 *  @param message The original MimeMessage.
 *  @return ID of the new message created 
 * @throws FileNotFoundException 
 * @throws FileExistsException 
 * @throws MessagingException 
 * @throws IOException 
 */
private long createMimeMessageInFolder(
        FileInfo folderFileInfo,
        MimeMessage message,
        Flags flags)
        throws FileExistsException, FileNotFoundException, IOException, MessagingException 
{
    String name = AlfrescoImapConst.MESSAGE_PREFIX + GUID.generate();
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    FileInfo messageFile = fileFolderService.create(folderFileInfo.getNodeRef(), name, ContentModel.TYPE_CONTENT);
    final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);
    name = AlfrescoImapConst.MESSAGE_PREFIX  + newMessageUid + AlfrescoImapConst.EML_EXTENSION;
    fileFolderService.rename(messageFile.getNodeRef(), name);
    Flags newFlags = new Flags(flags);
    newFlags.add(Flag.RECENT);
    imapService.setFlags(messageFile, newFlags, true);

    if (extractAttachmentsEnabled)
    {
        imapService.extractAttachments(messageFile.getNodeRef(), message);
    }
    // Force persistence of the message to the repository
    new IncomingImapMessage(messageFile, serviceRegistry, message);
    return newMessageUid;        
}
项目:alfresco-repository    文件:ImapServiceImpl.java   
/**
 * Return flags that belong to the specified imap folder.
 * 
 * @param messageInfo imap folder info.
 * @return flags.
 */
public Flags getFlags(FileInfo messageInfo)
{
    Flags flags = new Flags();
    Map<QName, Serializable> props = nodeService.getProperties(messageInfo.getNodeRef());

    for (QName key : qNameToFlag.keySet())
    {
        Boolean value = (Boolean) props.get(key);
        if (value != null && value)
        {
            flags.add(qNameToFlag.get(key));
        }
    }

    return flags;
}
项目:alfresco-repository    文件:AlfrescoImapFolder.java   
/**
 * Replaces flags for the message with the given UID. If {@code addUid} is set to {@code true}
 * {@link FolderListener} objects defined for this folder will be notified.
 * {@code silentListener} can be provided - this listener wouldn't be notified.
 * 
 * @param flags - new flags.
 * @param uid - message UID.
 * @param silentListener - listener that shouldn't be notified.
 * @param addUid - defines whether or not listeners be notified.
 * @throws FolderException 
 * @throws MessagingException 
 */
@Override
protected void replaceFlagsInternal(
        Flags flags,
        long uid,
        FolderListener silentListener,
        boolean addUid)
        throws FolderException, MessagingException 
{
    int msn = getMsn(uid);
    FileInfo fileInfo = searchMails().get(uid);
    imapService.setFlags(fileInfo, MessageFlags.ALL_FLAGS, false);
    imapService.setFlags(fileInfo, flags, true);

    Long uidNotification = addUid ? uid : null;
    notifyFlagUpdate(msn, flags, uidNotification, silentListener);
}
项目:alfresco-greenmail    文件:RsetCommand.java   
public void execute(Pop3Connection conn, Pop3State state, String cmd) {
    conn.println("+OK");
    try {
        MailFolder inbox = state.getFolder();
        List msgList = inbox.getMessages();
        int count = 0;
        for(int i=0;i<msgList.size();i++) {
            SimpleStoredMessage msg = (SimpleStoredMessage) msgList.get(i);
            Flags flags = msg.getFlags();
            if (flags.contains(Flags.Flag.DELETED)) {
                count++;
                flags.remove(Flags.Flag.DELETED);
            }
        }

        conn.println("+OK maildrop has "+count+" messages undeleted.");
    } catch (Exception e) {
        conn.println("-ERR " + e);
    }
}
项目:alfresco-greenmail    文件:InMemoryStore.java   
public long appendMessage(MimeMessage message,
                                  Flags flags,
                                  Date internalDate) {
            long uid = nextUid;
            nextUid++;

//            flags.setRecent(true);
            SimpleStoredMessage storedMessage = new SimpleStoredMessage(message, flags,
                    internalDate, uid);
            storedMessage.getFlags().add(Flags.Flag.RECENT);

            mailMessages.add(storedMessage);
            int newMsn = mailMessages.size();

            // Notify all the listeners of the new message
            synchronized (_mailboxListeners) {
                for (int j = 0; j < _mailboxListeners.size(); j++) {
                    FolderListener listener = (FolderListener) _mailboxListeners.get(j);
                    listener.added(newMsn);
                }
            }

            return uid;
        }
项目:product-ei    文件:GreenMailServer.java   
/**
 * Delete all emails in the inbox.
 *
 * @param protocol protocol used to connect to the server
 * @throws MessagingException if we're unable to connect to the store
 */
public static void deleteAllEmails(String protocol, GreenMailUser user) throws MessagingException {
    Folder inbox = null;
    Store store = getConnection(user, protocol);
    try {
        inbox = store.getFolder(EMAIL_INBOX);
        inbox.open(Folder.READ_WRITE);
        Message[] messages = inbox.getMessages();

        for (Message message : messages) {
            message.setFlag(Flags.Flag.DELETED, true);
            log.info("Deleted email Subject : " + message.getSubject());
        }
    } finally {
        if (inbox != null) {
            inbox.close(true);
        }
        if (store != null) {
            store.close();
        }
    }
}
项目:Unicorn    文件:EmailUtilTest.java   
@Test
public void testSendingAndReceiving() throws MessagingException {
    Session session = EmailUtils.getGMailSession(EmailUtils.user, EmailUtils.pass);
    String key = (new Long(System.currentTimeMillis())).toString();
    EmailUtils.postMail(session, EmailUtils.user, "test" + key, "testmsg" + key);
    Folder inbox = EmailUtils.openPop3InboxReadWrite(session);
    Folder trash = EmailUtils.openPop3TrashReadWrite(session);
    boolean emailReceived = false;
    for (Message m : inbox.getMessages()) {
        if (m.getSubject().startsWith("test" + key)) {
            emailReceived = true;
            Message[] m_array = inbox.getMessages(m.getMessageNumber(), m.getMessageNumber());
            // delete test mail
            inbox.copyMessages(m_array, trash);
            m.setFlag(Flags.Flag.DELETED, true);
        }
    }
    EmailUtils.closeFolder(inbox);
    EmailUtils.closeFolder(trash);
    assertTrue(emailReceived);
}
项目:Camel    文件:MailDoNotDeleteIfProcessFailsTest.java   
private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();

    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("imap");
    store.connect("localhost", 25, "claus", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();

    // inserts two new messages
    Message[] msg = new Message[2];
    msg[0] = new MimeMessage(sender.getSession());
    msg[0].setText("Message 1");
    msg[0].setHeader("Message-ID", "0");
    msg[0].setFlag(Flags.Flag.SEEN, false);
    msg[1] = new MimeMessage(sender.getSession());
    msg[1].setText("Message 2");
    msg[0].setHeader("Message-ID", "1");
    msg[1].setFlag(Flags.Flag.SEEN, true);
    folder.appendMessages(msg);
    folder.close(true);
}
项目:Camel    文件:MailProcessOnlyUnseenMessagesTest.java   
private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("imap");
    store.connect("localhost", 25, "claus", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();

    // inserts two messages with the SEEN flag
    Message[] msg = new Message[2];
    msg[0] = new MimeMessage(sender.getSession());
    msg[0].setText("Message 1");
    msg[0].setHeader("Message-ID", "0");
    msg[0].setFlag(Flags.Flag.SEEN, true);
    msg[1] = new MimeMessage(sender.getSession());
    msg[1].setText("Message 2");
    msg[0].setHeader("Message-ID", "1");
    msg[1].setFlag(Flags.Flag.SEEN, true);
    folder.appendMessages(msg);
    folder.close(true);
}
项目:Ardulink-1    文件:MailListener.java   
private static void clear(Folder folder) throws MessagingException {
    if(folder.exists() && (folder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
        int totMessages = folder.getMessageCount();
        System.out.println(totMessages + " messages from folder: " + folder.getFullName());
        folder.open(Folder.READ_WRITE);
        Message[] messages = folder.getMessages();
        for (int i = 0; i < messages.length; i++) {
            System.out.println("Deleting message: " + (i+1) + " of " + totMessages);
            messages[i].setFlag(Flags.Flag.DELETED, true);
        }
        folder.close(true);
    }
    Folder[] childs = folder.list();
    for (int i = 0; i < childs.length; i++) {
        clear(childs[i]);
    }
}
项目:omr    文件:MailClient.java   
public void checkInbox(int mode) throws MessagingException, IOException {
    if (mode == 0) {
        return;
    }
    boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
    boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
    String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
    System.out.println(action + " INBOX for " + from);
    Store store = session.getStore();
    store.connect();
    Folder root = store.getDefaultFolder();
    Folder inbox = root.getFolder("inbox");
    inbox.open(Folder.READ_WRITE);
    Message[] msgs = inbox.getMessages();
    if (msgs.length == 0 && show) {
        System.out.println("No messages in inbox");
    }
    for (Message msg2 : msgs) {
        MimeMessage msg = (MimeMessage) msg2;
        if (show) {
            System.out.println("    From: " + msg.getFrom()[0]);
            System.out.println(" Subject: " + msg.getSubject());
            System.out.println(" Content: " + msg.getContent());
        }
        if (clear) {
            msg.setFlag(Flags.Flag.DELETED, true);
        }
    }
    inbox.close(true);
    store.close();
    System.out.println();
}
项目:omr    文件:MailClient.java   
public void checkInbox(int mode) throws MessagingException, IOException {
    if (mode == 0) {
        return;
    }
    boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
    boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
    String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
    System.out.println(action + " INBOX for " + from);
    Store store = session.getStore();
    store.connect();
    Folder root = store.getDefaultFolder();
    Folder inbox = root.getFolder("inbox");
    inbox.open(Folder.READ_WRITE);
    Message[] msgs = inbox.getMessages();
    if (msgs.length == 0 && show) {
        System.out.println("No messages in inbox");
    }
    for (Message msg2 : msgs) {
        MimeMessage msg = (MimeMessage) msg2;
        if (show) {
            System.out.println("    From: " + msg.getFrom()[0]);
            System.out.println(" Subject: " + msg.getSubject());
            System.out.println(" Content: " + msg.getContent());
        }
        if (clear) {
            msg.setFlag(Flags.Flag.DELETED, true);
        }
    }
    inbox.close(true);
    store.close();
    System.out.println();
}
项目:omr    文件:MailClient.java   
public void checkInbox(int mode) throws MessagingException, IOException {
    if (mode == 0) {
        return;
    }
    boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
    boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
    String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
    System.out.println(action + " INBOX for " + from);
    Store store = session.getStore();
    store.connect();
    Folder root = store.getDefaultFolder();
    Folder inbox = root.getFolder("inbox");
    inbox.open(Folder.READ_WRITE);
    Message[] msgs = inbox.getMessages();
    if (msgs.length == 0 && show) {
        System.out.println("No messages in inbox");
    }
    for (Message msg2 : msgs) {
        MimeMessage msg = (MimeMessage) msg2;
        if (show) {
            System.out.println("    From: " + msg.getFrom()[0]);
            System.out.println(" Subject: " + msg.getSubject());
            System.out.println(" Content: " + msg.getContent());
        }
        if (clear) {
            msg.setFlag(Flags.Flag.DELETED, true);
        }
    }
    inbox.close(true);
    store.close();
    System.out.println();
}
项目:omr    文件:MailClient.java   
public void checkInbox(int mode) throws MessagingException, IOException {
    if (mode == 0) {
        return;
    }
    boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
    boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
    String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
    System.out.println(action + " INBOX for " + from);
    Store store = session.getStore();
    store.connect();
    Folder root = store.getDefaultFolder();
    Folder inbox = root.getFolder("inbox");
    inbox.open(Folder.READ_WRITE);
    Message[] msgs = inbox.getMessages();
    if (msgs.length == 0 && show) {
        System.out.println("No messages in inbox");
    }
    for (Message msg2 : msgs) {
        MimeMessage msg = (MimeMessage) msg2;
        if (show) {
            System.out.println("    From: " + msg.getFrom()[0]);
            System.out.println(" Subject: " + msg.getSubject());
            System.out.println(" Content: " + msg.getContent());
        }
        if (clear) {
            msg.setFlag(Flags.Flag.DELETED, true);
        }
    }
    inbox.close(true);
    store.close();
    System.out.println();
}
项目:omr    文件:MailClient.java   
public void checkInbox(int mode) throws MessagingException, IOException {
    if (mode == 0) {
        return;
    }
    boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
    boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
    String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
    System.out.println(action + " INBOX for " + from);
    Store store = session.getStore();
    store.connect();
    Folder root = store.getDefaultFolder();
    Folder inbox = root.getFolder("inbox");
    inbox.open(Folder.READ_WRITE);
    Message[] msgs = inbox.getMessages();
    if (msgs.length == 0 && show) {
        System.out.println("No messages in inbox");
    }
    for (Message msg2 : msgs) {
        MimeMessage msg = (MimeMessage) msg2;
        if (show) {
            System.out.println("    From: " + msg.getFrom()[0]);
            System.out.println(" Subject: " + msg.getSubject());
            System.out.println(" Content: " + msg.getContent());
        }
        if (clear) {
            msg.setFlag(Flags.Flag.DELETED, true);
        }
    }
    inbox.close(true);
    store.close();
    System.out.println();
}
项目:Lucee    文件:MailClient.java   
/**
    * delete all message in ibox that match given criteria
    * @param messageNumbers
    * @param uIds
    * @throws MessagingException
 * @throws IOException 
    */
   public void deleteMails(String as[], String as1[]) throws MessagingException, IOException {
    Folder folder;
    Message amessage[];
    folder = _fldelse.getFolder("INBOX");
    folder.open(2);
    Map<String, Message> map = getMessages(null,folder, as1, as, startrow, maxrows,false);
    Iterator<String> iterator = map.keySet().iterator();
    amessage = new Message[map.size()];
    int i = 0;
    while(iterator.hasNext()) {
        amessage[i++] =  map.get(iterator.next());
    }
    try {
        folder.setFlags(amessage, new Flags(javax.mail.Flags.Flag.DELETED), true);
    }
    finally {
        folder.close(true);
    }
}
项目:community-edition-old    文件:ImapServiceImpl.java   
@Override
public void onRestoreNode(final ChildAssociationRef childAssocRef)
{
    doAsSystem(new RunAsWork<Void>()
    {
        @Override
        public Void doWork() throws Exception
        {
            NodeRef childNodeRef = childAssocRef.getChildRef();
            if (serviceRegistry.getDictionaryService().isSubClass(nodeService.getType(childNodeRef), ContentModel.TYPE_CONTENT))
            {
                setFlag(childNodeRef, Flags.Flag.DELETED, false);
                setFlag(childNodeRef, Flags.Flag.SEEN, false);
            }

            NodeRef folderRef = childAssocRef.getParentRef();
            long newId = (Long) nodeService.getProperty(childNodeRef, ContentModel.PROP_NODE_DBID);
            if (nodeService.hasAspect(folderRef, ImapModel.ASPECT_IMAP_FOLDER))
            {
                // Force generation of a new change token and updating the UIDVALIDITY 
                getUidValidityTransactionListener(folderRef).recordNewUid(newId);
            }
            return null;
        }
    });
}
项目:community-edition-old    文件:InMemoryStore.java   
public long copyMessage(long uid, MailFolder toFolder)
        throws FolderException {
    SimpleStoredMessage originalMessage = getMessage(uid);
    MimeMessage newMime = null;
    try {
        newMime = new MimeMessage(originalMessage.getMimeMessage());
    } catch (MessagingException e) {
        // TODO chain.
        throw new FolderException("Messaging exception: " + e.getMessage());
    }
    Flags newFlags = new Flags();
    newFlags.add(originalMessage.getFlags());
    Date newDate = originalMessage.getInternalDate();

    return toFolder.appendMessage(newMime, newFlags, newDate);
}
项目:javamaildir    文件:MaildirMessage.java   
public void setFlags(Flags f, boolean set)
            throws MessagingException {
        final Flags.Flag[] flags = f.getSystemFlags();
        boolean changed = false;

        for (int i = 0; i < flags.length; i++)
            changed = changed | (_setFlag(flags[i], set));

        log.debug("setFlags() changed: " + changed);

        if (!changed)
            return;

//        try {
//            updateFilename();
//        } catch (MessagingException mex) {
//            log.error(mex.toString());
//        }

        ((MaildirFolder) getFolder()).localNotifyMessageChangedListeners(MessageChangedEvent.FLAGS_CHANGED, FlagChangedEvent.getEventType(f, set), this);
    }
项目:alfresco-repository    文件:AbstractImapFolder.java   
/**
 * Appends message to the folder.
 * 
 * @param message - message.
 * @param flags - message flags.
 * @param internalDate - not used. Current date used instead.
 * @return long
 */
public long appendMessage(final MimeMessage message, final Flags flags, final Date internalDate) throws FolderException
{
    if (isReadOnly())
    {
        throw new FolderException("Can't append message - Permission denied");
    }

    CommandCallback<Long> command = new CommandCallback<Long>()
    {
        public Long command() throws Throwable
        {
            return appendMessageInternal(message, flags, internalDate);
        }
    };
    return command.runFeedback();
 }
项目:alfresco-repository    文件:AbstractImapFolder.java   
/**
 * Sets flags for the message with the given UID. If {@code addUid} is set to {@code true}
 * {@link FolderListener} objects defined for this folder will be notified.
 * {@code silentListener} can be provided - this listener wouldn't be notified.
 * 
 * @param flags - new flags.
 * @param value - flags value.
 * @param uid - message UID.
 * @param silentListener - listener that shouldn't be notified.
 * @param addUid - defines whether or not listeners be notified.
 */
public void setFlags(
        final Flags flags,
        final boolean value,
        final long uid,
        final FolderListener silentListener,
        final boolean addUid)
        throws FolderException
{
    CommandCallback<Object> command = new CommandCallback<Object>()
    {
        public Object command() throws Throwable
        {
            setFlagsInternal(flags, value, uid, silentListener, addUid);
            return null;
        }
    };
    command.runFeedback();
}
项目:alfresco-repository    文件:ImapServiceImpl.java   
public void expungeMessage(FileInfo fileInfo)
{
    Flags flags = getFlags(fileInfo);
    if (flags.contains(Flags.Flag.DELETED))
    {
        // See MNT-12259
        //fileFolderService.delete(fileInfo.getNodeRef());
        hideAndDelete(fileInfo.getNodeRef());
        messageCache.remove(fileInfo.getNodeRef());
    }
}
项目:alfresco-repository    文件:ImapServiceImpl.java   
/**
 * Set flags to the specified imapFolder.
 * 
 * @param messageInfo FileInfo of imap Folder.
 * @param flags flags to set.
 * @param value value to set.
 */
public void setFlags(FileInfo messageInfo, Flags flags, boolean value)
{
    checkForFlaggableAspect(messageInfo.getNodeRef());


    for (Flags.Flag flag : flags.getSystemFlags())
    {
        setFlag(messageInfo, flag, value);
    }
}
项目:alfresco-repository    文件:ImapServiceImpl.java   
@Override
public void onRestoreNode(final ChildAssociationRef childAssocRef)
{
    doAsSystem(new RunAsWork<Void>()
    {
        @Override
        public Void doWork() throws Exception
        {
            NodeRef childNodeRef = childAssocRef.getChildRef();
            if (serviceRegistry.getDictionaryService().isSubClass(nodeService.getType(childNodeRef), ContentModel.TYPE_CONTENT))
            {
                setFlag(childNodeRef, Flags.Flag.DELETED, false);
                setFlag(childNodeRef, Flags.Flag.SEEN, false);
            }

            NodeRef folderRef = childAssocRef.getParentRef();
            long newId = (Long) nodeService.getProperty(childNodeRef, ContentModel.PROP_NODE_DBID);
            if (nodeService.hasAspect(folderRef, ImapModel.ASPECT_IMAP_FOLDER))
            {
                // Force generation of a new change token and updating the UIDVALIDITY 
                getUidValidityTransactionListener(folderRef).recordNewUid(newId);
            }
            return null;
        }
    });
}
项目:alfresco-repository    文件:AlfrescoImapFolder.java   
/**
 * Appends message to the folder.
 * 
 * @param message - message.
 * @param flags - message flags.
 * @param internalDate - not used. Current date used instead.
 */
@Override
protected long appendMessageInternal(
        MimeMessage message,
        Flags flags,
        Date internalDate)
        throws FileExistsException, FileNotFoundException, IOException, MessagingException 
{
    long uid;
    NodeRef sourceNodeRef = extractNodeRef(message);
    if (sourceNodeRef != null)
    {
        uid = copyOrMoveNode(this.folderInfo, message, flags, sourceNodeRef, false);
    }
    else
    {
        uid = createMimeMessageInFolder(this.folderInfo, message, flags);
    }
    // Invalidate current folder status
    this.folderStatus = null;
    return uid;
}
项目:alfresco-repository    文件:AlfrescoImapFolder.java   
/**
 * Moves the node <code>sourceNodeRef</code> extracted from the message id.
 * A part of a complex move operation.
 * 
 * @param folderInfo FileInfo
 * @param message MimeMessage
 * @param flags Flags
 * @param sourceNodeRef NodeRef
 * @return UUID of the moved node
 * @throws FileExistsException
 * @throws FileNotFoundException
 */
@SuppressWarnings("deprecation")
private long copyOrMoveNode(FileInfo folderInfo, MimeMessage message, Flags flags, NodeRef sourceNodeRef, boolean move)
        throws FileExistsException, FileNotFoundException
{
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    FileFilterMode.setClient(FileFilterMode.Client.imap);
    FileInfo messageFile = null;
    if (move)
    {
        fileFolderService.setHidden(sourceNodeRef, false);
        messageFile = fileFolderService.move(sourceNodeRef, folderInfo.getNodeRef(), null);
    }
    else
    {
        NodeRef newNodeRef = serviceRegistry.getCopyService().copyAndRename(sourceNodeRef, folderInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, null, false);
        fileFolderService.setHidden(newNodeRef, false);
        messageFile = fileFolderService.getFileInfo(newNodeRef);
    }
    final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);

    imapService.persistMessageHeaders(messageFile.getNodeRef(), message);

    Flags newFlags = new Flags(flags);
    newFlags.add(Flag.RECENT);

    imapService.setFlags(messageFile, newFlags, true);
    imapService.setFlag(messageFile, Flag.DELETED, false);

    return newMessageUid;
}
项目:alfresco-repository    文件:AlfrescoImapFolder.java   
/**
 * Marks all messages in the folder as deleted using {@link javax.mail.Flags.Flag#DELETED} flag.
 */
@Override
public void deleteAllMessagesInternal() throws FolderException
{
    if (isReadOnly())
    {
        throw new FolderException("Can't delete all - Permission denied");
    }

    for (Map.Entry<Long, FileInfo> entry : searchMails().entrySet())
    {
        imapService.setFlag(entry.getValue(), Flags.Flag.DELETED, true);
        // comment out to physically remove content.
        // fileFolderService.delete(fileInfo.getNodeRef());
    }
}
项目:alfresco-repository    文件:AlfrescoImapFolder.java   
/**
 * Returns the list of messages that have no {@link javax.mail.Flags.Flag#DELETED} flag set for current user.
 * 
 * @return the list of non-deleted messages.
 */
@Override
protected List<SimpleStoredMessage> getNonDeletedMessagesInternal()
{
    if (logger.isDebugEnabled())
    {
        logger.debug("[getNonDeletedMessagesInternal] " + this);
    }
    List<SimpleStoredMessage> result = new ArrayList<SimpleStoredMessage>();

    Collection<SimpleStoredMessage> values = getMessagesInternal();
    for (SimpleStoredMessage message : values)
    {
        if (!getFlags(message).contains(Flags.Flag.DELETED))
        {
            result.add(message);
        }

    }
    if (logger.isDebugEnabled() && folderInfo != null)
    {
        logger.debug(folderInfo.getName() + " - Non deleted messages count:" + result.size());
    }
    return result;
}
项目:alfresco-repository    文件:AlfrescoImapFolder.java   
/**
 * Returns count of messages with {@link javax.mail.Flags.Flag#RECENT} flag.
 * If {@code reset} parameter is {@code true} - removes {@link javax.mail.Flags.Flag#RECENT} flag from
 * the message for current user.
 * 
 * @param reset - if true the {@link javax.mail.Flags.Flag#RECENT} will be deleted for current user if exists.
 * @return returns count of recent messages.
 */
@Override
public int getRecentCount(boolean reset)
{
    int recent = getFolderStatus().recentCount;
    if (reset && recent > 0)
    {
        CommandCallback<Void> command = new CommandCallback<Void>()
        {
            public Void command() throws Throwable
            {
                for (FileInfo fileInfo : folderStatus.search.values())
                {
                    Flags flags = imapService.getFlags(fileInfo);
                    if (flags.contains(Flags.Flag.RECENT))
                    {
                        imapService.setFlag(fileInfo, Flags.Flag.RECENT, false);
                    }
                }
                return null;
            }
        };
        try
        {
            command.run();
        }
        catch (AccessDeniedException ade)
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("Access denied to reset RECENT FLAG");
            }
        }
    }
    return recent;        
}
项目:alfresco-repository    文件:AlfrescoImapFolder.java   
/**
 * Sets flags for the message with the given UID. If {@code addUid} is set to {@code true}
 * {@link FolderListener} objects defined for this folder will be notified.
 * {@code silentListener} can be provided - this listener wouldn't be notified.
 * 
 * @param flags - new flags.
 * @param value - flags value.
 * @param uid - message UID.
 * @param silentListener - listener that shouldn't be notified.
 * @param addUid - defines whether or not listeners be notified.
 * @throws MessagingException 
 * @throws FolderException 
 */
@Override
protected void setFlagsInternal(
        Flags flags,
        boolean value,
        long uid,
        FolderListener silentListener,
        boolean addUid)
        throws MessagingException, FolderException 
{
    int msn = getMsn(uid);
    FileInfo fileInfo = searchMails().get(uid);
    imapService.setFlags(fileInfo, flags, value);

    Long uidNotification = null;
    if (addUid)
    {
        uidNotification = new Long(uid);
    }
    notifyFlagUpdate(msn, flags, uidNotification, silentListener);

}
项目:alfresco-repository    文件:ImapServiceImplTest.java   
public void testSetFlag() throws Exception
{
    NavigableMap<Long, FileInfo> fis = imapService.getFolderStatus(authenticationService.getCurrentUserName(), testImapFolderNodeRef, ImapViewMode.ARCHIVE).search;
    if (fis != null && fis.size() > 0)
    {
        FileInfo messageFileInfo = fis.firstEntry().getValue();

        reauthenticate(USER_NAME, USER_PASSWORD);

        permissionService.setPermission(testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true);

        reauthenticate(anotherUserName, anotherUserName);

        imapService.setFlag(messageFileInfo, Flags.Flag.RECENT, true);

        Serializable prop = nodeService.getProperty(messageFileInfo.getNodeRef(), ImapModel.PROP_FLAG_RECENT);
        assertNotNull("Can't set RECENT flag", prop);
    }
}
项目:alfresco-repository    文件:ImapServiceImplTest.java   
public void testGetFlags() throws Exception
{
    NavigableMap<Long, FileInfo> fis = imapService.getFolderStatus(authenticationService.getCurrentUserName(), testImapFolderNodeRef, ImapViewMode.ARCHIVE).search;
    if (fis != null && fis.size() > 0)
    {
        FileInfo messageFileInfo = fis.firstEntry().getValue();

        reauthenticate(USER_NAME, USER_PASSWORD);

        permissionService.setPermission(testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true);

        imapService.setFlags(messageFileInfo, flags, true);

        reauthenticate(anotherUserName, anotherUserName);

        Flags fl = imapService.getFlags(messageFileInfo);
        assertTrue(fl.contains(flags));
    }
}
项目:alfresco-greenmail    文件:SearchTermBuilder.java   
private static javax.mail.Flags.Flag toFlag(String pFlag) {
    if (pFlag == null || pFlag.trim().length() < 1) {
        throw new IllegalArgumentException("Can not convert empty string to mail flag");
    }
    pFlag = pFlag.trim().toUpperCase();
    if (pFlag.equals("ANSWERED")) {
        return javax.mail.Flags.Flag.ANSWERED;
    }
    if (pFlag.equals("DELETED")) {
        return javax.mail.Flags.Flag.DELETED;
    }
    if (pFlag.equals("DRAFT")) {
        return javax.mail.Flags.Flag.DRAFT;
    }
    if (pFlag.equals("FLAGGED")) {
        return javax.mail.Flags.Flag.FLAGGED;
    }
    if (pFlag.equals("RECENT")) {
        return javax.mail.Flags.Flag.RECENT;
    }
    if (pFlag.equals("SEEN")) {
        return javax.mail.Flags.Flag.SEEN;
    }
    return null;
}
项目:alfresco-greenmail    文件:RetrCommand.java   
public void execute(Pop3Connection conn, Pop3State state,
                    String cmd) {
    try {
        MailFolder inbox = state.getFolder();
        String[] cmdLine = cmd.split(" ");

        String msgNumStr = cmdLine[1];
        List msgList = inbox.getMessages(new MsgRangeFilter(msgNumStr, false));
        if (msgList.size() != 1) {
            conn.println("-ERR no such message");

            return;
        }

        SimpleStoredMessage msg = (SimpleStoredMessage) msgList.get(0);
        String email = GreenMailUtil.getWholeMessage(msg.getMimeMessage());
        conn.println("+OK");
        conn.print(new StringReader(email));
        conn.println();
        conn.println(".");
        msg.getFlags().add(Flags.Flag.SEEN);
    } catch (Exception e) {
        conn.println("-ERR " + e);
    }
}
项目:alfresco-greenmail    文件:InMemoryStore.java   
public void setFlags(Flags flags, boolean value, long uid, FolderListener silentListener, boolean addUid) throws FolderException {
    int msn = getMsn(uid);
    SimpleStoredMessage message = (SimpleStoredMessage) mailMessages.get(msn - 1);

    if (value) {
        message.getFlags().add(flags);
    } else {
        message.getFlags().remove(flags);
    }

    Long uidNotification = null;
    if (addUid) {
        uidNotification = new Long(uid);
    }
    notifyFlagUpdate(msn, message.getFlags(), uidNotification, silentListener);
}
项目:alfresco-greenmail    文件:MessageFlags.java   
/**
 * Returns IMAP formatted String of MessageFlags for named user
 */
public static String format(Flags flags) {
    StringBuffer buf = new StringBuffer();
    buf.append("(");
    if (flags.contains(Flags.Flag.ANSWERED)) {
        buf.append("\\Answered ");
    }
    if (flags.contains(Flags.Flag.DELETED)) {
        buf.append("\\Deleted ");
    }
    if (flags.contains(Flags.Flag.DRAFT)) {
        buf.append("\\Draft ");
    }
    if (flags.contains(Flags.Flag.FLAGGED)) {
        buf.append("\\Flagged ");
    }
    if (flags.contains(Flags.Flag.RECENT)) {
        buf.append("\\Recent ");
    }
    if (flags.contains(Flags.Flag.SEEN)) {
        buf.append("\\Seen ");
    }
    // Remove the trailing space, if necessary.
    if (buf.length() > 1) {
        buf.setLength(buf.length() - 1);
    }
    buf.append(")");
    return buf.toString();
}
项目:ats-framework    文件:ImapFolder.java   
/**
 * Cleans up the associated IMAP folder
 * @throws RbvStorageException
 */
@PublicAtsApi
public void expunge() throws RbvStorageException {

    //first check if the folder is open
    if (!isOpen) {
        throw new MatchableNotOpenException(getDescription() + " is not open");
    }

    try {
        folder.setFlags(folder.getMessages(), new Flags(Flags.Flag.DELETED), true);
        folder.expunge();
    } catch (MessagingException me) {
        throw new RbvStorageException(me);
    }

    log.info("Expunged " + getDescription());
}
项目:jsf-core    文件:ReciveMail.java   
/**  
 * 【判断此邮件是否已读,如果未读返回返回false,反之返回true】  
 */  
public boolean isNew() throws MessagingException {   
    boolean isnew = false;   
    Flags flags = ((Message) mimeMessage).getFlags();   
    Flags.Flag[] flag = flags.getSystemFlags();   
    logger.info("flags's length: " + flag.length);   
    for (int i = 0; i < flag.length; i++) {   
        if (flag[i] == Flags.Flag.SEEN) {   
            isnew = true;   
            logger.info("seen Message.......");   
            break;   
        }   
    }   
    return isnew;   
}